/*
Yobur Expand Class
Author：Yobur Wung
E-Mail:yobur@vip.qq.com
ASP+AJAX→Site:http://www.upasp.net
Version:v1.1.8
Update:11:08 2009-4-10
*/

//引用变量说明：变量的书写采用匈牙利命名法，即以数据类型的小写字母作为变量的第一个字母，另外补充了一种数据类型：v 不确定类型变量
function $(s,t,v,s2,o){
	if(!t) return document.getElementById(s);
	switch(t){
		case 0:
			return (typeof v=="undefined")?document.getElementsByName(s):v.getElementsByName(s);
			break;
		case 1:
			return (typeof v=="undefined")?document.getElementsByTagName(s):v.getElementsByTagName(s);
		case 2:
			var oObject=(!o)?document.getElementsByName(s):o.getElementsByName(s);
		case 3:
			var oObject=(!oObject)?((!o)?document.getElementsByTagName(s):o.getElementsByTagName(s)):oObject;
			var aReturn=[];
			if(!document.all&&v=="className") v="class";//兼容FIREFOX的class属性，IE为className
			if(document.all&&v=="class") v="className";
			if(navigator.userAgent.toLowerCase().indexOf("msie 8.0")!=-1&&v=="className")
				v="class";
			for(var iI=0;iI<oObject.length;iI++)
				if(oObject[iI].getAttribute(v)==s2)
					aReturn.push(oObject[iI]);
			return aReturn;
			break;
	}
}

//填充数据到对象
function $B(v,o,v2,s)
{
	switch(o.nodeName.toLowerCase())
	{	
		case "div":
		case "td":
		case "span":
			o.innerHTML=v;
			break;
		case "textarea":
		case "input":
			o.value=v;
			break;
		case "select":
			$B2S(v,o,false,v2,s);
	}
	//alert(o.nodeName+"\n"+o.type);
}
/*填充数据到下拉框
参数说明：
第一个参数为传入数据，为字符串或者数组对象
第二个参数为需要绑定的对象
第三个为是否需要保留现有的数据
第四个参数用于option的value值，如果为空则引用text为value
*/
function $B2S(v,o,b,v2,s)
{
	v=(typeof v=="string")?a.split("[$$]"):v;//将字符串转换成数组
	b=(typeof b=="undefined")?false:b;//对b不存在进行初始化
	v2=(typeof v2=="undefined")?v:(typeof v2=="string")?v2.split("[$$]"):v2;//引用v2不存在时为v1
	if(!b) for(var i=o.length-1;i>=0;i--) o.options[i]=null;//b为false剔除原数据
	var iLen=(o.length>0)?o.length:0;
	for(var i=0;i<v.length;i++)
	{
		o.options[iLen+i]=new Option(v[i],v2[i]);
		(typeof s!="undefined"&&v2[i]==s)?o.options[iLen+i].setAttribute("selected","selected"):"";
	}
}

//绑定Tab键事件到对象。setCaret,CatchTab均为捕捉事件，insertAtCaret为执行将光标定位插入

function $BT(o)
{
	o.onkeydown=new Function("CatchTab(arguments[0],this)");
	//o.onkeydown=function(event)
//		{
//			CatchTab(event,o);
//		}
	o.onselect=new Function("setCaret(this)");
	o.onclick=new Function("setCaret(this)");
	o.onkeyup=new Function("setCaret(this)");
}

function CatchTab(e,o)
{
	e=window.event?window.event:e;
	if(e.keyCode==9||e.charCode==9)
	{
		insertAtCaret(o,"\t");
		e.returnValue=false;
	}
}

function setCaret(o)
{   
	if(o.createTextRange){
		o.caretPos=document.selection.createRange().duplicate();   
	}
}

function insertAtCaret(o,sValue)
{   
	if(document.all){     
		if(o.createTextRange&&o.caretPos)
		{   
			var caretPos=o.caretPos;   
			caretPos.text=caretPos.text.charAt(caretPos.text.length-1)==''?sValue+'':sValue;   
		}else{   
			o.value=sValue;   
		}   
	}else{
		if(o.setSelectionRange){   
			var iRangeStart=o.selectionStart;   
			var iRangeEnd=o.selectionEnd;   
			var s1=o.value.substring(0,iRangeStart);   
			var s2=o.value.substring(iRangeEnd);   
			o.value=s1+sValue+s2;   
		}else{   
			alert("This version of Mozilla based browser does not support setSelectionRange");
		}
	}   
}

