<!--

function codiceFISCALEbenStrutturato(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 partitaIVAbenStrutturata(sz_Codice) {
   var n_Val,n_Som1=0,n_Som2=0,lcv;

// alert("intoPIBS");

   if (sz_Codice.length!=11 || isNaN(parseFloat(sz_Codice)) || parseFloat(sz_Codice)<parseFloat(0)) return false;
   return true;

   // segue codice per controllo vero e proprio come da ministero finanze
   // che pupps ha voluto abolire il 30 sett 2008

   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 validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="") {alert(alerttxt);return false;}
		else {return true}
	}
}

function validate_cofispiva(field,alerttxt) { // document.write(field.value);		
	if (field.value.length == 11 || field.value.length == 16) {return true;}
	else {alert(alerttxt);return false;}
}

function validate_email(field,alerttxt) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
// alert("dentro validate email");	
// alert(apos); alert(dotpos);
		if (apos<1||dotpos-apos<2) {alert(alerttxt);return false;}
		else {return true;}
	}
}

function validate_checkbox(field,alerttxt) {
	if (field.checked) {return true;}
	else {alert(alerttxt);return false;}
}

function validate_form(thisform) {
	with (thisform) {

		if (validate_required(c_autoovc,"Scegliete se vi interessa un automobile o un veicolo commerciale")==false)
		{c_autoovc.focus();return false;}

		if (validate_required(c_marca,"Scegliete la marca che vi interessa per favore ")==false)
		{c_marca.focus();return false;}

		if (validate_required(c_modello,"Scegliete il modello di ".concat(c_marca.value, " che vi interessa per favore "))==false)
		{c_modello.focus();return false;}

		if (validate_required(c_versione,"Scegliete la versione di ".concat(c_marca.value, " ", c_modello.value, " che vi interessa per favore "))==false)
		{c_versione.focus();return false;}

		if ((c_marca2.selectedIndex > 0) && (validate_required(c_modello2,"Scegliete il modello di ".concat(c_marca2.value, " che vi interessa per favore ")))==false)
		{c_modello2.focus();return false;}

		if ((c_marca2.selectedIndex > 0) && (c_modello2.selectedIndex > 0) && (validate_required(c_versione2,"Scegliete la versione di ".concat(c_marca2.value, " ", c_modello2.value, " che vi interessa per favore ")))==false)
		{c_modello2.focus();return false;}

		if (validate_required(c_mesi,"Scegliete per quanti mesi intendete sottoscrivere il renting ")==false)
		{c_mesi.focus();return false;}
		if (validate_required(c_km,"Scegliete quanti Km che prevedete di percorrere in ".concat(c_mesi.value, " mesi "))==false)
		{c_km.focus();return false;}

// document.write(c_mesi.selectedIndex + "  -  " + c_km.selectedIndex );

if (((c_mesi.selectedIndex==4) && (c_km.selectedIndex>4))==true || ((c_mesi.selectedIndex==5) && (c_km.selectedIndex>3))==true ) // || ((c_mesi.selectedIndex==3) && (c_km.selectedIndex>7))==true )
{alert("Scelti troppi km per un periodo di ".concat(c_mesi.value, " mesi "));return false;}

		if (validate_required(c_figura_professionale,"Selezionate la vs. figura professionale per favore ")==false)
		{c_figura_professionale.focus();return false;}

		if (validate_required(c_cognomeoazienda,"Inserite il Vs. Cognome o il nome delle Vs. Azienda per favore ")==false)
		{c_cognomeoazienda.focus();return false;}

		if (validate_required(c_provincia,"Scegliete la provincia in cui operate per favore ")==false)
		{c_provincia.focus();return false;}

		if (validate_required(c_cofispiva,"Per potervi fornire un preventivo di massima è necessario un codice fiscale o una partita iva ")==false)
		{c_cofispiva.focus();return false;}
		if (validate_cofispiva(c_cofispiva,"Per il codice fiscale inserite 16 caratteri secondo la struttura standard dei codici fiscali, per la partita iva è necessario un numero di 11 cifre ")==false)
		{c_cofispiva.focus();return false;}


		if (c_cofispiva.value.length == 11) {
// alert(c_cofispiva.value.length);
			if (partitaIVAbenStrutturata(c_cofispiva.value)==false) {
				alert("Il dato inserito non è riconosciuto come un numero di partita IVA valido");c_cofispiva.focus();return false;
			}
		}

		if (c_cofispiva.value.length == 16) {
			if (codiceFISCALEbenStrutturato(c_cofispiva.value)==false) {
				alert("Il dato inserito non è riconosciuto come un codice fiscale valido");c_cofispiva.focus();return false;
			}
		}

// alert("prima di email");
		if (validate_required(c_email,"Inserite un email in modo che vi si possa rispondere ")==false)
			{c_email.focus();return false;}
		if (validate_email(c_email,"L'email inserita non ha un formato accettabile. Inserite un email in formato standard per favore ")==false)
			{c_email.focus();return false;}

// alert("prima di telefono");
		if (validate_required(c_telefono,"Inserite un per favore un numero di telefono in modo che vi si possa contattare ")==false)
			{c_telefono.focus();return false;}
		if (c_telefono.value.length < 8) {
			alert("Il dato inserito non sembra essere un numero di telefono valido");c_telefono.focus();return false;
		}

// alert("di accettazione");
		if (validate_checkbox(c_accetta,"E' richiesta esplicita accettazione del trattamento dati sensibili come imposto dalla legge sulla Privacy ")==false)
		{c_accetta.focus();return false;}
	}
}

//-->