﻿function encode(str){str=utf16to8(str);var out,i,len;var c1,c2,c3;var EncodeChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";len=str.length;i=0;out="";while(i<len){c1=str.charCodeAt(i++)&0xff;if(i==len){out+=EncodeChars.charAt(c1>>2);out+=EncodeChars.charAt((c1&0x3)<<4);out+="==";break}c2=str.charCodeAt(i++);if(i==len){out+=EncodeChars.charAt(c1>>2);out+=EncodeChars.charAt(((c1&0x3)<<4)|((c2&0xF0)>>4));out+=EncodeChars.charAt((c2&0xF)<<2);out+="=";break}c3=str.charCodeAt(i++);out+=EncodeChars.charAt(c1>>2);out+=EncodeChars.charAt(((c1&0x3)<<4)|((c2&0xF0)>>4));out+=EncodeChars.charAt(((c2&0xF)<<2)|((c3&0xC0)>>6));out+=EncodeChars.charAt(c3&0x3F)}return out}function decode(str){var c1,c2,c3,c4;var i,len,out;var DecodeChars=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);len=str.length;i=0;out="";while(i<len){do{c1=DecodeChars[str.charCodeAt(i++)&0xff]}while(i<len&&c1==-1);if(c1==-1)break;do{c2=DecodeChars[str.charCodeAt(i++)&0xff]}while(i<len&&c2==-1);if(c2==-1)break;out+=String.fromCharCode((c1<<2)|((c2&0x30)>>4));do{c3=str.charCodeAt(i++)&0xff;if(c3==61)return out;c3=DecodeChars[c3]}while(i<len&&c3==-1);if(c3==-1)break;out+=String.fromCharCode(((c2&0XF)<<4)|((c3&0x3C)>>2));do{c4=str.charCodeAt(i++)&0xff;if(c4==61)return out;c4=DecodeChars[c4]}while(i<len&&c4==-1);if(c4==-1)break;out+=String.fromCharCode(((c3&0x03)<<6)|c4)}out=utf8to16(out);return out}function utf8to16(str){var out,i,len,c;var char2,char3;out="";len=str.length;i=0;while(i<len){c=str.charCodeAt(i++);switch(c>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:out+=str.charAt(i-1);break;case 12:case 13:char2=str.charCodeAt(i++);out+=String.fromCharCode(((c&0x1F)<<6)|(char2&0x3F));break;case 14:char2=str.charCodeAt(i++);char3=str.charCodeAt(i++);out+=String.fromCharCode(((c&0x0F)<<12)|((char2&0x3F)<<6)|((char3&0x3F)<<0));break}}return out}function utf16to8(str){var out,i,len,c;out="";len=str.length;for(i=0;i<len;i++){c=str.charCodeAt(i);if((c>=0x0001)&&(c<=0x007F)){out+=str.charAt(i)}else if(c>0x07FF){out+=String.fromCharCode(0xE0|((c>>12)&0x0F));out+=String.fromCharCode(0x80|((c>>6)&0x3F));out+=String.fromCharCode(0x80|((c>>0)&0x3F))}else{out+=String.fromCharCode(0xC0|((c>>6)&0x1F));out+=String.fromCharCode(0x80|((c>>0)&0x3F))}}return out}function getCookie(cookieName){var cookieString = document.cookie;var start = cookieString.indexOf(cookieName + '=');if (start == -1)return null;start += cookieName.length + 1;var end = cookieString.indexOf(';', start);if (end == -1) return unescape(cookieString.substring(start));return unescape(cookieString.substring(start, end));}function LoginInfo(){var login=getCookie("BDSLogin");var logoutURL="http://passport.coimp.cn/logout.asp";var regURL="http://passport.coimp.cn/register.asp";var loginURL="http://passport.coimp.cn/login.asp"; var thisURL=document.location.href;if (login!=null&&login!=""){userName=getUserName(); info='\u60A8\u597D\uFF0C'+userName+'\uFF01 <a href="http://www.coimp.cn/my/" style="color:#c00">\u8FDB\u5165\u6211\u7684\u7528\u6237\u4E2D\u5FC3</a> <a href="'+logoutURL+'?backURL='+encodeURIComponent(thisURL)+'">[\u9000\u51FA\u767B\u5F55]</a>'}else{info='<form id="clfm" name="clfm" method="post" action="'+loginURL+'?backURL='+encodeURIComponent(thisURL)+'">\u7528\u6237\u540D <input type="text" name="UserName" id="UserName" style="border:1px inset #eee;height:17px;width:90px;padding:0;line-height:16px;margin:0" /> \u5BC6\u7801 <input type="password" name="Password" id="Password" style="border:1px inset #eee;height:17px;width:90px;padding:0; line-height:16px;margin:0" /> <input type="submit" name="button" id="button" value="\u767B\u5F55" style="border:1px outset #ccc;height:19px;width:40px;padding:0;line-height:19px;margin:0" /> <a href="'+regURL+'?backURL='+encodeURIComponent(thisURL)+'" style="color:#c00">\u514D\u8D39\u6CE8\u518C</a></form>'}document.write(info);}function getUserName(){var userName = String(unescape(getCookie("BDSLogin"))).split(":")[2];userName = userName == "undefined" ? "" : userName; userName= decode(userName); return userName;}
var isIE = (document.all) ? true : false;
var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);

