function FactoryXMLHttpRequest() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		var msxmls = new Array(
			'Msxml2.XMLHTTP.5.0',
			'Msxml2.XMLHTTP.4.0',
			'Msxml2.XMLHTTP.3.0',
			'Msxml2.XMLHTTP.5.0',
			'Msxml2.XMLHTTP',
			'Microsoft.XMLHTTP');
		for(var i=0; i<msxmls.length; i++) {
			try {
				return new ActiveXObject(msxmls[i]);
			}catch(E) {
			}
		}
	}
	throw new Error("Could not instantiate XMLHttpRequest");
}

function AsynchronousParameter() {
	this._data = {};
}

function AsynchronousParameter_clear(key, value) {
	this._data = {};
}

function AsynchronousParameter_add(key, value) {
	this._data[key] = value;
}

function AsynchronousParameter_toString() {
  var str = "";
  for(var property in this._data) {
  	str += property + "=" + escape(this._data[property]) + "&";
  }	
	return str;
}
AsynchronousParameter.prototype.clear = AsynchronousParameter_clear;
AsynchronousParameter.prototype.add = AsynchronousParameter_add;
AsynchronousParameter.prototype.toString = AsynchronousParameter_toString;

function Asynchronous() {
	this._xmlhttp = new FactoryXMLHttpRequest();
	this.parameters = new AsynchronousParameter();
}

function Asynchronous_get(url) {
	this.call({
		method : "GET", 
		url: encodeURI(url+"?"+this.parameters.toString()), 
		data: null});
}
	
function Asynchronous_post(url) {
	this.call({
		method : "POST", 
		url: url, 
		data: encodeURI(this.parameters.toString())});
}

function Asynchronous_call(caller) {
	var instance = this;
	this._xmlhttp.open(caller.method, caller.url, true);
	this._xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	this._xmlhttp.setRequestHeader("Accept-Language", "zh-cn")	
	
	this._xmlhttp.onreadystatechange = function() {
		switch(instance._xmlhttp.readyState) {
		case 1:
			instance.loading();
			break;
		case 2:
			instance.loaded();
			break;
		case 3:
			instance.interactive();
			break;
		case 4:
			instance.complete(instance._xmlhttp.status,
				instance._xmlhttp.statusText,
				unescape(instance._xmlhttp.responseText), 
				instance._xmlhttp.responseXML);
			break;
		}
	}
	this._xmlhttp.send(caller.data);
}
function Asynchronous_loading() {
}
function Asynchronous_loaded() {
}
function Asynchronous_interactive() {
}
function Asynchronous_complete(status, statusText, responseText, responseHTML) {
}
function Asynchronous_loading() {
}

Asynchronous.prototype.loading = Asynchronous_loading;
Asynchronous.prototype.loaded = Asynchronous_loaded;
Asynchronous.prototype.interactive = Asynchronous_interactive;
Asynchronous.prototype.complete = Asynchronous_complete;
Asynchronous.prototype.call = Asynchronous_call;
Asynchronous.prototype.get = Asynchronous_get;
Asynchronous.prototype.post = Asynchronous_post;
