/* FUNZIONI GENERICHE DI DATA RETRIEVE CON HTTP ASINCRONO */

var xmlHttp

function GetXmlHttpObject(handler){ 
	var objXmlHttp=null
	if (navigator.userAgent.indexOf("Opera")>=0){
		alert("Browser OPERA non supportato") 
		return 
	}
	if (navigator.userAgent.indexOf("MSIE")>=0){ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
		strName="Microsoft.XMLHTTP"
		} 
		try	{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e){ 
			alert("Errore: è necessario attivare lo scripting ActiveX") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0){
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
}

function sendHTTP(url,handler){ 
	xmlHttp=GetXmlHttpObject(handler)
	xmlHttp.open('get', url , true)
	xmlHttp.send(null)
} 

/* FUNZIONI UTILIZZATRICI */

var toBeClosed = false;
var idCaricato = 0;
var idTimerWin = 0;
var posSubMenu = 0;

function subMenuGen(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		var objMenu = document.getElementById("submenu");
		objMenu.innerHTML=xmlHttp.responseText;
		objMenu.style.visibility="visible";
		objMenu.style.height="auto";
		objMenu.style.width="auto";
	} 
} 

function openSubMenu(idp){
	toBeClosed = false;
	if(idp == idCaricato) return false;
	var objMenu = document.getElementById("submenu");
	objMenu.style.visibility="hidden";
	objMenu.style.height="0px";
	objMenu.style.width="0px";
	objMenu.style.left=posSubMenu+"px";
	objMenu.style.top="35px";
	sendHTTP("submenu.php?ID_padre="+((idp)?idp:0),subMenuGen);
	idCaricato = idp;
}

function startCloseSubMenu(){
	toBeClosed = true;
	if(idTimerWin) clearTimeout(idTimerWin);
	idTimerWin = setTimeout("closeSubMenu()",500);
}

function abortCloseSubMenu(){
	toBeClosed = false;
}

function closeSubMenu(){
	if(!toBeClosed) return;
	idCaricato = 0;
	var objMenu = document.getElementById("submenu");
	objMenu.style.visibility="hidden";
	objMenu.style.height="0px";
	objMenu.style.width="0px";
	clearTimeout(idTimerWin);
}