/* Autore Cristiano Ceglia
	anno 2006 */

function AJAXUtil() {
	var objXmlHttp = null;
	var target = function(){};
	
	function GetXmlHttpObject() { 
		var XMLHttp=null;
		try {
			XMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {}
		}
		if (XMLHttp==null) {
			XMLHttp=new XMLHttpRequest();
		}
		return XMLHttp;
	};
	
	function stateChanged()  { 
		if (objXmlHttp.readyState==4  || objXmlHttp.readyState=="complete") { 
			document.getElementById(target).innerHTML=objXmlHttp.responseText;
		} 
	};

	function valoreRitorno()  { 
		if (objXmlHttp.readyState==4  || objXmlHttp.readyState=="complete") { 
			target(objXmlHttp.responseText);
		} 
	};
	
	this.setValue = function(t, v) {
		document.getElementById(t).innerHTML=v;
	};	
	
	this.setValueFromFile = function(t, url) {
		target = t;
		objXmlHttp=GetXmlHttpObject();
		if (objXmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		} 
		objXmlHttp.onreadystatechange=stateChanged;
		objXmlHttp.open("GET",url,true);
		objXmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		objXmlHttp.send(null);
	};	

	this.getValue = function(t, url) {
		target = t;
		objXmlHttp=GetXmlHttpObject();
		if (objXmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		} 
		objXmlHttp.onreadystatechange=valoreRitorno;
		objXmlHttp.open("GET",url,true);
		objXmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		objXmlHttp.send(null);
	};	
    
	this.callPage = function(url) {
		objXmlHttp=GetXmlHttpObject();
		if (objXmlHttp==null) {
			alert ("Browser does not support HTTP Request");
			return;
		} 
		objXmlHttp.open("GET",url,true);
		objXmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		objXmlHttp.send(null);
	};
};
