/*var img = new Image();
img.src = "../immagini/minus_default.gif";

var img2 = new Image();
img2.src = "../immagini/plus_default.gif";

var img3 = new Image();
img3.src = "../immagini/minus_xp.gif";

var img4 = new Image();
img4.src = "../immagini/plus_xp.gif";
*/
// 28/05/2010 Branciari Lorenzo:	aggiunta funzioni liOnmouseover e liOnmouseout per gestire la evidenziazione automatica del nodo/foglia del menù al passaggio del mouse
//									in ingresso prendono l'oggetto parent <li>, e applicano/tolgono il css sfondoOver all'oggetto
function liOnmouseover(objLI){
	var arrayLiChild = new Array();
	arrayLiChild = objLI.getElementsByTagName("a");
	var posLastElement = arrayLiChild.length-1;
	var contenuto = arrayLiChild[posLastElement].innerHTML;
	// se il nodo/foglia non ha alcuna descrizione a video, non applica l'evidenziazione
	if(contenuto && contenuto!=" "){
		objLI.className="sfondoOver";
	}
}
function liOnmouseout(objLI){
	objLI.className="";
}

// 30/03/2010 Branciari Lorenzo: funzione riscritta completamente. ora chiude i nodi aperti quando ne clicco un altro
var array_aperti = new Array(4);											// array in cui salva gli id dei nodi attualmente aperti ([0]=> id nodo livello 1,[1]=> id nodo livello 2,[3]=> id nodo livello 2,[4]=> id nodo livello 3)
var livelloNodo = 0;
function expand_collapse(id,style,idRadice){
	if(document.getElementById(id)!=null){
		var flag=0;
		livelloNodo = 0;
		var livello = cerca_nodo(id,idRadice);								// in livello, ho il livello dell'albero cui appartiene il nodo cliccato, ora ne gestisce 4 (i valori vanno da 0 a 3)
		for (var a=livello; a<array_aperti.length; a++){						// scorro l'array dei nodi aperti
			if(array_aperti[a]){											// se c'è un id nodo aperto
				if(id == array_aperti[a])									// se ho cliccato su un nodo già aperto, dopo averlo chiuso non dovrò riaprirlo
					flag=1;
				var objNodo = document.getElementById(array_aperti[a]);		// oggetto nodo già aperto
				objNodo.style.display = "none";								// lo chiudo
				var img = document.getElementById("img_"+array_aperti[a]);	// oggetto immagine associata al nodo
				img.src="../immagini/plus_"+style+".gif";					// cambio l'immagine, metto quella relativa al nodo chiuso
				array_aperti[a]='';											// tolgo il nodo dall'array, perchè non è più aperto
			}
		}
		if(flag==0){														// se ho cliccato su un nodo che non era aperto, lo devo aprire
			var objNodo = document.getElementById(id);						// oggetto nodo cliccato
			objNodo.style.display = "block";								// lo apro
			array_aperti[livello]=id;										// salvo nell'array l'id del nodo che è stato aperto, nel livello corretto
			var img = document.getElementById("img_"+id);					// oggetto immagine associata al nodo
			img.src="../immagini/minus_"+style+".gif";						// cambio l'immagine, metto quella relativa al nodo aperto
		}
	}
}

// 30/03/2010 Branciari Lorenzo: nuova funzione. scorre tutta la struttura DOM dell'albero, cerca il nodo cliccato e restituisce il livello cui appartiene
// 04/06/2010 Branciari Lorenzo: resa la funzione ricorsiva
function cerca_nodo(idNodo,idRadice){
	livelloNodo++;
	var objroot1 = document.getElementById(idRadice);						// radice dell'albero
	for (var i=0; i<objroot1.childNodes.length; i++){						// livello 1 - scorro tutti gli elementi
		var objchild1 = objroot1.childNodes[i];								// oggetto di livello 1
		for (var j=0; j<objchild1.childNodes.length; j++){						// scorro tutti i sottooggetti dell'oggetto trovato
			if(objchild1.childNodes[j].nodeName=="UL"){						// se c'è un sottooggetto con tag UL, allora l'oggetto di livello 1 è un nodo
				if(objchild1.childNodes[j].id == idNodo){					// se l'oggetto di livello 1 è il nodo che è stato cliccato, restituisco il valore corrispondente al livello cui appartiene. passo 0 invece di 1 per mantenere la corrispondenza con gli elementi dell'array "array_aperti", poichè gli elementi dell'array partono da 0 (vedi commento nella dichiarazione dell'array)
					return livelloNodo;
				} else{														// se non ho trovato il nodo cliccato in un livello, lo cerco ricorsivamente nel successivo
					var ritorno = cerca_nodo(idNodo,objchild1.childNodes[j].id);
					if(ritorno != -1)
						return ritorno;
				}
			}
		}
	}
	livelloNodo--;
	return -1;
}

