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";

function expand_collapse(id,style)
{	
	if(document.getElementById(id)!=null)
	{
		var img = document.getElementById("img_"+id);
		if(document.getElementById(id).style.display=='none')
		{	
			document.getElementById(id).style.display='block';
			if(img!=null)
				img.src="../immagini/minus_"+style+".gif";
		}
		else
		{
			document.getElementById(id).style.display='none';
			if(img!=null)
				img.src="../immagini/plus_"+style+".gif";
		}
	}
}

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){}
}

function onLoadAlbero(){
	var objMenu = document.getElementById("menu");
	if(!objMenu)return;

	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.';
}
