function MM_openBrWindow(theURL,winName,features) { //v2.0
 window.open(theURL,winName,features);
}
function MM_jumpMenu_1(targ,selObj,restore)
{ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenu_2(targ,selObj,restore)
{ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenu_3(targ,selObj,restore)
{ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
}
function apriInGrande(pagina)
{ msg=open(pagina,'SOP',			'toolbar=no,directories=no,menubar=no,hotkeys=no,location=no,scrollbars=yes,width=650,height=700,top=0,left=0');
}

function apriMenu(pagina)
{ msg=open(pagina,
		'SOP',		'toolbar=no,directories=no,menubar=no,hotkeys=no,location=no,scrollbars=yes,width=600,height=600,top=0,left=0'
	);
}
	
function apriRivenditore(pagina)
	{
		msg=open(
			pagina,
			'SOP',			'toolbar=no,directories=no,menubar=no,hotkeys=no,location=no,scrollbars=yes,width=500,height=500,top=0,left=0'
		);
	}
	
function indirizzoEmailValido(indirizzo) {
  if (window.RegExp) {
    var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(nonvalido);
    var regv = new RegExp(valido);
    if (!regnv.test(indirizzo) && regv.test(indirizzo))
      return true;
    return false;
	}
  else {
    if(indirizzo.indexOf("@") >= 0)
      return true;
    return false;
  	}
  };
  
	
function controllaDati(modulo) {
	if (!indirizzoEmailValido(modulo.email.value)) {
		 	modulo.email.select();
			alert("Si prega di inserire un indirizzo email valido");
			return false;
		 	}

	if(modulo.remove.checked == false){	
		if( modulo.privacy.checked != true ) {
			alert ("Prima di registrarsi leggere l'informativa sulla privacy e selezionare SI nell'opzione relativa!");
			modulo.privacy.focus();
			return false;
			}
	 	}
		else
			return true;		
};
   
function searchCode_Validator(theForm){
	   if (theForm.codice.value == "")
  		{
			alert("Specificare un codice articolo valido.");
			theForm.codice.focus();
			return (false);
  		}
};


function login_validator() {
	//controlla che venga inserito un valore nello username
	if (frmLogin.txtUsername.value == "") 
	{
		frmLogin.txtUsername.select();
			alert("Si prega di inserire uno username valido, utilizzare l'indirizzo email usato nella registrazione");
			return false;
	}

	//controlla che venga inserito un valore per la password
	if (frmLogin.txtPassword.value == "") 
	{
	frmLogin.txtPassword.select();
	alert("Si prega di inserire una password valida");
		return false;
	}
	else
	return true;
};

function ControllaPIVA(pi)
{
    if( pi == '' )  return '';
    if( pi.length != 11 )
        return "La lunghezza della partita IVA non ?" +
            "corretta: la partita IVA dovrebbe essere lunga\n" +
            "esattamente 11 caratteri.\n";
    validi = "0123456789";
    for( i = 0; i < 11; i++ ){
        if( validi.indexOf( pi.charAt(i) ) == -1 )
            return "La partita IVA contiene un carattere non valido `" +
                pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
    }
    s = 0;
    for( i = 0; i <= 9; i += 2 )
        s += pi.charCodeAt(i) - '0'.charCodeAt(0);
    for( i = 1; i <= 9; i += 2 ){
        c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
        if( c > 9 )  c = c - 9;
        s += c;
    }
    if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
        return "La partita IVA non ?alida:\n" +
            "il codice di controllo non corrisponde.\n";
    return '';
}

function ControllaCF(cf)
{
    var validi, i, s, set1, set2, setpari, setdisp;
    if( cf == '' )  return '';
    cf = cf.toUpperCase();
    if( cf.length != 16 )
        return "La lunghezza del codice fiscale non ?"
        +"corretta: il codice fiscale dovrebbe essere lungo\n"
        +"esattamente 16 caratteri.\n";
    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for( i = 0; i < 16; i++ ){
        if( validi.indexOf( cf.charAt(i) ) == -1 )
            return "Il codice fiscale contiene un carattere non valido `" +
                cf.charAt(i) +
                "'.\nI caratteri validi sono le lettere e le cifre.\n";
    }
    set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
    s = 0;
    for( i = 1; i <= 13; i += 2 )
        s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    for( i = 0; i <= 14; i += 2 )
        s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
        return "Il codice fiscale non ?orretto:\n"+
            "il codice di controllo non corrisponde.\n";
    return "";
}




//controlla l'abilitazione dei campi nel modulo registrazione a seconda si tratti di azienda o privato
////////privato
function privatesubject(){
	document.registrazione_utente_Form.codice_fiscale.disabled 			= false;
	document.registrazione_utente_Form.codice_fiscale_azienda.disabled 	= true;
	document.registrazione_utente_Form.cboFormaGiuridica.disabled 		= true;
	document.registrazione_utente_Form.partita_iva.disabled 			= true;
	document.registrazione_utente_Form.codice_fiscale.value 			= "";
	document.registrazione_utente_Form.codice_fiscale_azienda.value 	= '';
	document.registrazione_utente_Form.partita_iva.value 				= '';
	document.registrazione_utente_Form.ragione_Sociale.disabled 		= true;
	document.registrazione_utente_Form.partita_iva.style.background 	= '#cccccc'
	document.registrazione_utente_Form.codice_fiscale_azienda.style.background 	= '#cccccc'
	document.registrazione_utente_Form.codice_fiscale.style.background 	= '#ffffff'
	document.registrazione_utente_Form.ragione_Sociale.style.background = '#cccccc'
	};
	
////////azienda
function publicsubjectd(theForm){
	document.registrazione_utente_Form.codice_fiscale.disabled 			= true;
	document.registrazione_utente_Form.codice_fiscale_azienda.disabled 	= false;
	document.registrazione_utente_Form.cboFormaGiuridica.disabled 		= false;
	document.registrazione_utente_Form.partita_iva.disabled 			= false;
	document.registrazione_utente_Form.ragione_Sociale.disabled 		= false;
	document.registrazione_utente_Form.codice_fiscale_azienda.value 	= "";
	document.registrazione_utente_Form.partita_iva.value 				= "";
	document.registrazione_utente_Form.codice_fiscale.value 			= "";
	document.registrazione_utente_Form.partita_iva.style.background 	= '#ffffff'
	document.registrazione_utente_Form.codice_fiscale_azienda.style.background 		= '#ffffff'
	document.registrazione_utente_Form.codice_fiscale.style.background 	= '#cccccc'
	document.registrazione_utente_Form.ragione_Sociale.style.background = '#ffffff'
	};
					
function registrazione_utente_Form_Validator(theForm)
{

  /*controllo sullo username*/
		
  if (theForm.txtUsername.value == "")
  {
    alert("Inserire una email per il campo relativo allo Username");
    theForm.txtUsername.focus();
    return (false);
  }
  
   if (theForm.txtUsername.value.length > 35)
  {
    alert("Inserire al massimo 35 caratteri nel campo email per lo Username");
    theForm.txtUsername.focus();
    return (false);
  }
		
  if(!isEmail(theForm.txtUsername.value))
    return false;
  
  /*controllo sulla password  */

  if (theForm.nuova_password.value == "")
  {
    alert("Inserire una Password per accedere da utente registrato");
    theForm.nuova_password.focus();
    return (false);
  }
  if (theForm.nuova_password.value.length > 12)
  {
    alert("Inserire al massimo 12 caratteri nel campo Password");
    theForm.nuova_password.focus();
    return (false);
  }
  if (theForm.nuova_password.value.length < 8)
  {
    alert("Inserire almeno 8 caratteri nel campo Password");
    theForm.nuova_password.focus();
    return (false);
  }

  
if (theForm.conferma_password.value != theForm.nuova_password.value){
    alert ("attenzione la password di conferma è diversa da quella inserita");
    theForm.conferma_password.value = "";
    theForm.conferma_password.focus()
    return (false);
}

  /*controllo sulla conferma della password  */

  if (theForm.conferma_password.value == "")
  {
    alert("Ripetere la password per sicurezza");
    theForm.conferma_password.focus();
    return (false);
  }
  
   
    
   if (theForm.nome_referente.value == "")
  {
    alert("Inserire un valore per il campo Nome referente");
    theForm.nome_referente.focus();
    return (false);
  }
  
     if (theForm.cognome_referente.value == "")
  {
    alert("Inserire un valore per il campo Cognome referente");
    theForm.cognome_referente.focus();
    return (false);
  }
  	
   if (theForm.indirizzo.value == "")
	  {
		alert("Inserire un valore per il campo Indirizzo");
		theForm.indirizzo.focus();
		return (false);
	  } 

  
  if (theForm.citta.value == "")
	  {
		alert("Inserire un valore per il campo Città");
		theForm.citta.focus();
		return (false);
	  }

  if (theForm.provincia.value == "")
	  {
		alert("Inserire un valore per il campo Provincia");
		theForm.provincia.focus();
		return (false);
	  }
  
  
   

    if (theForm.indirizzo.value.length > 50)
  {
    alert("Inserire al massimo 50 caratteri nel campo Indirizzo");
    theForm.indirizzo.focus();
    return (false);
  }

  var checkOK = "-_.,:;'^?£$%&/\|*éèìòàABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789- \t\r\n\f";
  var checkStr = theForm.indirizzo.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
     for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo lettera, cifra, spazio e \"-/\\,.\" caratteri nel campo Indirizzo");
    theForm.indirizzo.focus();
    return (false);
  }

if (theForm.cap.value == "")
	  {
		alert("Inserire il Codice di Avviamento Postale");
		theForm.cap.focus();
		return (false);
	  }
  
  if (theForm.cap.value.length < 5 )
	  {
		alert("Inserire 5 numeri nel campo Codice di Avviamento Postale");
		theForm.cap.focus();
		return (false);
	  }

  if (theForm.cap.value.length > 5)
	  {
		alert("Inserire al massimo 5 caratteri nel campo Cap");
		theForm.cap.focus();
		return (false);
	  }

  var checkOK = "0123456789-.";
  var checkStr = theForm.cap.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ".")
      allNum += ch;
  }

  if (!allValid)
  {
    alert("Inserire solo cifra caratteri nel campo Cap");
    theForm.cap.focus();
    return (false);
  }

  if (theForm.citta.value.length > 25)
  {
    alert("Inserire al massimo 25 caratteri nel campo Città");
    theForm.citta.focus();
    return (false);
  }

  var checkOK = "-_.,:;'^?£$%&/\|*éèìòàABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789- \t\r\n\f";
  var checkStr = theForm.citta.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo lettera, cifra, spazio e \"-\\/\" caratteri nel campo Città");
    theForm.citta.focus();
    return (false);
  }

  if (theForm.telefono.value.length > 16)
  {
    alert("Inserire al massimo 16 caratteri nel campo Telefono`");
    theForm.telefono.focus();
    return (false);
  }

  var checkOK = "0123456789-+";
  var checkStr = theForm.telefono.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Inserire solo cifra caratteri nel campo Telefono");
    theForm.telefono.focus();
    return (false);
  }
  
    if (theForm.telefono.value == "")
	  {
		alert("Inserire almeno un numero di telefono per eventuali contatti.");
		theForm.telefono.focus();
		return (false);
	  }

