function toggleTab()
{
	if (document.getElementById('descrizione') && document.getElementById('descrizione').getElementsByTagName('dl').length>0) {
		var definitionLists = document.getElementsByTagName('dl');
		for (k=0; k < definitionLists.length; k++) {
			var currentList = definitionLists[k];
			var labels = currentList.getElementsByTagName('dt');
			for (i=0; i<labels.length; i++)
			{
				var dd = labels[i].parentNode.getElementsByTagName("dd")[0];
				dd.style.display="none";
				labels[i].onclick = function() {
					var dd = this.parentNode.getElementsByTagName("dd")[0];
					if (dd) {
						if (this.className.match("opened")) {
							this.className = this.className.replace("opened", "");
						} else {
							this.className += " opened ";
						}
						Effect.toggle(dd, 'slide', {duration:0.4});
					}
				}
				labels[i].onmouseover = function() {
					this.className += " hover ";
				}
				labels[i].onmouseout = function() {
					this.className = this.className.replace("hover", "");
				}
			}
		}
	}
}

function rollmenu(container)
{
	var arr = document.getElementById(container).getElementsByTagName("li");
	var i, j;
	
	function __mostraAlbero(element)
	{		
		if (element.parentNode)
		{
			var parent = element.parentNode;
			if (parent.nodeName.match("DIV")) {
				parent.style.display = "block";
			}
			if (parent.nodeName.match("LI")) {
				var parent_a = parent.getElementsByTagName('a')[0];
				parent.className += " meno ";
				parent_a.className += " meno ";
				parent.className = parent.className.replace("piu", "");
				parent_a.className = parent_a.className.replace("piu", "");
			}
			__mostraAlbero(parent);
		}
	}
	
	function __chiudiFratelli(li)
	{
		//var fratelli = li.parentNode.getElementsByTagName("li");
		var fratelli = li.parentNode.childNodes;
		for (j=0; j<fratelli.length; j++)
		{
			var fratello = fratelli[j];
			if (fratello.nodeName=='LI') {
				var fratello_ul = fratello.getElementsByTagName("ul")[0] ? fratello.getElementsByTagName("ul")[0] : false;
				var fratello_a = fratello.getElementsByTagName("a")[0];
				if (fratello!=li && fratello_ul && fratello.className.match("meno")) {
					fratello.className += " piu ";
					fratello_a.className += " piu ";
					fratello.className = fratello.className.replace("meno", "");
					fratello_a.className = fratello_a.className.replace("meno", "");
					//fratello_ul.parentNode.style.display="none";
					new Effect.BlindUp(fratello_ul.parentNode, {duration:0.1});
				}
			}
		}
	}	
	
	//cerco l'elemento current e apro tutto l'albero
	for (i=0; i<arr.length; i++)
	{
		var li = arr[i]; //list item
		var ul = li.getElementsByTagName("ul")[0] ? li.getElementsByTagName("ul")[0] : false; //sottolista
		var div = ul.parentNode;
		var a = li.getElementsByTagName('a')[0]; //link
		
		if (ul) {
			if (!a.className.match('current')) {
				div.style.display ="none";
				li.className += " piu ";
				a.className += " piu ";
			} else {
				//sono nell'elemento current che ha una sottolista, non la chiudo e metto il meno
				li.className += " meno ";
				a.className += " meno ";
			}
		}
		
		if (a.className.match('current')) { //se sono in questo elemento...
			__mostraAlbero(li); //apro i genitori
		}
		
		//if (a.href.match("#") && !ul) li.style.display = "none"; //nascondo le categorie vuote
		
		if (ul && !a.className.match('prodotto')) {
			a.onmouseup = function()
			{
				var a = this;
				var li = this.parentNode;
				var ul = li.getElementsByTagName("ul")[0] ? li.getElementsByTagName("ul")[0] : false;
				var div = (ul)?ul.parentNode : false;
				
				if (!li.className.match("meno")) //albero chiuso...
				{
					//menu chiuso, quindi lo mostro e metto l'icona meno
					if (ul)
					{
						li.className += " meno ";
						a.className += " meno ";
						li.className = li.className.replace("piu", "");
						a.className = a.className.replace("piu", "");
						//div.style.display="block";
						new Effect.BlindDown(div, {duration:0.1});
						
					}
					//ora chiudo i fratelli...
					__chiudiFratelli(li);
				}
				else //albero aperto...
				{
					//ha già la classe active, è aperto quindi lo nascondo e metto il più
					if (ul)
					{
						li.className += " piu ";
						a.className += " piu ";
						li.className = li.className.replace("meno", "");
						a.className = a.className.replace("meno", "");
						//div.style.display="none";
						new Effect.BlindUp(div, {duration:0.1});
					}
				}
				return false;
			}
		}
	}
}

