/*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 ar = document.getElementById("menusx").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 ar = document.getElementById("menusx").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 openPrivacy(){
		window.open("privacy.php",'wndPrivacy','width=450,height=400,resizable=no,scrollbars=yes,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();
	}		
}
		function checkEmail(s) {
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
		return filter.test(s);
	};	
function trimstr(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 doSubmitContact(lang) {
		var ok = true;
		var check=false;
		var errore = "";
		var countCheckBoxes = document.forms["registraForm"].elements['ba[]'].length;
		var errore1="I seguenti campi sono obbligatori:\n";	
		
		if (trimstr(document.forms["registraForm"].name.value) == "") {
			errore=errore+"*Nome\n";
		}		
		if (trimstr(document.forms["registraForm"].surname.value) == "") {
			errore=errore+"*Cognome\n";
		}
		if (trimstr(document.forms["registraForm"].email.value) == "") {

			errore=errore+"*Email\n";

			ok = false;

		}	else {			

   		if (!checkEmail(document.forms["registraForm"].email.value)) {
   
   			errore=errore+"*Indirizzo e-mail non e' valido\n";
   
   			ok = false;
   
   		}
		}
		if (trimstr(document.forms["registraForm"].officephone.value) == "") {

			errore=errore+"*Telefono\n";
		}
		for (i=0; i < countCheckBoxes; i++ ) {
  		if (document.forms["registraForm"].elements["ba[]"][i].checked){
          check=false;
					break;
       }else{
			 		check=true;
					continue;
			 }
		 }
		 if (check==true) {
		 		errore=errore+"Selezionare almeno una soluzione\n\n";
		 }
		
//fine
		
		if (errore!=""){
			 if (lang==1){
			 		erroretotale = errore1+errore;
					alert(erroretotale);
				}else{
					alert("Fill required fields(*)\n");
				}
		}else{
			if (document.forms["registraForm"].personaldataack.checked==false){		
				alert("Devi acconsentire al trattamento dei dati personali");			
				ok = false;
			}else{
				document.forms["registraForm"].newsletter.value = 1;
				document.forms["registraForm"].invio.value = 1;
				document.forms["registraForm"].submit();
			}
		}
	}
