var objHTTP;
var strReturn;
function Ajax()
{
	this.PostSiteUrl = "http://127.0.0.1/";	//站点URL
	this.PostSiteFileName = "";			//发送到哪个程序
	this.http_request = false;
	//objHTTP = "";
	this.PostVal = "";	//发送的数据
	this.ReturnVal = "";
	this.RetrunOK = true;
	this.ErrorInfo = "";	
		

}



//是否建立Ajax对象，返回ture/false
Ajax.prototype.CheckAjax = function()
{
	if (!this.http_request)
	{
var Versions = [ "MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
                for (var i = 0; i < Versions.length; i++) {
                try {
               		objHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	                this.http_request = true;
		    }
		    catch(e2)
		    {
		    	
		    }
		   } 

	            /*try {
	                objHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	                this.http_request = true;
	
	            } catch (e2) {
	                try {
	                    objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	                    this.http_request = true;
	                } catch (e3) {}
	            }*/
	            
	        /*if (!http_request) {
	            alert('不能创建XMLHTTP组件!');
	            window.close();
	            //return false;
	        }*/	        
	 }       
	 return this.http_request;
}	 

//增加Post数据
Ajax.prototype.AddVal  =   function (strValName,strVal)   {  
	if(this.PostVal == "")
	{
		this.PostVal = strValName + '=' + encodeURIComponent(strVal);
	}
	else
	{
		this.PostVal += '&' + strValName + '=' + encodeURIComponent(strVal);
	}	
	
	
     //return   true ;  
} 

//增加Post数据，不做编码
Ajax.prototype.AddValNoEscape  =   function (strValName,strVal)   {  
if(this.PostVal == "")
{
  this.PostVal = strValName + '=' + (strVal);
}
else
{
  this.PostVal += '&' + strValName + '=' + (strVal);
} 
}

//卸载事件，可重写
Ajax.prototype.onunload  =   function ()   {  
     return   true ;  
}  



Ajax.prototype.makeRequest = function ()     
    {    	
        objHTTP.onreadystatechange = this.alertContents;                        
        objHTTP.open('POST', this.PostSiteUrl + this.PostSiteFileName , false);	//同步                    
        objHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");        
    	try {    		     
        	objHTTP.onreadystatechange=this.alertContents;            	
        	objHTTP.send(this.PostVal);
        	this.ReturnVal = strReturn;
        	this.PostVal = "";
        	return this.RetrunOK;
        	
            }
        catch (e2) 
         {
         	this.RetrunOK = false;
         	//alert("出现错误");         	
         	this.ErrorInfo = e2.description;
               
          }   
    }


Ajax.prototype.alertContents = function () {
	//intContinue = 0;
	//alert(objHTTP.readyState);
        if (objHTTP.readyState == 4) 
        {
            if(objHTTP.status==200) 
            	{                	
                	this.RetrunOK = true;   
                	strReturn = unescape(objHTTP.responseText);    
                	//alert(unescape(objHTTP.responseText));     
                	//alert('ha1' + this.ReturnVal);           	
                	this.ErrorInfo = "";      	             	
            	}             	
            else 
            {            	
                	this.RetrunOK = false;   
                	this.ReturnVal = "";
                	this.ErrorInfo = unescape(objHTTP.responseText);                       
            }
            
            
        }
	
    }
    
    