if (theForm.codice_fiscale.disabled == false){
	if (theForm.codice_fiscale.value != ""){   
		  err = ControllaCF(theForm.codice_fiscale.value);
		  if( err > '' ){
			alert("Il codice fiscale inserito non è corretto!");
			theForm.codice_fiscale.focus();
			return (false);
		  }
		}
		if (theForm.codice_fiscale.value == "")
		{
			alert("Inserire un valore per il codice fiscale");
			theForm.codice_fiscale.focus();
			return (false);
		}
	}
	
if (theForm.partita_iva.disabled == false){
		if (theForm.partita_iva.value != "")
		{   
		  err = ControllaPIVA(theForm.partita_iva.value);
		  if( err > '' ){
			alert("La partita iva inserita non è corretta!");
			theForm.partita_iva.focus();
			return (false);
		  }
		}
		 if (theForm.partita_iva.value == "")
		{
		alert("Inserire un valore per la partita iva");
		theForm.partita_iva.focus();
		return (false);
		}
	}

if (theForm.codice_fiscale_azienda.disabled == false){
	if (theForm.codice_fiscale_azienda.value == "")
	{
		alert("Inserire un valore per il codice fiscale aziendale.");
		theForm.codice_fiscale_azienda.focus();
		return (false);
	}
}

	
if (theForm.cboFormaGiuridica.disabled == false){
   if (theForm.cboFormaGiuridica.value == "")
  {
    alert("Inserire una forma giuridica per l'azienda");
    theForm.cboFormaGiuridica.focus();
    return (false);
  }
}	  