// 12/06/2010 Branciari Lorenzo: nuova funzione. nel caso in cui vengano gestiti due alberi, quello dell'area e quello del servizio, con questa funzione apro e chiudo il primo
function mostraNascondiAlbero1(){
	try {
	var objCorpo=document.getElementById("corpoMenuAlbero1");
	var objImgAlberoFreccia = document.getElementById("imgAlberoFreccia");	// oggetto span che contiene la freccia del menù che si può aprire e chiudere
	if(objCorpo.style.display=="none"){
		objCorpo.style.display="";
		//objImgAlberoFreccia.src = "../immagini/alberoFrecciaBasso.png";	// visualizzo freccia in basso, menù aperto
		objImgAlberoFreccia.innerHTML = "&#9660;";
	}else{
		objCorpo.style.display="none";
		//objImgAlberoFreccia.src = "../immagini/alberoFrecciaDestra.png";	// visualizzo freccia a destra, menù chiuso
		objImgAlberoFreccia.innerHTML = "&#9658;";
	}
	} catch (e) {}
}

function sleep(numberMillis){
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	
	while (true){
	now = new Date();
	if (now.getTime() > exitTime) return;
	}
};

function albero_preloadImmagine(imgSrc){
	try{
		var tmpImg=new Image();
		tmpImg.src=imgSrc;				
		if(tmpImg.complete)return true;
	}
	catch(exIgn){
		return false;
	}	
	return true;
}
albero_preloadImmagine("../immagini/sfondomenu.png");


//Inizio Modifica Andrea per problemi menu
function albero_addCompatibleLoadListener(fn){ 
	if (typeof window.addEventListener != "undefined"){ 
		window.addEventListener("load", fn, false); 
		} 
		else if (typeof document.addEventListener != "undefined"){ 
		document.addEventListener("load", fn, false); 
		} 
		else if (typeof window.attachEvent != "undefined"){ 
		window.attachEvent("onload", fn); 
	} 
	else { 
		var oldfn = window.onload; 
		if (typeof window.onload != "function") { 
					window.onload = fn; 
		} 
		else {
				window.onload = function(){
				oldfn(); 
				fn(); 
				}; 
			}
	}
}

function albero_debug(txt){
	if(true==true)return;
	try{
		if(window.console){
			window.console.debug(txt);
		}
	}
	catch(exIgn){}
}

//Inizio Modifica Andrea - controllo che effettivamente l'oggetto con id menu sia il leftmenu
function albero_startsWith(str, prefix) {
	return str.substring(0, prefix.length) == prefix;
}
//Fine Modifica Andrea - controllo che effettivamente l'oggetto con id menu sia il leftmenu

function onLoadAlbero(){
	var objMenu = document.getElementById("menu");
	if(!objMenu)return;
	
	//Inizio Modifica Andrea - controllo che effettivamente l'oggetto con id menu sia il leftmenu
	if((""+objMenu.nodeName).toUpperCase()!="DIV")return;
	if( !albero_startsWith((""+objMenu.className).toUpperCase(), "LEFTMENU"))  return;
	//Fine Modifica Andrea - controllo che effettivamente l'oggetto con id menu sia il leftmenu

	objMenu.onmouseover= function(e){
		if (!e) var e = window.event;
		var tg = (window.event) ? e.srcElement : e.target;
		//albero_debug("MOUSE OVER CALLED su elemento = " + tg.id);
		nascondi_list();
	};

	objMenu.onmouseout= function(e){
		if (!e) var e = window.event;
		var tg = (window.event) ? e.srcElement : e.target;

		//albero_debug("MOUSE OUT CALLED su elemento = " + tg.id);
		
		//if (tg.nodeName != 'DIV') return;
		
		var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
		//albero_debug("... per parent = " + reltg.id);
		
		if((tg!=reltg)&&(reltg!=null))pNode = reltg;
		else pNode = tg;
		
		while (pNode.id!="menu" && pNode.nodeName != 'BODY'){
			pNode= pNode.parentNode
			if(!pNode)break;
			//albero_debug("... parent.id = " + pNode.id);
		}
		if(pNode){
			if(pNode.id=="menu")return;
			//albero_debug("....pNode.id = " +pNode.id);		
		}
		mostra_list();
		
	};
}
albero_addCompatibleLoadListener(onLoadAlbero);
//Fine Modifica Andrea

