﻿//判断是否为浏览器
var isIE = false;
if(document.all){
	isIE = true;
}
//初始化XMLHTTP
function ajaxInit(){
	var A;
	try{
		A = new XMLHttpRequest();
	}catch(e){
		try{
			A = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			try{
				A = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				A = false;
			}
		}
	}
	return A;
}

//Shared Event
function addListener(elem,eventType,eventFunc) {
	if (isIE) { //For IE
		elem.attachEvent(eventType,eventFunc);
	}else{ //For Mozilla
		elem.addEventListener(eventType.substr(2,eventType.length-2),eventFunc,true);
		//Event.observe(elem,'submit',this.onSubmit.bind(this),false)
	}
}
function releaseEvent(elem,eventType,eventFunc) {
	if (isIE) { //For IE
		elem.detachEvent(eventType,eventFunc);
	}else{ //For Mozilla
		elem.removeEventListener(eventType.substr(2,eventType.length-2),eventFunc,true);
	}
}

//取消事件及事件冒泡
function donon(evt){
	var evt = (evt)?evt:(window.event)?window.event:"";
	if(isIE){
		evt.returnValue = false;
		evt.cancelBubble = true;
	}else{
		evt.stopPropagation();
		evt.preventDefault();
	}
}

//重定义定时函数，使用方法：_st("fadeout('a','b')",1000);
var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay) {
	if(typeof fRef == 'function'){
		var argu = Array.prototype.slice.call(arguments,2);
		var f = (function(){ fRef.apply(null, argu); });
		return _st(f, mDelay);
	}
	return _st(fRef,mDelay);
}

//获取Cookie
function GetCookie(name){ 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while(i < clen){ 
		var j = i + alen; 
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j); 
		i = document.cookie.indexOf(" ", i) + 1; 
		if (i == 0) break; 
	} 
	return null;
}
//设置Cookie
function SetCookie(name, value){ 
	var argv = SetCookie.arguments; 
	var argc = SetCookie.arguments.length; 
	var expires = (argc > 2) ? argv[2] : null; 
	var path = (argc > 3) ? argv[3] : null; 
	var domain = (argc > 4) ? argv[4] : null; 
	var secure = (argc > 5) ? argv[5] : false; 
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}
//删除Cookie
function DeleteCookie(name){ 
	var exp = new Date(); 
	exp.setTime (exp.getTime() - 1); 
	// This cookie is history 
	var cval = 0; 
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//获取具体的Cookie值
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

//返回字符串字节长
String.prototype.lenB = function() {
    var cArr = this.match(/[^\x00-\xff]/ig);
    return this.length + (cArr == null ? 0 : cArr.length);
}
String.prototype.trim = function() { 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

function IsEnglish(elem)
{
    var str = elem.value;
    if(str == '')
        return;
        
    var isErr = false;
      for(var i = 0;i<str.length;i++){ 
        if(str.charAt(i).toString().lenB() > 1){
            isValid = false;
            isErr = true;
		    throwError(elem.id,arguments[1]);
            break;
        }
    }
    
    if(!isErr){
		throwValid(elem.id,arguments[2]);
    }
}

//转义字符
function XMLEncode(str){
	str=str.trim();
	str = str.replace("&","&amp;");
	str = str.replace("<","&lt;");
	str = str.replace(">","&gt;");
	str = str.replace("'","&apos;");
	str = str.replace("\"","&quot;");
	return str;
}

//获取对象
//当参数为对象时，返回对象
//当参数为字符串时，返回该ID的对象
//允许多个参数，返回对象数组
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == "string"){
			element = document.getElementById(element);
		}
		if (arguments.length == 1){
			return element;
		}
		elements.push(element);
	}
	return elements;
}

//根据表单元素名获取对象，返回数组
function $A() {
	return document.getElementsByName(arguments[0]);
}

//根据表单名获取对象，返回该表单
function $F() {
	return eval("document."+arguments[0]);
}

//根据标记名获取对象，返回数组
function $T() {
	return document.getElementsByTagName(arguments[0]);
}

