function chiudi_trova(livello, riga_max)
{
// PER AGGIUNGERE UN LIVELLO INSERIRE UN CICLO FOR
for(a=1; a<=riga_max; a++)
	{
	livello_new=livello+"-"+a;
	chiudi(livello_new)
	a = (document.getElementById(livello_new)) ? a : riga_max;
	for(b=1; b<=riga_max; b++)
		{
		livello_new1=livello_new+"-"+b;
		chiudi(livello_new1)
		b = (document.getElementById(livello_new1)) ? b : riga_max;
		for(c=1; c<=riga_max; c++)
			{
			livello_new2=livello_new1+"-"+c;
			chiudi(livello_new2)
			c = (document.getElementById(livello_new2)) ? c : riga_max;
			for(d=1; d<=riga_max; d++)
				{
				livello_new3=livello_new2+"-"+c;
				chiudi(livello_new3)
				d = (document.getElementById(livello_new3)) ? d : riga_max;
				}
			}
		}
	}
}
 
function chiudi(livello)
{
if (document.getElementById(livello))
	{
	document.getElementById(livello).style.display = "none";
	}
}
 
function apri(livello)
{
if (document.getElementById(livello))
	{
	document.getElementById(livello).style.display = "block";
	}
}
 
function menu(livello, riga_max, nascondi)
{
// { ALT+123
// } ALT+125
 
// VERIFICA SE E' L'ULTIMO LIVELLO
azione="LINK";
oggetto = document.getElementById(livello+"-1");
if (oggetto)
	{
	azione = (oggetto.style.display!="none") ? "CHIUDI" : "APRI";
	}
if (azione=="CHIUDI")
	{
	chiudi_trova(livello, riga_max)
	}
 
if (azione=="APRI")
	{
	if (nascondi=="SI")
		{
		// CALCOLA IL LIVELLO CLIKKATO
		righe=livello.split("-");
		n_liv=righe.length;
		livello_chiudi="";
		for(i=0; i<=n_liv-2 ; i++)
			{
			livello_chiudi=livello_chiudi + righe[i] + "-";
			}
		for(mm=1; mm<=riga_max; mm++)
			{
 
			livello_chiudi1=livello_chiudi+mm;
			if (livello!=livello_chiudi1)
				{
				chiudi_trova(livello_chiudi1, riga_max)
				}
			mm = (document.getElementById(livello_chiudi1)) ? mm : riga_max;
			}
		}
	
	for(a=1; a<=riga_max; a++)
		{
		livello_new=livello+"-"+a;
		apri(livello_new);
		a = (document.getElementById(livello_new)) ? a : riga_max;
		}
	}
 
if (azione!="LINK")
	{
	return false;
	}
}