var $$ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
	create: function() {
		return function() {this.initialize.apply(this, arguments);}
	}
}
var Extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
}
var Bind = function(object, fun) {
	return function() {
		return fun.apply(object, arguments);
	}
}
var Each = function(list, fun){
	for (var i = 0, len = list.length; i < len; i++) {fun(list[i], i);}
};
var Contains = function(a, b){
	return a.contains ? a != b && a.contains(b) : !!(a.compareDocumentPosition(b) & 16);
}

var OverLay = Class.create();
OverLay.prototype = {
  initialize: function(options) {

	this.SetOptions(options);
	
	this.Lay = $$(this.options.Lay) || document.body.insertBefore(document.createElement("div"), document.body.childNodes[0]);
	
	this.Color = this.options.Color;
	this.Opacity = parseInt(this.options.Opacity);
	this.zIndex = parseInt(this.options.zIndex);
	
	with(this.Lay.style){
		display = "none"; zIndex = this.zIndex; left = top = 0; position = "fixed"; width = height = "100%";
	}
	
	if(isIE6){
		this.Lay.style.position = "absolute";
		//ie6设置覆盖层大小程序
		this._resize = Bind(this, function(){
			this.Lay.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
			this.Lay.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
		});
		//遮盖select
		this.Lay.innerHTML = '<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe>'
	}
  },
  //设置默认属性
  SetOptions: function(options) {
    this.options = {//默认值
		Lay:		null,//覆盖层对象
		Color:		"#000",//背景色
		Opacity:	50,//透明度(0-100)
		zIndex:		1000//层叠顺序
    };
    Extend(this.options, options || {});
  },
  //显示
  Show: function() {
	//兼容ie6
	if(isIE6){this._resize(); window.attachEvent("onresize", this._resize);}
	//设置样式
	with(this.Lay.style){
		//设置透明度
		isIE ? filter = "alpha(opacity:" + this.Opacity + ")" : opacity = this.Opacity / 100;
		backgroundColor = this.Color; display = "block";
	}
  },
  //关闭
  Close: function() {
	this.Lay.style.display = "none";
	if(isIE6){window.detachEvent("onresize", this._resize);}
  }
};

