
NS4 = (document.layers);
NS6 =  ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 5));

var overmenu = false;
var openmenu = null;
var overcheck = null;
var overcheck_produscts = null;
var loaded = false;

var overcheck_Prodotti = null;



// Show Menu Layer
function showMenu(imgname) {
	if (NS6){
	menu=document.getElementById(imgname+"layer");
	} else if (NS4) {
		menu=eval("document.layers."+imgname+"layer");
	} else {
		menu=eval(imgname+"layer");
		//Menu = document.frames[0].servizilayer;
		//Menu = document.frames[0].document.all[0];
	}
	
	if (NS4) {
		if(imgname=="prodotti"){
			w = document.images['logo'].width;
		} else {
			w = "590";	
		}
		menu.left = w;
		menu.visibility = "show";
	} else {
		if(imgname=="prodotti"){
			w = document.images['logo'].width;
		} else {
			w = "590";	
		}
		menu.style.left = w+"px";
		menu.style.visibility = "visible";
		menu.style.display = "block";
	}
}

// Check to see if menu is open but not used, if so it is closed
function checkmenu_produsctsmenu(openmenu_,check_){
   if ((overmenu_produscts == 0) && (check_ == overcheck_produscts) && (openmenu_!=null)) {		
   	if (NS6) {
     		menu=document.getElementById(openmenu_+"layer");
       		menu.style.visibility = "hidden";
       	} else if (NS4) {
       		menu=eval("document.layers."+openmenu_+"layer");
       		menu.visibility = "hide";
       	} else{
      		menu=eval(openmenu_+"layer");
      		menu.style.visibility = "hidden";
      	}
   }
}

// Check to see if menu is open but not used, if so it is closed
function checkmenu_Prodottimenu(openmenu_,check_){
   if ((overmenu_Prodotti == 0) && (check_ == overcheck_Prodotti) && (openmenu_!=null)) {		
   	if (NS6) {
     		menu=document.getElementById(openmenu_+"layer");
       		menu.style.visibility = "hidden";
       	} else if (NS4) {
       		menu=eval("document.layers."+openmenu_+"layer");
       		menu.visibility = "hide";
       	} else{
      		menu=eval(openmenu_+"layer");
      		menu.style.visibility = "hidden";
      	}
   }
}

// Check to see if menu is open but not used, if so it is closed
function checkmenu_tourmenu(openmenu_,check_){
   if ((overmenu_tour == 0) && (check_ == overcheck_tour) && (openmenu_!=null)) {		
   	if (NS6) {
     		menu=document.getElementById(openmenu_+"layer");
       		menu.style.visibility = "hidden";
       	} else if (NS4) {
       		menu=eval("document.layers."+openmenu_+"layer");
       		menu.visibility = "hide";
       	} else{
      		menu=eval(openmenu_+"layer");
      		menu.style.visibility = "hidden";
      	}
   }
}

function checkmenu(openmenu){
   if (overmenu[openmenu] == 0) {		
   	if (NS6) {
     		menu=document.getElementById(openmenu+"layer");
       		menu.style.visibility = "hidden";
       	} else if (NS4) {
       		menu=eval("document.layers."+openmenu+"layer");
       		menu.visibility = "hide";
       	} else{
      		menu=eval(openmenu+"layer");
      		menu.style.visibility = "hidden";
      	}
   }
}

function menutimeout(openmenu) {
    setTimeout("checkmenu('"+openmenu+"')",500);
}

function changePage1(input){
	tmp = input.split("_");
	table = tmp[0];
	session = tmp[1];
	loc = tmp[2];
	voice = tmp[3].replace("+"," ");
	if(voice!=undefined && voice !=""){
		voice = "&voice="+voice;
	} else {
		voice = "";
	}
	loca="intro_vino"
	
	if(table!="classi" && table!="tipologie" && table!="gestioneOrdini" && table!="gestioneClienti" && table!="aree" && table!="xlinee" && table!="ricerca" && table!="servizi" && table!="modifica" && table!="archivio" && table!="produttore" && table!="tipologie"){
		idselected=document.cd[table].value;
	}
	else if(table=="classi" || table=="tipologie" || table=="gestioneClienti" || table=="gestioneOrdini" || table=="aree" || table=="xlinee" || table=="servizi" || table=="modifica" || table=="archivio" || table=="produttore" || table=="tipologie"){
		idselected=loc;
		if(table=="xlinee"){
			table="linea";
		}
		if(table=="aree" || table=="classi"){
			loca="area_vino";
		}
		if(table=="servizi"){
			loca="servizi";
		}
		if(table=="modifica"){
			loca="modifica";
		}
		if(table=="archivio"){
			loca="archivio";
		}
		if(table=="gestioneOrdini"){
			loca="gestioneOrdini";
		}
		if(table=="gestioneClienti"){
			loca="gestioneClienti";
		}
		if((table=="tipologie" || table=="produttore") && isNaN(loc)){
			idselected=document.forms['cd'].tipologie.value;
		}
	}
	else if(table=="ricerca"){
		idselected=document.dbricerca.ricerca.value;
	}
	document.location=loca+".php?pid="+idselected+"&table="+table+voice;
}