//创建对象
function $C(s,b){return (!b)?document.createElement(s):document.createTextNode(s);}

//取对象在浏览器中的位置
function $P(o)
{
	var ua=navigator.userAgent.toLowerCase();
	var isOpera=(ua.indexOf('opera') != -1);
	var isIE=(ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
	if(o.parentNode===null||o.style.display == 'none')
		return {x:0,y:0};    
	var parent=null;
	var pos=[];
	var box;     
	if(o.getBoundingClientRect)//IE
	{
		box=o.getBoundingClientRect();
		var scrollTop=Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		var scrollLeft=Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		return {x:box.left+scrollLeft,y:box.top+scrollTop};
	}else if(document.getBoxObjectFor){// gecko
		box=document.getBoxObjectFor(o); 
		varborderLeft=(o.style.borderLeftWidth)?parseInt(o.style.borderLeftWidth):0; 
		var borderTop=(o.style.borderTopWidth)?parseInt(o.style.borderTopWidth):0; 
		pos=[box.x - borderLeft, box.y - borderTop];
	}else{// safari & opera    
		pos=[o.offsetLeft, o.offsetTop]; 
		parent=o.offsetParent;     
		if(parent!=o)
		{ 
			while(parent)
			{ 
				pos[0] += parent.offsetLeft; 
				pos[1] += parent.offsetTop; 
				parent=parent.offsetParent;
			} 
		}
		if(ua.indexOf('opera')!=-1||( ua.indexOf('safari')!=-1&&el.style.position=='absolute'))
		{ 
			pos[0] -= document.body.offsetLeft;
			pos[1] -= document.body.offsetTop;         
		}    
	}              
	if(o.parentNode)
	{ 
		parent=o.parentNode;
	}else{
		parent=null;
	}
	while(parent&&parent.tagName!='BODY'&&parent.tagName!='HTML')
	{ // account for any scrolled ancestors
		pos[0] -= parent.scrollLeft;
		pos[1] -= parent.scrollTop;
		if(parent.parentNode)
		{
			parent=parent.parentNode;
		}else{
			parent=null;
		}
	}
	return {x:pos[0],y:pos[1]};
}

//b不存在为普通跳转 b为true时
function $U(sUrl,b)
{
	if(!sUrl)
	{
		window.location.reload(true);
		return false;
	}
	if(typeof b=="undefined")
		window.location=sUrl;
	else
		window.location.replace(sUrl);
}

//获取某表单对象的值  --DIV/TD/SPAN的取值
function $V(s)
{
	switch($(s).nodeName.toLowerCase())
	{
		case "input":
		case "textarea":
		case "select":
			return $(s).value;
			break;
		default:
			return $(s).innerHTML;
	}
};

//扩展HTMLElement对象，使其支持outerHTML方法
if(typeof(HTMLElement)!="undefined" && !window.opera) 
{ 
	HTMLElement.prototype.__defineGetter__("outerHTML",function() 
	{
		var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++) 
		if(a[i].specified) 
		str+=" "+a[i].name+'="'+a[i].value+'"'; 
		if(!this.canHaveChildren) 
		return str+" />"; 
		return str+">"+this.innerHTML+"</"+this.tagName+">"; 
	}); 
    HTMLElement.prototype.__defineSetter__("outerHTML",function(s) 
    { 
        var r = this.ownerDocument.createRange(); 
         r.setStartBefore(this); 
        var df = r.createContextualFragment(s); 
        this.parentNode.replaceChild(df, this); 
        return s; 
     }); 
    HTMLElement.prototype.__defineGetter__("canHaveChildren",function() 
    { 
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase()); 
     }); 
}

