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();
	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.parseJSON());
			} 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();

