/*scroll menu*/
if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.menu_int{display: none;}\n')
document.write('</style>\n')
}

function trim(stringa){    
			while (stringa.substring(0,1) == ' '){
			stringa = stringa.substring(1, stringa.length);
			}
			while (stringa.substring(stringa.length-1, stringa.length) == ' '){
			stringa = stringa.substring(0,stringa.length-1);}
	return stringa;
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);	
	var display = el.style.display;
	el.parentNode.style.listStyleImage = (display == "block") ? "url(images/menu/close_menu.jpg)" : "url(images/menu/open_menu.jpg)";
	var ar = document.getElementById("menu").getElementsByTagName("span");
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="menu_int")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function initMenu(obj){
	if((typeof(obj) == 'undefined')||(obj == null)){
		var el = document.getElementById("sub_1");
	}else{
		var el = document.getElementById(obj);		
	}
	var display = el.style.display;
	el.parentNode.style.listStyleImage = (display == "block") ? "url(images/menu/close_menu.jpg)" : "url(images/menu/open_menu.jpg)";
	var ar = document.getElementById("menu").getElementsByTagName("span");
	if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="menu_int"){
					ar[i].style.display = "none";
				}
			}
			el.style.display = "block";
	}
}

function openPopupInterno(contenuto,w,h){
	if (w=='') w='400';
	if (h=='') h='300';
		window.open("../popup.php?idcontenuto="+contenuto,'wndPopup','width='+w+',height='+h+',resizable=no,scrollbars=no,toolbar=no,status=yes,location=no,left=50,top=50');
}

function accedi(){
	var f = document.forms["login"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["username"].value==""){
		errore+="Codice cliente\n";
	}
	if (els["pwd"].value==""){
		errore+="Password\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		f.submit();
	}
}

function inviaContatti(){
	var f = document.forms["contatti"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["riferimento"].value==""){
		errore+="Persona di riferimento\n";
	}
	if (els["ragionesoc"].value==""){
		errore+="Ragione sociale\n";
	}
	if (els["telefono"].value==""){
		errore+="Recapito telefonico\n";
	}
	if (els["mail"].value==""){
		errore+="Email\n";
	}		
	if (els["area"].value==0){
		errore+="Area di contatto\n";
	}		
	if (els["messaggio"].value==""){
		errore+="Messaggio\n";
	}	
	if(!els["acconsento"].checked){
		errore +="Acconsentire al trattamento dei dati personali\n";
	}	

	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;
		f.submit();
	}
}

function iscrivinewsletter(){
	var f = document.forms["newsletter"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["nome"].value==""){
		errore+="Nome\n";
	}
	if (els["cognome"].value==""){
		errore+="Cognome\n";
	}	
	if (els["mail"].value==""){
		errore+="Email\n";
	}	
		if(!els["acconsento"].checked){
		errore +="Acconsentire al trattamento dei dati personali\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		f.submit();
	}	
	
}

function viewmsg(msg){
   if((typeof(msg) != 'undefined')&&(msg != null)&&(msg!="")){
    alert(msg);
   }
}

