function Ajax()
{
	var browser = "IE";
	if (navigator.userAgent.indexOf("Gecko") != -1)//FireFox
		browser = "FF";
	
	this.CreateXmlHttp = function()
	{
		var xmlHttp = null;
		
		if (window.XMLHttpRequest)
		{
			xmlHttp = new XMLHttpRequest();/*Microsoft IE*/
			if (xmlHttp.overrideMimeType)
				xmlHttp.overrideMimeType("text/xml");
		  
		}
		else if (window.ActiveXObject)
		{
			try
			{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		
		if (xmlHttp == null)
		{
			alert("支XMLHttpRequest!");/*支XMLHttpRequest*/
		}
		
		return xmlHttp;
	}
	
	this.AddAjaxMark = function(url)
	{
		if (url.indexOf("DoAjax=") != -1)
			return url;
		
		if (url.indexOf("?") != -1)
			url += "&DoAjax=true";
		else
			url += "?DoAjax=true";
		
		return url;
	}
	
	var Send = function(url, method, data, callback, urlencoded)
	{
		url = _ajax.AddAjaxMark(url);
		
		var xmlHttp = _ajax.CreateXmlHttp();
		xmlHttp.onreadystatechange = function()
		{
			if (callback == null) return;
			if(xmlHttp.readyState == 4)
			{
				if (xmlHttp.status < 400)
					(method == "POST") ? callback(xmlHttp) : callback(xmlHttp, data);
				else
					alert("发生错误！\n错误信息：" + xmlHttp.statusText);
			}
		}
		
		if (method == "POST")
		{
			xmlHttp.open("POST", url, true);
			if (urlencoded) xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			if (data == null && browser == "FF") data = "\r\n";
			
			xmlHttp.send(data);
		}
		else
		{
			xmlHttp.open("GET", url, true);
			xmlHttp.send(null);
		}
	}
	
	this.RawPost = function(url, data, callback)
	{
		Send(url, "POST", data, callback, false);
	}
	
	this.Post = function(url, data, callback)
	{
		Send(url, "POST", data, callback, true);
	}
	
	this.Get = function(url, args, callback)
	{
		return Send(url, "GET", args, callback);
	}
}

var _ajax = new Ajax();
