// Code by Andrea Moi (IUX) - Mind srl - http://wwmind.com 

var InternetExplorer=navigator.appName.indexOf("Microsoft")!=-1;
var NetscapeNavigator=navigator.appName.indexOf("Netscape")!=-1;
var browserVer=parseInt(navigator.appVersion);
var Win=navigator.userAgent.indexOf("Win")!=-1;	
var	NS4=(typeof document.layers!="undefined")?1:0;
var Gecko=navigator.userAgent.indexOf("Gecko")!=-1;
var Opera=navigator.userAgent.indexOf("Opera")!=-1;
var	IE=((typeof document.all!="undefined") && (browserVer >= 4))?1:0;


// select: autosubmit
function autoSubmitSelect (selObj,emptyAlso)	{
	var v=selObj[selObj.selectedIndex].value;
	if (v!=""||emptyAlso)	selObj.form.submit();
}

// global menu var
var floatMenuOpen=null;
var floatMenuClose=null;
var selectFieldList=null;

// show or hide page select field (IE bug with float menu)
function switchSelectField (show)	{
	if (!InternetExplorer||!floatMenuOpen)	return;
	var s;

	if (show)	{	// mostro field
		if (!selectFieldList||selectFieldList.length<1)	return;
		
		// show stored fields
		for (s=0;s<selectFieldList.length;s++)	selectFieldList[s].style.visibility="visible";
		
	} else {	// nascondo field
		if (!document.getElementsByTagName)	return;		// funzione non supportata
	
		// se non e' gia' stato fatto, costruisco lista dei select della pagina
		if (!selectFieldList)	{	
		
			// prendo array dei select presenti nella pagina
			var selList=document.getElementsByTagName("select");
			if (selList.length<1)	return;	// nessun select trovato

			// variabili di appoggio
			var sLeft,sRight,sTop,sBottom,mLeft,mRight,mTop,mBottom,objParent;
			
			// calcolo gli offset del menu aperto rispetto al body
			mLeft = floatMenuOpen.offsetLeft;
			mTop = floatMenuOpen.offsetTop;
			objParent = floatMenuOpen.offsetParent;
			while (objParent&&objParent.tagName.toUpperCase()!="BODY") {	// scorro tutti gli oggetti parent
				mLeft += objParent.offsetLeft;
				mTop += objParent.offsetTop;
				objParent = objParent.offsetParent;
			}
			// calcolo larghezza e aggiungo bordo di sicurezza
			mRight=mLeft+floatMenuOpen.clientWidth+10;
			mBottom=mTop+floatMenuOpen.clientHeight+10;
			mLeft-=10;
			mTop-=10;

			// creo array globale elementi
			selectFieldList=new Array();	
			
			// loop elements
			for (s=0;s<selList.length;s++)	{
			
				if (!selList[s].offsetParent)	continue;
			
				// calcolo gli offset del select rispetto al body
				sLeft = selList[s].offsetLeft;
				sTop = selList[s].offsetTop;
				objParent = selList[s].offsetParent;
				while (objParent&&objParent.tagName.toUpperCase()!="BODY") {	// scorro tutti gli oggetti parent
					sLeft += objParent.offsetLeft;
					sTop += objParent.offsetTop;
					objParent = objParent.offsetParent;
				}
				// calcolo larghezza e aggiungo bordo di sicurezza
				sRight=sLeft+selList[s].clientWidth+10;
				sBottom=sTop+selList[s].clientHeight+10;
				sLeft-=10;
				sTop-=10;
				
				//alert("menu  = "+mLeft+" , "+mTop+" x "+mRight+" , "+mBottom +"\n\n"+selList[s].name+" = "+sLeft+" , "+sTop+" x "+sRight+" , "+sBottom);				
				
				// controllo incrocio box
				if (sLeft>mRight||sTop>mBottom)	continue;
				if (sRight<mLeft||sBottom<mTop)	continue;

				// save
				selectFieldList[selectFieldList.length]=selList[s];
			}
		}
		if (!selectFieldList||selectFieldList.length<1)	return;			// no element found
		
		// hide fields
		for (s=0;s<selectFieldList.length;s++)		selectFieldList[s].style.visibility="hidden";
	}
}