Date.prototype.dateAdd = function(interval,number) 
{ 
	var d = this; 
	var k={'y':'FullYear', 'q':'Month', 'm':'Month', 'w':'Date', 'd':'Date', 'h':'Hours', 'n':'Minutes', 's':'Seconds', 'ms':'MilliSeconds'}; 
	var n={'q':3,'w':7}; 
	eval('d.set'+k[interval]+'(d.get'+k[interval]+'()+'+((n[interval]||1)*number)+')'); 
	return d;
} 
Date.prototype.dateDiff = function(interval,objDate2) 
{ 
	var d=this, i={}, t=d.getTime(), t2=objDate2.getTime(); 
	i['y']=objDate2.getFullYear()-d.getFullYear(); 
	i['q']=i['y']*4+Math.floor(objDate2.getMonth()/4)-Math.floor(d.getMonth()/4); 
	i['m']=i['y']*12+objDate2.getMonth()-d.getMonth(); 
	i['ms']=objDate2.getTime()-d.getTime(); 
	i['w']=Math.floor((t2+345600000)/(604800000))-Math.floor((t+345600000)/(604800000)); 
	i['d']=Math.floor(t2/86400000)-Math.floor(t/86400000); 
	i['h']=Math.floor(t2/3600000)-Math.floor(t/3600000); 
	i['n']=Math.floor(t2/60000)-Math.floor(t/60000); 
	i['s']=Math.floor(t2/1000)-Math.floor(t/1000); 
	return i[interval]; 
}

String.prototype.Trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");} 
String.prototype.LTrim = function(){ return this.replace(/(^\s*)/g, ""); } 
String.prototype.RTrim = function(){return this.replace(/(\s*$)/g, ""); }
String.prototype.eLength=function()
{
	var iCount=0;
	for(var i=0;i<this.length;i++)
	{
		iCount++;
		if(this.charCodeAt(i)<0||this.charCodeAt(i)>255)
			iCount++;
	}
	return iCount;
}
String.prototype.left	=function(iLen){return (typeof iLen=="undefined")?this:this.substr(0,iLen);}
String.prototype.eLeft	=function(iLen){
	if(typeof iLen=="undefined"||this.eLength<=iLen) return this;
	var i=0,iRealLen=0;
	while(iLen>0)
	{
		if(0<=this.charCodeAt(i)&&this.charCodeAt(i)<=255)
		{
			iLen--;
		}
		else
		{
			iLen -= 2;
		}
		i++;
		if(iLen>=0) {iRealLen++;}
	}
	return this.substr(0,iRealLen);
}
String.prototype.right	=function(iLen){return (typeof iLen=="undefined")?this:this.substr(this.length-iLen);}
String.prototype.eRight	=function(iLen){
	if(typeof iLen=="undefined"||this.eLength<=iLen) return this;
	var i=0,iRealLen=0;
	while(iLen>0)
	{
		if(0<=this.charCodeAt(this.length-i)&&this.charCodeAt(this.length-i)<=255)
		{
			iLen--;
		}
		else
		{
			iLen -= 2;
		}
		i++;
		if(iLen>=0) iRealLen++;
	}
	return this.substr(this.length-iRealLen);
}

Array.prototype.rndSelect=function(iNum,bReserve,bReturn,sJoin)
{	//参数说明：iNum——取出几个，默认全取出；sJoin——sJoin以什么分隔，默认为英文的","；bReserve——是否保留源数组，默认为true，即保留；bReturn——以字符串还是以数组形式返回,默认为true，即字符串返回
	//return all array whose length is 1 
	if(this.length==1) return this[0];
	//Initialized the options
	if(typeof iNum=="undefined"||typeof iNum!="number"||iNum>this.length||iNum<1) iNum=this.length;
	if(typeof bReserve!="boolean") bReserve=true;
	if(typeof bReturn!="boolean") bReturn=true;
	if(typeof sJoin=="undefined") sJoin=",";
	
	var aTempArray;
	aTempArray=bReserve?this.toString().split(","):this;
	
	var iTempNum;
	var oStringBuffer=new StringBuffer();
	
	while(iNum>0)
	{
		var iLength=aTempArray.length;
		iTempNum=Math.floor(Math.random()*iLength);
		oStringBuffer.append(aTempArray[iTempNum]);
		aTempArray.splice(iTempNum,1);
		iNum--;
	}
	
	return oStringBuffer.toString(bReturn,sJoin);
}