if (theForm.ragione_Sociale.disabled == false){
  if (theForm.ragione_Sociale.value.length > 39)
  {
    alert("Inserire al massimo 39 caratteri per il campo Ragione Sociale");
    theForm.ragione_Sociale.focus();
    return (false);
  }

  if (theForm.ragione_Sociale.value.length == "")
  {
    alert("Inserire un valore per il campo Ragione Sociale");
    theForm.ragione_Sociale.focus();
    return (false);
  }

  var checkOK = "-_.,:;'^?£$%&/\|*éèìòàABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆ`ÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789- \t\r\n\f";
  var checkStr = theForm.ragione_Sociale.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire solo lettera, cifra e spazio caratteri nel campo Ragione sociale");
    theForm.ragione_Sociale.focus();
    return (false);
  }
}

   if (theForm.cap_consegna.value.length > 5)
  {
    alert("Inserire al massimo 5 caratteri nel campo Cap per la consegna");
    theForm.cap_consegna.focus();
    return (false);
  }
  
    if (theForm.cap_consegna.value.length > 5)
  {
    alert("Inserire al massimo 5 caratteri nel campo Cap per la consegna");
    theForm.cap_consegna.focus();
    return (false);
  }

  var checkOK = "0123456789-.";
  var checkStr = theForm.cap_consegna.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ".")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Inserire solo cifra caratteri nel campo Cap per la consegna");
    theForm.cap_consegna.focus();
    return (false);
  }
  
  if (theForm.telefono_consegna.value.length > 16)
  {
    alert("Inserire al massimo 16 caratteri nel campo Telefono consegna`");
    theForm.telefono_consegna.focus();
    return (false);
  }

  var checkOK = "0123456789-+";
  var checkStr = theForm.telefono_consegna.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Inserire solo cifra caratteri nel campo Telefono consegna");
    theForm.telefono_consegna.focus();
    return (false);
  }
   

  if (theForm.nome_referente.value.length > 16)
  {
    alert("Inserire al massimo 16 caratteri per il campo Nome referente");
    theForm.nome_referente.focus();
    return (false);
  }

  var checkOK = "-_.,:;'^?£$%&/\|*éèìòàABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789- \t\`r\n\f";
  var checkStr = theForm.nome_referente.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  
  if (!allValid)
  {
    alert("Inserire solo lettera, cifra e spazio caratteri nel campo Nome referente");
    theForm.nome_referente.focus();
    return (false);
  }
  
  if (theForm.cognome_referente.value.length > 16)
  {
    alert("Inserire al massimo 16 caratteri per il campo Cognome referente");
    theForm.cognome_referente.focus();
    return (false);
  }

  var checkOK = "-_.,:;'^?£$%&/\|*éèìòàABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789- \t\r\n\f";
  var checkStr = theForm.cognome_referente.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  
  if (!allValid)
  {
    alert("Inserire solo lettera, cifra e spazio caratteri nel campo Cognome referente");
    theForm.cognome_referente.focus();
    return (false);
  }
  

  if (theForm.telefono_cellulare.value.length > 15)
  {
    alert("Inserire al massimo 15 caratteri nel campo Telefono cellulare");
    theForm.telefono_cellulare.focus();
    return (false);
  }
  
  var checkOK = "0123456789-+";
  var checkStr = theForm.telefono_cellulare.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
     }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Inserire solo cifra caratteri nel campo Telefono cellulare");
    theForm.telefono_cellulare.focus();
    return (false);
  }

  if (theForm.fax.value.length > 15)
  {
    alert("Inserire al massimo 15 caratteri nel campo Fax");
    theForm.fax.focus();
    return (false);
  }
 
  var checkOK = "0123456789-.+";
  var checkStr = theForm.fax.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ".")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Inserire solo cifra caratteri nel campo Fax");
    theForm.fax.focus();
    return (false);
  }

  if (theForm.cboProvenienza.value == "")
  {
    alert("La preghiamo di specificare come ci ha conosciuto");
    theForm.cboProvenienza.focus();
    return (false);
  }

  if( theForm.privacy.checked != true ) 
  {
	alert ("Prima di registrarsi leggere l'informativa sulla privacy e selezionare la check al suo fianco!");
	theForm.privacy.focus();
	return false;
  }