function changePage(table, session, loc, voice){
	if(voice!=undefined && voice !=""){
		voice = "&voice="+voice;
	} else {
		voice = "";
	}
	loca="intro_vino"
	
	if(table!="classi" && table!="tipologie" && table!="gestioneOrdini" && table!="gestioneClienti" && table!="aree" && table!="xlinee" && table!="ricerca" && table!="servizi" && table!="modifica" && table!="archivio" && table!="produttore" && table!="tipologie"){
		idselected=document.cd[table].value;
	}
	else if(table=="classi" || table=="tipologie" || table=="gestioneClienti" || table=="gestioneOrdini" || table=="aree" || table=="xlinee" || table=="servizi" || table=="modifica" || table=="archivio" || table=="produttore" || table=="tipologie"){
		idselected=loc;
		if(table=="xlinee"){
			table="linea";
		}
		if(table=="aree" || table=="classi"){
			loca="area_vino";
		}
		if(table=="servizi"){
			loca="servizi";
		}
		if(table=="modifica"){
			loca="modifica";
		}
		if(table=="archivio"){
			loca="archivio";
		}
		if(table=="gestioneOrdini"){
			loca="gestioneOrdini";
		}
		if(table=="gestioneClienti"){
			loca="gestioneClienti";
		}
		if((table=="tipologie" || table=="produttore") && isNaN(loc)){
			idselected=document.forms['cd'].tipologie.value;
		}
	}
	else if(table=="ricerca"){
		idselected=document.dbricerca.ricerca.value;
	}
	document.location=loca+".php?pid="+idselected+"&table="+table+voice;
}

function openInfo(lang){
	document.location='info.php';//?lang='+lang
}

function muovi(dove,quanto){
	low = Number(document.forms['skip'].low.value);
	pagg = Number(document.forms['skip'].pagg.value);
	high = Number(document.forms['skip'].high.value);
	currPag = Number(document.forms['skip'].currPag.value);
	if(dove=="av"){
		if(currPag<pagg){
			low = Number(low)+Number(quanto);
			high = Number(high)+Number(quanto);
			currPag = Number(currPag)+1;
		}
	} else if(dove=="in"){
		if(currPag>1){
			low = Number(low)-Number(quanto);
			high = Number(high)-Number(quanto);
			currPag = Number(currPag)-1;
		}
	}
	document.forms['skip'].low.value = low;
	document.forms['skip'].high.value = high;
	document.forms['skip'].currPag.value = currPag;
	document.forms['skip'].submit();
}

function forgotPwd(){
	mail = document.forms['forgot'].mail.value;
	correct = true;
	if(mail!=""){
		at = mail.indexOf("@");
		dot = mail.indexOf(".");
		if(at==-1 || dot==-1){
			alert("Il valore inserito nel campo email non è valido");
			correct = false;	
		} else {
			tmp = mail.substring((dot+1),mail.length);
			if(tmp<2 || tmp>7){
				alert("Il valore inserito nel campo email non è valido");
				correct = false;
			}
		}
	} else {
		alert("Inserire il proprio indirizzo email");
		correct = false;
	}
	if(correct == true){
		pwd = window.open("contact.php?sub=p&mail="+mail,"Forgot_Password","width=350,height=250,toolbar=0,status=0,location=0,resizable=0,scrollbars=0,menubar=0");
		pwd.focus();
	} else {
		document.forms['forgot'].mail.focus();
	}
}

function news() {
	email = document.forms['newsletter'].email.value;
	ling  = document.forms['newsletter'].lang.value;
	correct = true;
	if(email!=""){
		at = email.indexOf("@");
		dot = email.indexOf(".");
		if(at==-1 || dot==-1){
			alert("Il valore inserito nel campo email non è valido");
			correct = false;	
		} else {
			tmp = email.substring((dot+1),email.length);
			if(tmp<2 || tmp>7){
				alert("Il valore inserito nel campo email non è valido");
				correct = false;
			}
		}
	} else {
		alert("Inserire il proprio indirizzo email");
		correct = false;
	}
	if(correct==true){
		if(document.forms['newsletter'].radiobutton[0].checked==true){
			a = "n";
		} else {
			a = "d";
		}
		w = window.open("newsletter.php?azione="+a+"&email="+email+"&lang="+ling,"Register","width=350,height=250,toolbar=0,status=0,location=0,resizable=0,scrollbars=0,menubar=0");
	}
}

function printOrder(id){
	o = window.open('printOrder.php?id='+id,'print','"width=500,height=600,toolbar=0,status=0,location=0,resizable=0,scrollbars=1,menubar=0"')
}

function changeLang(lang){
	document.forms['lang'].lang.value = lang;
	document.forms['lang'].submit();
}

function asmenu(mID) {
	var menu = document.getElementById(mID);
	var display = menu.style.display;
	menu.style.display = (display == "block") ? "none" : "block";
	menu.parentNode.style.listStyleImage = (display == "block") ? "url(images/cartellachiusa.gif)" : "url(images/cartellaaperta.gif)";
}

function init_tree(){
	var uls = document.getElementsByTagName("ul");
	for (i=0;i<uls.length;i++) {
		if(uls[i].className=="submenu"){
			uls[i].style.display = "none";
		}
	}
}