//<![CDATA[
var XMLHTTPRequest_Object=null;
var XMLHTTPRequest_Response=null;
var XMLHTTPRequest_QueryString=null;
/*
Funzione che ingloba la costruzione dell'oggetto request.
Parametri:
	reqType: il tipo di richiesta HTTP
	url: l'Url del programma lato server
	async: specifica se la richiesta è asincrona o meno
	respHandle: funzione di gestione risposta
*/
function httpRequest(reqType,url,async,respHandle) {
	//browser mozilla
	if (window.XMLHttpRequest) {
		XMLHTTPRequest_Object=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		XMLHTTPRequest_Object=new ActiveXObject("Msxml2.XMLHTTP");
		if (!XMLHTTPRequest_Object) {
			XMLHTTPRequest_Object=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	//Se nessuna inizializzazione ActiveXObject è ok, XMLHTTPRequest_Object può essere null
	if (XMLHTTPRequest_Object) {
		//Se reqType è POST il quinto argomento della funzione ha i dati
		if (reqType.toLowerCase()!="post") {
			initReq(reqType,url,async,respHandle);
		} else {
			//invio POST
			var args=arguments[4];
			if (args!=null&&args.length>0) {
				initReq(reqType,url,async,respHandle,args);
			}
		}	
	} else {
		//Applicazione non disponibile
		alert("Errore: applicazione non disponibile");
	}
}
//Inizializzazione oggetto XMLHTTPRequest_Object stanziato in precedenza
function initReq(reqType,url,bool,respHandle) {
	try {
		//Specifica la funzione che gestirà la risposta HTTP
		XMLHTTPRequest_Object.onreadystatechange=respHandle;
		XMLHTTPRequest_Object.open(reqType,url,bool); 
		if (reqType.toLowerCase=="post") {
			//Imposta la header content type della richiesta POST
			XMLHTTPRequest_Object.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			XMLHTTPRequest_Object.send(arguments[4]);
		} else {
			XMLHTTPRequest_Object.send(null);
		}
	} catch (errv) {
		alert("Errore: "+errv.message);
	}
}
//]]>