function richiedipwd(){
	var f = document.forms["richiedipass"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["piva"].value==""){
		errore+="Partita IVA\n";
	}
	if (els["codice"].value==""){
		errore+="Codice cliente\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}

function ricordapass(){
	var f = document.forms["ricordapass"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["piva"].value==""){
		errore+="Partita IVA\n";
	}
	if (els["codice"].value==""){
		errore+="Codice cliente\n";
	}	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}
function cambiapwd(){
	var f = document.forms["modpassword"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";
	if (els["newpwd"].value==""){
		errore+="Nuova password\n";
	}
	if (els["confpwd"].value==""){
		errore+="Conferma nuova password\n";
	}	
	if ((els["newpwd"].value!="")&&(els["confpwd"].value!="")){
		 if((els["newpwd"].value)!=(els["confpwd"].value)){
		 errore+="La password immessa è diversa da quella confermata\n";
		 }
	}
	
	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}	
}

function ricnecessita(obj,num){
	var f = document.forms["customer"];
	var els = f.elements;
	if (obj.value!=""){
		 if(num==0){
		 		els["area"].value = obj.value;
			}else{
				els["areaint"].value = obj.value;
			}
		 f.submit();
	}
}

function inviaCustomer(){
	var f = document.forms["customer"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";

	if (els["riferimento"].value==""){
		errore+="Riferimento\n";
	}
	if (els["mail"].value==""){
		errore+="E-mail\n";
	}	
	if (els["telefono"].value==""){
		errore+="Telefono\n";
	}	
	if (els["area"].value=="0"){
		errore+="Necessità\n";
	}	
	if (typeof(els["areaint"]) != 'undefined'){
		 if (els["areaint"].value=="0"){
		 		errore+="Problema\n";
		 }
	}
  	
  if (typeof(els["richiestacampi"]) != 'undefined'){
  	var richiestac = els["richiestacampi"].value;
  	if (richiestac==1){
  		 if(els["numdoc"].value=="0"){
  		 	errore+="Numero documento di trasporto\n";
  		}	
  		if(els["datadoc"].value=="0"){
  		 	errore+="Data documento di trasporto\n";
  		 }	
  	}
	}
	if (els["messaggio"].value==""){
		errore+="Messaggio\n";
	}	
	
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}		
}

function ricerca(){
	var f = document.forms["ricerca"];
	var els = f.elements;
	var errore = "";
	var msg = "I seguenti campi sono obbligatori:\n";

	if (trim(els["stringadac"].value)==""){
		errore+="Stringa da cercare\n";
	}
	if (errore!=""){
		alert(msg+errore);
	}else{
		els["invia"].value=1;		
		f.submit();
	}		
}

/* gestione del menu */
function mmenu(ID) {
   var menu = document.getElementById(ID);
   var display = menu.style.display;
   var uls = document.getElementsByTagName("ul");
   for (var i=0;i<uls.length;i++) {
         if(uls[i].getAttribute("class")=="submenu")uls[i].style.display = "none";
				if(uls[i].getAttribute("id") && uls[i].getAttribute("id").search("submenu-")!= -1){
					uls[i].style.display = "none";
   				/*uls[i].parentNode.style.listStyleImage = "url(images/menu/open_menu.jpg)";*/					
				}
   	}
		menu.style.display = (display == "block") ? "none" : "block";
   	menu.style.display = "block"; 
   	//menu.parentNode.style.listStyleImage = (display == "block") ? "url(images/menu/open_menu.jpg)" : "url(images/menu/close_menu.jpg)";
   	menu.parentNode.style.listStyleImage = (display == "block") ? "none" : "none";

}

function mmenu2(ID) {
	var menu = document.getElementById(ID);
	var display = menu.style.display;
	menu.style.display = (display == "block") ? "none" : "block";
	menu.parentNode.style.listStyleImage = (display == "block") ? "url(images/menu/plus.gif)" : "url(images/menu/minus.gif)";
}

/* inizializzazione del menu */
function caricaMenu(id, idpadre) {
var uls = document.getElementsByTagName("ul");
   if (id==""){
      for (i=0;i<uls.length;i++) {
      	if(uls[i].getAttribute("class")=="submenu")uls[i].style.display = "block";
         	if(uls[i].getAttribute("id") && uls[i].getAttribute("id").search("submenu-")!= -1){	
      	 		if (i==1){/*modifica di Gio*/
   						uls[i].style.display = "";
      			}else{
   		   			uls[i].style.display = "none";
      			}
         }
      }
   }else{
   	 for (i=0;i<uls.length;i++) {
   	 if(uls[i].getAttribute("class")=="submenu")uls[i].style.display = "block";
   	 if(uls[i].getAttribute("id") && uls[i].getAttribute("id").search("submenu-")!= -1){	
   			uls[i].style.display = "none";
					if (i==id){/*modifica di Gio*/
   					uls[i].style.display = "none";
   				}
   		}else{
   				if (i==id){/*modifica di Gio*/
   					uls[i].style.display = "block";
   				}		
   		}
   	}
   }
	 if (id!="")	{
		if (document.getElementById("submenu-"+id).className=="menu_int"){
			document.getElementById("submenu-"+id).style.display = "block";
			document.getElementById("submenu-"+idpadre).style.display = "block";
		}else{
			document.getElementById("submenu-"+id).style.display = "block";
		}
	}
}

function openTab(obj,active){
    
    this.active = (active) ? active : 1,
    this.timeout = null,
    this.tabclass = 'tab',
    this.activeclass = 'active',
    
    this.getTabs = function(){
 
        var retnode = [];
        var elem = document.getElementById(obj).childNodes;     //modified for IE 5.x support
        for (var i = 0; i < elem.length; i++) {
        if (elem[i].className==this.tabclass) retnode[retnode.length]=elem[i];
        }
    
        return retnode;
    
    },
        
    this.links = document.getElementById(obj+'-nav').getElementsByTagName('a'),
    this.tabs = this.getTabs();
    
    this.show = function(number){
        
        for (var i = 0; i < this.tabs.length; i++) {
        this.tabs[i].style.display = ((i+1)==number) ? 'block' : 'none';
        this.links[i].className = ((i+1)==number) ? this.activeclass : '';
        }
    
    },
    
    this.rotate = function(interval){
    
        this.show(this.active);
        this.active++;
    
        if(this.active > this.tabs.length) this.active = 1;
    
        var self = this;
        this.timeout = setTimeout(function(){self.rotate(interval);}, interval*1000);
    
    },
    
    this.init = function(interval){
    
        this.show(this.active);
        
        var self = this; 
        for (var i = 0; i < this.links.length; i++) {
        this.links[i].customindex = i+1;
        this.links[i].onclick = function(){ if (self.timeout) clearTimeout(self.timeout); self.show(this.customindex); return false; };
        } 
        
        if (interval) this.rotate(interval);
            
    };

};

function openPrivacy(){
		window.open("privacy.php",'wndPrivacy','width=450,height=400,resizable=no,scrollbars=yes,toolbar=no,status=yes,location=no,left=50,top=50');
}