//判断输入是否为空
function checkEmpty(elem) {
	elem.value=elem.value.trim();
	if (elem.value=="") {
		throwError(elem.id,arguments[1]);
	} else {
		throwValid(elem.id,arguments[2]);
	}
}
//判断输入长度
function checkLength(elem, min, max) {
	elem.value=elem.value.trim();
	if (elem.value=="") {
		isValid = true;
		return;
	}
	if(min==max){
		if (elem.value.lenB() != min) {
			throwError(elem.id,arguments[3])
		} else {
			throwValid(elem.id,arguments[4]);
		}
	}else{
		if (elem.value.lenB() < min) {
			throwError(elem.id,arguments[3])
		} else {
			throwValid(elem.id,arguments[4]);
		}
		if (isValid) {
			if (elem.value.lenB() > max) {
				throwError(elem.id,arguments[3])
			} else {
				throwValid(elem.id,arguments[4]);
			}
		}
	}
}
//判断两次输入是否相同
function checkCompare(elem, string_fst, string_sed) {
	elem.value=elem.value.trim();
	if (elem.value=="")  {
		isValid = true;
		return;
	}
	if (string_fst!=string_sed) {
		throwError(elem.id,arguments[3]);
	}else{
		throwValid(elem.id,arguments[4])
	}
}
//判断是否符合正则表达式
function checkRegExp(elem, exp) {
	elem.value=elem.value.trim();
	if (elem.value==""){
		isValid = true;
		return;
	}
	if (!new RegExp(exp).test(elem.value)) {
		throwError(elem.id,arguments[2]);
	}else{
		throwValid(elem.id,arguments[3])
	}
}
//判断文件类型
function checkType(elem, type){
	elem.value=elem.value.trim();
	if (elem.value==""){
		isValid = true;
		return;
	}
	if(!new RegExp(","+elem.value.substring(elem.value.lastIndexOf(".")+1,elem.value.length)).test(","+type)){
		throwError(elem.id,arguments[2]);
	}else{
		throwValid(elem.id,arguments[3])
	};
}
//判断选项个数是否不小于要求的个数
function checkSelect(elemstr, min){
	var elem=$A(elemstr), num=0;
	for(var i=0;i<elem.length;i++){
		if(elem[i].checked){
			num++;
		}
	}
	if(num<min){
		throwError(elemstr,arguments[2]);
	}else{
		throwValid(elemstr,arguments[3])
	}
}
//判断是否包含在数组内
function checkInArray(){
	for(var i=0;i<arguments[0].length;i++){
		if(arguments[0][i]==arguments[1]){
			return true;
		}
	}
	return false;
}

//验证返回false时执行此函数
function throwError(elemstr,msgState) {
	isValid = false;
	swapClass(elemstr+"State", "valid", "error");
	swapInnerHTML(elemstr+"State", msgState);
	//$(elemstr).focus();
}
//验证返回true时执行此函数
function throwValid(elemstr,msgState) {
	isValid = true;
	swapClass(elemstr+"State", "error", "valid");
	swapInnerHTML(elemstr+"State", msgState);
}

//设置对象的style.display属性值
function swapDisplay(taget,state) {
	var elem_taget = $(taget);
	if (elem_taget) {
		elem_taget.style.display = state;
	}
}

//对象是否拥有该classname
function hasClass(taget) {
	return $(taget).className.indexOf(arguments[1])>=0;
}
//移除第一个classname，添加第二个classname
function swapClass(taget) {
	delClass(taget,arguments[1]);
	addClass(taget,arguments[2]);
}
//添加一个classname
function addClass(taget) {
	var elem_taget = $(taget);
	if (elem_taget) {
		if(elem_taget.className!=""){
			if(!checkInArray(elem_taget.className.split(" "),arguments[1])){
				elem_taget.className = elem_taget.className + " " + arguments[1];
			}
		}else{
			elem_taget.className = arguments[1];
		}
	}
}
//删除一个classname
function delClass(taget) {
	var elem_taget = $(taget);
	if (elem_taget) {
		elem_taget.className = elem_taget.className.replace(new RegExp(arguments[1],"g"),"").replace(/\s\s/g," ").trim();
	}
}
//为对象设置新的classname
function setClass(taget) {
	var elem_taget = $(taget);
	if (elem_taget) {
		elem_taget.className = arguments[1];
	}
}

//设置对象的innerhtml值
function swapInnerHTML(taget,msg) {
	var elem_taget = $(taget);
	if (elem_taget) {elem_taget.innerHTML=msg;}
}

