<!--
/*===========================================================================*/
/* (c)copyright 2000 FreeSky & liqwei                                        */
/* Email: liqwei#liqwei.com                                                  */
/*   Web: http://www.liqwei.com/                                             */
/*  Oicq: 20865662                                                           */
/*   Msn: wei_liqiang#hotmail.com                                            */
/*===========================================================================*/

//===========================================================================
// 功能：读写 cookie 中信息
function getCookie(name) {
  var value = "";
  if(document.cookie.length > 0){
	  var prefix = name + "="; 
	  var begin = document.cookie.indexOf(prefix);
	  if (begin != -1) {
			begin += prefix.length;
			var end = document.cookie.indexOf(";", begin);
			if (end == -1)	end = document.cookie.length;
			value = unescape(document.cookie.substring(begin, end));
	  }
  }
  return value;
}

function setCookie(name, value, hour) {
  var cookie = name + "=" + escape(value);
  if(hour != null){
    var expire = new Date((new Date()).getTime() + hour * 3600000);
    cookie += "; expires=" + expire.toGMTString();
  }
  document.cookie = cookie + "; path=/";
}
//===========================================================================
// 功能：添加到收藏夹；
function addFavorite(){
	try{ window.external.AddFavorite("http://www.ibicn.com", "国联资源网"); }catch(e){}
}
// 功能：设置主页；
function setHomePage(){
	try{
		var url = "http://www.ibicn.com";
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}catch(e){}
}
// 功能：打印页面；
function doPrint(){
	print(document);
}
// 功能：添加到收藏夹；
function doCollect(theType, theId){
	var theUrl = "http://www.ibicn.com/member/collect.jsp?type="+ theType +"&relationId="+ theId;
	window.open(theUrl, "collectWin", "height=160,width=300");
}
// 功能：推荐页面；
function doRecommend(title, link){
	window.clipboardData.setData('text', title + link); 
	alert('复制链接成功！');
}

// 自动缩放图片在指定大小范围之内；
function zoomImage(imageHaddle, maxWidth, maxHeight){
	if(imageHaddle.width>0 && imageHaddle.height>0){
		var rate, isSelectWidth;
		if(maxWidth>0 && maxHeight>0){		
			isSelectWidth = (maxWidth/imageHaddle.width > maxHeight/imageHaddle.height);
			rate = isSelectWidth?(maxHeight/imageHaddle.height):(maxWidth/imageHaddle.width);			
		}else if(maxWidth < 0){
			isSelectWidth = false;
			rate = (maxHeight-imageHaddle.height)>0?1:maxHeight/imageHaddle.height;
		}else if(maxHeight < 0){
			isSelectWidth = false;
			rate = (maxWidth-imageHaddle.width)>0?1:maxWidth/imageHaddle.width;
		}
		if(rate < 1){
			if(isSelectWidth) 
				imageHaddle.width = imageHaddle.width*rate;
			else
				imageHaddle.height = imageHaddle.height*rate;
		}
	}
}

// 自动缩放图片在指定大小范围之内，留白区域使用指定颜色或背景图片填充，针对 div 标签；
function showImage(imageSrc, alt, maxWidth, maxHeight, maskBg, strUrl, strTarget){
	var imageHaddle = new Image();
	imageHaddle.src = imageSrc;
	if(imageHaddle.width>0 && imageHaddle.height>0){
		var rate, isSelectWidth;
		if(maxWidth>0 && maxHeight>0){		
			isSelectWidth = (maxWidth/imageHaddle.width > maxHeight/imageHaddle.height);
			rate = isSelectWidth?(maxHeight/imageHaddle.height):(maxWidth/imageHaddle.width);
		}else if(maxWidth < 0){
			isSelectWidth = false;
			rate = (maxHeight-imageHaddle.height)>0?1:maxHeight/imageHaddle.height;
		}else if(maxHeight < 0){
			isSelectWidth = false;
			rate = (maxWidth-imageHaddle.width)>0?1:maxWidth/imageHaddle.width;
		}
		if(rate < 1){
			if(isSelectWidth){
				imageHaddle.width = imageHaddle.width*rate;
			}else{
				imageHaddle.height = imageHaddle.height*rate;
			}
		}
		
		var divStyle = "margin:0px;padding:0px;";
		maskBg = (maskBg=="")?"#fff":maskBg;
		if(maskBg.indexOf(".")>0) 
			divStyle += "background:url("+maskBg+");";
		else
			divStyle += "background:"+maskBg+";";
		var imageStyle = "";
		if(maxWidth > 0){
			divStyle += "width:"+ maxWidth +"px;";
			if ((maxWidth-imageHaddle.width)>0) 
				imageStyle += "margin-left:"+ parseInt((maxWidth-imageHaddle.width)/2)+";";
		}
		if(maxHeight > 0){
			divStyle += "height:"+ maxHeight +"px;";
			if ((maxHeight-imageHaddle.height)>0) 
				imageStyle += "margin-top:"+ parseInt((maxHeight-imageHaddle.height)/2)+";";
		}
	}
	
	document.write("<div style='"+ divStyle +"'>");
	if(strUrl!= undefined && strUrl!=""){
		if(strTarget!= undefined && strTarget!="") strTarget="_blank";
		document.write("<a href='"+ strUrl +"' title='"+ alt +"' target='"+ strTarget +"'>");
	}
	document.write("<img src='"+ imageSrc +"' alt='"+ alt +"'");
	if(isSelectWidth) document.write(" width='"+ parseInt(imageHaddle.width) +"'");
	else document.write(" height='"+ parseInt(imageHaddle.height) +"'");
	document.write(" style='"+ imageStyle +"' border='0'/>");
	if(strUrl!=undefined && strUrl!=""){ document.write("</a>"); }
	document.write("</div>");
}

// 功能：禁止右键；
function disableRightClick(e){
  if(!document.rightClickDisabled) {
    if(document.layers) {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }else{
		document.oncontextmenu = disableRightClick;
	}
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all)) {
    if (e.which==2||e.which==3)  {
      return false;
    }
  } else {
    return false;
  }
}

function openWindow(url, name, width, height, style) { //自动居中
  var left = (window.screen.availWidth-10-width)/2;
  var top = (window.screen.availHeight-30-height)/2;
  var win_style = 'height='+height+',innerHeight='+height+',width='+width+',innerWidth='+width+',top='+top+',left='+left;
  if(style != null && style != "")
  	win_style += ',' + style;
  window.open(url, name, win_style).focus();
}
-->