/*最后修收时间：20080616*/

function $(objID) {return document.getElementById(objID)};
function $F(objID) {return document.getElementById(objID).value};
function $$(node){return document.getElementsByTagName(node)};
function $U(str){return encodeURIComponent(escape(str))};
function $E(str){return encodeURIComponent(str)};
String.prototype.trim =function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
/*动态加载JS*/
function JsLoader(sUrl,fCallback){
	var _script = document.createElement("script");
	_script.setAttribute("type","text/javascript");
	_script.setAttribute("src", sUrl);
	$$("head")[0].appendChild(_script);
}
/*动态加CSS*/
function CssLoader(sUrl){
	var _style=document.createElement('link');
	_style.setAttribute("type","text/css");
	_style.setAttribute("href", sUrl);
	_style.setAttribute("rel", "stylesheet");
	$$("head")[0].appendChild(_style);
}
/*添加事件监听*/
function addEvent(obj,type,fn){ 
	if (obj.attachEvent){ 
		obj['e'+type+fn] = fn; 
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );} 
		obj.attachEvent('on'+type,obj[type+fn]); 
	}else{
		obj.addEventListener(type,fn,false); 
	}
} 
/*移除事件监听*/
function removeEvent(obj,type,fn) { 
	if (obj.detachEvent){ 
		obj.detachEvent('on'+type,obj[type+fn]); 
		obj[type+fn]=null; 
	}else{
		obj.removeEventListener(type,fn,false); 
	}
}
/*设置对象的样式名*/
function setClassName(objID,objClassName){
	$(objID).className=objClassName;
}
/*设置对象的样式属生值*/
function setStyle(objID,objStyle,StyleValue){
	$(objID).style.objStyle=StyleValue;
}
/*判断是否为数字*/
function isnum(str) {
	var patn = /^[0-9-\/]+$/;
	if(!patn.test(str)) return false;
	return true;
}
//写入COOKIE
function setcookie(name,value){
	var Days = 15;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();
}
//获取COOKIE
function getcookie(name){
	var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr!= null) return unescape(arr[2]);
        return null;
}
//ajax类
function AJAX(){
	var _p={asynchronous:true,method:"GET",parameters:"",mime:"text/html;charset=GB2312",loadingid:"loading",isdisabled:true};
	for(var key in arguments[0]){ _p[key]=arguments[0][key]; };
	this.xmlhttp=function (){
		var Version = ["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
		try{ for(var i=0;i<Version.length;i++)return new ActiveXObject(Version[i]);}
		catch(e){try{return new XMLHttpRequest();}catch(e){return null;}}
	};
	this.dis=function(str){
		if(_p["isdisabled"]==true){
			var _arr;
			str==1? _arr=new Array("false","hidden"):_arr=new Array("true","visible");
			for (k=0;k<$$("select").length;k++){$$("select")[k].style.visibility=_arr[1];};
			document.body.onselectstart = function(){return _arr[0];};
			document.body.oncontextmenu = function(){return _arr[0];};
			if (str==1){
				for(j=0;j<$$("input").length;j++){$$("input")[j].disabled=true;}
				for(m=0;m<$$("textarea").length;m++){$$("textarea")[m].disabled=true;}
			}
			else {
				for(j=0;j<$$("input").length;j++){$$("input")[j].disabled=false;}
				for(m=0;m<$$("textarea").length;m++){$$("textarea")[m].disabled=false;}
			};
		};
	};
	var _x=this.xmlhttp();
	var _t=this;
	if (_x!=null){
		var _url=_p["url"];
		if (_p["parameters"]==""||_p["method"].toUpperCase()=="POST"){ _url=_url}
		else {_url+="?"+_p["parameters"]};
		_url+=(_url.indexOf("?") >= 0)?"&nowtime="+new Date().getTime():"?nowtime=" + new Date().getTime();
		_x.open(_p["method"],_url,_p["asynchronous"]);
		if(_x.overrideMimeType)_x.overrideMimeType(_p["mime"]);
		_x.onreadystatechange=function (){
			if(_x.readyState==4){
				if(_x.status==200) {  
					if($(_p["loadingid"])){_t.dis(0);$(_p["loadingid"]).innerHTML="";};
					_p["onComplete"]?_p["onComplete"](_x):"";
				}else _p["onError"]?_p["onError"](_x):"";
			}else if($(_p["loadingid"])){_t.dis(1);$(_p["loadingid"]).innerHTML=(_p["onLoading"]?_p["onLoading"]:"")};
		};
		if(_p["method"].toUpperCase()=="POST"){_x.setRequestHeader("Content-Type","application/x-www-form-urlencoded")};	
		_x.send(_p["method"].toUpperCase()=="POST"?_p["parameters"]:null);	
	};
};

/*取得对象的坐标及宽高*/
function getTLWH(e){
	var t=e.offsetTop; 
	var l=e.offsetLeft;
	var w=e.offsetWidth; 
	var h=e.offsetHeight;
	while(e=e.offsetParent) {t+=e.offsetTop;l+=e.offsetLeft;}; 
	return{top:t,left:l,width:w,height:h,bottom:t+h,right:l+w};
};

/*取得网页实际宽高*/
function getWH(){
	with(document.documentElement){
		var w=(scrollWidth>clientWidth)?scrollWidth:clientWidth
		var h=(scrollHeight>clientHeight)?scrollHeight:clientHeight
	}
	return{width:w,height:h};
}

function tip(event,_t,tipcontent,ajaxurl){
	this._hidediv=function(){if(document.getElementById("_tipdiv")!=null)document.body.removeChild(document.getElementById("_tipdiv"));}
	evt=event?event:window.event
	var x=evt.clientX;
	var y=evt.clientY;
	//alert(document.documentElement.scrollTop);
    this._hidediv();
	var tipdiv=document.createElement("DIV");
	tipdiv.setAttribute("id","_tipdiv");
	tipdiv_width=200;
	if(document.documentElement.scrollWidth-x>tipdiv_width)
		tipdiv.style.left = x + document.documentElement.scrollLeft + "px";
	else
		tipdiv.style.left = x + document.documentElement.scrollLeft-tipdiv_width + "px";
	tipdiv.style.top =  y + document.documentElement.scrollTop + "px";
	tipdiv.style.width=tipdiv_width+"px";
	tipdiv.style.background="#E5F2F8"
	tipdiv.style.padding="5px";
	tipdiv.style.ZIndex='15';
	tipdiv.style.fontSize='12px';
	tipdiv.style.position='absolute';
	tipdiv.style.textalign="left";
	document.body.appendChild(tipdiv);
	addEvent(_t,"mouseout",this._hidediv)
	if (tipcontent==""){
        if (ajaxurl!=""){
			if (ajaxurl.indexOf("?")>0){var post_url=ajaxurl.split("?")[0];var post_param=ajaxurl.split("?")[1];
			}else{var post_url=ajaxurl;var post_param="";};
			AJAX({
				url:post_url,
				parameters:post_param,
				isdisabled:"disabled",
				loadingid:"_tipdiv",
				onLoading:"<font color=red><img src=\"gbook/load.gif\"/>正在加载...</font>",
				onComplete:function(e){
					$("_tipdiv").innerHTML=e.responseText;
				}
			});
		}
	}else{
		$("_tipdiv").innerHTML=tipcontent;
	}
}

//DIV对话框
function Alert(alert_width,alert_height,div_title,div_content){
    this.ok= function(){
		if ($("Discoloration_id"))document.body.removeChild($("Discoloration_id"));
		if ($("alert_div"))document.body.removeChild($("alert_div"));
		document.body.oncontextmenu = function(){return true;}
		for (i=0;i<$$("select").length;i++){$$("select")[i].style.visibility="visible";}
	}
    this.ok();
	if (typeof(alert_width)=="undefined")return false;
	with(document.documentElement){
		var Discoloration_id = document.createElement("DIV");
		Discoloration_id.id = "Discoloration_id";
		Discoloration_id.style.position = "absolute";
		Discoloration_id.style.left = "0px";
		Discoloration_id.style.top = "0px";
		if(scrollWidth>clientWidth)Discoloration_id.style.width=scrollWidth+"px";
		else Discoloration_id.style.width=clientWidth+"px";
		if(scrollHeight>clientHeight)Discoloration_id.style.height=scrollHeight+"px";
		else Discoloration_id.style.height=clientHeight+"px";
		Discoloration_id.style.background = "#E7F5FF";
		Discoloration_id.style.zIndex = "10000";
		Discoloration_id.style.filter = "alpha(opacity=50)";
		Discoloration_id.style.opacity = 0.5;
		document.body.appendChild(Discoloration_id);
		var alert_div = document.createElement("DIV");
		alert_div.id="alert_div";
		alert_div.style.position = "absolute";
		/*var intwh=20;
		this.setwidth=function(){
			var ii=parseInt(alert_div.style.width.replace("px",""))
			if(isNaN(ii)==true)ii=0;
			if(ii<alert_width.replace("px","")){
				ii+=intwh;
				alert_div.style.width=ii+"px";
			}else{
				clearInterval(ttw);
			}
		}
		var ttw=setInterval(this.setwidth,5);
		*/
		alert_div.style.width=alert_width;
		alert_div.style.height=alert_height;
		alert_div.style.zIndex = "10001";
		alert_div.style.left = clientWidth/2-alert_width.replace(/px/g,"")/2+"px";
		alert_div.style.top = clientHeight/2-alert_height.replace(/px/g,"")/2+"px";	
		var strHtml="";
		strHtml="<div style=\"margin:0px;padding:0px;border:1px solid #A2D2F0;background:#FFF;width:100%;height:110% !important;height:100%;\">\n";
		strHtml+="<div style=\"padding:1px;height:25px !important;height:28px;line-height:25px;background:#E8F6FF;color:##0042FF;font-weight:bold;\"><span style=\"float:left;padding-left:20px;\">"+div_title+"</span><span style=\"float:right;cursor:pointer;margin-right:10px;padding-top:5px;\"><img src=\"gbook/logout.gif\" onclick=\"ok()\" style=\"vertical-align:middle;\" alt=\"关闭窗口\"/></span></div>\n";
		strHtml+="<div style=\"clear:both;padding:8px;\">"+div_content+"</div>";
		strHtml+="</div>\n";
		alert_div.innerHTML = strHtml;
		document.body.appendChild(alert_div);
		for (i=0;i<$$("select").length;i++){$$("select")[i].style.visibility="hidden";}
		oncontextmenu = function(){return false;}
	}
}

//自动提示
//onKeyUp='new Suggest({thisobj:this,callback:function(){playmp3("",1)},ajaxurl:"mp3.asp?s=suggest&songname="+encodeURI(this.value).replace(/%/gi,"!"),isdisabled:false,splitstr:"\n",ssplitstr:" "});'
function Suggest(){
	var _p={isdisabled:false,splitstr:",",ssplitstr:""};
	for(var key in arguments[0]){ _p[key]=arguments[0][key];};	
	thisself=_p["thisobj"];
	callback=_p["callback"];
	var ajaxurl=_p["ajaxurl"];
	var _t=this;
	if (ajaxurl.indexOf("?")>0){
		var post_url=ajaxurl.split("?")[0];
		var post_param=ajaxurl.split("?")[1];
	}else{
        var post_url=ajaxurl;
		var post_param="";
	};
	this.back=function(){};
	this.hide_suggest=function(){if($("suggest"))thisself.parentNode.removeChild($("suggest"));};
	//if(!document.all) {window.document.addEventListener("click",this.hide_suggest,false)}
	//else {window.document.attachEvent("onclick",this.hide_suggest)};
	AJAX({
	    url:post_url,
		parameters:post_param,
		onComplete:suggestbody,
        isdisabled:_p["isdisabled"]	
	});
	function suggestbody(req){
		if(req.responseText!=""){
			if(!$("suggest")){
				var suggestdiv=document.createElement("DIV");
				suggestdiv.setAttribute("id","suggest");
				suggestdiv.style.width=getTLWH(thisself).width+'px';
				suggestdiv.style.left=getTLWH(thisself).left+"px";
				suggestdiv.style.top=getTLWH(thisself).bottom+'px';
				suggestdiv.style.height=0;
				suggestdiv.style.zIndex='1500';
				suggestdiv.style.position='absolute';
				suggestdiv.style.textalign="left";
				thisself.parentNode.appendChild(suggestdiv);
			}
			var result=""
			arr=req.responseText.split(_p["splitstr"]);
			for (i=0;i<arr.length ;i++ ){
				if (arr[i]!=""||arr[i]!="undefined"||arr[i]!=null){
					if(_p["ssplitstr"].length>0){
						if (typeof(callback)==""||typeof(callback)=="undefined") {
							result+="<li onclick=\"thisself.value=this.childNodes[0].nodeValue;\" onmouseover=\"this.className='select'\" onmouseout=\"this.className=''\">"+arr[i].split(" ")[1]+"<span class=\"c2\">约"+arr[i].split(" ")[0]+"条结果</span></li>";
						}else{
							result+="<li onclick=\"thisself.value=this.childNodes[0].nodeValue;callback()\" onmouseover=\"this.className='select'\" onmouseout=\"this.className=''\">"+arr[i].split(" ")[1]+"<span class=\"c2\">约"+arr[i].split(" ")[0]+"条结果</span></li>";
						};
					}else{
						if (typeof(callback)==""||typeof(callback)=="undefined") {
							result+="<li onclick=\"thisself.value=this.childNodes[0].nodeValue;\" onmouseover=\"this.className='select'\" onmouseout=\"this.className=''\">"+arr[i]+"</li>";
						}else{
							result+="<li onclick=\"thisself.value=this.childNodes[0].nodeValue;callback()\" onmouseover=\"this.className='select'\" onmouseout=\"this.className=''\">"+arr[i]+"</li>";
						};
					};
				};
			};
			$("suggest").innerHTML="<ul>"+result+"</ul>";
		};
	};
};


//消息提示可定时
function msg(errstr,msgid,timeout){
    if (msgid==""||typeof(msgid)=="undefined")msgid="loading";
    if (timeout==""||typeof(timeout)=="undefined")timeout=3000;
	if ($(msgid)){
		$(msgid).innerHTML="<font color=red>"+errstr+"</font>";
		setTimeout('$("'+msgid+'").innerHTML=""',timeout);
	}
}

//显示隐藏
function showhide(id) {
	var panel=$(id);
	if(panel) {
		if(panel.style.display=='none'){
			panel.style.display='block';
		}else {
			panel.style.display='none';
		}
	}
}		

window.onerror=reportError;
function reportError(msg,url,line){var str="发现如下的的错误:\n"; str +="错误:"+msg+"第:"+line+"行"; alert(str);return true;}