//从dom里移除对象
function removeObj(id) {
	try {
		var o = $(id);
	} catch(e) {
		return false;
	}
	try {
		o.parentElement.removeChild(o);
	} catch(e) {
		try {
			o.parentNode.removeChild(o);
		} catch(e) {
			return false;
		}
	}
}

function getStyleValue(obj,style){
	if(isIE){
	    return obj.currentStyle[style];
	}else{
	    return document.defaultView.getComputedStyle(obj,null).getPropertyValue(style);
	}
}

//获取对象的坐标及尺寸，当参数为空时返回body对象的参数
function getOffset(obj){
	function getCurrentStyle(style){
		var number=parseInt(obj.currentStyle[style]);
		return isNaN(number)?0:number;
	}
	function getComputedStyle(style){
		return parseInt(document.defaultView.getComputedStyle(obj,null).getPropertyValue(style));
	}
	if (!arguments[0]) {//获取body对象的参数   
	     
		return o = {
			"left":Math.max(document.body.scrollLeft,document.documentElement.scrollLeft),
			"top":Math.max(document.body.scrollTop,document.documentElement.scrollTop),
			"vwidth": Math.max(document.body.clientWidth, document.documentElement.clientWidth),
			"vheight":document.documentElement.clientHeight,
			"width":Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
			"height":Math.max(document.body.offsetHeight,document.documentElement.offsetHeight)
		}; 
	}else{
		var obj = arguments[0];
		var o = {
			"left":obj.offsetLeft,
			"top":obj.offsetTop,
			"width":obj.offsetWidth,
			"height":obj.offsetHeight
		};
		while(true){
			obj=obj.offsetParent;
			if(obj==(document.body&&null))break;
			o.left+=obj.offsetLeft;
			o.top+=obj.offsetTop;
			if(isIE){
				o.left+=getCurrentStyle("borderLeftWidth");
				o.top+=getCurrentStyle("borderTopWidth");
			}else{
				o.left+=getComputedStyle("border-left-width");
				o.top+=getComputedStyle("border-top-width");
			}
		}
		return o;
	}
}

function handleIEhasLayout(){
	document.body.style.zoom = 1.1;
	document.body.style.zoom = 1;
}

//显示进度条
function DrawLoadingBar(obj,txt){
	if($("myLoadingBar")){removeObj("myLoadingBar");}
	var myLB = document.createElement("DIV");
	myLB.id = "myLoadingBar";
	myLB.style.position = "absolute";
	myLB.style.zIndex = "9";
	myLB.style.backgroundColor = "rgb(255,255,255)";

	var offsetObj = getOffset(obj);
	
	myLB.style.width = offsetObj.width+"px";
	myLB.style.height = offsetObj.height+"px";
	myLB.style.left = offsetObj.left+"px";
	myLB.style.top = offsetObj.top+"px";
	myLB.style.textAlign = "center";
	myLB.style.filter = "alpha(opacity=90)";
	myLB.style.mozOpacity = "0.9";
	myLB.style.opacity = "0.9";

	var myImg = new Image();
	myImg.src = "/img/loading.gif";
	myImg.style.marginTop = parseInt(myLB.style.height)/2-8+"px";
	myImg.style.width = "16px";
	myImg.style.height = "16px";

	myLB.appendChild(myImg);
	if(txt){
		var myDiv = document.createElement("div");
		myDiv.style.color = "rgb(144,144,144)";
		var myTxt = document.createTextNode(txt);
		myDiv.appendChild(myTxt);
		myLB.appendChild(myDiv);
	}
	document.body.appendChild(myLB);
}

