// ZDSOFT.NET JavaScript Base Ver 040910

var ActRd;
var ActRs=new Array();
function Act(obj,str){eval(obj.type+'.'+str+'(obj)')}
function LoadClass(name){eval(name+'=new '+name+'()')}

function GetIndex(obj)
{
  for(var i=0; i < obj.form.elements.length; i++)
		if ( obj.form.elements[i].uniqueID == obj.uniqueID) return(i);
  return(-1);
}

function GetOffset(obj)
{
	var x=0,y=0;
	if(!obj) return [x,y];
	while(obj)
	{
		x+=parseInt(obj.offsetLeft);
		y+=parseInt(obj.offsetTop);
		obj=obj.offsetParent;
	}
	return [x,y];
}

function Cookie()
{
	this._Cookie=[];
	
	this.Load=function()
	{
		if(document.cookie.indexOf(";")!=-1)
		{
			var _sp,_name,_tp,_tars,_tarslength;
			var _item=document.cookie.split("; ");
			var _itemlength=_item.length;
			while(_itemlength>0)
			{
				_sp=_item[--_itemlength].split("=");
				_name=_sp[0];
				if (_sp.length <2 )
				{
					continue;
				}
				_tp=_sp[1].split(",");
				_tars=_tp.slice(1,_tp.length);
				this._Cookie[_name]=[];
				this._Cookie[_name]=_tars;
				this._Cookie[_name]["timeout"]=_tp[0];
			}
			return true;
		}
	return false;
	}
        
	this.Save=function()
	{
		var _str,_ars,_mars,_marslength,timeout,i,key;
		for(key in this._Cookie)
		{
			if(!this._Cookie[key])return;
			_str=[];
			_mars=this._Cookie[key];
			_marslength=_mars.length;
			for(i=0;i<_marslength;i++)_str[_str.length]=escape(_mars[i]);
			document.cookie=key+"="+_mars["timeout"]+(_str.length>0?",":"")+_str+(_mars["timeout"]==0?"":";expires="+new Date(parseInt(_mars["timeout"])).toGMTString());
		}        
	}
        
	this.Create=function(name,days)
	{
		days=days?days:0;
		if(!this._Cookie[name])this._Cookie[name]=[];
		this._Cookie[name]["timeout"]=days!=0?new Date().getTime()+parseInt(days)*86400000:0;
	}    
        
	this.Modify=function(name,days)
	{
		this.Create(name,days);
	}
			
	this.Delete=function(name)
	{
		this.Create(name,0);
	}     
			
	this.AddItem=function(name,value)
	{
		this._Cookie[name][this._Cookie[name].length]=value;
	}
			
	this.DelItem=function(name,index)
	{
		var _ttime=this._Cookie[name]["timeout"];
		this._Cookie[name]=this._Cookie[name].slice(0,index).concat(this._Cookie[name].slice(parseInt(index)+1,this._Cookie[name].length));
		this._Cookie[name]["timeout"]=_ttime;
	}

	this.GetItem=function(name,index)
	{
		return this._Cookie[name][index];
	}

	this.GetTime=function(name)
	{
		return new Date(parseInt(this._Cookie[name]["timeout"]));
	}

	this.GetCount=function(name)
	{
		return this._Cookie[name].length;
	}

	this.GetCookieCount=function()
	{
		var _length=0,key;
		for(key in this._Cookie)_length++;
		return _length;
	}
        
	this.SetCookie=function(name,value)
	{
		var today = new Date()
		var expires = new Date()
		expires.setTime(today.getTime() + 1000*60*60*24*365)
		document.cookie = name + "=" + escape(value)	+ "; expires=" + expires.toGMTString()
	}
	
	this.GetCookie=function(Name)
	{
		var search = Name + "="
		if(document.cookie.length > 0) 
		{
			offset = document.cookie.indexOf(search)
			if(offset != -1) 
			{
				offset += search.length
				end = document.cookie.indexOf(";", offset)
				if(end == -1) end = document.cookie.length
				return unescape(document.cookie.substring(offset, end))
			}	
		}
		return ""
	}
}	

Number.prototype.Fix = function()
{
	return numFix(this)
}

Number.prototype.Int = function()
{
	return numInt(this)
}

Array.prototype.Clear = function()
{
	this.length=0;
}

Array.prototype.Max = function()
{
	var i, max = this[0];
	for (i = 1; i < this.length; i++)
		if (max < this[i]) max = this[i];
	return max;
}

Array.prototype.Min = function()
{
	var i, min = this[0];
	for (i = 1; i < this.length; i++)
		if (min > this[i]) min = this[i];
	return min;
}