return (true);
}

// modulo contatti
function isEmail(what){
	var i=new RegExp("^.*\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	if(!i.test(what)) 
	{ 
		alert("Il campo email specificato non è valido."); 
			return false
	}   
	return true;
}
		
function frmContatti_Validator(theForm){
if (theForm.nome.value == "")
  {
	alert("Inserire un valore per il campo Nome");
	theForm.nome.focus();
	return (false);
	}
	
if (theForm.cognome.value == "")
  {
	alert("Inserire un valore per il campo Cognome");
	theForm.cognome.focus();
	return (false);
	}

if(!isEmail(theForm.email.value)) 
return false;

if (theForm.messaggio.value == "")
  {
	alert("Inserire un valore per il campo messaggio");
	theForm.messaggio.focus();
	return (false);
	}
	}
	
function frmPreventivi_Validator(theForm){
if (theForm.nome.value == "")
  {
	alert("Inserire un valore per il campo Nome");
	theForm.nome.focus();
	return (false);
	}

if (theForm.cognome.value == "")
  {
	alert("Inserire un valore per il campo Cognome");
	theForm.cognome.focus();
	return (false);
	}
	
if (theForm.citta.value == "")
 {
	alert("Inserire un valore per il campo Città");
	theForm.citta.focus();
	return (false);
  }
	
if (theForm.nomeAzienda.value == "")
  {
	alert("Inserire un valore per il campo Azienda o inserire Privato.");
	theForm.nomeAzienda.focus();
	return (false);
  }
 
 if (theForm.telefono.value.length > 16)
  {
    alert("Inserire al massimo 16 caratteri nel campo Telefono");
    theForm.telefono.focus();
    return (false);
  }
  
  var checkOK = "0123456789-+";
  var checkStr = theForm.telefono.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Inserire solo cifra caratteri nel campo Telefono");
    theForm.telefono.focus();
    return (false);
  }
  
    if (theForm.telefono.value == "")
	  {
		alert("Inserire almeno un numero di telefono per eventuali contatti.");
		theForm.telefono.focus();
		return (false);
	  }
  
  if (theForm.telefono.value.length > 16)
  {
    alert("Inserire al massimo 16 caratteri nel campo Telefono consegna`");
    theForm.telefono.focus();
    return (false);
  }
  
  if (theForm.PIva.disabled == false){
		if (theForm.PIva.value != "")
		{   
		  err = ControllaPIVA(theForm.PIva.value);
		  if( err > '' ){
			alert("La partita iva inserita non è corretta!");
			theForm.PIva.focus();
			return (false);
		  }
		}
	}	  
	
	if( theForm.privacy.checked != true ) 
  	{
	alert ("Prima di registrarsi leggere l'informativa sulla privacy e selezionare la check al suo fianco!");
	theForm.privacy.focus();
	return false;
  	}

if(!isEmail(theForm.email.value)) 
return false;

if (theForm.messaggio.value == "")
  {
	alert("Inserire un valore per il campo messaggio");
	theForm.messaggio.focus();
	return (false);
  }

}

