// JavaScript Document

String.prototype.trim = function(){	return this.replace(/(^\s*)|(\s*$)/g, "");}
String.prototype.lengthW = function(){	return this.replace(/[^\x00-\xff]/g,"**").length;}
String.prototype.isEmail = function(){	return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this);}
String.prototype.existChinese = function(){return /^[\x00-\xff]*$/.test(this);}
String.prototype.isUrl = function(){	return /^http[s]?:\/\/([\w-]+\.)+[\w-]+([\w-./?%&=]*)?$/i.test(this);}
String.prototype.isPhoneCall = function(){	return /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(this);}
String.prototype.isNumber=function(){return /^[0-9]+$/.test(this);}
//动态加载js类   IncludeJs(a.js)
function IncludeJs(sSrc){
var oHead = document.getElementsByTagName('head')[0];
var oScript = document.createElement('script');
 oScript.type = "text/javascript";
 oScript.src = sSrc;
 oHead.appendChild(oScript);
}

//动态加载js类  多个 IncludeJsFiles(a.js,b.js,c.js)
function IncludeJsFiles(sUrls) {
 var sUrls=sUrls.split(",");
 for(var i=0;i<sUrls.length;i++) {
 IncludeJs(sUrls[i]);
 }
}

var Browser={};
Browser.isMozilla=(typeof document.implementation!='undefined')&&(typeof document.implementation.createDocument!='undefined')&&(typeof HTMLDocument!='undefined');
Browser.isIE=window.ActiveXObject ? true : false;
Browser.isFirefox=(navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isSafari=(navigator.userAgent.toLowerCase().indexOf("safari")!=-1);
Browser.isOpera=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1);

 ///创建dom
 function parseXML(st){
	var result = null;
	if(Browser.isIE){
		result = getXMLDOM();
		if(result) result.loadXML(st);
	}else{
		var parser = new DOMParser();
		result = parser.parseFromString(st, "text/xml");
	}
	return result;
}
function getXMLDOM(){
	if(!Browser.isIE) return null;
	var xmldomversions = ['MSXML2.DOMDocument.5.0', 'MSXML2.DOMDocument.4.0', 'MSXML2.DOMDocument.3.0', 'MSXML2.DOMDocument', 'Microsoft.XMLDOM'];
	for(var i=xmldomversions.length-1;i>=0;i--)
		try{
			return new ActiveXObject(xmldomversions[i]);
		}catch(e){}
	return document.createElement("XML");
}

//得到id
function $(id) {
 if (document.getElementById != null) {
 return document.getElementById(id);
 }
 else if (document.all != null) {
 return document.all[id];
 }
 else {
 return null;
 }
}

//得到Css  在所有标记tags,obj的对象里面
function GetTagesObjects(tag,obj) {
 var classObjects = []; //for all divs
 classObjects =  ($(obj) || document.body).getElementsByTagName(tag);
 return classObjects;
}

//得到Css  在所有标记tags,中查找样式choice的集合
function GetClassObjects(tags,choice) {
 var divMap = []; //for all divs
 divMap = document.getElementsByTagName(tags);
 var classObjects = [];
 var i, j;
 for (i=0,j=0;i<divMap.length;i++) {
 var c = divMap[i].className;
 if (c.indexOf(choice) != -1) {
 classObjects[j] = divMap[i];
 j++;
 }
 }
 return classObjects;
}

//开创xmlhttp对象   var req = createXMLHttp();
function CreateXMLHttp() {
 if (typeof XMLHttpRequest != "undefined") {
 browser = 1 //Mozilla
 return new XMLHttpRequest(); 
 }
 else if (window.ActiveXObject) {
 browser = 2 //IE
 var aVersions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
 for (var i = 0 ; i < aVersions.length ; i++) {
 try {
 var oXmlHttp = new ActiveXObject(aVersions[i]);
 return oXmlHttp;
 }
 catch (oError) {
 //Do Nothing
 }
 }
 } 
 throw new Error("XMLHttp Object could not be created.");
}