//显示消息
function ShowMsg(txt){
	if($("myOuterDiv")){removeObj("myOuterDiv");}
	if($("myInnerDiv")){removeObj("myInnerDiv");}
	var myOuterDiv = document.createElement("div");
	myOuterDiv.id = "myOuterDiv";
	myOuterDiv.style.position = "absolute";
	myOuterDiv.style.zIndex = "7";
	myOuterDiv.style.backgroundColor = "rgb(0,0,0)";

	var offsetObj = getOffset();

	myOuterDiv.style.width = offsetObj.width+"px";
	myOuterDiv.style.height = offsetObj.height+"px";
	myOuterDiv.style.left = "0px";
	myOuterDiv.style.top = "0px";
	myOuterDiv.style.filter = "alpha(opacity=20)";
	myOuterDiv.style.mozOpacity = "0.2";
	myOuterDiv.style.opacity = "0.2";

	var myInnerDiv = document.createElement("div");
	myInnerDiv.id = "myInnerDiv";
	myInnerDiv.style.position = "absolute";
	myInnerDiv.style.zIndex = "8";
	myInnerDiv.style.backgroundColor = "rgb(255,255,255)";
	myInnerDiv.style.border = "3px solid rgb(183,183,183)";
	myInnerDiv.style.padding = "1.5em";

	myInnerDiv.style.width = "30%";
	myInnerDiv.style.overflow = "hidden";
	myInnerDiv.innerHTML = "<div style=\"text-align:center;color:#1B579D;line-height:150%;\">"+txt+"</div><div class=\"btns\"><a title=\"关闭\" href=\"javascript:removeObj('myInnerDiv');removeObj('myOuterDiv');\">关闭</a></div>";
	
	document.body.appendChild(myInnerDiv);
	document.body.appendChild(myOuterDiv);
	
	var offsetObj2 = getOffset(myInnerDiv);
	
	myInnerDiv.style.left = (offsetObj.vwidth-offsetObj2.width)/2+offsetObj.left+"px";
	myInnerDiv.style.top = (offsetObj.vheight-offsetObj2.height)/2+offsetObj.top+"px";
	
	window.onscroll = window.onresize = function(){
		offsetObj = getOffset();
	
		myOuterDiv.style.width = offsetObj.width+"px";
		myOuterDiv.style.height = offsetObj.height+"px";
		myInnerDiv.style.left = (offsetObj.vwidth-offsetObj2.width)/2+offsetObj.left+"px";
		myInnerDiv.style.top = (offsetObj.vheight-offsetObj2.height)/2+offsetObj.top+"px";
	}
}

//显示消息
function ShowMsg1(txt,width){
	if($("myOuterDiv")){removeObj("myOuterDiv");}
	if($("myInnerDiv")){removeObj("myInnerDiv");}
	var myOuterDiv = document.createElement("div");
	myOuterDiv.id = "myOuterDiv";
	myOuterDiv.style.position = "absolute";
	myOuterDiv.style.zIndex = "7";
	myOuterDiv.style.backgroundColor = "rgb(0,0,0)";

	var offsetObj = getOffset();

	myOuterDiv.style.width = offsetObj.width+"px";
	myOuterDiv.style.height = offsetObj.height+"px";
	myOuterDiv.style.left = "0px";
	myOuterDiv.style.top = "0px";
	myOuterDiv.style.filter = "alpha(opacity=20)";
	myOuterDiv.style.mozOpacity = "0.2";
	myOuterDiv.style.opacity = "0.2";

	var myInnerDiv = document.createElement("div");
	myInnerDiv.id = "myInnerDiv";
	myInnerDiv.style.position = "absolute";
	myInnerDiv.style.zIndex = "8";
	myInnerDiv.style.backgroundColor = "rgb(255,255,255)";
	myInnerDiv.style.border = "3px solid rgb(183,183,183)";
	myInnerDiv.style.padding = "1.5em";

	myInnerDiv.style.width = width;
	myInnerDiv.style.overflow = "hidden";
	myInnerDiv.innerHTML = "<div style=\"text-align:center;color:#1B579D;line-height:150%;\">"+txt+"</div><div class=\"btns\"><a title=\"关闭\" href=\"javascript:removeObj('myInnerDiv');removeObj('myOuterDiv');\">关闭</a></div>";	
	
	document.body.appendChild(myInnerDiv);
	document.body.appendChild(myOuterDiv);
	
	if(myInnerDiv.offsetHeight > offsetObj.vheight){
	    myInnerDiv.style.height = (offsetObj.vheight - 60)+"px";
	    myInnerDiv.style.overflow = "scroll";
	}
	
	if(myInnerDiv.offsetWidth > offsetObj.vwidth){
	    myInnerDiv.style.width = (offsetObj.vwidth - 60)+"px";
	    myInnerDiv.style.overflow = "scroll";
	}
	
	var offsetObj2 = getOffset(myInnerDiv);
	
	myInnerDiv.style.left = (offsetObj.vwidth-offsetObj2.width)/2+offsetObj.left+"px";
	myInnerDiv.style.top = (offsetObj.vheight-offsetObj2.height)/2+offsetObj.top+"px";
	 
	    
	
	window.onscroll = window.onresize = function(){
		offsetObj = getOffset();
	
		myOuterDiv.style.width = offsetObj.width+"px";
		myOuterDiv.style.height = offsetObj.height+"px";
		myInnerDiv.style.left = (offsetObj.vwidth-offsetObj2.width)/2+offsetObj.left+"px";
		myInnerDiv.style.top = (offsetObj.vheight-offsetObj2.height)/2+offsetObj.top+"px";
	}
}

