/* Funzioni varie */

function ricercaForm(){
  
  if (document.getElementById("qu").value.length!=0 && document.getElementById("qu").value!="Cerca nel sito")
	if (document.getElementById("results"))
	{
		rs.onSubmit(document.forms.ricerca.qu.value);
		document.getElementById("cmbCat").value="";
	}
	else
	{
		location.href="/ricerca.asp?token="+document.forms.ricerca.qu.value;
	}
  }
  
  var docURL
	ecom=String.fromCharCode(38)
	if (document.URL.match("=")) {
		if (document.URL.match("dnz=1")){
			docURL=document.URL.replace("?dnz=1"+ecom,"?");
			docURL=docURL+ecom+"stampa=S"
		}
		else{
		docURL=document.URL+ecom+"stampa=S"
		}
	} else {
		docURL=document.URL+"?stampa=S"
	}

/* Menu */

var MA_OffColor="#FFFFFF";
var MA_ExpColor="#dcc073";
var MA_OnColor="#FAE3BA";

var MB_OffColor="#eee4cb";
var MB_ExpColor="#FFFFFF";
var MB_OnColor="#ebd59d";

var MC_OffColor="#FFFFFF";
var MC_OnColor="#FAE3BA";

var MA_backIMG="/img/rigaMA_submenu.gif"

//

var MA_elementi=new Array();
var MB_elementi=new Array();
var MC_elementi=new Array();

var MA_nomi=new Array();
var MB_nomi=new Array();
var MC_nomi=new Array();

var MA_stati=new Array();
var MB_stati=new Array();

var MA_espansa=null;
var MB_espansa=null;
var MC_selezionato=null;

var MA_indice=-1;
var MB_indice=-1;
var MC_indice=0;

var tipoA='';
var tipoB='';
var tipoC='';

function inizializza() {
var elementi=document.getElementsByTagName('div');

for (var i=0; i<elementi.length; i++) { 
		if (typeof(elementi[i].className)=="string")
		if (elementi[i].className.indexOf("MA")!=-1) {
			MA_indice++;
			MA_elementi[MA_indice]=elementi[i];
			MA_nomi[MA_indice]=elementi[i].id;
			MA_stati[MA_indice]=false;
			//
			//
			// --- ELEMENTI ---
			eval ("MB"+MA_indice+"_elementi=new Array();");
			eval ("MB_elementi["+MA_indice+"]=MB"+MA_indice+"_elementi;");
			//
			eval ("MC"+MA_indice+"_elementi=new Array();");
			eval ("MC_elementi["+MA_indice+"]=MC"+MA_indice+"_elementi;");
			//
			//
			// --- NOMI ---
			eval ("MB"+MA_indice+"_nomi=new Array();");
			eval ("MB_nomi["+MA_indice+"]=MB"+MA_indice+"_nomi;");
			//
			eval ("MC"+MA_indice+"_nomi=new Array();");
			eval ("MC_nomi["+MA_indice+"]=MC"+MA_indice+"_nomi;");
			//
			//
			// --- STATI ---
			eval ("MB"+MA_indice+"_stati=new Array();");
			eval ("MB_stati["+MA_indice+"]=MB"+MA_indice+"_stati;");
			//
			MB_indice=-1;
		} else if (elementi[i].className.indexOf("MB")!=-1) {
			MB_indice++;
			//
			//
			// --- ELEMENTI ---
			eval ("MB"+MA_indice+"_elementi["+MB_indice+"]=elementi["+i+"];");
			eval ("MB_elementi["+MA_indice+"]=MB"+MA_indice+"_elementi;");
			//
			eval ("MC"+MA_indice+"_elementi["+MB_indice+"]=\"\";");
			eval ("MC"+MA_indice+"_"+MB_indice+"_elementi=new Array();");
			eval ("MC_elementi["+MA_indice+"]["+MB_indice+"]=MC"+MA_indice+"_"+MB_indice+"_elementi;");
			//
			//
			// --- NOMI ---
			eval ("MB"+MA_indice+"_nomi["+MB_indice+"]=elementi["+i+"].id;");
			eval ("MB_nomi["+MA_indice+"]=MB"+MA_indice+"_nomi;");
			//
			eval ("MC"+MA_indice+"_nomi["+MB_indice+"]=elementi["+i+"].id;");
			eval ("MC"+MA_indice+"_"+MB_indice+"_nomi=new Array();");
			eval ("MC_nomi["+MA_indice+"]["+MB_indice+"]=MC"+MA_indice+"_"+MB_indice+"_nomi;");
			//
			//
			// --- STATI ---
			eval ("MB"+MA_indice+"_stati["+MB_indice+"]=false;");
			eval ("MB_stati["+MA_indice+"]=MB"+MA_indice+"_stati;");
			//
			MC_indice=0
		} else if (elementi[i].className.indexOf("MC")!=-1) {
			// --- ELEMENTI ---
			eval ("MC"+MA_indice+"_"+(MB_indice)+"_elementi["+MC_indice+"]=elementi["+i+"];");
			eval ("MC_elementi["+MA_indice+"]["+(MB_indice)+"]=MC"+MA_indice+"_"+(MB_indice)+"_elementi;");
			//
			// --- NOMI ---
			eval ("MC"+MA_indice+"_"+(MB_indice)+"_nomi["+MC_indice+"]=elementi["+i+"].id;");
			eval ("MC_nomi["+MA_indice+"]["+(MB_indice)+"]=MC"+MA_indice+"_"+(MB_indice)+"_nomi;");
			//
			MC_indice++;
		}
		//}
	}
}




