﻿//Custom window opening routine, for opening a screen-centred window of a given width and height at a given URL.  This window is barebones/no-frills.
function contentPopup( w, h, url ) {

    //get monitor resolution
        var sw = screen.width;
        var sh = screen.height;

    //define coordinates to open at
        var leftpos = (sw / 2) - (w / 2);
        var toppos = (sh / 2) - (h / 2);

    //Open the window:
    //Note: IE7 produces an error at "moveTo()" - therefore revised implementation is to specify "left=" and "top=" in the window.open() args below:-
    window.open( url, 'CFRSContentPopupWindow', 'width='+w+',height='+h+'status=no,toolbar=no,menubar=no,resizable=yes,location=no,scrollbars=yes,left='+leftpos+',top='+toppos ); //some browsers are set to not let JavaScipt dictate the appearance of screen elements like the status bar - consider this when allocating sizing for the media file/window!

    return false;
} 



	 

function showTab(index)

{

    var tabs =  document.all("tabs") ;

    var as = tabs.getElementsByTagName("a") ;

    for(var i=0;i<as.length;i++)

    {

        if (i == index)

        {

            as[i].className = "active-tab" ;

            document.all("panel" + i).style.display = "" ;

        }

        else

        {

            as[i].className = "" ;

            document.all("panel" + i).style.display = "none" ;

        }

    }

}





/*

本Js代码用于创建一个自定义的确认窗口,

具体功能包括:自定义窗口标题,自定义窗口内容,是否显示取消按钮,焦点位置设定



Author:Jedliu

Blog :Jedliu.cublog.cn 

【网页转载请保留版权信息,实际使用时可以除去该信息】

*/

function get_width(){

   return (document.body.clientWidth+document.body.scrollLeft);

}

function get_height(){

   return (document.body.clientHeight+document.body.scrollTop);

}

function get_left(w){

   var bw=document.body.clientWidth;

   var bh=document.body.clientHeight;

   w=parseFloat(w);

   return (bw/2-w/2+document.body.scrollLeft);

}

function get_top(h){

   var bw=document.body.clientWidth;

   var bh=document.body.clientHeight;

   h=parseFloat(h);

   return (bh/2-h/2+document.body.scrollTop);

}

function create_mask(){//创建遮罩层的函数

   var mask=document.createElement("div");

   mask.id="mask";

   mask.style.position="absolute";

   mask.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=4,opacity=75)";//IE的不透明设置

   mask.style.opacity=0.4;//Mozilla的不透明设置

   mask.style.background="black";

   mask.style.top="0px";

   mask.style.left="0px";

   mask.style.width=get_width();

   mask.style.height=get_height();

   mask.style.zIndex=1000;

   document.body.appendChild(mask);

}

function create_msgbox(w,h,t){//创建弹出对话框的函数

   var box=document.createElement("div") ;

   box.id="msgbox";

   box.style.position="absolute";

   box.style.width=w;

   box.style.height=h;

   box.style.overflow="visible";

   box.innerHTML=t;

   box.style.zIndex=1001;

   document.body.appendChild(box);

   re_pos();

  

}

function re_mask(){

   /*

   更改遮罩层的大小,确保在滚动以及窗口大小改变时还可以覆盖所有的内容

   */

   var mask=document.getElementById("mask") ;

   if(null==mask)return;

   mask.style.width=get_width()+"px";

   mask.style.height=get_height()+"px";

}

function re_pos(){

   /*

   更改弹出对话框层的位置,确保在滚动以及窗口大小改变时一直保持在网页的最中间

   */
   var offsetHor = 0, offsetVer = 0;
   var box=document.getElementById("msgbox");

   if(null!=box){

    var w=box.style.width;

    var h=box.style.height;


	/*window.alert( 'Width = ' + alertWidth() );	
	window.alert( 'Height = ' + alertHeight() );		
    box.style.left=get_left(w)+"px";

    box.style.top=get_top(h)+"px";
	*/
	offsetHor = (alertWidth() - 732)/2;
	offsetVer = (alertHeight() - 576)/2;

	box.style.left = offsetHor + "px";
	box.style.top = offsetVer + "px";
   }

}