//显示窗口
function ShowWindow(URL,WindowName,Width,Height,Scro){
	if($("myOuterDiv")){removeObj("myOuterDiv");}
	if($("myInnerDiv")){removeObj("myInnerDiv");}
	var myOuterDiv = document.createElement("div");
	myOuterDiv.id = "myOuterDiv";
	myOuterDiv.style.position = "absolute";
	myOuterDiv.style.zIndex = "7";
	myOuterDiv.style.backgroundColor = "rgb(0,0,0)";

	var offsetObj = getOffset();

	myOuterDiv.style.width = offsetObj.width+"px";
	myOuterDiv.style.height = offsetObj.vheight + "px";
	myOuterDiv.style.left = offsetObj.left + "px";
	myOuterDiv.style.top = offsetObj.top + "px";
	myOuterDiv.style.filter = "alpha(opacity=20)";
	myOuterDiv.style.mozOpacity = "0.2";
	myOuterDiv.style.opacity = "0.2";

	var myInnerDiv = document.createElement("div");
	myInnerDiv.id = "myInnerDiv";
	myInnerDiv.style.position = "absolute";
	myInnerDiv.style.zIndex = "8";
	myInnerDiv.style.backgroundColor = "rgb(255,255,255)";
	myInnerDiv.style.border = "3px solid rgb(183,183,183)";

	myInnerDiv.style.width = Width+"px";
	myInnerDiv.style.height = Height+"px";
	myInnerDiv.style.overflow = "hidden";
	myInnerDiv.innerHTML = "<iframe src=\""+URL+"\" name=\""+WindowName+"\" width=\""+Width+"\" height=\""+Height+"\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" hspace=\"0\" vspace=\"0\" scrolling=\""+Scro+"\" ></iframe>";
	
	document.body.appendChild(myInnerDiv);
	document.body.appendChild(myOuterDiv);

	var outerOffset = getOffset(myOuterDiv);
	var offsetObj2 = getOffset(myInnerDiv);

	myInnerDiv.style.left = (outerOffset.width - offsetObj2.width) / 2 + outerOffset.left + "px";
	
	if(offsetObj.vheight == document.body.scrollHeight)
	{
	    myInnerDiv.style.top = (outerOffset.height - offsetObj2.height) / 2 + offsetObj.top + "px";
	}
	else
	{
	    myInnerDiv.style.top = (outerOffset.height - offsetObj2.height) / 2 + offsetObj.top + "px";
	} 
	//$("MyMsgTxtDiv").style.paddingTop = (109-$("MyMsgTxtDiv").offsetHeight)/2+"px";
	
		//alert(offsetObj.vheight + "," + document.body.scrollHeight);
	window.onscroll = window.onresize = function () {
	    offsetObj = getOffset();

	    myOuterDiv.style.width = offsetObj.width + "px";
	    myOuterDiv.style.height = offsetObj.vheight + "px";

	    var outerOffset = getOffset(myOuterDiv);
	    var offsetObj2 = getOffset(myInnerDiv);

	    myInnerDiv.style.left = (offsetObj.vwidth - offsetObj2.width) / 2 + offsetObj.left + "px";

	    myInnerDiv.style.left = (outerOffset.width - offsetObj2.width) / 2 + outerOffset.left + "px";

	    if (offsetObj.vheight == document.body.scrollHeight) {
	        myInnerDiv.style.top = (outerOffset.height - offsetObj2.height) / 2 + offsetObj.top + "px";
	    }
	    else {
	        myInnerDiv.style.top = (outerOffset.height - offsetObj2.height) / 2 + offsetObj.top + "px";
	    }
         
	    myOuterDiv.style.width = offsetObj.width + "px";
	    myOuterDiv.style.height = offsetObj.vheight + "px";
	    myOuterDiv.style.left = offsetObj.left + "px";
	    myOuterDiv.style.top = offsetObj.top + "px";

	}
}