function ctrlMenu(par,flag) {
	//var par=document.getElementById(par1);
	if (flag==0) {
		var nome=par.id;
	} else {
		var nome=par;
	}
	//
	var indiceA=null;
	var indiceB=null;
	var indiceC=null;
	// ---TROVA NOME ---
	ciclo :
	for (var i=0; i<MA_elementi.length; i++) {
		if (MA_elementi[i].id==nome) {
			indiceA=i;
			indiceB=null;
			indiceC=null;
			tipoA="MA";
			tipoB=null;
			tipoC=null;
			break ciclo;
		} else {
			for (var j=0; j<MB_elementi[i].length; j++) {
				if (MB_elementi[i][j]) {
					indiceA=i;
					indiceB=j;
					indiceC=null;
					if (MB_elementi[i][j].id==nome) {
						tipoA="MA";
						tipoB="MB";
						tipoC=null;
						break ciclo;
					} else {
						for (var k=0; k<MC_elementi[i][j].length; k++) {
							if (MC_elementi[i][j][k]) {
								indiceA=i;
								indiceB=j;
								indiceC=k;
								if (MC_elementi[i][j][k].id==nome) {
									tipoA="MA";
									tipoB="MB";
									tipoC="MC";
									break ciclo;
								} 
							}
						}
					}
				}
			}
		}
	}
	//
	if (tipoA=="MA") {
		if (MA_stati[indiceA]==false) {
			MA_stati[indiceA]=true;
			MA_img=MA_elementi[indiceA].id;
			if (eval ("MB"+indiceA+"_elementi.length")>0) {
				MA_elementi[indiceA].style.backgroundColor=MA_ExpColor;
			} else{
				MA_elementi[indiceA].style.backgroundColor=MA_OnColor;
			}
			
			MA_elementi[indiceA].style.backgroundImage="url(/img/rigaMA_submenu.gif)";
			for (var i=0; i<eval ("MB"+indiceA+"_elementi.length"); i++) {
				MB_elementi[indiceA][i].style.backgroundColor=MB_OffColor;
				MB_elementi[indiceA][i].style.display="block";
			}
			if (MA_espansa!=null){
				MA_stati[MA_espansa]=false;
				MA_elementi[MA_espansa].style.backgroundColor=MA_OffColor;
				MA_elementi[MA_espansa].style.backgroundImage="url(/img/rigaMA_submenu.gif)";
				for (var i=0; i<eval ("MB"+MA_espansa+"_elementi.length"); i++) {
					MB_elementi[MA_espansa][i].style.backgroundColor=MB_OffColor;
					MB_elementi[MA_espansa][i].style.display="none";
					MB_stati[MA_espansa][i]=false;
					for (var j=0; j<eval ("MC"+MA_espansa+"_elementi["+i+"].length"); j++) {
						if (MC_elementi[MA_espansa][i][j]) {
							MC_elementi[MA_espansa][i][j].style.backgroundColor=MC_OffColor;
							MC_elementi[MA_espansa][i][j].style.display="none";
						}
					}
				}
			}
			MA_espansa=indiceA;
			MB_espansa=null;
			
		}
	} 
	if (tipoB=="MB") {
		if (!MC_elementi[indiceA][indiceB][0]) {
			MB_elementi[indiceA][indiceB].style.backgroundColor=MB_OnColor;
		}
		
		if (MB_stati[indiceA][indiceB] == false){
			MB_stati[indiceA][indiceB] = true;
			for (var i=0; i<eval ("MC"+MA_espansa+"_elementi["+indiceB+"].length"); i++) {
				if (MC_elementi[indiceA][indiceB][i]){
					MB_elementi[indiceA][indiceB].style.backgroundColor=MB_ExpColor;
					MC_elementi[indiceA][indiceB][i].style.display="block";
				}
			}
			if (MB_espansa!=null){
				MB_stati[indiceA][MB_espansa] = false;
				MB_elementi[indiceA][MB_espansa].style.backgroundColor=MB_OffColor;
				for (var i=0; i<eval ("MC"+MA_espansa+"_elementi["+MB_espansa+"].length"); i++) {
					if (MC_elementi[indiceA][MB_espansa][i]){
						MC_elementi[indiceA][MB_espansa][i].style.backgroundColor=MC_OffColor;
						MC_elementi[indiceA][MB_espansa][i].style.display="none";
					}
				}
			}
			MB_espansa=indiceB;
			MC_selezionato=null
		}
	}
	if (tipoC=="MC") {
		MC_elementi[indiceA][indiceB][indiceC].style.backgroundColor=MC_OnColor;
		if (MC_selezionato!=null){
			MC_elementi[indiceA][indiceB][MC_selezionato].style.backgroundColor=MC_OffColor;
		}
		MC_selezionato=indiceC
	}
}


