/* centra i pop up sullo schermo */
function centerPopX(popW){ if(!popW) popW=500; return ((screen.availWidth - popW)/2);  }
function centerPopY(popH){ if(!popH) popH=270; return ((screen.availHeight - popH)/2); }


/*
	Tree Menu Drop Down
	argomenti:
	var topOgg = oggetto che riceve l'onclick
	var e = oggetto event

	Da inserire nell'onclick della riga con sottomenu
*/
function TMdd(topOgg,e)
{
	// trova l'elemento da cui è partito l'evento
	if(e.srcElement) tt = e.srcElement; //ie
	else tt = e.target; // dom

	// non effettua le modifiche se è stato cliccato il link, ma solo la riga con la freccietta
	if(tt.nodeName == 'DIV' || (tt.nodeName == '#text' && tt.parentNode.nodeName == 'DIV'))
	{
		// scambia classi a voci con sottomenu
		topOggClassi = topOgg.className.split(' ');
		classNotFound = true;
		var i = 0;
		do
		{
			if(topOggClassi[i] == 'TMOp')
			{
				topOggClassi[i] = 'TMCl';
				classNotFound = false;
			}
			else if(topOggClassi[i] == 'TMCl')
			{
				topOggClassi[i] = 'TMOp';
				classNotFound = false;
			}
		}while(classNotFound && ++i < topOggClassi.length)
		topOgg.className = topOggClassi.join(' ');

		// apre/chiude sottomenu
		/*
		subIdOgg = document.getElementById('TMsm' + subId);
		if(subIdOgg.style.display != 'none') subIdOgg.style.display = 'none';
		else subIdOgg.style.display = '';
		*/

		/* cerca il submenu relativo alla riga cliccata e lo apre/chiude */
		currSibling = topOgg.nextSibling;
		siblingNotFound = true;
		while(siblingNotFound && currSibling != null)
		{
			if(currSibling.className != null && currSibling.className == 'TMsub')
				siblingNotFound = false;
			else
				currSibling = currSibling.nextSibling;
		}
		if(currSibling != null)
		{
			if(currSibling.style.display != 'none') currSibling.style.display = 'none';
			else currSibling.style.display = '';
		}
	}
}

function TM(topOgg)
{
	// trova l'elemento da cui è partito l'evento
	//if(e.srcElement) tt = e.srcElement; //ie
	//else tt = e.target; // dom

	// non effettua le modifiche se è stato cliccato il link, ma solo la riga con la freccietta
	//if(tt.nodeName == 'DIV' || (tt.nodeName == '#text' && tt.parentNode.nodeName == 'DIV'))
	{
		// scambia classi a voci con sottomenu
		topOggClassi = topOgg.className.split(' ');
		classNotFound = true;
		var i = 0;
		do
		{
			if(topOggClassi[i] == 'TMOp')
			{
				topOggClassi[i] = 'TMCl';
				classNotFound = false;
			}
			else if(topOggClassi[i] == 'TMCl')
			{
				topOggClassi[i] = 'TMOp';
				classNotFound = false;
			}
		}while(classNotFound && ++i < topOggClassi.length)
		topOgg.className = topOggClassi.join(' ');

		// apre/chiude sottomenu
		/*
		subIdOgg = document.getElementById('TMsm' + subId);
		if(subIdOgg.style.display != 'none') subIdOgg.style.display = 'none';
		else subIdOgg.style.display = '';
		*/

		/* cerca il submenu relativo alla riga cliccata e lo apre/chiude */
		currSibling = topOgg.nextSibling;
		siblingNotFound = true;
		while(siblingNotFound && currSibling != null)
		{
			if(currSibling.className != null && currSibling.className == 'TMsub')
				siblingNotFound = false;
			else
				currSibling = currSibling.nextSibling;
		}
		if(currSibling != null)
		{
			if(currSibling.style.display != 'none') currSibling.style.display = 'none';
			else currSibling.style.display = '';
		}
	}
}