//SIMULA LA PSEUDO-CLASSE "FOCUS" - v.1.1 (ora può avere la propria classe, ne viene aggiunta un'altra)
function setFocus(elemento) {
	elemento.className+=" focus";
}

function unsetFocus(elemento) {
	elemento.className=elemento.className.replace('focus', '');
}

//FUNZIONE PER MOSTRARE I LINK ATTIVI
// richiamare la funzione nel tag body con onLoad e passare come parametro l'id del contenitore del menu
// non serve assegnare nessun valore particolare all'html.
// non funziona coi link indicizzabili ma tanto nel menu di navigazione non ci sono le categorie ;)

function currentlink(contenitore) {

	var stringa_get = document.location.href;		
	var menu = new Array();		
	menu = document.getElementById(contenitore).getElementsByTagName("a");
	if (stringa_get.match("php")) { //cioè se sono nel caso www.nomedominio.com/qualcosa.PHP <--
		var i;
		for (i=0; i<menu.length; i++) {			
			if (stringa_get.match(menu[i].href)) menu[i].className = "active";
		}
	} else menu[0].className = "active";
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


var wiN;

function openWin(nomeFile,nomeFinestra,parametri,larghezza,altezza,barre,ridimensione,centrato) {

	option="toolbar=no,width=" + larghezza + ",height=" + altezza +",resizable=" + ridimensione + ",scrollbars=" + barre
	if (centrato=='yes') {
		LeftPosition = (screen.width) ? (screen.width-larghezza)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-altezza)/2 : 0;
		option=option + ",top="+TopPosition+",left="+LeftPosition
	}
	wiN = window.open(nomeFile + "?titolo=" + nomeFinestra + parametri,nomeFinestra,option);
}

 function checkFormPrivacy() {
    obj=eval("document.contatti");
    nome=obj.nome.value;
    cognome=obj.cognome.value;
    prov=obj.provincia.value;
    email=obj.email.value;
    messaggio=obj.messaggio.value;
    privacy=obj.privacy.checked;
    if ( (nome=="") || (cognome=="") || (prov==-1) || (email=="") || (messaggio=="") || (!privacy))
	{
        alert("ATTENZIONE\nCompletare tutti i dati obbligatori per inviare la richiesta\n\nGrazie")
    }
    else if(confirm("Sei sicuro di voler inviare la richiesta di contatto?"))
    {
        obj.submit();
    }
 }

 function checkForm() {
    obj=eval("document.contatti");
    nome=obj.nome.value;
    cognome=obj.cognome.value;
    prov=obj.provincia.value;
    email=obj.email.value;
    messaggio=obj.messaggio.value;
    if ( (nome=="") || (cognome=="") || (prov==-1) || (email=="") || (messaggio=="") )
	{
        alert("ATTENZIONE\nCompletare tutti i dati obbligatori per inviare la richiesta\n\nGrazie")
    }
    else if(confirm("Sei sicuro di voler inviare la richiesta di contatto?"))
    {
        obj.submit();
    }
 }

 // Spam-proof email by deanq.com
function vmemail(who,subject,domain,body) {
  if (!who) var who = "info";
  if (!domain) var domain = "sito.com";
  if (!subject) var subject = "Richiesta Informazioni";
  if (!body) var body = " ";
  eval("location.href='mailto:" + who + "@" + domain + "?subject=" + subject + "&body=" + body + "'");
}

function verificaUsername() {
	if (document.frmVerificaUsername.username.value=="") {
		alert("Devi inserire la tua username con la quale hai effettuato l'iscrizione");
	} else {
		document.frmVerificaUsername.submit();
	}
}

function cambiaPwd() {
	if (confirm("Sei sicuro di voler ottenere una nuova password?")) {
		document.frmCambiaPwd.submit();
	} else {
		return false;
	}
}


