var Ajax = function() {

	this.http = false;	

	this.onSuccess;
	this.onFailure;
	this.onProcess;
	this.onComplete;	

	this.error = false;
	this.errorMessage = "";

	this.method = "POST";
	this.params = "";

}

Ajax.prototype.getHTTPObject = function() {

	var http = false;
	
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}

		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}

	} else if (XMLHttpRequest) {
		try { http = new XMLHttpRequest(); }
		catch (e) { http = false; }
	}

	return http;

}



Ajax.prototype.Request = function (url, onSuccess, onFailure, onProcess, onComplete) {

	this.init(); 

	if(!this.http||!url) return;

	if(onSuccess) this.onSuccess = onSuccess;
	if(onFailure) this.onFailure = onFailure;
	if(onProcess) this.onProcess = onProcess;
	if(onComplete) this.onComplete = onComplete;
	var thisReference = this;	

	this.AddParam("uid", new Date().getTime());

	switch(this.method.toUpperCase()) {
	
		case "POST":
			this.http.open("POST", url, true);
			break;
		case "GET":
			url += "&" + this.params;
			this.http.open("GET", url, true);
			break;
		default:
			return;
	}	

	if(this.onProcess) this.onProcess();

	this.http.onreadystatechange = function() {
	
		if(!thisReference) return;
		
		var http = thisReference.http;

		if (http.readyState == 4) {
			if(http.status == 200) {
				var result = "";
				if(http.responseText) result = http.responseText;
				if(thisReference.onSuccess) thisReference.onSuccess(result);
			} else {
				thisReference.error = true;
				thisReference.errorMessage = http.responseText;
				if(thisReference.onFailure) thisReference.onFailure(thisReference.errorMessage);
			}
			if(thisReference.onComplete) thisReference.onComplete();
		}
	}


	switch(this.method.toUpperCase()) {	
		case "POST":
		this.http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		this.http.send(this.params);
			break;
		case "GET":
			this.http.send(null);
			break;
		default:
			return;
	}
}



Ajax.prototype.AddParam = function (name, value) {
	this.params += (this.params!="")?"&":"";
	if(typeof value == "string") this.params += name + "=" + value.replace(/&/gi, escape("&")).replace(/;/gi, escape(";"));
	else this.params += name + "=" + value;
}


Ajax.prototype.init = function() { 
	this.http = this.getHTTPObject(); 
};

var JSON = {
	build: function(string) {
		var result = eval("("+string+")");
		return result;
	}
}