//查找数组中等于参数s的项
Array.prototype.indexOf=function(s)
{
	for(var i=0;i<this.length;i++) if(s==this[i]) return i;
	return -1;
}


//打包的字符串连接类，用于提高字符串的连接速度
function StringBuffer()
{
	this._strings_=new Array;
	
	if(typeof StringBuffer._initialized=="undefined")
	{
		StringBuffer.prototype.append=function(str)
		{
			this._strings_.push(str);
		}
		StringBuffer.prototype.toString=function(bReturn,sJoin)
		{
			if(typeof bReturn!="boolean") bReturn=true;
			if(typeof sJoin=="undefined") sJoin="";
			if(bReturn) return this._strings_.join("");
			else return this._strings_.join(sJoin);
		};
		StringBuffer._initialized=true;
	}
}

function Ajax()
{
	Ajax.Queue=[];
	var oXmlHttp=false;
	Ajax.pointer=this;//存储指针
	Ajax.locked=false;
	
	if(typeof Ajax._initialized=="undefined")
	{
		//入列
		Ajax.prototype.enqueue=function(sUrl,bMethod,sQuery,oFun,aArgs)
		{
			try{Ajax.Queue.push([sUrl,bMethod,sQuery,oFun,aArgs]);}catch(e){alert("error");}
		}
		
		//创建Ajax请求对象
		Ajax.prototype.createAjax=function()
		{
			if(window.ActiveXObject)
			{
				try
				{
					oXmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					Ajax.createRequestObject=new ActiveXObject('Microsoft.XMLHTTP');
					//Ajax.createString="oXmlHttp=new ActiveXObject('Microsoft.XMLHTTP')";
				}catch(e){
					oXmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
					Ajax.createRequestObject=new ActiveXObject('Msxml2.XMLHTTP');
					//Ajax.createString="oXmlHttp=new ActiveXObject('Msxml2.XMLHTTP')";
				}
			}else if(window.XMLHttpRequest){
				oXmlHttp=new XMLHttpRequest();
				Ajax.createRequestObject=new XMLHttpRequest();
				//Ajax.createString="oXmlHttp=new XMLHttpRequest()";
			}
			
			if(!oXmlHttp) window.status="对不起，您的浏览器不支持Ajax，请升级浏览器或者开启JavaScript功能！";
		}
		
		Ajax.prototype.appendRequest=function(sUrl,bMethod,sQuery,oFun,aArgs)
		{
			
			if(Ajax.locked){
				this.enqueue(sUrl,bMethod,sQuery,oFun,aArgs);
				//window.status="Wait for a moment,the Ajax Request was Locked!";
				return false;
			}
			Ajax.locked=true;
			if(typeof Ajax.createRequestObject=="undefined") this.createAjax();
			else oXmlHttp=Ajax.createRequestObject;
				//eval(Ajax.createString);

			if(bMethod)
			{
				oXmlHttp.open("POST",sUrl,true);
				oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				oXmlHttp.setRequestHeader("Content-length",sQuery.length);
				oXmlHttp.send(sQuery);
			}else{
				oXmlHttp.open("GET",sUrl,true);
				oXmlHttp.send(null);
			}
			
			oXmlHttp.onreadystatechange=function()
			{
				if(oXmlHttp.readyState==4)
				{
					try{//兼容FIREFOX的错误：Component returned failure code: 0x80040111 
						if(oXmlHttp.status=="200")
						{
							if(typeof oFun=="function")
							{
								function oF(){};
								(typeof aArgs=="undefined")?aArgs=[oXmlHttp.responseText]:aArgs.unshift(oXmlHttp.responseText);
								oFun.call(oF,aArgs);
	
								oF();
								//eval(oFun+"("+aArgs+");");
							}else{
								//alert(oXmlHttp.responseText);
								document.body.appendChild(document.createTextNode(oXmlHttp.responseText));
								//window.status=oXmlHttp.responseText;
							}
						}else{
							if(typeof oFun=="undefined")
							{
								window.status="友情提示：网络延时或者服务程序出错，请刷新页面重试！        Error Code:"+oXmlHttp.status;
							}else{
								function oF(){};
								oFun.call(oF,'ServerError');
								oF();
							}
							
						}
					}catch(e){
						
						if(typeof oFun=="undefined")
						{
							window.status="友情提示：网络延时或者服务程序出错，请刷新页面重试！        Error Code:"+oXmlHttp.status;
						}else{
							function oF(){};
							oFun.call(oF,'ServerError');
							oF();
						}
					}
					Ajax.locked=false;
				
					if(Ajax.Queue.length>0){
						var a=Ajax.Queue[0];
						Ajax.Queue.shift();
						Ajax.pointer.appendRequest(a[0],a[1],a[2],a[3],a[4]);
					}//else{window.status="";}
				}
				
			}
		}
		Ajax._initialized=true;
	}
}