//gb2312转转utf-8函数 再xmlhttp获得数据有中文可以用到
window.gb2utf8=function(data)
{
　　　　var glbEncode=[],t,i,j,len
　　　　gb2utf8_data=data
　　　　execScript("gb2utf8_data = MidB(gb2utf8_data, 1)+' '", "vbscript")
　　　　t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2")
　　　　t=t.split("@")
　　　　i=0
　　　　len=t.length
　　　　while(++i<len){
　　　　　　j=t[i].substring(0,4)
　　　　　　if(!glbEncode[j]) {
　　　　　　　　gb2utf8_char = eval("0x"+j)
　　　　　　　　execScript("gb2utf8_char=Chr(gb2utf8_char)","vbscript")
　　　　　　　　glbEncode[j]=escape(gb2utf8_char).substring(1,6)
　　　　　　}
　　　　　　t[i]=glbEncode[j]+t[i].substring(4)
　　　　}
　　　　gb2utf8_data=gb2utf8_char=null
　　　　return unescape(t.join("%")).slice(0,-1)
}

String.prototype.jsurlencode = function()
{
	var str = this;
	str = str.replace(/./g,function(sHex)
	{
		window.EnCodeStr = "";
		window.sHex = sHex;
		window.execScript('window.EnCodeStr=Hex(Asc(window.sHex))',"vbscript");
		return window.EnCodeStr.replace(/../g,"%$&");
	});
	return str;
}

  function alters()
  {
    this.title="正在加载，请稍后..";
	this.heigth=80;
	this.width=300;
	this.show=function()
	{
		if(!document.getElementById("loader"))
		{
			var str='<div id="loader" style="display:none;z-index;10000;position:absolute"><table style="FILTER: Alpha(opacity=90);"  border="0" cellpadding="5" cellspacing="1" bgcolor="#bbbbb" >';
			str=str+'<tr><td bgcolor="#FFFFFF" align="left"><p>';
			str=str+'<img src="/n_images/ajax/loading.gif" align="left" style="margin:3px" alt="请等待"/><strong id="loadermsg">'+this.title+'</strong><br /> <span style="font-size:8pt;">Please wait until this screen is completely loaded.</span></p></td>';
			str=str+'</tr></table></div>';
			var bgObj=document.createElement("span");
			bgObj.innerHTML=str;
			document.body.appendChild(bgObj);
			
		   //document.write(str);
		}
			var scrollPos,scrollLeft,clientHeight,clientWidth; 
		   if (typeof(document.compatMode) != 'undefined' &&   document.compatMode != 'BackCompat') { 
			   scrollPos = document.documentElement.scrollTop;
			   scrollLeft= document.documentElement.scrollLeft;
			   clientHeight= document.documentElement.clientHeight;
			   clientWidth= document.documentElement.clientWidth;
			}
			else
			{
			   scrollPos = document.body.scrollTop;
			   scrollLeft= document.body.scrollLeft;
			   clientHeight= document.body.clientHeight;
			   clientWidth= document.body.clientWidth;
	
			}
			document.getElementById("loader").style.top = scrollPos + (clientHeight - this.heigth) / 2;
			document.getElementById("loader").style.left = scrollLeft + (clientWidth - this.width) / 2;

        document.getElementById("loader").style.display='inline';
	}
	this.hide=function(){document.getElementById("loader").style.display='none';}
	this.changemsg=function(s){document.getElementById("loadermsg").innerHTML=s;}
  
  }
  
  
  function check(source,len){   
var num=0,out="";   
for (var i=0; i<source.length; i++)   
{   
if((num+=(/[^\x00-\xff]/.test(source.charAt(i))?2:1))<=len)   
out+=source.charAt(i)   
//num+=(/[^\x00-\xff]/.test(temp[i])?2:1)   
continue;   
}   
return out;   
}  
