
// ############################################################
// \fn createXMLHttpRequestObject
// \brief erstellt ein XMLHTTP-Objekt und gibt dieses zurück
// \return Object - neu erstelltes XMLHTTP-Objekt
// ############################################################
function createXMLHttpRequestObject() 
{
	var oRequest = null;
	try 
	{
		this.oRequest = new ActiveXObject("MSXML2.XMLHTTP");
	}
	catch (oException) 
	{
		try 
		{
			this.oRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (oException) 
		{
			if (typeof XMLHttpRequest != "undefined") 
				this.oRequest = new XMLHttpRequest;
		}
	}
	return(this.oRequest);
}		


// ############################################################
// \class cHttpReader
// \brief cHttpReader-KLasse. Mit dieser Klasse ist es möglich Webseiten 
//		einzuladen
// ############################################################
function cHttpReader() 
{
	this.sContent	= "";			// enthält den Inhalt des Documents
	this.sState		= 0;
	this.oRequest	= null;

	// Callback-FunktionsZeiger, für die verschiedenen Lade-Statis 
	this.onLoadComplete = null;
	this.onLoading		= null;
	this.onUninitialized= null;
	this.onLoaded		= null;
	this.onInteractive	= null;
}

// ############################################################
// \fn setCallback
// \brief setzt die Callback-Funktion für ein bestimmtes Ereignis 
//		Ereignisse: uninitialized, loading, loaded, interactive, loadcomplete
// \param sCallbackType = bestimmt welche Callback-Funktion gesetzt wird (loading, complete,...)
// \param pCallbackFunction = CallBack-Funktion
// ############################################################
cHttpReader.prototype.setCallback = function (sCallbackType, pCallbackFunction)	// interne Callback-Funktion
{
	sType = sCallbackType.toUpperCase();
	if (sType == "uninitialized")
		this.onUninitialized = pCallbackFunction;
	else if (sType == "loading")
		this.onLoading = pCallbackFunction;
	else if (sType == "loaded")
		this.onLoaded = pCallbackFunction;
	else if (sType == "interactive")
		this.onInteractive = pCallbackFunction;
	else if (sType == "loadcomplete")
		this.onLoadComplete = pCallbackFunction;
}


// ############################################################
// \fn loadUrl
// \brief Lädt den Inhalt einer Url ein und speichert den Seiteninhalt 
//		in der "sContent"-Eigenschaft 
// \param sUrl = Url der zu ladenen Webseite
// \param sMethod = Art der Parameterübergabe ("GET", "POST")
// \param bSynchron = gibt an, ob die Webseite Syncron(true) 
// 			oder Asynchron(false) geladen werden soll
// ############################################################
cHttpReader.prototype.loadUrl = function (sUrl, sMethod, bSynchron)
{
	this.sContent = "";
	this.oRequest = createXMLHttpRequestObject();
	if (bSynchron == true)
		this.oRequest.onreadystatechange = this.callback_StateChange;
	this.oRequest.open(sMethod, sUrl, bSynchron);				
	this.oRequest.send(null);
	if (bSynchron == false)
		this.sContent = this.oRequest.responseText;
}


// ############################################################
// \fn callback_StateChange
// \brief CallBack-Funktion die vom XMLHTTP-Objekt  bei Statusänderungen 
//		aufgerufen wird
//		Hier wird dann je nach status die jeweilige Callback-Funktion 
//		gestartet, um die STatusänderung zu verarbeiten
// ############################################################
cHttpReader.prototype.callback_StateChange = function ()
{
	switch (this.oRequest.readyState) 
	{
		case 0 : // UNINITIALIZED
			this.onUninitialized(this);
			break;
		case 1 : // LOADING
			this.onLoading(this);
			break;
		case 2 : // LOADED
			this.onLoaded(this);
			break;
		case 3 : // INTERACTIVE
			this.onInteractive(this);
			break;
		case 4 : // COMPLETED
			this.sContent =  this.oRequest.responseText;
			sState	= oRequest.status;
			this.onLoadComplete(this);
			break;
			
		default : 
			break; // fehlerhafter Status
	}
}