function MoveOverTip(sID,iWidth,iHeight)
{
	this.id		=(!sID)?"yoburTip":sID;
	this.width	=(!iWidth)?200:iWidth;
	this.height	=(!iHeight)?"auto":iHeight;
			
	if(typeof MoveOverTip._initialized=="undefined")
	{
		MoveOverTip.prototype.$C=function()
		{
			var o=$C("div");
			o.id			=this.id;
			o.style.width	=this.width+"px";
			
			if(this.height=="auto"||!document.all)
				o.style.height	="auto";
			else
				o.style.height	=this.height+"px";
			o.style.position="absolute";
			o.style.backgroundColor="#FFFFFF";
			o.style.display	="none";
			o.style.border	="1px solid #8ccfff";
			o.style.padding	="5px 10px";
			o.style.textAlign="left";
			o.style.lineHeight="22px";
			o.style.filter="Alpha(Opacity=90)";
			o.style.opacity="0.90";
			o.style.zIndex=15;
			
			document.body.appendChild(o);
		}
		
		
		MoveOverTip.prototype.$B=function(o,v)
		{
			if(!o) return false;
			
			if(!$(this.id)){this.$C();}
			
			if(typeof v=="string")
			{
				this.innerHTML=v;
				$(this.id).innerHTML=this.innerHTML;
			}
			
			var oThis = this;
			o.onmouseover = function(event)
			{
				oThis.onmouseOver(event);
			}
			o.onmousemove = function(event)
			{
				oThis.onmouseMove(event);
			}
			o.onmouseout = function(event)
			{
				oThis.onmouseOut(event);
			}
		}
		
		MoveOverTip.prototype.$NB=function(o)
		{
			$(this.id).style.display="none";
			
			o.onmouseover="";
			o.onmousemove="";
			o.onmouseout="";
		}
		
		MoveOverTip.prototype.onmouseOver=function(e)
		{
			var e=(!e)?window.event:e;
			var o=$(this.id);
			o.innerHTML=this.innerHTML;

			var iClientWidth=Math.max(document.body.clientWidth,document.documentElement.clientWidth);
			var iScrollTop=Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			o.style.left=(e.clientX+this.width>iClientWidth)?(e.clientX-(this.width+10))+"px":(e.clientX-2)+"px";    
			o.style.top=(e.clientY+20+iScrollTop)+"px";
			o.style.display="block";
		}
		
		MoveOverTip.prototype.onmouseMove=function(e)
		{
			this.onmouseOver(e);
		}
		
		MoveOverTip.prototype.onmouseOut=function()
		{
			$(this.id).style.display="none";
		}
		
		MoveOverTip._initialized=true;
	}
}

function loadXMLDoc(sUrl) 
{
	try //Internet Explorer
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	catch(e)
	{
		try //Firefox, Mozilla, Opera, etc.
		{
			xmlDoc=document.implementation.createDocument("","",null);
		}
		catch(e) {alert(e.message)}
	}
	try 
	{
		xmlDoc.async=false;
		xmlDoc.load(sUrl);
		return(xmlDoc);
	}
	catch(e) {alert(e.message)}
	return(null);
}

function copy_clip(s)
{
	if (window.clipboardData) 
	{
		window.clipboardData.setData("Text", s);
	}else if(window.netscape){
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}catch(e){
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
		}
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=s;
		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;
}