//图片预览
function PreviewImg(URL,WindowName,Width,Height,Scro){
	if($("myOuterDiv")){removeObj("myOuterDiv");}
	if($("myInnerDiv")){removeObj("myInnerDiv");}
	var myOuterDiv = document.createElement("div");
	myOuterDiv.id = "myOuterDiv";
	myOuterDiv.style.position = "absolute";
	myOuterDiv.style.zIndex = "7";
	myOuterDiv.style.backgroundColor = "rgb(0,0,0)";

	var offsetObj = getOffset();

	myOuterDiv.style.width = offsetObj.width+"px";
	myOuterDiv.style.height = offsetObj.height+"px";
	myOuterDiv.style.left = "0px";
	myOuterDiv.style.top = "0px";
	myOuterDiv.style.filter = "alpha(opacity=20)";
	myOuterDiv.style.mozOpacity = "0.2";
	myOuterDiv.style.opacity = "0.2";

	var myInnerDiv = document.createElement("div");
	myInnerDiv.id = "myInnerDiv";
	myInnerDiv.style.position = "absolute";
	myInnerDiv.style.zIndex = "8";
	myInnerDiv.style.backgroundColor = "rgb(255,255,255)";
	myInnerDiv.style.border = "3px solid rgb(183,183,183)";
	myInnerDiv.style.overflow = "scroll";
	myInnerDiv.style.scrollbarBaseColor = "rgb(183,183,183)";

	myInnerDiv.style.width = Width+"px";
	myInnerDiv.style.height = Height+"px";
	myInnerDiv.style.overflow = Scro=="yes"?"scroll":"hidden";
	
	var img = document.createElement("img");
	img.src = URL;
	
    var maxWidth = Width - 100;
    var maxHeight = Height - 100;
    
    var imgWidth = img.width;
    var imgHeight = img.height;
     
    if(imgWidth > imgHeight && imgWidth > maxWidth){ 
        img.width = maxWidth; 
	    myInnerDiv.innerHTML = "<div style=\"text-align:center;margin-top:1em;\"><img src=\""+URL+"\" width=\"" + img.width + "\"/></div><div class=\"btns\"><div class=\"btns\"><a title=\"放大\" href=\"" + URL + "\" target=\"_blank\">放大</a><a title=\"关闭\" href=\"javascript:removeObj('myInnerDiv');removeObj('myOuterDiv');\">关闭</a></div>";
    }
    
    if(imgHeight > imgWidth && imgHeight > maxHeight){ 
        img.height = maxHeight;
	    myInnerDiv.innerHTML = "<div style=\"text-align:center;margin-top:1em;\"><img src=\""+URL+"\" height=\"" + imgHeight + "\"/></div><div class=\"btns\"><a title=\"放大\" href=\"" + URL + "\" target=\"_blank\">放大</a><a title=\"关闭\" href=\"javascript:removeObj('myInnerDiv');removeObj('myOuterDiv');\">关闭</a></div>";
    } 
    
	if(myInnerDiv.innerHTML == ''){
	    myInnerDiv.innerHTML = "<div style=\"text-align:center;margin-top:1em;\"><img src=\""+URL+"\"/></div><div class=\"btns\"><a title=\"放大\" href=\"" + URL + "\" target=\"_blank\">放大</a><a title=\"关闭\" href=\"javascript:removeObj('myInnerDiv');removeObj('myOuterDiv');\">关闭</a></div>";
	}
	
	document.body.appendChild(myInnerDiv);
	document.body.appendChild(myOuterDiv);
	
	var offsetObj2 = getOffset(myInnerDiv);
	
	myInnerDiv.style.left = (offsetObj.vwidth-offsetObj2.width)/2+offsetObj.left+"px";
	myInnerDiv.style.top = (offsetObj.vheight-offsetObj2.height)/2+offsetObj.top+"px";
	
	//$("MyMsgTxtDiv").style.paddingTop = (109-$("MyMsgTxtDiv").offsetHeight)/2+"px";
	
	window.onscroll = window.onresize = function(){
		offsetObj = getOffset();
	
		myOuterDiv.style.width = offsetObj.width+"px";
		myOuterDiv.style.height = offsetObj.height+"px";
		myInnerDiv.style.left = (offsetObj.vwidth-offsetObj2.width)/2+offsetObj.left+"px";
		myInnerDiv.style.top = (offsetObj.vheight-offsetObj2.height)/2+offsetObj.top+"px";
	}
}

