
function Site(){
	
	this.xhr = false;
	
	/** 
	 * Sends a xmlHttpRequest
	 *
	 */
	this.sendXmlHttpRequest = function(url, idOutput, arrParameter, callBackMethod){
		this.xhr = false;
		
		if(!arrParameter){
			arrParameter = new Array();
		}
		
		// try to create a xmlHttpRequest-Object
		// Mozilla, Opera, Safari or Internet Explorer 7
		if ( typeof XMLHttpRequest != 'undefined') {
		    this.xhr = new XMLHttpRequest();
		}
/*	
		if ( !this.xhr) {
		    // Internet Explorer 6 or older
		    try {
		        this.xhr  = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch(e) {
		        try {
		            this.xhr  = new ActiveXObject("Microsoft.XMLHTTP");
		        } catch(e) {
		            this.xhr  = false;
		        }
		    }
		}
*/	
		if(!this.xhr){
			// creation of the xmlHttpReq-Object failed
			alert('Creation of the xmlHttpRequest-Object failed.');
			return false;
		}
			
		// send the request 
		this.xhr.idOutput = idOutput;
		this.xhr.open('POST', url, true);
		
		if(!callBackMethod){
			this.xhr.onreadystatechange = this.display;
		} else{
			this.xhr.onreadystatechange = callBackMethod;
		}
		
		this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		this.xhr.send(arrParameter.join('&'));
	
		return true;
	}
	
	
	/**
	 * Default Call-back Method for the xmlHttpRequest
	 *
	 */
	this.display = function(){
	
		var objDivOutput = false;
	
		if(objSite.xhr.readyState == 4) {
			
			if(!(objDivOutput = document.getElementById(objSite.xhr.idOutput))){
				alert('xmlHttpRequest failed. Can\'t get div: output id = ' + objSite.xhr.idOutput);
				return false;
			}
			
			if (objSite.xhr.status == 200) {
				if ( !objSite.xhr.responseText) {
					alert('xmlHttpRequest failed');
					return false;			
				}
				
				objDivOutput.innerHTML = objSite.xhr.responseText;
				return true;
				
			} else{
				// Print the error message
				objDivOutput.innerHTML = objSite.xhr.responseText;
				//alert('== 4 stat = ' + objSite.xhr.status + ' - ' + objSite.xhr.responseText);
			}
		} // END xmlHttpReq.readyState == 4
		
		return false;
	}
}

var objSite = new Site();
