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 apriMenu2(pagina)
{ msg=open(pagina,
		'SOP',		'toolbar=no,directories=no,menubar=no,hotkeys=no,location=no,scrollbars=yes,width=495,height=600,top=20,left=100'
	);
}
	
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();
			cMSGjs_email = modulo.cMSGjs_email.value;
			alert(cMSGjs_email);
			return false;
	}
	if(modulo.remove.checked == false){	
		if( modulo.privacy.checked != true ) {
			cMSGjs_privacy = modulo.cMSGjs_privacy.value;
			alert (cMSGjs_privacy);
			modulo.privacy.focus();
			return false;
		}
	 }
	return true;		
};
   
function searchCode_Validator(theForm){
	if (theForm.codice.value == "")
  	{
		cMSG_cercaCodice = theForm.cMSG_cercaCodice.value;
		alert(cMSG_cercaCodice);
		theForm.codice.focus();
		return (false);
  	}
	return true;
};


function login_validator(frmLogin) {
	cMSGjs_email = frmLogin.cMSGjs_email.value;
	cMSGjs_pwd = frmLogin.cMSGjs_pwd.value;
	//controlla che venga inserito un valore nello username
	if (frmLogin.txtUsername.value == ""){
		frmLogin.txtUsername.select();
		alert(cMSGjs_email);
		return false;
	}
	//controlla che venga inserito un valore per la password
	if (frmLogin.txtPassword.value == ""){
		frmLogin.txtPassword.select();
		alert(cMSGjs_pwd);
		return false;
	}
	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.ragione_Sociale.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.value			= "";
	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.value 			= "";
	document.registrazione_utente_Form.codice_fiscale_azienda.value 	= "";
	document.registrazione_utente_Form.partita_iva.value 				= "";
	document.registrazione_utente_Form.ragione_Sociale.value 			= "";
	
	document.registrazione_utente_Form.codice_fiscale.style.background 	= '#cccccc';
	document.registrazione_utente_Form.codice_fiscale_azienda.style.background 	= '#ffffff';
	document.registrazione_utente_Form.partita_iva.style.background 	= '#ffffff';
	document.registrazione_utente_Form.ragione_Sociale.style.background = '#ffffff';
	document.registrazione_utente_Form.cboFormaGiuridica.style.background = '#ffffff';
	};
					