function homepagelink (url,displayclass)
{
	if (document.all)
	{
		document.write('<a href="' + url + '" target="_top" onclick="this.style.behavior=\'url(#default#homepage)\';this.setHomePage(\'' + url + '\')">');
		document.write('<span class="' + displayclass + '">Fai di ETWstore la tua Home Page!</span></a>');
	}

	// If it's Netscape 6, tell user to drag link onto Home button
	else if (document.getElementById)
	{
		document.write('<a href="' + url + '"><span class="' + displayclass + '">Fai di ETWstore la tua Home Page!</span></a>');
	}
}

<!-- "La tua Home Page" -->
function homepage(){ 
	if(document.all)
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://etwstore.com/');
} 
	
function bookmarklink (url,title,displayclass)
{
	var app = navigator.appName;
	var ver = parseInt(navigator.appVersion);

	if ((app == "Microsoft Internet Explorer") && (ver >= 4)) {
		document.write("<a href=\"javascript:window.external.AddFavorite('" + url + "',\'" + title + "')\"><span class=\"" + displayclass + "\">Aggiungi ETWstore ai tuoi preferiti!</span></a>");
	} else {
		document.write('<span class="' + displayclass + '">CTRL + D per aggiungere ETWstore ai tuoi preferiti!</span>');
	}
		return;
}