function esplodi(par) {
	ctrlMenu(par,1);
}


function url_blank(str_url) {
	window.open(str_url);
}

function url_new_win(str_url,dim_lar,dim_alt)	{
	titolo=""
	larghezza=dim_lar
	altezza=dim_alt
	ridim=1
	scrolla=1
	centroX=(screen.width-larghezza)/2
	centroY=(screen.height-altezza)/2
	fnpup=window.open(str_url,titolo,"width="+larghezza+",height="+altezza+",resizable="+ridim+",scrollbars="+scrolla+",screenX="+centroX+",left="+centroX+",screenY="+centroY+",top="+centroY);
	fnpup.focus();
}

/* Scroll banner */

function setVariables(margineSuperiore){
	px="+'px'";
	if (navigator.appName == "Netscape") {
		if (parseInt(navigator.appVersion) >= 5){
			v=".top=";
			h=".left=";
			dS="document.getElementById(\"";
			sD="\").style";
			y="window.pageYOffset-"+margineSuperiore;
			x="window.pageXOffset";
		} else {
			v=".top=";
			h=".left=";
			dS="document.";
			sD="";
			y="window.pageYOffset-"+margineSuperiore;
			x="window.pageXOffset";
			px="";
		}
	} else {
		var validDoc=(document.compatMode && document.compatMode != "BackCompat")?1:0;
		h=".left=";
		v=".top=";
		dS="";
		sD=".style";
		y=(validDoc)?"document.documentElement.scrollTop-"+margineSuperiore:"document.body.scrollTop";
		x=(validDoc)?"document.documentElement.scrollLeft":"document.body.scrollLeft";	
	}
	ystart=eval(y);
	xstart=eval(x);
}

movex=0,movey=0,xdiff=0,ydiff=0,ystart=0,xstart=0

function checkLocation(objName){
	yy=eval(y);
	xx=eval(x);
	ydiff=ystart-yy;
	xdiff=xstart-xx;
	if ((ydiff<(-1))||(ydiff>(1))) movey=Math.round(ydiff/10),ystart-=movey
	if ((xdiff<(-1))||(xdiff>(1))) movex=Math.round(xdiff/10),xstart-=movex
	if (ystart>=0){
		eval(dS+objName+sD+v+ystart+px);
	} else {
		eval(dS+objName+sD+v+0+px);
	}
	//eval(dS+object+sD+h+xstart+px);
	setTimeout("checkLocation('"+objName+"')",5);
}

function aprifin(nome,titolo,larghezza,altezza,ridim,scrolla)	{
	
			centroX=(screen.width-larghezza)/2
			centroY=(screen.height-altezza)/2
			afin=window.open(nome,titolo,"width="+larghezza+",height="+altezza+",resizable="+ridim+",scrollbars="+scrolla+",screenX="+centroX+",left="+centroX+",screenY="+centroY+",top="+centroY);
			afin.focus();
		}
		
		