Array.prototype.Sum = function()
{
	var i, sum = 0;
	for (i = 0; i < this.length; i++)
		sum+=this[i]
	return sum;
}

Array.prototype.Left=function(length)
{
	return this.slice(0,length);
}

Array.prototype.Mid=function(start,length)
{
	return this.slice(start,start+length);
}

Array.prototype.Right=function(length)
{
	if(length>=this.length) 
		return this;
	return this.slice(this.length-length,this.length);
}


String.prototype.IsDate = function()
{
	var myReg = /^(\d{4})(-|\/|.)(\d{1,2})\2(\d{1,2})$/; 
	var result=this.match(myReg);
    if(result==null) return false;
	var test= new Date(result[1],result[3]-1,result[4]);
	if ((test.getFullYear()==result[1]) && (test.getMonth()+1==result[3]) && (test.getDate()==result[4]))
	{
		ActRs.Clear();
		ActRs[0]=result[1];ActRs[1]=result[3];ActRs[2]=result[4];
		return true;
	}
	else return false;
}

String.prototype.IsTime = function()
{
	var myReg = /^(\d{1,2})(:)(\d{1,2})\2(\d{1,2})$/; 
	var result=this.match(myReg);
  if(result==null) 
		return false;
	var test= new Date(2000,1,1,result[1],result[3],result[4]);
	if ((test.getHours()==result[1]) && (test.getMinutes()==result[3]) && (test.getSeconds()==result[4]))
	{
		ActRs[3]=result[1];ActRs[4]=result[3];ActRs[5]=result[4];
		return true;
	}
	else return false;
}

String.prototype.IsDateTime = function()
{
	var myReg = this.split(" ");
	if(myReg.length!=2) return false;
	if(myReg[0].IsDate() && myReg[1].IsTime()) return true;
	return false;
}

String.prototype.IsEmail = function()
{
	var myReg = /[\u4e00-\u9fa5]/;
	if(!myReg.test(this))
	{
		myReg = /^[_a-zA-Z0-9][-._a-zA-Z0-9]*@[-_a-zA-Z0-9]+\.[-._a-zA-Z0-9]+(\.[-._a-zA-Z])*$/;
		if (myReg.test(this)) return true;
	}
	else
	{
		myReg = /^[_a-zA-Z0-9\u4e00-\u9fa5][-_.a-zA-Z0-9\u4e00-\u9fa5]*@[-._a-zA-Z0-9\u4e00-\u9fa5]+(\.[-._0-9a-zA-Z\u4e00-\u9fa5]+)*$/;
		if (myReg.test(this)) return true;
	}
	return false;
}

String.prototype.IsIdcard = function()
{
  var myReg = /^[1-9][0-9]{14}$|^[1-9][0-9]{16}[0-9a-zA-Z]$/;
	if(myReg.test(this)) 
		return true;
  return false;
}