var LightBox = Class.create();
LightBox.prototype = {
  initialize: function(box, options) {
	
	this.Box = $$(box);//显示层
	
	this.OverLay = new OverLay(options);//覆盖层
	
	this.SetOptions(options);
	
	this.Fixed = !!this.options.Fixed;
	this.Over = !!this.options.Over;
	this.Center = !!this.options.Center;
	this.onShow = this.options.onShow;
	
	this.Box.style.zIndex = this.OverLay.zIndex + 1;
	this.Box.style.display = "none";
	
	//兼容ie6用的属性
	if(isIE6){
		this._top = this._left = 0; this._select = [];
		this._fixed = Bind(this, function(){this.Center ? this.SetCenter() : this.SetFixed();});
	}
  },
  //设置默认属性
  SetOptions: function(options) {
    this.options = {//默认值
		Over:	true,//是否显示覆盖层
		Fixed:	true,//是否固定定位
		Center:	true,//是否居中
		onShow:	function(){}//显示时执行
	};
    Extend(this.options, options || {});
  },
  //兼容ie6的固定定位程序
  SetFixed: function(){
	this.Box.style.top = document.documentElement.scrollTop - this._top + this.Box.offsetTop + "px";
	this.Box.style.left = document.documentElement.scrollLeft - this._left + this.Box.offsetLeft + "px";
	
	this._top = document.documentElement.scrollTop; this._left = document.documentElement.scrollLeft;
  },
  //兼容ie6的居中定位程序
  SetCenter: function(){
	this.Box.style.marginTop = document.documentElement.scrollTop - this.Box.offsetHeight / 2 + "px";
	this.Box.style.marginLeft = document.documentElement.scrollLeft - this.Box.offsetWidth / 2 + "px";
  },
  //显示
  Show: function(options) {
	//固定定位
	this.Box.style.position = this.Fixed && !isIE6 ? "fixed" : "absolute";

	//覆盖层
	this.Over && this.OverLay.Show();
	
	this.Box.style.display = "block";
	
	//居中
	if(this.Center){
		this.Box.style.top = this.Box.style.left = "50%";
		//设置margin
		if(this.Fixed){
			this.Box.style.marginTop = - this.Box.offsetHeight / 2 + "px";
			this.Box.style.marginLeft = - this.Box.offsetWidth / 2 + "px";
		}else{
			this.SetCenter();
		}
	}
	//兼容ie6
	if(isIE6){
		if(!this.Over){
			//没有覆盖层ie6需要把不在Box上的select隐藏
			this._select.length = 0;
			Each(document.getElementsByTagName("select"), Bind(this, function(o){
				if(!Contains(this.Box, o)){o.style.visibility = "hidden"; this._select.push(o);}
			}))
		}
		//设置显示位置
		this.Center ? this.SetCenter() : this.Fixed && this.SetFixed();
		//设置定位
		this.Fixed && window.attachEvent("onscroll", this._fixed);
	}
	
	this.onShow();
  },
  //关闭
  Close: function() {
	this.Box.style.display = "none";
	this.OverLay.Close();
	if(isIE6){
		window.detachEvent("onscroll", this._fixed);
		Each(this._select, function(o){o.style.visibility = "visible";});
	}
  }
};
// 浮动层通用函数
function fuceng_common(){
		box.Show();
}
function closePropmtBox(){
		box.Close();
}
function MsgBox(tt,url,wd,ht,tp){
		$$("msgbox").style.width = wd+"px"
		$$("msgbox").style.height = ht+"px"
		$$("bartit").innerHTML = tt;
		mini.location = url;
		fuceng_common();
}
document.writeln("<style type=\"text/css\" media=\"screen\">");
document.writeln("#msgbox{postition:absolute;width:500px;height:200px}");
document.writeln("#popbar{width:100%;height:25px;background:#999}");
document.writeln("#ifram{width:100%;height:100%;background:#fff}");
document.writeln(".bartit{color:#fff;font-size:14px;padding:5px 0 0 5px;font-weight:bold}");
document.writeln(".close{padding:5px 5px 0 0}");
document.writeln(".l{float:left}");
document.writeln(".r{float:right}");
document.writeln("</style>");
document.writeln("<div style=\"z-index:1001;display:none;position:fixed;left:50%;top:50%;margin-top:-92px;margin-left:-190px;\" id=\"msgbox\">");
document.writeln("  <div id=\"popbar\">");
document.writeln("    <div class=\"l bartit\" id=\"bartit\"></div>");
document.writeln("    <div class=\"r close\"><a href=\"javascript:closePropmtBox();\"><img src=\"http://www.coimp.cn/images/msg_close.gif\" border=\"0\"></a></div>");
document.writeln("  </div>");
document.writeln("  <div id=\"ifram\">");
document.writeln("    <iframe marginwidth=\"0\" marginheight=\"0\" framespacing=\"0\" vspace=\"0\" hspace=\"0\" id=\"mini\" name=\"mini\" src=\"about:blank\" scrolling=\"no\" frameborder=\"0\" height=\"100%\" width=\"100%\"></iframe>");
document.writeln("  </div>");
document.writeln("</div>");
var box = new LightBox("msgbox");

//图片调整函数
var flag=false; 
function DrawImage(ImgD,newWidth,newHeight){ 
var image=new Image(); 
image.src=ImgD.src; 
if(image.width>0 && image.height>0){ 
flag=true; 
if(image.width/image.height>= newWidth/newHeight){ 
if(image.width>newWidth){ 
ImgD.width=newWidth; 
ImgD.height=(image.height*newWidth)/image.width; 
}else{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 
} 
else{ 
if(image.height>newHeight){ 
ImgD.height=newHeight; 
ImgD.width=(image.width*newHeight)/image.height; 
}else{ 
ImgD.width=image.width; 
ImgD.height=image.height; 
} 
} 
} 
} 