function ckForm() {
	// ck la form per inserire un nuovo cliente

	/**
	 *	Controllo solo Ragione sociale, Telefono, Email
	 *	gli altri controlli li lascio per dopo.
	 */

	error = false;
	msgError = "";
	fieldToFocus = "";

	form = eval("document.new_customer");

	if (form.privacy.checked) {
		nome = form.elements["cliente[nome]"].value;
		cognome = form.elements["cliente[cognome]"].value;
		ragSoc = form.elements["cliente[rag_soc]"].value;
		//indirizzo = form.elements["cliente[indirizzo]"].value;
		telefono = form.elements["cliente[telefono]"].value;
        username = form.elements["cliente[user]"].value;
		pwd1 = form.elements["cliente[pwd1]"].value;
		pwd2 = form.elements["cliente[pwd2]"].value;

		if ((pwd1 == "") || (pwd2 == "")) {
			error = true;
			msgError += "Compilare il campo 'Password'.\n";
			if (pwd1 == "") {
				fieldToFocus = "cliente[pwd1]";
			} else {
				fieldToFocus = "cliente[pwd2]";
			}
		} else {
			if (pwd1 != pwd2) {
				error = true;
				msgError = "Le password inserite devono coincidere.\n"+msgError;
				fieldToFocus = "cliente[pwd2]";
			} else {
				if (pwd1.length < 6) {
					error = true;
					msgError = "La password deve contenere almeno 6 caratteri.\n"+msgError;
					fieldToFocus = "cliente[pwd1]";
				}
			}
		}
		if (username == "") {
			error = true;
			msgError = "Compilare il campo 'Email/Username'.\n"+msgError;
			fieldToFocus = "cliente[user]";
		}
		if (nome == "") {
			error = true;
			msgError = "Compilare il campo 'Nome'.\n"+msgError;
			fieldToFocus = "cliente[nome]";
		}
        if (cognome == "") {
			error = true;
			msgError = "Compilare il campo 'Cognome'.\n"+msgError;
			fieldToFocus = "cliente[cognome]";
		}
        if (telefono == "") {
			error = true;
			msgError = "Compilare il campo 'Telefono'.\n"+msgError;
			fieldToFocus = "cliente[telefono]";
		}
		if (ragSoc == "") {
			error = true;
			msgError = "Compilare il campo 'Azienda/Società'.\n"+msgError;
			fieldToFocus = "cliente[rag_soc]";
		}

		if (!error) {
			// nn ci sn errori
			if (confirm("Confermi i dati inseriti?")) {
				document.new_customer.azione.value="salva";
				document.new_customer.submit();
			}
		} else {
			alert(msgError);
			form.elements[fieldToFocus].focus();
		}
	} else {
		alert("E' necessario accettare l'autorizzazione per il trattamento dei dati personali per procedere con l'iscrizione.")
	}
}

function cambiaInfoUtente() {

	form = eval("document.frmCambiaInfoUtente");
	error = false;
	msgError="";

	ragSoc = form.elements["rag_soc"].value;
	telefono = form.elements["telefono"].value;
    citta = form.elements["citta"].value;
    cap = form.elements["cap"].value;
    provincia = form.elements["prov_id"].value;
	email = form.elements["email"].value;
    indirizzo = form.elements["indirizzo"].value;

	if (email == "") {
		error = true;
		msgError = "Compilare il campo 'Email/Username'.\n"+msgError;
	}
	if (citta == "") {
		error = true;
		msgError = "Compilare il campo 'Città'.\n"+msgError;
	}
    if (cap == "") {
		error = true;
		msgError = "Compilare il campo 'CAP'.\n"+msgError;
	}
    if (provincia == -1) {
		error = true;
		msgError = "Compilare il campo 'Provincia'.\n"+msgError;
	}
	if (telefono == "") {
		error = true;
		msgError = "Compilare il campo 'Telefono'.\n"+msgError;
	}
    if (indirizzo == "") {
		error = true;
		msgError = "Compilare il campo 'Indirizzo'.\n"+msgError;
	}
	if (ragSoc == "") {
		error = true;
		msgError = "Compilare il campo 'Ragione Sociale'.\n"+msgError;
	}

	if (!error) {
		// nn ci sn errori
		if (confirm("Confermi i dati inseriti?")) {
			document.frmCambiaInfoUtente.submit();
		}
	} else {
		alert(msgError);
	}

}


function controllaPermessi() {
	if ((window.opener!==null) && (window.opener!==undefined) ) {
	} else {
		window.location.href = "http://www.blisite.net";
	}
}