//controlla l'accettazione delle clausole di vendita all'invio dell'ordine
function sendorder_validator(sender){
  if(!sender.rdBuyCond.checked){
	alert ("Per procedere con l'ordine bisogna necessariamente accettare le condizioni di vendita!");
	return false;
  }
}

// script calcolo rate finanziamento
var gb_Finan = 0;
var gb_Tasso = 11;
var gb_err = 00;
var Strimporto = "";

function Calcola1(Finanzia, TassoInt, Rata, Mesi, NC1, NC2, NC3, NC4)
{
   var URata = 0;
   var rataM = 0;
   var NRata = 0;
   var Ca1 = "FINANZ"; 

   var nomeForma=document.forms[0];
   if (Finanzia < 150)
   {
      alert("L'importo richiesto deve essere almeno di ,00 Euro");
      nomeForma.elements[Ca1].select();
      nomeForma.elements[Ca1].focus();
      gb_err = 91;
      return false;
   }   

   if ((Rata < 1) && (Mesi < 1))
   {
      alert("E' necessario disporre il numero rate");
      return false;
   }

/* ==============================================================================
   CALCOLO IL TEMPO NECESSARIO
   Interessi calcolati con il metodo classico
   Interess1 = interessi
   I2 = totale da rimborsare
   NRata = totale rate (rate al 100% comppresa ultima rata) Math.ceil(NRata)
   URata = Ultima rata da rimborsare      
*/
   if (Rata != "")
   {
      var I1 = Finanzia / Rata;
      var Interess1 = (((Finanzia * TassoInt * (360 / 12 * I1)) / 36000) / 2);
      var I2 = eval(Finanzia)  + eval(Interess1);
      I2 =Math.round(I2 * 100) / 100 ;
      NRata = I2 / Rata;
      NRata = Math.ceil(NRata);

      /* calcolo ultima rata semplificato */
      URata = I2 - (Rata * (NRata - 1));

      URata =Math.round(URata * 100) / 100 ;
      rataM = Rata;

   }   
/* ==============================================================================
   CALCOLO la rata
   Interessi  = calcolati con il metodo classico
   I2 = totale da rimborsare
   NRata = totale rate
*/
   if (Mesi != "")
   {
      var Interessi = (((Finanzia * TassoInt * (360 / 12 * Mesi)) / 36000) / 2);
      var I2 = eval(Finanzia)  + eval(Interessi);
      I2 =Math.round(I2 * 100) / 100 ;
            
      rataM = (eval(Finanzia) + eval(Interessi)) / Mesi;
      rataM = Math.round(rataM * 100) / 100 ;
      URata = 0;
      NRata = Mesi;
   }

/*
   alert("Finanziamento: " + Finanzia + 
         " - Mesi: " + Mesi +
         " - Tasso int.: " + TassoInt +
         " - Interessi: " + Interessi +
         " - Totale: " + I2
         );
*/

   nomeForma.elements[NC1].value = Finanzia;
   puntaImp(nomeForma.elements[NC1].value, nomeForma.elements[NC1] );
   
   nomeForma.elements[NC2].value = I2;
   puntaImp(nomeForma.elements[NC2].value, nomeForma.elements[NC2]);

   nomeForma.elements[NC3].value = NRata;
   nomeForma.elements[NC4].value = rataM;
   puntaImp(nomeForma.elements[NC4].value, nomeForma.elements[NC4]);

   
   return false;

/* ============================================================================== */

}

