
//Ajax begin
function oAjax(url,callback,callbackarg1,callbackarg2)
{//alert(callback);
    try{this.Rs=null;
	this.XmlDoc=null;
        this.HttpRequest = null;
        this.Debug  = false;
        this.Url = url;
        this.ContentType ="application/x-www-form-urlencoded";// "text/xml";
        this.HttpRequest = this.createXMLHttpRequest();

        if ( this.HttpRequest == null )
        {
            alert("XMLHttpRequest create failure!");
            return;
        }

        var xhReq = this.HttpRequest;
        xhReq.onreadystatechange = function (){
		//alert("on ajxa");
            oAjax._OnReadyStateChange( xhReq,callback,callbackarg1,callbackarg2 );
        }

    } catch(e){
       alert( "unknow err: " + e.message );
    }
}
oAjax.prototype.createXmlDoc = function() {
//alert("crexmldoc");
    try { return new ActiveXObject("Msxml2.DOMDocument");    } catch(e) {}
    
    return null;
}

oAjax.prototype.createRs = function() {
//alert("creRs");
    try { return new ActiveXObject("ADODB.Recordset");    } catch(e) {}
    
    return null;
}
oAjax.prototype.createXMLHttpRequest = function() {

    try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
    try { return new XMLHttpRequest();                   } catch(e) {}
    return null;
}
oAjax._OnReadyStateChange = function( xreq, callback,callbackarg1,callbackarg2 ){

    if ( xreq == null )
    {
        return;    }
    
    /*Status is completed, then process result */
    if ( xreq.readyState == 4)
    {
        // OK        
        if ( xreq.status == 200 )
        {
			if (callback==null)
			return;
			//alert("onready" + callbackarg);
          	callback (xreq.responseText,callbackarg1,callbackarg2 );                     
        }else{
			//document.all.con_uib.value=xreq.responseText;
			alert('服务器端错误！可能原因：①服务器超时，请您重新登陆试试②技术人员正在调试程序，请稍后再试');
			alert(xreq.responseText.substr(xreq.responseText.length-1000,1000));
		//$("contain").innerHTML=xreq.responseText;
		return
		}
    } else {
        // Others
    }
}
oAjax.prototype._SendRequest = function(HttpMethod, data,synflag){

    //alert( 'Send Request ' + HttpMethod + this.Url );
    
    if ( this.HttpRequest != null )
    {
        this.HttpRequest.open(HttpMethod, this.Url, synflag);

        if ( this.ContentType != null )
        {
            //   MIME type: application/x-www-form-urlencoded
            this.HttpRequest.setRequestHeader("Content-Type", this.ContentType);
        }
		//alert(HttpMethod);
        this.HttpRequest.send(data);
        return true;
    }
    return false;
}
oAjax.prototype.Post = function( arrKey, arrValue ) {

    var data = '';
    this.ContentType="application/x-www-form-urlencoded";
    for( i = 0; i < arrKey.length; i ++)
    {
        data += "&" + escape(arrKey[i]) + "=" + escape(arrValue[i]);
		//data += "&" + arrKey[i] + "=" + arrValue[i];
    }
	//document.write(data);
    data = data.replace(/^&/g, "");
    this._post(data);
}
oAjax.prototype._post = function (url,data,synflag) {

    //alert( 'POST' );
	this.Url=url;
	this.ContentType="application/x-www-form-urlencoded";
    return this._SendRequest("POST", data,synflag);
}
oAjax.prototype.post_stream=function(stream,size){
if ( this.HttpRequest != null )
    {
        this.HttpRequest.open("POST", this.Url, true);
        this.HttpRequest.setRequestHeader('Content-Type', 'multipart/form-data');
	this.HttpRequest.setRequestHeader("Content-Length", size);
        this.HttpRequest.send(stream);
        return true;
    }
    return false;
}
oAjax.prototype.getrs=function (callback,argu,reqtxt){

this.Rs = this.createRs();
   if ( this.Rs == null )
      {
       alert("Rs create failure!");
       return;
       }
this.XmlDoc = this.createXmlDoc();
   if ( this.XmlDoc == null )
   {
     alert("XmlDoc create failure!");
      return;
     }
this._SendRequest("POST",reqtxt,false);
try{
//alert(this.HttpRequest.responseText);
this.XmlDoc.loadXML(this.HttpRequest.responseText); //load the returned stream into the dom document

this.Rs.Open(this.XmlDoc);
//alert(this.Rs.Recordcount);
}
catch(e){
alert(e.description)
}
	if (callback !=null)
	callback(argu);
}

//oAjax end