String.prototype.IsTelephone = function()
{
	myReg = /[(]/;
	if (!myReg.test(this))
	{
		myReg = /^[1-9][0-9]{6,7}$|^[0-9]{3,4}-[1-9][0-9]{6,7}$|^[0-9]{3,4}-[1-9][0-9]{6,7}-[0-9]{2,8}$/;
		if (myReg.test(this)) return true;
	}
	//else {
		//myReg = /^[1-9][0-9]{6,7}$|^([0-9]{3,4})[1-9][0-9]{6,7}$|^([0-9]{3,4})[1-9][0-9]{6,7}-[0-9]{2,8}$/;
		//if (myReg.test(this)) return true;
	//}
	return false;
}

String.prototype.IsNumber = function()
{
	var myReg = /^[0-9]+$/;
	if(!myReg.test(this)) return false;
	ActRd=parseInt(this)	
	return true;
}

String.prototype.IsFloat = function()
{
	var myReg = /^[0-9.]+$/;
	if(!myReg.test(this)) return false;
	var pos=this.indexOf('.')
	if(pos==-1) return false;
	if(pos!=this.lastIndexOf('.')) return false;
	if(pos==0 || (pos+1)==this.length) return false;
	ActRd=parseFloat(this)
	return true;
}

String.prototype.IsPhone = function()
{
	if(!this.IsNumber()) return false;
	if(this.length != 11 || this<13000000000 || this>13999999999) return false;
	return true;
}

String.prototype.IsDomain = function()
{
	var myReg = /^[0-9a-zA-Z\-]+$/;
	if(myReg.test(this)) return true;
	return false;
}

String.prototype.IsAvail = function()
{
	var myReg = /^[0-9a-zA-Z]+$/;
	if(myReg.test(this)) return true;
	return false;
}

String.prototype.IsEn = function()
{
	var myReg = /^[a-zA-Z]+$/;
	if(myReg.test(this)) return true;
	return false;
}

String.prototype.ConvertHtml = function()
{
	var tmp = this.replace(/\&/g, "&amp;");
  tmp = tmp.replace(/\"/g, "&quot;");
	tmp = tmp.replace(/ /g, "&nbsp;");
  tmp = tmp.replace(/</g, "&lt;");
  //tmp = tmp.replace(/\'/g, "&apos;");
  tmp = tmp.replace(/>/g, "&gt;");
  return tmp;
}

String.prototype.ConvertHtmlWithN = function()
{
	var tmp = this.replace(/\&/g, "&amp;");
    tmp = tmp.replace(/\"/g, "&quot;");
	tmp = tmp.replace(/ /g, "&nbsp;");
    tmp = tmp.replace(/</g, "&lt;");
    tmp = tmp.replace(/>/g, "&gt;");
    //tmp = tmp.replace(/\'/g, "&apos;");
    tmp = tmp.replace(/\r\n/g, "<br>");
    return tmp;
}

String.prototype.ConvertHtmlWithP = function()
{
	var tmp = this.replace(/\&/g, "&amp;");
    tmp = tmp.replace(/\"/g, "&quot;");
	tmp = tmp.replace(/ /g, "&nbsp;");
    tmp = tmp.replace(/</g, "&lt;");
    tmp = tmp.replace(/>/g, "&gt;");
    //tmp = tmp.replace(/\'/g, "&apos;");
    tmp = tmp.replace(/\r\n/g, "</p><p>");
    return tmp;
}

String.prototype.IsCn = function()
{
	var ch,temp,isCN,isTrue;
	isTrue = true;
	for(var i=0;i<this.length;i++)
	{
		ch = this.substring(i,i+1);
		temp = escape(ch);
		isCN = (temp.length == 6)? true:false;
		if(!isCN)
		{
			isTrue = false;
			break;
		}
	}
	return isTrue;
}

String.prototype.isCom_sep_char = function()
{
	var myReg = /^[-()_+*]*$/;
	if(myReg.test(this)) return true;
	return false;
}

String.prototype.IsReg1 = function()
{
	var s,i;
	for(i=0;i<this.length;i++)
	{
		s=this.charAt(i);
		if(s.IsNumber() || s.IsEn() || s.IsCn()) continue;
		return false;
	}
	return i?true:false;
}

String.prototype.IsReg12 = function()
{
	var s,i;
	for(i=0;i<this.length;i++)
	{
		s=this.charAt(i);
		if(s.IsNumber() || s.IsEn() || s.IsCn() || s.isCom_sep_char()) continue;
		return false;
	}
	return i?true:false;
}


String.prototype.Trim = function()
{
	var tmp = this.replace(/(^\s*)|(\s*$)/g, "");
	return tmp.replace(/(^\2005-9-28*)|(\　*$)/g,"");
}

String.prototype.Left = function(n)
{
	return strLeft(this,n);
}

String.prototype.Right = function(n)
{
	return strRight(this,n);
}

String.prototype.Len = function()
{
	var len=0;
	for (var i=0;i<this.length;i++)
	{
		if (this.charCodeAt(i)>255) len+=2; 
		else len++;
	}
	return len;
}

String.prototype.Text = function()
{
	var elm = document.createElement("DIV");
	elm.innerHTML = this;
	return elm.innerText;
}

String.prototype.Html = function()
{
	var elm = document.createElement("DIV");
	elm.innerText = this;
	return elm.innerHTML;
}

String.prototype.Escape = function()
{
	return escape(this);
}

String.prototype.UnEscape = function()
{
	return unescape(this);
}

String.prototype.toInt = function()
{
	
	return parseInt(this);
}

String.prototype.toFloat = function()
{
	return parseFloat(this);
}

String.prototype.toHex = function()
{
	if(!this.IsNumber()) return "";
	var x=parseInt(this);
	var out = "";
	var remainder;
	while (x > 0)
	{
		remainder = x % 16;
		if (remainder < 10)
		{
		  out = remainder + out;
		} 
		else if (remainder == 10)
		{
			out = "a" + out;
		} 
		else if (remainder == 11)
		{
			out = "b" + out;
		} 
		else if (remainder == 12)
		{
			out = "c" + out;
		} 
		else if (remainder == 13)
		{
			out = "d" + out;
		} 
		else if (remainder == 14)
		{
			out = "e" + out;
		} 
		else if (remainder == 15)
		{
			out = "f" + out;
		}
		x = Math.floor(x / 16);
	}
	return out;
}

String.prototype.toDate = function()
{
	ActRs.Clear();
	this.IsDate();
	return new Date(ActRs[0],ActRs[1]-1,ActRs[2]);
}

String.prototype.Hexto = function()
{
	var myReg = /^[0-9a-fA-F]+$/;
	if(!myReg.test(this)) return "0";
	ActRd=parseInt(this,16);
	return ""+ActRd;
}

String.prototype.Octto = function()
{
	var myReg = /^[0-7]+$/;
	if(!myReg.test(this)) return "0";
	ActRd=parseInt(this,8);
	return ""+ActRd;
}

String.prototype.Binto = function()
{
	var myReg = /^[0-1]+$/;
	if(!myReg.test(this)) return "0";
	ActRd=parseInt(this,2);	
	return ""+ActRd;
}

String.prototype.Repeat = function(n)
{
	if (typeof(n) != "number") return "";
	var out = this;
	for (var i = 1; i < n; i++) out += this;
	return out;
}

String.prototype.Reverse = function()
{
	var out = "";
	for (var i = this.length; i >= 0; i--)
	{
		out += this.charAt(i);
	}
	return out;
}

String.prototype.Comp = function(str,m)
{
	return Compstr(this,str,m);
}

String.prototype.addDate = function(mode,d)
{
	return addDate(mode,d,this);
}

String.prototype.Count = function()
{
	var out = new Array(256);
	for (var i = 0; i < this.length; i++)
	{
		if (out[this.charCodeAt(i)] == undefined)
		{
			out[this.charCodeAt(i)] = 1;
		} 
		else 
		{
			out[this.charCodeAt(i)]++;
		}
	}
	return out;
}

function cutStr(str,strlen)
{
  var temp_i=0;
	var temp=0;
	var temp_str="";
	for(temp_i=0;temp_i<str.length;temp_i++)
	{
	
	   if(Math.abs(str.charCodeAt(temp_i))>255)
	      temp+=2;
	   else 
	      temp+=1;
	   
	   if(temp>strlen) 
		 {
	     temp_str=str.substr(0,temp_i)+"...";
		   break;
		 }
		else
		{
		  temp_str=str;
		}
	}
  return  temp_str;   
}

/** 
 *返回查询字符串 已经用encodeURI转码过
 *输入 form对象
 *输出 用encodeURI转码过查询字符串，最前边是没有&号的，如：str1=aaa&str2=bbb
 */

String.prototype.myEncode = function()
{
	return this.replace(/\&/g, "%26").replace(/\?/g,"%3F").replace(/\#/g,"%23").replace(/\+/g,"%2B");
}

/** 
 *返回查询字符串 已经用encodeURI转码过
 *输入 form对象
 *输出 用encodeURI转码过查询字符串，最前边是没有&号的，如：str1=aaa&str2=bbb
 */
function generateQueryString(aform)
{
	var qstr = "";
	if (aform != null)
	{
		for (var i = 0 ; i < aform.length ; i++ )
		{
			//qstr += aform[i].name + "=" + escape(aform[i].value) + "&";
			//qstr += aform[i].name + "=" + encodeURI(aform[i].value) + "&";
			if (aform[i].type == "text" || aform[i].type == "textarea")
			{
				qstr += aform[i].name + "=" + aform[i].value.myEncode() + "&";
			}
			else if (aform[i].type == "radio")
			{
				if (aform[i].checked)
				{
					qstr += aform[i].name + "=" + aform[i].value.myEncode() + "&";
				}
			}
			else if (aform[i].type == "checkbox")
			{
				if (aform[i].checked)
				{
					qstr += aform[i].name + "=" + aform[i].value.myEncode() + "&";
				}
			}			
			else if (aform[i].type == "button")
			{
			}
			else {
				qstr += aform[i].name + "=" + aform[i].value.myEncode() + "&";
			}
		}
		if (qstr.length > 0 )
		{
			qstr = qstr.substring(0,qstr.length - 1);
		}
	}
	return qstr;
}

//Cookie
function setCookie(name, value, path, domain) 
{
  var curCookie = name + "=" + escape(value) +
      "; expires=Thu, 6 Jan 2033 08:05:36 UTC" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "");
  document.cookie = curCookie;
}

function getCookie(name) 
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) 
	{
    begin = dc.indexOf(prefix);
    if (begin != 0) return "";
  } 
  else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) 
{
  if (getCookie(name)) 
	{
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}