function azzeraGB(NC)
{
   gb_Finan = 0;
   gb_Tasso = 0;
   gb_err = 0;
   Strimporto = "";

   document.forms[0].elements[NC].focus();
   return true;


}

/* ============================================================================== 
   ============================================================================== */

function riempiCorr(Valore,NomeCampo,NC)
{
var nomeForma=document.forms[0];
/* riempio il campo corrispettivo finanz finanz1 e viceversa etc. */
   switch(NomeCampo)
   {
      case "FINANZ":         
         if (((gb_Finan > 0) && (gb_Finan == Valore)) || (Valore == ""))
         {
            return true;
         }
         
         if (Valore < 150)
         {
            alert("Attenzione: il finanziamento minimo deve essere di 150,00 Euro");
            nomeForma.elements[NC].select();
            nomeForma.elements[NC].focus();
            gb_err = 91;
            return false;
         }
         else
         {
            if (Valore > 5000)
            {
               alert("Attenzione: il finanziamento non pu' superare i 5.000 Euro");
               nomeForma.elements[NC].value="";
               nomeForma.elements[NC].select();
               nomeForma.elements[NC].focus();
               gb_err = 92;
               return false;
            }
         }
         gb_Finan = Valore;
         break;
      
      case "TASSO":
         if ((gb_Tasso > 0) && (gb_Tasso == Valore))
         {
            return true;
         }         
         if (Valore > 11)
         {
            alert("tasso fisso 11%");
            nomeForma.elements[NC].value="";
            nomeForma.elements[NC].select();
            nomeForma.elements[NC].focus();
            gb_err = 93;
            return false;            
         }
         if (Valore < 11)
         {
            alert("tasso fisso 11%");
            nomeForma.elements[NC].select();
            nomeForma.elements[NC].focus();
            gb_err = 94;
            return false;
         }

         if (Valore != "")
         {
            puntaPC(Valore, nomeForma.elements[NC]);
            Valore = Strimporto;
            gb_Tasso = Valore  ;    
            return true;
         } 

         break;

      default:
         break;
   }
   return true;
}

/* ============================================================================== 
   ============================================================================== */
   
function checkImporto(ImportoPassato, nmDec, inNeg )
{
   if (gb_err == 0)
   {
      if (chkimp(ImportoPassato.value, nmDec,inNeg ) == false)
      {
         ImportoPassato.select();
         switch (gb_err)
         {
            case 01:
               alert("Importo non numerico");
               break;
            case 02:
               alert("Importo negativo");
               break;
            default:
               alert("Importo non numerico");
         }
         ImportoPassato.focus();
         return false;
      }
      else
      {
         ImportoPassato.value = Strimporto;
         return true;
      }
   }
   else
   {
      gb_err = 0;
      return true;
   }
}

/* ============================================================================== */

