var ajax = new function()	{
	
	//Function to create an XMLHttpRequest.
	this.getxmlhttp = function (){
		var oXmlHttp = null;
		//If, the activexobject is available, we must be using IE.
		if (window.ActiveXObject){
			oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			//Else, we can use the native Javascript handler.
			oXmlHttp = new XMLHttpRequest();
		}
		return oXmlHttp;
	}
	
	//Function to process an XMLHttpRequest.
	this.process = function (sServerPage, sGetOrPost, sParameter, pfHandleFunc){
		//Get an XMLHttpRequest object for use.
		var oXmlHttp = this.getxmlhttp();
		if (sGetOrPost == "get"){
			oXmlHttp.open("GET", sServerPage);
			oXmlHttp.onreadystatechange = function() {
				if (oXmlHttp.readyState == 4 && oXmlHttp.status == 200) {
					//Handle the response with the function passed
					pfHandleFunc(oXmlHttp.responseText);
				}
			}
			oXmlHttp.send(null);
		} else {
			oXmlHttp.open("POST", sServerPage, true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			oXmlHttp.onreadystatechange = function() {
				if (oXmlHttp.readyState == 4 && oXmlHttp.status == 200) {
					//Handle the response with the function passed
					pfHandleFunc(oXmlHttp.responseText);
				}
			}
			oXmlHttp.send(sParameter);
		}
	}
	
	this.parseresponse = function(sText){
		return (sText != null && parseInt(sText.substring(sText.indexOf("<risposta>") + 10, sText.indexOf("</risposta>"))));
	}
	
	this.getnumericresponse = function(sText){
		if (sText == null)
			return null;
		return parseInt(sText.substring(sText.indexOf("<risposta>") + 10, sText.indexOf("</risposta>")));
	}
	
}