function remove(){

   /*

   清除遮罩层以及弹出的对话框

   */

 

   var mask=document.getElementById("mask");

   var msgbox=document.getElementById("msgbox");

   if(null==mask&&null==msgbox)return;

   

   msgbox.innerHTML = "" ;

   document.body.removeChild(mask);

   document.body.removeChild(msgbox);

}

function msgbox(title,text,func,cancel,focus){

   /*  

   参数列表说明:

   title :弹出对话框的标题,标题内容最好在25个字符内,否则会导致显示图片的异常               

   text :弹出对话框的内容,可以使用HTML代码,例如<font color='red'>删除么?</font>,如果直接带入函数,注意转义

   func :弹出对话框点击确认后执行的函数,需要写全函数的引用,例如add(),如果直接带入函数,注意转义。

   cancel:弹出对话框是否显示取消按钮,为空的话不显示,为1时显示

   focus :弹出对话框焦点的位置,0焦点在确认按钮上,1在取消按钮上,为空时默认在确认按钮上

  

   Author:Jedliu

   Blog :Jedliu.cublog.cn 

   【网页转载请保留版权信息,实际使用时可以除去该信息】

   */

   create_mask();

   var temp="<table width=\"355\" height=\"127\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"font:14px Verdana, Geneva, Arial, Helvetica, sans-serif\">";

   temp+="<tr><td background=\"msgbox/alert_01.gif\" width=\"355\" height=\"22\" style=\"padding-left:8px;padding-top:2px;font-weight: bold;color:white;\">"+title+"</td></tr>";

   temp+="<tr><td background=\"msgbox/alert_02.gif\" width=\"355\" height=\"75\" style=\"padding-left:6px;padding-right:2px;padding-bottom:10px;\">&nbsp;<img src=\"msgbox/alert_mark.gif\">&nbsp;"+text+"</td>";

   temp+="</tr><tr><td width=\"355\" height=\"22\" align=\"center\" background=\"msgbox/alert_03.gif\"><input name=\"msgconfirmb\" type=\"button\" id=\"msgconfirmb\" value=\"确认\" onclick=\"remove();"+func+";\">";

   if(null!=cancel){temp+="&nbsp;&nbsp;<input name=\"msgcancelb\" type=\"button\" id=\"msgcancelb\" value=\"取消\" onclick=\"remove();\"></td>";}

   temp+="</tr><tr><td background=\"msgbox/alert_04.gif\" width=\"355\" height=\"8\"></td></tr></table>";

   create_msgbox(400,200,temp);

   if(focus==0||focus=="0"||null==focus){document.getElementById("msgconfirmb").focus();}

   else if(focus==1||focus=="1"){document.getElementById("msgcancelb").focus();}  

}



function play(title,file){
   /*  
   参数列表说明:
   title :弹出对话框的标题,标题内容最好在25个字符内,否则会导致显示图片的异常               
   text :弹出对话框的内容,可以使用HTML代码,例如<font color='red'>删除么?</font>,如果直接带入函数,注意转义
   func :弹出对话框点击确认后执行的函数,需要写全函数的引用,例如add(),如果直接带入函数,注意转义。
   cancel:弹出对话框是否显示取消按钮,为空的话不显示,为1时显示
   focus :弹出对话框焦点的位置,0焦点在确认按钮上,1在取消按钮上,为空时默认在确认按钮上
  
   Author:Jedliu
   Blog :Jedliu.cublog.cn 
   【网页转载请保留版权信息,实际使用时可以除去该信息】
   */
   create_mask();
   var s = "" ;
   s += "<div class='play' onKeyDown='var code = window.event.keyCode ; if(code==27){remove();}'>" ;
   s += "<div class='playBar'><div class='playTitle'>" + title + "</div><div class='playClose' onclick='remove();'>Close</div></div>" ;
   s += "<object  classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width='732' height='576'>" ;
   s += " <param name=movie value='" +file  + "' />" ;
   s += "<param name=quality value='high' />" ;
   s += "<param name='wmode' value='transparent' />" ;
   s += "<embed src='" + file  + "' quality='high' wmode='transparent' width='732' height='576' type='application/x-shockwave-flash'" ;
   s += "pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' /> " ;        
   s += "</object>" ;    
   s += "</div>" ;
   create_msgbox(733,600,s);
 
}