function registrazione_utente_Form_Validator(theForm)
{
				cMSGjs_email = theForm.cMSGjs_email.value;
				cMSGjs_pwd	= theForm.cMSGjs_pwd.value;
				cMSGjs_pwdl= theForm.cMSGjs_pwdl.value;
				cMSGjs_pwd2= theForm.cMSGjs_pwd2.value;
				cMSGjs_nome= theForm.cMSGjs_nome.value;
				cMSGjs_cognome= theForm.cMSGjs_cognome.value;
				cMSGjs_indirizzo= theForm.cMSGjs_indirizzo.value;
				cMSGjs_indirizzo1= theForm.cMSGjs_indirizzo1.value;
				cMSGjs_cap= theForm.cMSGjs_cap.value;
				cMSGjs_cap1= theForm.cMSGjs_cap1.value;
				cMSGjs_cap2= theForm.cMSGjs_cap2.value;
				cMSGjs_citta= theForm.cMSGjs_citta.value;
				cMSGjs_citta1= theForm.cMSGjs_citta1.value;
				cMSGjs_prov= theForm.cMSGjs_prov.value;
				cMSGjs_tel= theForm.cMSGjs_tel.value;
				cMSGjs_tel1= theForm.cMSGjs_tel1.value;
				cMSGjs_tel2= theForm.cMSGjs_tel2.value;
				cMSGjs_piva= theForm.cMSGjs_piva.value;
				cMSGjs_azienda= theForm.cMSGjs_azienda.value;
				cMSGjs_cfiscale= theForm.cMSGjs_cfiscale.value;
				cMSGjs_formaGiur= theForm.cMSGjs_formaGiur.value;
				cMSGjs_provenienza= theForm.cMSGjs_provenienza.value;
				cMSGjs_privacy= theForm.cMSGjs_privacy.value;
				
				
  /*controllo sullo username*/
	if(!isEmail(theForm.txtUsername.value)){
		alert(cMSGjs_email);
		theForm.txtUsername.focus();
		return false;
	  }
	if (theForm.txtUsername.value.length > 50){
    	alert(cMSGjs_email);
   	 	theForm.txtUsername.focus();
    	return (false);
  	}  
  /*controllo sulla password  */
  if (theForm.nuova_password.value == ""){
    alert(cMSGjs_pwd);
    theForm.nuova_password.focus();
    return (false);
  }
  if (theForm.nuova_password.value.length < 8 || theForm.nuova_password.value.length > 12){
    alert(cMSGjs_pwd);
    theForm.nuova_password.focus();
    return (false);
  }
  if (theForm.conferma_password.value == ""){
    alert(cMSGjs_pwdl);
    theForm.conferma_password.focus();
    return (false);
  }
  if (theForm.conferma_password.value != theForm.nuova_password.value){
    alert(cMSGjs_pwd2);
    theForm.conferma_password.value = "";
    theForm.conferma_password.focus()
    return (false);
  }
  if (theForm.nome_referente.value == "")
  {
    alert(cMSGjs_nome);
    theForm.nome_referente.focus();
    return (false);
  }
  if (theForm.cognome_referente.value == "")
  {
    alert(cMSGjs_cognome);
    theForm.cognome_referente.focus();
    return (false);
  }
  if (theForm.indirizzo.value == "")
	  {
		alert(cMSGjs_indirizzo);
		theForm.indirizzo.focus();
		return (false);
	  } 
  if (theForm.cap.value == "")
	  {
		alert(cMSGjs_cap);
		theForm.cap.focus();
		return (false);
	  }
  if (theForm.citta.value == "")
	  {
		alert(cMSGjs_citta);
		theForm.citta.focus();
		return (false);
	  }
  if (theForm.provincia.selectedIndex == 0)
	  {
		alert(cMSGjs_prov);
		theForm.provincia.focus();
		return (false);
	  }
  if (theForm.indirizzo.value.length > 50)
  {
    alert(cMSGjs_indirizzo1);
    theForm.indirizzo.focus();
    return (false);
  }
  if (theForm.cap.value.length != 5 )
	  {
		alert(cMSGjs_cap1);
		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(cMSGjs_cap2);
    theForm.cap.focus();
    return (false);
  }
  if (theForm.citta.value.length > 50)
  {
    alert(cMSGjs_citta1);
    theForm.citta.focus();
    return (false);
  }
  if (theForm.telefono.value == "")
	  {
		alert(cMSGjs_tel);
		theForm.telefono.focus();
		return (false);
	  }
  if (theForm.telefono.value.length < 8 || theForm.telefono.value.length > 16)
  {
    alert(cMSGjs_tel1);
    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(cMSGjs_tel2);
    theForm.telefono.focus();
    return (false);
  }
  if (theForm.partita_iva.disabled == false){
	  if(theForm.partita_iva.value==""){
		alert(cMSGjs_piva);
		theForm.partita_iva.focus();
		return (false);
	  }
	err = ControllaPIVA(theForm.partita_iva.value);
	if( err > '' ){
		alert(cMSGjs_piva);
		theForm.partita_iva.focus();
		return (false);
	}
  }
  if (theForm.ragione_Sociale.disabled == false){
  	if (theForm.ragione_Sociale.value == "" || theForm.ragione_Sociale.value.length > 150)
  	{
    	alert(cMSGjs_azienda);
    	theForm.ragione_Sociale.focus();
    	return (false);
  	}
  }
  if (theForm.cboFormaGiuridica.disabled == false){
   	if (theForm.cboFormaGiuridica.selectedIndex == 0)
  	{
    	alert(cMSGjs_formaGiur);
    	theForm.cboFormaGiuridica.focus();
    	return (false);
  	}
  }	
 if (theForm.codice_fiscale.disabled == false){
	 if(theForm.codice_fiscale.value==""){
		alert(cMSGjs_cfiscale);
		theForm.codice_fiscale.focus();
		return (false);
	  }
	err = ControllaCF(theForm.codice_fiscale.value);
	if( err > '' ){
			alert(cMSGjs_cfiscale);
			theForm.codice_fiscale.focus();
			return (false);
	}
  }
  if (theForm.codice_fiscale_azienda.disabled == false){
	if (theForm.codice_fiscale_azienda.value == "" || theForm.codice_fiscale_azienda.value.length < 11 || theForm.codice_fiscale_azienda.value.length > 16)
	{
		alert(cMSGjs_cfiscale);
		theForm.codice_fiscale_azienda.focus();
		return (false);
	}
  }
  
  // DATI CONSEGNA
  if (theForm.cap_consegna.value != ""){
  	if (theForm.cap_consegna.value.length != 5)
  	{
    	alert(cMSGjs_cap1);
    	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(cMSGjs_cap2);
		theForm.cap_consegna.focus();
		return (false);
	  }
  }
  if (theForm.telefono_consegna.value != ""){
  	if (theForm.telefono_consegna.value.length < 8 || theForm.telefono_consegna.value.length > 16)
  	{
    	alert(cMSGjs_tel1);
    	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(cMSGjs_tel2);
		theForm.telefono_consegna.focus();
		return (false);
	  }
  }
  if (theForm.telefono_cellulare.value != "")
  {
	  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(cMSGjs_tel2);
		theForm.telefono_cellulare.focus();
		return (false);
	  }
  }
  if (theForm.fax.value != "")
  {
	  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(cMSGjs_tel2);
		theForm.fax.focus();
		return (false);
	  }
  }
  if (theForm.cboProvenienza.selectedIndex == 0)
  {
    alert(cMSGjs_provenienza);
    theForm.cboProvenienza.focus();
    return (false);
  }
  if( theForm.privacy.checked == false ) 
  {
	alert (cMSGjs_privacy);
	theForm.privacy.focus();
	return false;
  }
	return (true);
}

