	/*
	
	
	Ajax-Requests 0.4
	
	2008 Oliver Lenz, BITFOX Ltd. & Co. KG
	Frei für die private unkommerzielle Nutzung.
	
	2008-09-17	Status-Handler hinzugefügt. -- vielleicht noch Standart-Modis hinzufügen? ToolTip oder so etwas?


    Beispiele:

		function ajaxPost() {	// abholen, wert im input-element "name"
			var value = document.getElementById('name').value; 
			value = escape(value);
			var ajax = new AjaxRequest('test.php',{method:'POST',query:'test='+value,onComplete:handle});  
			ajax.doRequest();
		}

		function ajaxGet() {
			var ajax = new AjaxRequest('hallo.txt',{method:'GET',onComplete:handle});
			ajax.doRequest()
		}

		function handle(text, xml) {
			document.getElementById('divbox').innerHTML=text; // antwort in eine DIV-Box namens "divbox" geben
		}


	XMLHttpRequest.readyState		
	
		Remarks
		Variant. The property is read-only. It represents the state of the request as an I4 (4-byte integer). The following values are defined.
		0 (UNINITIALIZED)
		The object has been created, but not initialized (the open method has not been called).
		(1) LOADING
		The object has been created, but the send method has not been called.
		(2) LOADED
		The send method has been called, but the status and headers are not yet available.
		(3) INTERACTIVE
		Some data has been received. Calling the responseBody and responseText properties at this state to obtain partial results will return an error, because status and response headers are not fully available.
		(4) COMPLETED
		All the data has been received, and the complete data is available in the responseBody and responseText properties.
		This property returns a 4-byte integer.				

	Quelle(n):
	
		http://msdn.microsoft.com/en-us/library/ms753800(VS.85).aspx

	
	*/

      function AjaxRequest(url,options) {    

		this.url = url;
		this.method			= (options.method		) ? options.method			: 'GET';
		this.query			= (options.query		) ? options.query			: null;
		
		this.onLoad			= (options.onLoad	 	) ? options.onLoad			: null;
		this.onLoaded		= (options.onLoaded	 	) ? options.onLoaded 	 	: null;
		this.onInteractive	= (options.onInteractive) ? options.onInteractive	: null;
		this.onComplete		= (options.onComplete	) ? options.onComplete		: null;
		this.onError		= (options.onError		) ? options.onError			: null;
		
		if (window.XMLHttpRequest) {
			this.req=new XMLHttpRequest();
			if (this.req.overrideMimeType) { this.req.overrideMimeType('text/xml'); }			
		} else {
			if (window.ActiveXObject) {
				try { this.req=new ActiveXObject("Msxml2.XMLHTTP"); }
				catch(e) {
					try { this.req=new ActiveXObject("Microsoft.XMLHTTP"); }
					catch(e) {}
				}
			}
		}
		if (!this.req) { this.req=new XMLHttpRequest();				}
		if (!this.req) { alert('IO-Error: Kein Handle verfügbar.');	}

	}
	
	AjaxRequest.prototype.doRequest = function() {
		this.req.open(this.method,this.url,true);    
		if(this.method == 'POST') { this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")  }
		
		var objThis			= this;
		var onLoad			= this.onLoad;
		var onLoaded		= this.onLoaded;
		var onInteractive	= this.onInteractive;
		var onComplete		= this.onComplete;
		var onError			= this.onError;
		
		this.req.onreadystatechange = function() {
			switch (objThis.req.readyState)	{
				case 0: // Uninitialisiert
				break;
				case 1:	// Loading
						if(onLoad!= null) { onLoad(objThis.req.responseText, objThis.req.responseXML);   }
				break;
				case 2: // Loaded
						if(onLoaded!= null) { onLoaded(objThis.req.responseText, objThis.req.responseXML);   }
				break;
				case 3: // Interactive
						if(onInteractive!= null) { onInteractive(objThis.req.responseText, objThis.req.responseXML);   }
				break;
				case 4: // Completed
					if ( (objThis.req.status == 200) && (objThis.req.statusText == 'OK') ) {
						if(onComplete != null) { onComplete(objThis.req.responseText, objThis.req.responseXML);   }
					} else {
						if(onError!= null) { onError(objThis.req.status,objThis.req.statusText); }
					}
				break;
			}
		}
		this.req.send(this.query);
	}    