//Ajax 检查

var AjaxRequest=function(url,ajaxOptions)
{
	this.XmlHttpGetMessages=this.CreateXmlHttpRequestObject();
	this.Url=url;
	this.AjaxOptions=ajaxOptions;
	this.Exist=false;
}

AjaxRequest.prototype.Create=function()
{	
	this.RequestMessage();
}

AjaxRequest.prototype.RequestMessage=function()
{
	var oThis=this;
	if(this.XmlHttpGetMessages)
	{
		try
		{

			if(this.XmlHttpGetMessages.readyState==4||this.XmlHttpGetMessages.readyState==0)
			{

				if(this.AjaxOptions.parameters)
					this.Url+="?"+this.AjaxOptions.parameters;
				if(this.AjaxOptions.method.toLowerCase()=="get")
				{
					this.XmlHttpGetMessages.open(this.AjaxOptions.method,this.Url,true);
					this.XmlHttpGetMessages.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
					this.XmlHttpGetMessages.onreadystatechange=function(){oThis.HandleReceivingMessages();};
					this.XmlHttpGetMessages.send(null);
				}
				else
				{
					this.XmlHttpGetMessages.open(this.AjaxOptions.method,this.Url,true);
					this.XmlHttpGetMessages.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
					this.XmlHttpGetMessages.onreadystatechange=function(){oThis.HandleReceivingMessages();};
					this.XmlHttpGetMessages.send(this.AjaxOptions.parameters);
				}
			}
			else
			{
				setTimeout("AjaxRequest.RequestMessage();",0.5);
			}
		}
		catch (e)
		{
			document.write(e.toString());
		}
	}
}

AjaxRequest.prototype.HandleReceivingMessages=function()
{
	if(this.XmlHttpGetMessages.readyState==4)
	{
		if(this.XmlHttpGetMessages.status==200)
		{
			try
			{
				this.AjaxOptions.onComplete.call(this,this.XmlHttpGetMessages);//等价于下面的注释
//				this.m=this.AjaxOptions.onComplete;
//				this.m(this.XmlHttpGetMessages);
//				delete this.m;				
			}
			catch (e)
			{		
				document.write(e.toString());
			}
		}
		else
		{
			alert(this.XmlHttpGetMessages.statusText+" try again.");
		}
	}
}

AjaxRequest.prototype.CreateXmlHttpRequestObject=function()
{
	
	var xmlHttp;
	if(window.ActiveXObject)
	{
		try
		{				
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			
			xmlHttp=false;
		}
	}
	else
	{
		try
		{
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp=false;
		}
	}

	if(!xmlHttp)
		alert("error");
	else
		return xmlHttp;
}


