/* Simple AJAX Code-Kit (SACK) */
/* 2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence, see documentation or authors website for more details */

/* This is a modified version of the software indicated above 
 * Modified by Hermann Kaser */
 
 
function sack(){
	this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
	this.URLString = null;		
	this.object = null; 		

	this.onLoading = function() { };
	this.onLoaded = function() { };
	this.onInteractive = function() { };
	this.onCompletion = function() { };
	
	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err) {
				this.xmlhttp = null;
			}
		}
		if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
			this.xmlhttp = new XMLHttpRequest();
		if (!this.xmlhttp){
			this.failed = true; 
		}
	};
	
	this.runAJAX = function(xml){
		this.responseStatus = new Array(2);
		if(this.failed && this.AjaxFailedAlert)
		{ 
			alert(this.AjaxFailedAlert); 
		} else {
			if (this.xmlhttp) 
			{
				var self = this;
				this.xmlhttp.open("POST", this.URLString, true);
				this.xmlhttp.setRequestHeader("Content-Type", "text/xml");
				this.xmlhttp.send(xml);
				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState){
						case 1:
							self.onLoading();
							break;
							
						case 2:
							self.onLoaded();
							break;
							
						case 3:
							self.onInteractive();
							break;
							
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
							self.onCompletion();
							break;
					}
				};
			}
		}
	};
this.createAJAX();
}