// modulo contatti
function isEmail(what){
	var i=new RegExp("^.*\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
	if(!i.test(what)) 
		return false;
	return true;
}
		
function frmContatti_Validator(theForm){
	
	cMSGjs_email = theForm.cMSGjs_email.value;
	cMSGjs_nome = theForm.cMSGjs_nome.value;
	cMSGjs_cognome = theForm.cMSGjs_cognome.value;
	cMSGjs_messaggio = theForm.cMSGjs_messaggio.value;
	cMSGjs_privacy = theForm.cMSGjs_privacy.value;
	cMSGjs_indirizzo1 = theForm.cMSGjs_indirizzo1.value;
	cMSGjs_cap1 = theForm.cMSGjs_cap1.value;
	cMSGjs_cap2 = theForm.cMSGjs_cap2.value;
	cMSGjs_citta1 = theForm.cMSGjs_citta1.value;
	cMSGjs_tel1 = theForm.cMSGjs_tel1.value;
	cMSGjs_tel2 = theForm.cMSGjs_tel2.value;
	

	if (theForm.nome.value == ""){
		alert(cMSGjs_nome);
		theForm.nome.focus();
		return (false);
	}	
	if (theForm.cognome.value == ""){
		alert(cMSGjs_cognome);
		theForm.cognome.focus();
		return (false);
	}
	if(!isEmail(theForm.email.value)){
		alert(cMSGjs_email);
		theForm.email.focus();
		return false;
	}
	if (theForm.indirizzo.value != ""){
		 if (theForm.indirizzo.value.length > 50){
			alert(cMSGjs_indirizzo1);
			theForm.indirizzo.focus();
			return (false);
		 }
  	}
	if (theForm.cap.value != ""){
		if (theForm.cap.value.length != 5 ){
			alert(cMSGjs_cap1);
			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(cMSGjs_cap2);
		theForm.cap.focus();
		return (false);
	  }
	}
	if (theForm.citta.value != ""){
		if (theForm.citta.value.length > 50){
			alert(cMSGjs_citta1);
			theForm.citta.focus();
			return (false);
  		}
	}
	if (theForm.telefono.value != ""){
		if (theForm.telefono.value.length > 16  || theForm.telefono.value.length < 8){
			alert(cMSGjs_tel1);
			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(cMSGjs_tel2);
			theForm.telefono.focus();
			return (false);
		  }
	}
	if (theForm.messaggio.value == ""){
		alert(cMSGjs_messaggio);
		theForm.messaggio.focus();
		return (false);
	}
	if( theForm.privacy.checked != true ){
		alert (cMSGjs_privacy);
		theForm.privacy.focus();
		return false;
  	}
	return true;
}
	
function frmPreventivi_Validator(theForm){
	
	cMSGjs_nome = theForm.cMSGjs_nome.value;
	cMSGjs_cognome = theForm.cMSGjs_cognome.value;
	cMSGjs_azienda = theForm.cMSGjs_azienda.value;
	cMSGjs_email = theForm.cMSGjs_email.value;
	cMSGjs_tel = theForm.cMSGjs_tel.value;
	cMSGjs_tel1 = theForm.cMSGjs_tel1.value;
	cMSGjs_tel2 = theForm.cMSGjs_tel2.value;
	cMSGjs_indirizzo1 = theForm.cMSGjs_indirizzo1.value;
	cMSGjs_cap1 = theForm.cMSGjs_cap1.value;
	cMSGjs_cap2 = theForm.cMSGjs_cap2.value;
	cMSGjs_citta = theForm.cMSGjs_citta.value;
	cMSGjs_citta1 = theForm.cMSGjs_citta1.value;
	cMSGjs_privacy = theForm.cMSGjs_privacy.value;
	cMSGjs_piva = theForm.cMSGjs_piva.value;
	cMSGjs_prevMsg = theForm.cMSGjs_prevMsg.value;
	
	if (theForm.nome.value == ""){
		alert(cMSGjs_nome);
		theForm.nome.focus();
		return (false);
	}
	if (theForm.cognome.value == "")  {
		alert(cMSGjs_cognome);
		theForm.cognome.focus();
		return (false);
	}
	
	if(!isEmail(theForm.email.value)){
		alert(cMSGjs_email);
		theForm.email.focus();
		return false;
	}
	if (theForm.telefono.value == "") {
		alert(cMSGjs_tel);
		theForm.telefono.focus();
		return (false);
	}
 	if (theForm.telefono.value.length < 8 || theForm.telefono.value.length > 16) {
		alert(cMSGjs_tel1);
		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(cMSGjs_tel2);
		theForm.telefono.focus();
		return (false);
	  }
 	if (theForm.indirizzo.value != ""){
		 if (theForm.indirizzo.value.length > 50){
			alert(cMSGjs_indirizzo1);
			theForm.indirizzo.focus();
			return (false);
		 }
  	}
	if (theForm.cap.value != ""){
		if (theForm.cap.value.length != 5 ){
			alert(cMSGjs_cap1);
			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(cMSGjs_cap2);
		theForm.cap.focus();
		return (false);
	  }
	}
  	if (theForm.citta.value == "") {
		alert(cMSGjs_citta);
		theForm.citta.focus();
		return (false);
	}
  	if (theForm.PIva.value != ""){   
		  err = ControllaPIVA(theForm.PIva.value);
		  if( err > '' ){
			alert(cMSGjs_piva);
			theForm.PIva.focus();
			return (false);
		  }
	}
	if (theForm.messaggio.value == ""){
		alert(cMSGjs_prevMsg);
		theForm.messaggio.focus();
		return (false);
	}
	if( theForm.privacy.checked != true ) {
		alert (cMSGjs_privacy);
		theForm.privacy.focus();
		return false;
  	}
  	return true;
}

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 del nostro sito 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 del nostro sito la tua Home Page</span></a>');
	}
}

//Aggiungi ai preferiti	
function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}

//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'}
		}
	}
}