function AJAX() {
	/**
	成员变量
	*/
	this.XMLHttpReq = null;						//XML对象
	this.method = "post";						//执行的方法(post/get)
	this.URLString = "ajax.php";				//异步调用的页面地址
	this.response = "";							//异步返回的响应字符串
	this.responseXML = "";                      //异步返回的响应XML
	this.failed = false;                        //创建对象错误标志

	/**
	事件区
	*/
	this.onLoading = function() { };            //正在发送请求
	this.onLoaded = function() { };             //已经接收到全部响应内容
	this.onInteractive = function() { };        //正在解析响应内容
	this.onCompletion = function() { };         //响应内容解析完成
	this.onError = function() { };              //异步错误处理事件
	this.onFail = function() { };               //创建对象失败处理世界

	/**
	重置所有事件函数
	*/
	this.resetFunctions = function() {
		this.onLoading = function() { };
		this.onLoaded = function() { };
		this.onInteractive = function() { };
		this.onCompletion = function() { };
		this.onError = function() { };
		this.onFail = function() { };
	};

	/**
	初始化函数(构造时自动初始化)
	*/
	this.Init = function()
	{
		//对于Mozilla浏览器
		if(window.XMLHttpRequest)
		{
			//直接使用XMLHttpRequest函数来创建XMLHttpRequest对象
			this.XMLHttpReq = new XMLHttpRequest();
		}
		//对于IE浏览器
		else if (window.ActiveXObject)
		{
			try
			{
				this.XMLHttpReq = new ActiveXObject("Msxml4.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					this.XMLHttpReq = new ActiveXObject("Msxml3.XMLHTTP");
				}
				catch(e)
				{
					try
					{
						this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch(e)
					{
						try
						{
							this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
						}
						catch(oc)
						{
							this.failed=true;   //创建AJAX对象发生异常
						}
					}
				}
			}
		}
	};

	/**
	发送请求函数
	@param data 发送的数据
	@example send("id=1");
	*/
	this.Send=function(data)
	{
		var self=this;

		data = 'inajax=1&' + data;

		//通过open方法取得与服务器的连接
		if(this.method=="post")
		{
			this.XMLHttpReq.open(self.method,self.URLString,true);
		}
		else
		{
			this.XMLHttpReq.open(self.method,self.URLString+"?"+encodeURI(data),true);
		}
		//添加消息响应头
		this.XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		//异步回调函数
		this.XMLHttpReq.onreadystatechange = function()
		{
			//对象未创建
			if (self.failed) {
				self.onFail();
				return;
			}

			//消息响应标志
			switch (self.XMLHttpReq.readyState) {
				case 1:
				{
					self.onLoading();
					break;
				}
				case 2:
				{
					self.onLoaded();
					break;
				}
				case 3:
				{
					self.onInteractive();
					break;
				}
				case 4:
				{
					if(self.XMLHttpReq.status==200) {
						self.response = self.XMLHttpReq.responseText;
						self.responseXML = self.XMLHttpReq.responseXML;
						self.onCompletion();
					}
					else
					{
						self.onError();     //执行错误函数
					}
					break;
				}
			}
		};


		if(this.method=="post")
		{
			this.XMLHttpReq.send(encodeURI(data)); //发送请求
		}
		else
		{
			this.XMLHttpReq.send(); //发送请求
		}
	};

	this.Abort=function()
	{
		this.XMLHttpReq.abort();
	}

	this.Close=function()
	{
		this.XMLHttpReq=null;
	}
	//初始化AJAX库
	this.Init();
}

function formToStr(formObj) {
	var qstr = "", and = "", elems = formObj.elements, elem, value;
	for (var i = 0; i< elems.length; ++i) {
		elem = elems[i];
		if (elem.name !== '') {
			value = undefined;
			switch(elem.type) {
				case "select-one":
				if(elem.selectedIndex > -1) {
					value = elem.options[elem.selectedIndex].value;
				} else {
					value = "";
				}
				break;
				case "select-multiple":
				var opts = elem.options;
				for (var j = 0; j < opts.length; ++j) {
					if (opts[j].selected) {
						qstr += and + elem.name + "=" + opts[j].value;
						and = "&";
					}
				}
				break;
				case "checkbox":
				case "radio":
				if (elem.checked) {
					value = elem.value;
				}
				break;
				default:
				value = elem.value;
				break;
			}
			if(value != undefined) {
				qstr += and + elem.name + "=" + encodeURIComponent(value);
				and = "&";
			}
		}
	}

	return qstr;
}
/*
function ajaxEncode(str) {
str = str.replace(/\+/g,"%2B");
str = str.replace(/\&/g,"%26");

return str;
}
*/