function re_show(){

   /*

   重新显示遮罩层以及弹出窗口元素

   */

   re_pos();

   re_mask(); 

}

function load_func(){

   /*

   加载函数,覆盖window的onresize和onscroll函数

   */

   window.onresize=re_show;

   window.onscroll=re_show; 

}



function clip(id,evHandle)

{

  var input = document.getElementById(id) ;

  input.select();

  evHandle.className = "copied";

  evHandle.innerHTML = "copied" ;

  clipText(input.value);

}

function clipText(meintext)

{



  if (window.clipboardData) 

  {

  

  // the IE-manier

  window.clipboardData.setData("Text", meintext);

  

  // waarschijnlijk niet de beste manier om Moz/NS te detecteren;

  // het is mij echter onbekend vanaf welke versie dit precies werkt:

  }

  else if (window.netscape) 

  { 

  

  // dit is belangrijk maar staat nergens duidelijk vermeld:

  // you have to sign the code to enable this, or see notes below 

  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

  

  // maak een interface naar het clipboard

  var clip = Components.classes['@mozilla.org/widget/clipboard;1']

  .createInstance(Components.interfaces.nsIClipboard);

  if (!clip) return;

  

  // maak een transferable

  var trans = Components.classes['@mozilla.org/widget/transferable;1']

  .createInstance(Components.interfaces.nsITransferable);

  if (!trans) return;

  

  // specificeer wat voor soort data we op willen halen; text in dit geval

  trans.addDataFlavor('text/unicode');

  

  // om de data uit de transferable te halen hebben we 2 nieuwe objecten 

  // nodig om het in op te slaan

  var str = new Object();

  var len = new Object();

  

  var str = Components.classes["@mozilla.org/supports-string;1"]

  .createInstance(Components.interfaces.nsISupportsString);

  

  var copytext=meintext;

  

  str.data=copytext;

  

  trans.setTransferData("text/unicode",str,copytext.length*2);

  

  var clipid=Components.interfaces.nsIClipboard;

  

  if (!clip) return false;

  

  clip.setData(trans,null,clipid.kGlobalClipboard);

  

  }



  return false;

  }
  
  
  function alertWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function alertHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && (document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && (document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}



function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
	

    //determine the direction for the blending, if start and end are the same nothing happens
	timer=0;
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 



function getCoordinates(element)
{
	var curleft = curtop = 0;
	var obj = element;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return {
			left:	curleft,
			top:	curtop,
			width:	element.width,
			height:	element.height
		};
	
}

function fadeIn(element, duration)
{
	element.style.opacity = 0.0;
	var effect = new Fx.Styles(element, {duration: duration});
	effect.start({ 'opacity': [0.0, 1.0] });
	element.style.visible = 'visible';
	return effect;
}

// Loads an image and calls the callback when it's done
function preloadImage(image, callback)
{
	var preload    = new Image;
	preload.onload = function() { callback(preload) };
	preload.src    = image;
	return preload;
}

function preloadStop(preload)
{
	preload.onload = null;
	preload.src    = '';
}

function showLargeBlogImage(src, fade, element, full)
{

	// Don't allow the user to click to enlarge the image again
	element.onclick = null;

	var coordinates = getCoordinates(element);
	var image = document.createElement("img");
	
	var parentCoordinates = getCoordinates(element.parentNode);
	
	image.className         = "zoomloading";
	image.style.position 	= "absolute";
	image.style.top 		= (coordinates.top - parentCoordinates.top) + "px";
	image.style.left		= (coordinates.left - parentCoordinates.left) + "px";
	image.style.width       = coordinates.width+"px";
	image.style.height      = coordinates.height+"px";
	image.style.zIndex 		= "1";
	image.style.cursor		= 'wait';
	image.onclick           = null;
	
	var effect = null;
	
	var showLoading = function(preload)
		{
			image.src = preload.src;
			image.style.visibility   = "hidden";
			element.parentNode.appendChild(image);
			effect = fadeIn(image, 300);
		};
	
	// Set the image for the loading element to be an invisible GIF since otherwise the image
	// displays a "file not found" icon. We need to preload the image as well, since if it's not
	// loaded when we set the src we also get the file not found icon.
	var loadingPreload = preloadImage("plugins/invisible.gif", showLoading);
	
	var zoom = function(preload)
		{
		
			if (effect) {
				effect.stop();
			}
			preloadStop(loadingPreload);
			
			image.style.visible = 'hidden';
			image.style.top = coordinates.top + "px";
			image.style.left = coordinates.left + "px";
			document.body.appendChild(image);
			
			var duration = 500;
			var start_opacity = fade ? 0 : 1;
			
			image.style.opacity = start_opacity;
			image.style.cursor 	= "pointer";
			image.className 	= 'bot_thumbnail_large';
			image.src       	= preload.src;
			image.style.visible = 'visible';
			
			var browser_width  = getBrowserWidth();
			var browser_height = getBrowserHeight();

			var image_width  = Math.min(preload.width, 800);
			var image_height = image_width * preload.height / preload.width;
			
			var topPosition = getViewTop() + Math.max((browser_height - image_height) / 2, 10);
			var leftPosition = ((browser_width/2)-(image_width/2));
			
			// If a fullsize image was specified, create a button that will link to it when we're zoomed.
			var zoomButton = null;
			if (full) {
				zoomButton = document.createElement("a");
			}
			
			var contract = function() {
			
				// Get rid of the zoom button.
				if (zoomButton) {
					document.body.removeChild(zoomButton);
				}
				
				// Don't allow the user to "recontract" while we're contracting.
				image.onclick = null;					
				var contractImage = new Fx.Styles(image,{duration: duration,onComplete: function() {
					document.body.removeChild(image);
					// Re-enable the ability to enlarge the image.
					element.onclick = function() { showLargeBlogImage(src, fade, element, full); };
				}});
				// The browser may have resized and repositioned the element (say if it's centered), so get the current coordinates.
				var coordinates = getCoordinates(element);
				contractImage.start({
					'opacity': [1, start_opacity],				
					'top': [topPosition,coordinates.top],
					'left': [leftPosition,coordinates.left],
					'width': [image_width,coordinates.width],
					'height': [image_height,coordinates.height]
				});
			};	
					
			var enlargeImage = new Fx.Styles(image,{duration: duration,onComplete: function() {
				
				// Contract the image when it's clicked.
				image.onclick = contract
				
				// Setup the zoom button.
				if (zoomButton)
				{
					zoomButton.target		      = '_blank';
					zoomButton.href      		  = full;
					zoomButton.className          = "bot_thumbnail_zoombutton";             
					zoomButton.style.position 	  = "absolute";
					zoomButton.style.top 		  = topPosition + (image_height - 40) + "px";
					zoomButton.style.left		  = leftPosition + (image_width - 40) + "px";
					zoomButton.style.zIndex       = "1";
					zoomButton.style.visibility   = "hidden";
					document.body.appendChild(zoomButton);
					fadeIn(zoomButton, 400);
				}
				
			}});
			enlargeImage.start({
				'opacity': [start_opacity, 1],		
				'top': [coordinates.top,topPosition],
				'left': [coordinates.left,((browser_width/2)-(image_width/2))],
				'width': [coordinates.width,image_width],
				'height': [coordinates.height,image_height]
			});
			
			
		};
	
	// Load the image and when we're done, zoom.
	preloadImage(src, zoom);

}
