function AJAX() {
	this.HTTP = false;
	// Konstructor
	//this._open();
}

AJAX.prototype._open = function() {
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
		try {
			this.HTTP = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.HTTP = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				this.HTTP = false;
			}
		}
	@else
		this.HTTP = false
	@end @*/
	if (!this.HTTP && typeof XMLHttpRequest != 'undefined') {
		try {
			this.HTTP = new XMLHttpRequest();
		} catch (e) {
			this.HTTP = false;
		}
	}
	
	if (!this.HTTP && window.createRequest) {
		try {
			this.HTTP = window.createRequest();
		} catch (e) {
			this.HTTP = false;
		}
	}
}

AJAX.prototype.load = function(METHOD, URL, returnFunction, PARAMS) {
	this._open();
	var instanceOfAJAXObject = this;
	this.HTTP.onreadystatechange = function() {
		instanceOfAJAXObject.initialize(returnFunction);
	};
	
	this._sendRequest(METHOD, URL, PARAMS);
}

AJAX.prototype.initialize = function(returnFunction) {
	if(this.HTTP.readyState == 4) {
		if(this.HTTP.status == 200) {
		   //alert(this.HTTP.getAllResponseHeaders());
		   //alert(this.HTTP.responseText);
			returnFunction(this.HTTP.responseText.parseJSON());
		} else {
			//alert('URL does not exist');
		}
	}
}

AJAX.prototype.loadJSON = function(METHOD, URL, returnFunction, PARAMS) {
	this.load(METHOD, URL, returnFunction, PARAMS);
}

AJAX.prototype.RPC = function(URL, classAndMethod, PARAMS, returnFunction) {
	var jsonRpcReq = {
		method: classAndMethod,
		params: PARAMS,
		id: Math.floor(Math.random()*10001)
	};
	//alert(jsonRpcReq.toJSONString());
	this.load("POST", URL, returnFunction, jsonRpcReq.toJSONString());
}

AJAX.prototype.loadXHTML = function(METHOD, URL, returnFunction, PARAMS) {
	this._open();
	this.HTTP.onreadystatechange = function() {
		if(AJAX.HTTP.readyState == 4) {
			if(AJAX.HTTP.status == 200) {
			   //alert(AJAX.HTTP.getAllResponseHeaders());
			   //alert(AJAX.HTTP.responseText);
				returnFunction(AJAX.HTTP.responseText);
			} else {
				//alert('URL does not exist');
			}
		}
	};
	
	this._sendRequest(METHOD, URL, PARAMS);
}

AJAX.prototype.loadXML = function(METHOD, URL, returnFunction, PARAMS) {
	this._open();
	this.HTTP.onreadystatechange = function() {
		if(AJAX.HTTP.readyState == 4) {
			if(AJAX.HTTP.status == 200) {
			   //alert(AJAX.HTTP.getAllResponseHeaders());
			   //alert(AJAX.HTTP.responseText);
				returnFunction(AJAX.HTTP.responseXML);
			} else {
				//alert('URL does not exist');
			}
		}
	};
	
	this._sendRequest(METHOD, URL, PARAMS);
}

AJAX.prototype._sendRequest = function(METHOD, URL, PARAMS)	{
	switch(METHOD) {
		case 'POST':
			this.HTTP.open('POST', URL, true);
			//this.HTTP.setRequestHeader('Accept','text/x-json');
			this.HTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			this.HTTP.send(PARAMS);
			break;
		default:
			this.HTTP.open('GET', URL, true);
			//this.HTTP.setRequestHeader('Accept','text/x-json');
			this.HTTP.send(null);
			break;
	}
}

//var AJAX = new AJAX();
