var Http = {
	xmlHttp: null,
	handler: null,

	init: function() {
		if (!this.xmlHttp) {
			this.xmlHttp = this.createXmlHttpRequestObject();
		}
	},

	createXmlHttpRequestObject: function() {
		var xmlHttp;
		try {
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			var xmlHttpVersions = ["MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
			for (i=0; i<xmlHttpVersions.length && !xmlHttp; i++)
				try {
					xmlHttp = new ActiveXObject(xmlHttpVersions[i]);
				} catch (e) {}
		}
		return xmlHttp;
	},

	request: function(url, handler, action, data) {
		if (!this.xmlHttp) this.init();
		if (this.xmlHttp && (this.xmlHttp.readyState == 0 || this.xmlHttp.readyState == 4)) {
			var d = "ajax=true&action=" + escape(action);
			for (var i in data)
				d += "&" + i + "=" + encodeURIComponent(data[i]);
			try {
				this.handler = handler;
				this.xmlHttp.open("POST", url, true);
				this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				this.xmlHttp.onreadystatechange = this.handleRequest;
				this.xmlHttp.send(d);
//				this.xmlHttp.send("action="+escape(action)+"&data="+encodeURIComponent(data.toJSONString()));
			} catch(e) {alert(e.toString());}
		}
	},
	
	handleRequest: function() {
		if (Http.xmlHttp && Http.xmlHttp.readyState == 4 && Http.xmlHttp.status == 200) {
			//Http.handler(Http.xmlHttp.responseText.parseJSON());
			Http.handler(Http.xmlHttp.responseText);
		}
	}
}