function puntaImp(ImportoPassato, NomeCampo)
{
   var importo="";
   var y=0;
   var i=0;
   var tipoV1="";

// elimina precedenti caratteri "." e converte i caratteri ","  in "."
   y = 0;
   tipoV1="";
   for(i = 0; i < ImportoPassato.length; i++)
   {
      switch (ImportoPassato.substr(i,1))
      {
         case ",":
            importo = importo + ".";
            tipoV1 = ".";
            break;
         case ".":
            importo = importo + ",";
            tipoV1 = ",";
            break;
         case " ":
            break;
         default:
            importo = importo + ImportoPassato.substr(i,1);
            if (tipoV1 == "")
            {
               y++;
            }
            break;
      }
   }

// formatto la parte intera
   if (tipoV1 == "")
   {
      importo = importo + ",00";
   }
   Strimporto = importo;

   if (y > 3)
   {
      Strimporto = importo.substr(0,(y-3)) + "." + importo.substr((y-3))
   }
   NomeCampo.value = Strimporto;
}

/* ============================================================================== */

function puntaPC(ImportoPassato, NomeCampo)
{
   var importo="";
   var y=0;
   var i=0;
   var tipoV1="";

// elimina precedenti caratteri "." e converte i caratteri ","  in "."
   y = 0;
   for(i = 0; i < ImportoPassato.length; i++)
   {
      switch (ImportoPassato.substr(i,1))
      {
         case ",":
            importo = importo + ".";
            tipoV1 = ".";
            break;
         case " ":
            break;
         default:
            importo = importo + ImportoPassato.substr(i,1);
            if (tipoV1 == "")
            {
               y++;
            }
            break;
      }
   }
   Strimporto = importo;
   NomeCampo.value = Strimporto;
}

/* ============================================================================== */

function chkimp( ImportoPassato, nmDec, inNeg )
{
   var importo="";
   var val=0;
   var i=0;
   var y=0;
   var dec=0;
   var esp=0;
   var neg = inNeg;


   importo = ImportoPassato;

   val = parseFloat(Number(importo));

//campo vuoto
   if (importo == "")
      return true;

// non numerico
   if (isNaN(val))
   {
      gb_err=1;
      return false;
   }

// controllo se  è negativo solo se è rechiesto
   if (neg == 1 )
   {
      if (val < 0 )
      {
         gb_err=2;
         return false;
      }
   } 

// determino parte intera
   valInt=parseInt(val,10);

// formatto la parte intera
   importo=String(valInt);
   Strimporto = "";
   y=0;

   for(i=importo.length-1;i>=0;i--)
   {
      Strimporto = importo.substr(i,1) + Strimporto;
      y++;
      if(y==3 && i>0)
      {
         Strimporto = "." + Strimporto;
         y=0;
      }
   }
// aggiungo decimali
   if(val == valInt)
   {
      Strimporto = Strimporto + ",";
      for (i=1;i<=nmDec;i++)
      {
         Strimporto = Strimporto + "0";
      }
   }
   else
   {
      esp = Math.pow(10,nmDec);
      dec = parseInt((val*esp)+ 0.1,10) - parseInt((valInt*esp),10);
      Strimporto = Strimporto + ",";

      decStr = String(dec);
      for(i=1; i<=nmDec-decStr.length; i++)
      {
         Strimporto = Strimporto + "0";
      }
      Strimporto = Strimporto + String(dec);
   }
                                             
   return true;
}
/* ============================================================================== 
   ============================================================================== */
   function swptab(i,h,c)
{
	var he = document.getElementById(h);
	var ce = document.getElementById(c);
	var e;
	var n = 0;
	var clkov = '';
	var clkout = '';

	document.getElementById('a' + i).href = '#';
	
	for(n=0;n<he.childNodes.length;n++)
	{
		e = he.childNodes.item(n);
		if(e.id != null && e.id.charAt(0)=='h')
		{
			if(e.id == 'h' + i)
			{
				e.className='h-on'; 
			}
			else
			{
				e.className = 'h-off'; 
			}
		}
	}

	n = 0;
	for(n=0;n<ce.childNodes.length;n++)
	{
		e = ce.childNodes.item(n);
		if(e.id != null && e.id.charAt(0)=='c')
		{
			if(e.id == 'c' + i){e.className = 'show';}
			else{e.className = 'hide'}
		}
	}
}