function allarga(id)
{
		document.getElementById(id).className='leftmenu';
		document.getElementById(id).style.width='240px';
//		document.getElementById('img_right').style.display='none';

}
function restringi(id)
{
	document.getElementById(id).style.width='19px';
	document.getElementById(id).className='leftmenu_close';

//	document.getElementById('img_right').style.display='inline';
}

var mtimeout = null;
function nascondi_list() {

	if(document.getElementById("menu").className=='leftmenu')return;

	if(mtimeout!=null){
		window.clearTimeout(mtimeout);
		mtimeout=null;
	}
	
	var fn = function(){
		mtimeout=null;
		var list = document.getElementsByTagName("select"); 
		for (var i = 0; i < list.length; i++) 
		{ 
			list[i].style.visibility='hidden';
		}
		//restringi('menu');
		allarga('menu');
	}
	mtimeout = window.setTimeout(fn,100);
}

function mostra_list(){
	//albero_debug("MOSTRA list called!");
	
	if(mtimeout!=null){
		window.clearTimeout(mtimeout);
		mtimeout=null;
	}
	restringi('menu');
	
	var list = document.getElementsByTagName("select"); 
	for (var i = 0; i < list.length; i++) { 
		list[i].style.visibility='visible';
	}
	//allarga('menu');
	restringi('menu');
}

function quick_launch(selezionato)
{
	return;
	A = document.getElementById("AA");
	if(A!=null)
		A.style.border='1px solid #FFFFFF';
	B = document.getElementById("BB");
	if(B!=null)
		B.style.border='1px solid #FFFFFF';
	C = document.getElementById("CC");
	if(C!=null)
		C.style.border='1px solid #FFFFFF';
	D = document.getElementById("DD");
	if(D!=null)
		D.style.border='1px solid #FFFFFF';
	E = document.getElementById("EE");
	if(E!=null)
		E.style.border='1px solid #FFFFFF';
	F = document.getElementById("FF");
	if(F!=null)
		F.style.border='1px solid #FFFFFF';
	G = document.getElementById("GG");
	if(G!=null)
		G.style.border='1px solid #FFFFFF';
	H = document.getElementById("HH");
	if(H!=null)
		H.style.border='1px solid #FFFFFF';
	I = document.getElementById("II");
	if(I!=null)
		I.style.border='1px solid #FFFFFF';
	L = document.getElementById("LL");
	if(L!=null)
		L.style.border='1px solid #FFFFFF';
	M = document.getElementById("MM");
	if(M!=null)
		M.style.border='1px solid #FFFFFF';
	N = document.getElementById("NN");
	if(N!=null)
		N.style.border='1px solid #FFFFFF';
	O = document.getElementById("OO");
	if(O!=null)
		O.style.border='1px solid #FFFFFF';
	P = document.getElementById("PP");
	if(P!=null)
		P.style.border='1px solid #FFFFFF';
	Q = document.getElementById("QQ");
	if(Q!=null)
		Q.style.border='1px solid #FFFFFF';
	R = document.getElementById("RR");
	if(R!=null)
		R.style.border='1px solid #FFFFFF';
	S = document.getElementById("SS");
	if(S!=null)
		S.style.border='1px solid #FFFFFF';
	T = document.getElementById("TT");
	if(T!=null)
		T.style.border='1px solid #FFFFFF';
	U = document.getElementById("UU");
	if(U!=null)
		U.style.border='1px solid #FFFFFF';
	V = document.getElementById("VV");
	if(V!=null)
		V.style.border='1px solid #FFFFFF';
	Z = document.getElementById("ZZ");
	if(Z!=null)
		Z.style.border='1px solid #FFFFFF';
		
	if(selezionato!=0)
		selezionato.style.border='1px dotted #999999';
}


function expand_all(style)
{	
	var ulElements = document.getElementsByTagName('ul'); 
       
	for (i = 0; i < ulElements.length; i++) 
	{ 
		currentElement = ulElements[i];
		currentElement.style.display='block';
		
		var img_name;
		img_name="img_"+currentElement.id;
		
		var img;
		img=document.getElementById(img_name);
		if(img!=null)
			img.src="../immagini/minus_"+style+".gif";
	} 
}

function collapse_all(style)
{
 	var ulElements = document.getElementsByTagName('ul'); 
       
	for (i = 0; i < ulElements.length; i++) 
	{ 
		currentElement = ulElements[i];
		if(currentElement.id!="root")
		currentElement.style.display='none';
		
		var img_name;
		img_name="img_"+currentElement.id;
		
		var img;
		img=document.getElementById(img_name);
		if(img!=null)
			img.src="../immagini/plus_"+style+".gif";
	} 
}

function pulisci(text)
{
	if(text.value == 'Inserisci un valore.')
		text.value = '';
	else if(text.value == '')
		text.value = 'Inserisci un valore.';
}
