function apriMenu(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 apriPrivacy(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 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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

	
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 la check");
			return false;
			}
	 }
		else
			return true;
			
		};	

function login_validator() {
	if (frmLogin.txtUsername.value == "") 
	{
		frmLogin.txtUsername.select();
		alert("Si prega di inserire uno username valido valido");
			return false;
	}
	if (frmLogin.txtPassword.value == "") 
	{
		frmLogin.txtPassword.select();
		alert("Si prega di inserire una password valida");
			return false;
	}
	else
		return true;
	};
function partitaIVA(sz_Codice) 
   { 
   var n_Val,n_Som1=0,n_Som2=0,lcv; 
   if (sz_Codice.length!=11 || isNaN(parseFloat(sz_Codice)) || parseFloat(sz_Codice)<parseFloat(0)) 
      return false; 
   
   for (lcv=0;lcv<9;lcv+=2) 
   { 
      n_Val=parseInt(sz_Codice.charAt(lcv)); 
      n_Som1+=n_Val; 
      n_Val=parseInt(sz_Codice.charAt(lcv+1)); 
      n_Som1+=Math.floor(n_Val/5) + (n_Val<<1) % 10; 
   } 
   n_Som2 = 10 - (n_Som1 % 10); 
   n_Val=parseInt(sz_Codice.charAt(10)); 
   if (n_Som2==n_Val) 
      return true; 
   return false; 
   } 

function codiceFISCALE(cfins) 
{ 
var cf = cfins.toUpperCase(); 
var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/; 
   if (!cfReg.test(cf)) 
      return false; 
var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX"; 
var 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 false; 
   return true; 
   } 
   
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 non è valido."); 
		return false
				 }   
return true;
}
					
function registrazione_utente_Form_Validator(theForm)
{

  if( theForm.privacy.checked != true ) 
  {
	alert ("prima di registrarsi leggere l'informativa sulla privacy e selezionare la check");
	return false;
  }
  
  if (theForm.ragione_Sociale.value.length > 39)
  {
    alert("Inserire al massimo 16 caratteri 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.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.citta.value == "")
  {
    alert("Inserire un valore per il campo Città");
    theForm.citta.focus();
    return (false);
  }
  
      if (theForm.cap.value == "")
  {
    alert("Inserire il codice di avviamento postale");
    theForm.cap.focus();
    return (false);
  }

if (theForm.partita_iva.value != "")
  {  
   var PIvaOk=partitaIVA(theForm.partita_iva.value)
   if (PIvaOk==false) 
      { 
      alert("Partita IVA errata"); 
      return false; 
      } 
   }

if (theForm.codice_fiscale.value != "")
  {    
   var CFok=codiceFISCALE(theForm.codice_fiscale.value) 
   if (CFok==false)
      { 
      alert("Codice Fiscale errato"); 
      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.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.cap_consegna.value.length > 5)
  //{
    //alert("Inserire al massimo 5 caratteri nel campo CAP 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 CONSEGNA");
    //theForm.cap_consegna.focus();
   // return (false);
  //}

  if (theForm.citta.value.length > 25)
  {
    alert("Inserire al massimo 25 caratteri nel campo CITTA'");
    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 CITTA'");
    theForm.citta.focus();
    return (false);
  }

  if (theForm.telefono.value.length > 12)
  {
    alert("Inserire al massimo 12 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_consegna.value.length > 12)
  //{
   // alert("Inserire al massimo 12 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.email.value == "")
  {
    alert("Inserire un valore per il campo E-MAIL");
    theForm.email.focus();
    return (false);
  }
  
  if(!isEmail(theForm.email.value)) 
		return false;

  if (theForm.email.value.length > 80)
  {
    alert("Inserire al massimo 30 caratteri nel campo E-MAIL");
    theForm.email.focus();
    return (false);
  }

  var checkOK = "ç@-_.,:;'^?£$%&/\|*éèìòàABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789- \t\r\n\f";
  var checkStr = theForm.email.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 \"@.-\" caratteri nel campo E-MAIL");
    theForm.email.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);
  }
  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 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 frmArticoli_Validator(theForm){
	if (theForm.txtCodiceArticolo.value == "")
	  {
		alert("Inserire un valore per il codice articolo");
		theForm.txtCodiceArticolo.focus();
		return (false);
		}
	}
	
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;
}