function OpenWindow(URL,WindowName,Width,Height,Left,Top,Scro){
	window.open(URL,WindowName,'width='+Width+',height='+Height+',left='+Left+',top='+Top+',toolbar=no,menubar=no,scrollbars='+Scro);
}

function CheckAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if(e.name != 'chkall' && !e.disabled) e.checked = form.chkall.checked;
	}
}
        
//根据checkbox名字全选status选中状态,name checkbox list 的名字
function CheckAll(status,name){
	var items = $A(name);
	if(items){
		var length = items.length;
		for(var i = 0;i<length;i++){
			var item = items[i];
			if(item) item.checked = status;
		}
	}
}

//反选
function RCheckAll(name){
    var items = $A(name);
    if(items){
        var len = items.length;
        for(var i = 0;i<len;i++){
            if(items[i] && !items[i].disabled){
                items[i].checked = !items[i].checked;
            }
        }
    }
}

//加入收藏 支持IE和FF
function bookmarksite(){
    var title;
    var url;
    title = document.title;
    url = location.href;
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "");
}

//FF中设为首页
function setHomePageInFF()
{
//author:猫猫(brothercat)
//date:2006.12.4

  if(window.netscape)
  {
        try { 
          netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
        } 
        catch (e)
        { 
          alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
        }
  }

  var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  prefs.setCharPref('browser.startup.homepage',location.href);
}

//设为首页 判断是FF或者IE分别处理
function setHomePage(){
    if (document.all)
    {
        $("aSetHomePage").style.behavior='url(#default#homepage)';
        $("aSetHomePage").setHomePage(location.href);
    }
        

    if (window.sidebar)
    {
        if(confirm("是否将"+location.href+"设置为首页！"))
            setHomePageInFF();
    }
}
function pixviewer(obj,url,pics,links,texts,focus_width,focus_height,text_height){
	var str = ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ (focus_height+text_height) +'">');
	str += ('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="'+url+'"><param name="quality" value="high"><param name="bgcolor" value="#dfdfdf">');
	str += ('<param name="menu" value="false"><param name=wmode value="opaque">');
	str += ('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">');
	str += ('<embed src="'+url+'" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#dfdfdf" quality="high" width="'+ focus_width +'" height="'+ focus_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	str += ('</object>');
	obj.innerHTML = str;
}

// <script language="javascript" type="text/javascript">flashWrite('flash/intro.swf','350','350','','#ffffff','var=num','transparent')</script>
function flashWrite(url,w,h,id,bg,vars,win){

var flashStr=   "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
                "<param name='allowScriptAccess' value='always' />"+
                "<param name='movie' value='"+url+"' />"+
                "<param name='FlashVars' value='"+vars+"' />"+
                "<param name='wmode' value='"+win+"' />"+
                "<param name='menu' value='false' />"+
                "<param name='quality' value='high' />"+
                "<param name='bgcolor' value='"+bg+"' />"+
                "<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
                "</object>";

document.write(flashStr); 
}

