/** trans4mation cHttpRequest Class **
* version: 	0.0.1
* date:		24.06.2008
* author:	karsten pötschk
*
* description:
* stellt eine asynchrone Verbindung mit einem client server her
**/
function cHttpRequest() {
	
	
	// private
	var m_sLadeSeite = '';
	var m_oXmlHttpObject = null;
	var m_sIdName = "";
	
	this.setLadeanzeige = function(sLadeanzeige) {
		
		if(sLadeanzeige != "") {
			m_sLadeanzeige = sLadeanzeige;
		}
		else {
			m_sLadeSeite = '<div style=\"text-align:center; margin-bottom: 50px; margin-top: 50px;\" ><img style=\"margin-bottom: 50px; margin-top: 50px; \" src=\"templates\/de\/images\/allgemein\/progress.gif\" border=\"0\" \/><\/div>';
		}
		
	}
	
	function init() {
		if (typeof XMLHttpRequest != 'undefined' && window.XMLHttpRequest) {
    		return new XMLHttpRequest();
  		}
  		
  		try {
        	return new ActiveXObject("Msxml2.XMLHTTP");
    	}
    	catch(e) {
        	try {
           		return new ActiveXObject("Microsoft.XMLHTTP");
        	}
        	catch(e)  {
           		return null;
        	}
    	}
  		
  		return null;
	}
	
	this.isReady = function() {
		return m_bIsReady;
	}
	
	this.loadGetContent = function(sIdName, sUrl) {
		m_oXmlHttpObject = init();
		
    	if(m_oXmlHttpObject == null) {
      		return false;
    	}
    	
   	 	m_sIdName = sIdName;
   	 	
    	m_oXmlHttpObject.open('get', sUrl, true);    	
    	m_oXmlHttpObject.send(null);
    	m_oXmlHttpObject.onreadystatechange = handleContent;
    
    	return false;
	}
	
	this.loadPostContent = function(sIdName, sUrl, sParams) {
		m_oXmlHttpObject = init();
		
    	if(m_oXmlHttpObject == null) {
      		return false;
    	}
    	
   	 	m_sIdName = sIdName;
   	 	
    	m_oXmlHttpObject.open('POST', sUrl, true);
    	
    	m_oXmlHttpObject.setRequestHeader("Cache-Control", "no-cache, must-revalidate");
    	m_oXmlHttpObject.setRequestHeader("Expires", "Sat, 26 Jul 1997 05:00:00 GMT");
    	m_oXmlHttpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	m_oXmlHttpObject.setRequestHeader("Content-length", sParams.length);
    	m_oXmlHttpObject.setRequestHeader("Connection", "close");
    	m_oXmlHttpObject.send(sParams);
    	m_oXmlHttpObject.onReadyStateChange = handleContent;
    
    	return false;
	}
	
	function handleContent() {
		if(m_sIdName == "") {
			return false;
		}
		
		switch(m_oXmlHttpObject.readyState) {
			case 1:
				if(m_sLadeSeite.length > 1) {
					document.getElementById(m_sIdName).innerHTML = m_sLadeSeite;
				}
			break;
			case 2:
				if(m_sLadeSeite.length > 1) {
					document.getElementById(m_sIdName).innerHTML = m_sLadeSeite;
				}
			break;
			case 3:
				if(m_sLadeSeite.length > 1) {
					document.getElementById(m_sIdName).innerHTML = m_sLadeSeite;
				}
			break;
			case 4:
				m_sText = m_oXmlHttpObject.responseText;
				if(m_sIdName == "seiten_anzeige") {
					document.getElementById("seiten_anzeige_unten").innerHTML = m_sText;
				}
				document.getElementById(m_sIdName).innerHTML = m_sText;
			break;
		}
	}
	
}

