Ajax = function() {
	this.params = "";

	this.httpreq = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            this.httpreq = new XMLHttpRequest();
        } else if (window.ActiveXObject) { // IE
            try {
                this.httpreq = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    this.httpreq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

	if (!this.httpreq) {
		alert("Could not create HTTP request object");
		return;
	}
}

Ajax.prototype.onloaded = function() {};

Ajax.prototype.doReadyStateChange = function() {
	if (this.httpreq.readyState == 4) {
		if (this.httpreq.status == undefined // Safari on cached
		 || (this.httpreq.status >= 200 && this.httpreq.status < 300) // Standard
		 || this.httpreq.status == 0 // IE on cached
		  ) {
			this.onloaded(this.httpreq.responseText,this.httpreq.responseXML);
		} else {
			if (this.onerror) {
				this.onerror(this.httpreq.status,this.httpreq.statusText);
			} else {
				alert("Problem med kontakt til serveren (" + this.httpreq.status + ": " + this.httpreq.statusText + ")");
			}
		}
	}
}

Ajax.prototype.abort = function()
{
		this.httpreq.onreadystatechange = function () {};
		this.httpreq.abort();
}

Ajax.prototype.execute = function(url) {
	params = this.params || "";
	url += "?" + params;
	// Abort any previous Ajax call:
	this.httpreq.abort();

	this.httpreq.open("GET",url,true);
	this.httpreq.onreadystatechange = this.doReadyStateChange.inScope(this);
	this.httpreq.send("");
}

