var Ajax = function() {

	this.http = false; //HTTP Object
	
	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;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try { http = new XMLHttpRequest(); }
		catch (e) { http = false; }
	}
	return http;
}

Ajax.prototype.Request = function (url, onSuccess, onFailure, onProcess, onComplete) {
	this.init(); //The XMLHttpRequest object is recreated at every call - to defeat Cache problem in IE

	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;
	
	//Kill the Cache problem in IE.
	var now = "uid=" + new Date().getTime();
	url += (url.indexOf("?")+1)?"&":"?";
	url += now;

	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;
				//Give the data to the onSuccess function.
				if(thisReference.onSuccess) thisReference.onSuccess(result);
			} 
			else { //An error occured
				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!="")?"&":"";
	this.params += name + "=" + value;
}

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