//媒体播放机
function WriteMediaPlayer(pid,id,w,h,s){
	var wmpstr = "<object classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" type=\"application/x-oleobject\" name=\"" + id + "\" width=\""+w+"\" height=\""+h+"\" standby=\"Loading Microsoft Windows Media Player components...\" id=\""+id+"\">";
	wmpstr += "	<param name=\"FileName\" value=\""+s+"\">";
	wmpstr += "	<param name=\"ShowStatusBar\" value=\"0\">";
	wmpstr += "	<param name=\"ShowControls\" value=\"1\">";
	wmpstr += "	<param name=\"AnimationAtStart\" value=\"1\">";
	wmpstr += "	<param name=\"ShowTracker\" value=\"1\">";
	wmpstr += "	<param name=\"EnableTracker\" value=\"0\">";
	wmpstr += "	<param name=\"ShowPositionControls\" value=\"0\">";
	wmpstr += "	<param name=\"EnablePositionControls\" value=\"0\">";
	wmpstr += "	<param name=\"enableContextMenu\" value=\"0\">";
	wmpstr += "	<param name=\"menu\" value=\"1\">";
	wmpstr += "	<param name=\"rate\" value=\"1\">";
	wmpstr += "	<param name=\"balance\" value=\"0\">";
	wmpstr += "	<param name=\"currentPosition\" value=\"0\">";
	wmpstr += "	<param name=\"defaultFrame\" value=\"0\">";
	wmpstr += "	<param name=\"playCount\" value=\"1\">";
	wmpstr += "	<param name=\"autoStart\" value=\"0\">";
	wmpstr += "	<param name=\"currentMarker\" value=\"0\">";
	wmpstr += "	<param name=\"invokeURLs\" value=\"-1\">";
	wmpstr += "	<param name=\"baseURL\" value=\"\">";
	wmpstr += "	<param name=\"volume\" value=\"100\">";
	wmpstr += "	<param name=\"mute\" value=\"0\">";
	wmpstr += "	<param name=\"uiMode\" value=\"mini\">";
	wmpstr += "	<param name=\"stretchToFit\" value=\"1\">";
	wmpstr += "	<param name=\"windowlessVideo\" value=\"0\">";
	wmpstr += "	<param name=\"enabled\" value=\"-1\">";
	wmpstr += "	<param name=\"enableContextMenu\" value=\"-1\">";
	wmpstr += "	<param name=\"fullScreen\" value=\"0\">";
	wmpstr += "	<param name=\"SAMIStyle\" value=\"\">";
	wmpstr += "	<param name=\"SAMILang\" value=\"\">";
	wmpstr += "	<param name=\"SAMIFilename\" value=\"\">";
	wmpstr += "	<param name=\"captioningID\" value=\"\">";
	wmpstr += "	<param name=\"enableErrorDialogs\" value=\"0\">";
	wmpstr += "	<param name=\"_cx\" value=\"8467\">";
	wmpstr += "	<param name=\"_cy\" value=\"8467\">";
	wmpstr += "	<param name=\"AutoSize\" value=\"0\"></object>";
	$(pid).innerHTML = wmpstr;
}
//媒体播放机
function PreloadMedia(id,s){
    $(id).autoStart = 1;
	if(s!="") $(id).FileName = s; 
}

function ToPlay(id){
    $(id).Play();
}

//预览
function PrintPreview(){
	if(isIE){
		if($("PrintPreviewObj")){
			//removeObj("PrintPreviewObj");
		}else{
			var o = document.createElement("div");
			o.id = "PrintPreviewObj"
			o.innerHTML = '<object id="webbrowser1" width="0" height="0" classid="clsid:8856f961-340a-11d0-a96b-00c04fd705a2"></object>';
			document.body.appendChild(o);
		}
		//预览
		$("webbrowser1").ExecWB(7,1);
	}else{
		window.print();
	}
}
//打印
function DoPrint(){
	window.print();
}
 
 
function DoCheckPrint(){
    if(isIE){
//		if($("PrintPreviewObj")){
//			removeObj("PrintPreviewObj");
//		}
//		
//			var o = document.createElement("div");
//			o.id = "PrintPreviewObj"
//			o.innerHTML = '<object id="webbrowser1" width="0" height="0" classid="clsid:8856f961-340a-11d0-a96b-00c04fd705a2"></object>';
//			document.body.appendChild(o);
//		 
		//预览 
		    try{
		        if($("webbrowser1")){
		            $("webbrowser1").parentNode.removeChild($("webbrowser1"));
		        }
		        
                var web = document.createElement("object");
                web.classid = "clsid:8856f961-340a-11d0-a96b-00c04fd705a2";
                web.id = "webbrowser1";
                document.body.appendChild(web);
                window.print();
		        //$("webbrowser1").ExecWB(6,1);
		    }catch(err){
		        alert("请先下载并安装打印补丁!");
		    } 
	}else{
	    alert("请使用IE打印!");
	}
}

addListener(window, 'onload', function () {
    try {
        var inputs = document.getElementsByTagName("input");
        if (inputs) {
            for (var i = 0; i < inputs.length; i++) {
                var input = inputs[i];
                if (input.type == 'text') {
                    input.focus();
                    break;
                }
            }
        }
    } catch (err) {
        
    }
});
