String.prototype.trim = function() {return this.replace(/^\s*|\s*$/g,"");}
Number.prototype.NaN0 = function(){return isNaN(this)?0:this;}
function $(_elemID) {return document.getElementById(_elemID);}
function htmlEncode (_text) {
	if(typeof _text == "string"){
		return (_text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;')).trim();
	}else{
		return _text;
	}
}
function loadScripts(_text,_language){
	var matchAll = new RegExp('(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 'img');
	var matchOne = new RegExp('(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 'im');
	var scripts  =_text.match(matchAll);
	if (scripts && scripts.length) {
		for (var i = 0; i < scripts.length; i++) {
			if (scripts[i] && scripts[i].match(matchOne) && scripts[i].match(matchOne)[1]) {
				loadScript(scripts[i].match(matchOne)[1],_language);
			}
		}
	}
};
function loadScript(_text,_language){
    if (_language!=undefined){
    	if (window.execScript){ window.execScript(_text,_language);
        }else{ window.eval(_text,_language);}      
    }else{
        if (window.execScript){window.execScript(_text);
        }else{window.eval(_text);}                 
    } 
}
function HttpRequestObject()
{ this.chunnel=null;this.instance=null;}
var Request=new function()
{
    this.httpRequestCache=[];
    this.createInstance=function(){
        var instance=null;
        if (window.XMLHttpRequest){
            instance=new XMLHttpRequest();
            if (instance.overrideMimeType){instance.overrideMimeType="text/xml";}
        }else if (window.ActiveXObject){
            var MSXML = [ 'Microsoft.XMLHTTP','MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
            for(var i = 0; i < MSXML.length; i++){
                try{instance = new ActiveXObject(MSXML[i]);break;}catch(e){}
            }
        }
        return instance;
    }

    this.getInstance=function(_chunnel)
    {
        var instance=null;
        var object  =null;
        var getOne=false;
        if (_chunnel==undefined) {_chunnel="default";}
        for(var i=0; i<this.httpRequestCache; i++){
            object=HttpRequestObject(this.httpRequestCache[i]);
            if (object.chunnel==_chunnel){
                if (object.instance.readyState==0 || object.instance.readyState==4){instance=object.instance;}
                getOne=true;break;                    
            }
        }
        if (!getOne) {
            object=new HttpRequestObject();
            object.chunnel=_chunnel;
            object.instance=this.createInstance();
            this.httpRequestCache.push(object);
            instance=object.instance;
        }         
        return instance;
    }  

    this.send=function(_url,_callback,_data,_chunnel,_asynchronous)
    {
        if (_url.length==0 || _url.indexOf("?")==0){alert("由于目的为空，请求失败，请检查！");return;}
        if (_chunnel==undefined || _chunnel==""){_chunnel="default";}
        if (_asynchronous == undefined){_asynchronous=true;}
        var instance=this.getInstance(_chunnel);
        if (instance==null){alert("浏览器不支持ajax，请检查！");return; }  
        if (_asynchronous==true && typeof(_callback)=="function"){
            instance.onreadystatechange = function(){
                if (instance.readyState == 4) {
                    if (instance.status == 200){
                        try{
		                    var bool = instance.responseText.search(/_ojsxgzlsozsv64dsnfrwkwzvgawdcmbqgaydambqgboq---_/);
		                    if(bool != -1){location.href='/manage/admin.jsp';}else{_callback(instance);}
                        }catch(e){
							alert("ajax回调处理时发生错误:"+e.message);
						}
                    }else{
                    	alert("您所请求的页面有异常!URL->"+_url + "  ::   data->"+_data +"   ::   \ncallback->"+_callback);
           			}
                }
            }
        }
        if (_url.indexOf("?")!=-1){_url+="&requestTime="+(new Date()).getTime()+"&ajax=true";
        } else{_url+="?requestTime="+(new Date()).getTime()+"&ajax=true";}
        if (_data == undefined || _data == "" || _data.length == 0){
            instance.open("GET",_url,_asynchronous); 
            instance.send(null);           
        }else{
            instance.open("POST",_url,_asynchronous);
            instance.setRequestHeader("Content-Length",_data.length);
           	instance.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
            instance.send(_data);
        }
    }
}
function killErrors() {return true;}
window.onerror = killErrors;
