/*=================================================================================================
The Ajax Class By Fengfeng ( fengfeng@itp.ac.cn )

Class Name : ajax_
Members 	:
	url_ 			the request url
	method_			the request method
	paras_			the object for the QueryString , format : paras_[key] = value
	xmlHttp_		the XML HTTP Request
	QueryString_		the QueryString to send
Functions 	:
	paraSet_		the add or reset the QueryString (key=>value)
	headerSet_		the add or reset the header (key=>value)
	send_			to send the request
	ReadStateChange_	handle the onreadystatus
	handler_		shutcut to handle the successful respose back

常见的Header参考
        xmlHttp.setRequestHeader("Accept", "*"+"/*");
        xmlHttp.setRequestHeader("Accept-Encoding", "gzip, deflate");
        xmlHttp.setRequestHeader("Accept-Language", "zh-cn");
        xmlHttp.setRequestHeader("Connection", "Keep-Alive");
        xmlHttp.setRequestHeader("Pragma", "no-cache");
        xmlHttp.setRequestHeader("Cache-Control", "no-cache");
        xmlHttp.setRequestHeader("Cookie", strCookie);  document.cookie 会自动将发送
        xmlHttp.setRequestHeader("Host", "community.csdn.net");
        xmlHttp.setRequestHeader("Referer", "http://community.csdn.net/Tree/tree.htm");
        xmlHttp.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; i-NavFourF; .NET CLR 1.1.4322; InfoPath.1)");
=================================================================================================*/
function ajax_()
{
	this.url_="http://www.itp.ac.cn";
	this.method_="GET";
	this.paras_={};
	this.header_={};
	this.QueryString_="";
	if(window.XMLHttpRequest) 
	{
		this.xmlHttp_ = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) 
	{
		this.xmlHttp_ = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else this.xmlHttp_=false;
}

ajax_.prototype.paraSet_ = function(key_,value_,overWrite_)
{
	overWrite_ = typeof(overWrite_)=="undefined" ? true : overWrite_ ;
	if(overWrite_) this.paras_[key_] = value_ ;
	else
	{
		this.QueryString_ += ( "&" + encodeURIComponent(key_) + "=" + encodeURIComponent(value_) );
	}
};

ajax_.prototype.headerSet_ = function(key_,value_)
{
	this.header_[key_] = value_ ;
};

ajax_.prototype.send_ = function()
{
	var key;
	for(key in this.paras_) 
	{
		this.QueryString_ += ( "&" + encodeURIComponent(key) + "=" + encodeURIComponent(this.paras_[key]) );
	}
	
	if(this.xmlHttp_)
	{
		this.xmlHttp_.onreadystatechange = theReadyStateChange_.bind(this);
		switch(this.method_)
		{
			case "GET":
				if(this.url_.indexOf("?")==-1) this.QueryString_=this.QueryString_.replace(/^&/,"?");
				this.xmlHttp_.open("GET",this.url_+this.QueryString_,true);
				for(key in this.header_) this.xmlHttp_.setRequestHeader(key,this.header_[key]);
				this.xmlHttp_.send(null);
				break;
			case "POST":
				this.QueryString_=this.QueryString_.replace(/^&/,"");
				this.xmlHttp_.open("POST",this.url_,true);
				this.xmlHttp_.setRequestHeader("Content-Length",this.QueryString_.length);
				this.xmlHttp_.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				for(key in this.header_) this.xmlHttp_.setRequestHeader(key,this.header_[key]);
				this.xmlHttp_.send(this.QueryString_);
				break;
			default:
				alert("The Method Is inCorrect !");
				return;
		}
	}
	else
	{
		alert("Your Browser Does not Support the XML Http Request!");
	}
};

theReadyStateChange_ = function()
{
	if (this.xmlHttp_.readyState == 4) 
	{
		if(this.xmlHttp_.status == 200) 
		{
			this.handler_();
		} 
		else 
		{
			alert("Error occurred \n"+this.xmlHttp_.status+" : "+this.xmlHttp_.statusText);
		}
	}	
};
//The End