// get element by ID (with browser check)
function getObj(objID){
	if (!document.getElementById)	return null;	// not compatible
	return document.getElementById(objID);
}

// show or hide a object
function switchObj(obj,show)	{
	if (!obj)	return;
	
	if (show)	obj.style.display = "block";	// show
	else		obj.style.display = "none";		// hide
	
	if (Opera)	{	// aggiro baco background menu di Opera
		if (show)	obj.style.visibility="visible";	// show
		else		obj.style.visibility="hidden";		// hide
	}
}

// check a object visibility
function isVisible(obj)	{
	return (obj&&obj.style.display!="hidden"&&obj.style.display!="none");
}

// toggle a object
function toggleObj(objName)	{
	var obj=getObj(objName);
	if (!obj)	return;
	if (isVisible(obj))		switchObj(obj,false);	// hide
	else					switchObj(obj,true);	// show
}

// show and hide DIV
function alternateShow(divToShow,divToHide) {
	// hide
	if (divToHide!=null&&divToHide.style!=null) {
		divToHide.style.display="none";
		if (Opera)		divToHide.style.visibility="hidden";	// aggiro baco background menu di Opera
	}
	// show
	if (divToShow!=null&&divToShow.style!=null) {
		divToShow.style.display="block";
		if (Opera)		divToShow.style.visibility="visible";	// aggiro baco background menu di Opera
	}
}

// switch float menu
function  switchMenu(pulldown)	{
	if (!document.getElementById)	return;	// not compatible
	
	// set object (first time only)
	if (!floatMenuOpen)		floatMenuOpen=getObj("floatMenuOpenDiv");
	if (!floatMenuClose)	floatMenuClose=getObj("floatMenuCloseDiv");
	if (!floatMenuOpen||!floatMenuClose)	return;

	
	if (!pulldown&&floatMenuOpen.style.display!="none")	{		// close menu
		alternateShow(floatMenuClose,floatMenuOpen);
				
		// visualizzo select nascosti precedentemente
		if (InternetExplorer)	switchSelectField(true);
		
	} else if (pulldown&&floatMenuOpen.style.display!="block")	{ 	// open menu
		alternateShow(floatMenuOpen,floatMenuClose);

		// nascondo select della pagina
		if (InternetExplorer)	switchSelectField(false);
	}
}


// open a custom windows (full parameters)
function customPopUp(url,x,y,name,param,focusOnPopUp,focusOnWindow)	{

	// dimensioni
	var winSize="";
	if (x>0)	winSize+="width="+x+",";
	if (y>0)	winSize+="height="+y+",";
	
	// new windows
	var siteWindowVar=open(url,name,winSize+"directories=no,"+param);
	
	if (siteWindowVar&&focusOnPopUp)	siteWindowVar.focus();	// popup in primo piano
	if (siteWindowVar&&focusOnWindow)	self.focus();			// finestra corrente in primo piano
	
	// il return serve per controllare eventuali popup bloccati o javascript non abilitato
	return (siteWindowVar==null);
}

// open popup
function openDocument(url,winSize,popname)		{

	// default popupsize
	if (winSize=="")	winSize="width=790,height=550";
	if (popname=="") 	popname="docWin"+winSize;

	// open popup (le dimensioni le passo direttamente come parametri)
	return customPopUp(url,0,0,popname,"toolbar=yes,status=no,menubar=no,scrollbars=yes,resizable=yes,location=no,"+winSize,true,false);
}



// menu artista
var currentMenuArtista="empty";
function swapMenuArtista(whatSez) {

	if (whatSez=="")	whatSez="empty";
	if (whatSez==currentMenuArtista)	return;
	
	// show - hide
	alternateShow(getObj(whatSez+"MenuArtista"),getObj(currentMenuArtista+"MenuArtista"));
	
	// save last
	currentMenuArtista=whatSez;
}

