function checkInput(theForm) {
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	
	if ((theForm.nome.value==0) && (theForm.nome.value.length<=0)) {
		alert("Non hai inserito il nome !");
		theForm.nome.focus();
		return false
		}

	if ((theForm.cogno.value==0) && (theForm.cogno.value.length<=0)) {
		alert("Non hai inserito il cognome !");
		theForm.cogno.focus();
		return false
		}

	if ((theForm.ragso.value==0) && (theForm.ragso.value.length<=0)) {
		alert("Non hai inserito la ragione sociale !");
		theForm.ragso.focus();
		return false
		}

	if ((theForm.paiva.value==0) && (theForm.paiva.value.length<=0)) {
		alert("Non hai inserito la partita IVA !");
		theForm.paiva.focus();
		return false
		}

	else if ((theForm.paiva.value.length>0) && (theForm.paiva.value.length<11)) {
		alert("Partita IVA non valida !");
		theForm.paiva.focus();
		return false
	}
	
	else if ((theForm.paiva.value.length>0) && (!checkPiva(theForm.paiva.value))) {
		alert("Partita IVA non valida !");
		theForm.paiva.focus();
		return false
	}
	
	if ((theForm.codfi.value==0) && (theForm.codfi.value.length<=0)) {
		alert("Non hai inserito il codice fiscale !");
		theForm.codfi.focus();
		return false
		}

	else if ((theForm.codfi.value.length>0) && (theForm.codfi.value.length!=16 && theForm.codfi.value.length!=11)) {
		alert("Codice fiscale non valido !");
		theForm.codfi.focus();
		return false
	}
	
	else if ((theForm.codfi.value.length>0) && (theForm.codfi.value.length==16) && (!checkCodFisc(theForm.codfi.value))) {
		alert("Codice fiscale non valido !");
		theForm.codfi.focus();
		return false
	}
	
	else if ((theForm.codfi.value.length>0) && (theForm.codfi.value.length==11) && (!checkPiva(theForm.codfi.value))) {
		alert("Codice fiscale non valido !");
		theForm.codfi.focus();
		return false
	}
	
	if ((theForm.indir.value==0) && (theForm.indir.value.length<=0)) {
		alert("Non hai inserito l'indirizzo !");
		theForm.indir.focus();
		return false
		}

	if ((theForm.numciv.value==0) && (theForm.numciv.value.length<=0)) {
		alert("Non hai inserito il numero civico !");
		theForm.numciv.focus();
		return false
		}

	if ((theForm.cap.value==0) && (theForm.cap.value.length<=0)) {
		alert("Non hai inserito il CAP !");
		theForm.cap.focus();
		return false
		}

	if ((theForm.comun.value==0) && (theForm.comun.value.length<=0)) {
		alert("Non hai inserito il comune o la localita' !");
		theForm.comun.focus();
		return false
		}

	if ((theForm.prov.value==0) && (theForm.prov.value.length<=0)) {
		alert("Non hai inserito la provincia !");
		theForm.prov.focus();
		return false
		}

	if ((theForm.pretel.value==0) && (theForm.pretel.value.length<=0)) {
		alert("Non hai inserito il prefisso del numero di telefono !");
		theForm.pretel.focus();
		return false
		}

	if ((theForm.telef.value==0) && (theForm.telef.value.length<=0)) {
		alert("Non hai inserito il numero di telefono !");
		theForm.telef.focus();
		return false
		}

	if ((theForm.email.value==0) && (theForm.email.value.length<=0)) {
		alert("Non hai inserito l'e-mail !");
		theForm.email.focus();
		return false
		}

	if ((theForm.emailck.value==0) && (theForm.emailck.value.length<=0)) {
		alert("Non hai confermato l'e-mail !");
		theForm.email.focus();
		return false
		}

	if (theForm.email.value!=theForm.emailck.value) {
		alert("Gli indirizzi e-mail sono diversi !");
		theForm.paswd.focus();
		return false
		}

	else if (!email_reg_exp.test(theForm.email.value)){
		alert("E-mail non corretta !");
		theForm.email.focus();
		return false
		}

	if ((theForm.paswd.value==0) && (theForm.paswd.value.length<=0)) {
		alert("Non hai inserito la password !");
		theForm.paswd.focus();
		return false
		}

	if (theForm.paswd.value.length<8) {
		alert("La password deve essere di almeno 8 caratteri !");
		theForm.paswd.focus();
		return false
		}

	if ((theForm.paswdck.value==0) && (theForm.paswdck.value.length<=0)) {
		alert("Non hai confermato la password !");
		theForm.paswdck.focus();
		return false
		}

	if (theForm.paswd.value!=theForm.paswdck.value) {
		alert("La password non e corretta !");
		theForm.paswd.focus();
		return false
		}

	if (theForm.pricy.value=="NO") {
		alert("Non hai dato il consenso al trattamento dei dati !");
		theForm.pricy.focus();
		return false
		}
}

function checkPiva(IVA)
{
checkIVA=true
numdis=0
numpar=0
temppar=0
tot=0
lastnum=parseInt(IVA.slice(10,11))

for (i=0;i<9;i+=2) {
	numdis+=parseInt(IVA.slice(i,i+1))
	}

for (i=1;i<10;i+=2) {
	temppar=parseInt(IVA.slice(i,i+1))*2
	if (temppar<10) {
		numpar+=temppar
		}
	else {
		numpar+=(temppar-10)+1
		}
	}

tot=parseInt(numdis)+parseInt(numpar)

while (tot>=10) {
	tot=10-(tot%10)
	}

if (lastnum!=tot)
	checkIVA=false

return checkIVA
}

function checkCodFisc(CodiceFiscale) {
	CodiceFiscale = CodiceFiscale.toUpperCase();
	Lettere = new Array(36);

	for(i=0; i<Lettere.length; i++) {
		Lettere[i] = new Array(3);
		}
	
	ConfrontoCarattereControllo = new Array(25);
	
	var I, J;
	
	var Carattere, ValorePari, ValoreDispari;
	var SommaCaratteri, PariDispari, Risultato;
	
	var CarattereControllo, Temp, Test;

	Lettere[0][0] = "A";
	Lettere[0][1] = "0";
	Lettere[0][2] = "1";
	
	Lettere[1][0] = "B";
	Lettere[1][1] = "1";
	Lettere[1][2] = "0";
	
	Lettere[2][0] = "C";
	Lettere[2][1] = "2";
	Lettere[2][2] = "5";
	
	Lettere[3][0] = "D";
	Lettere[3][1] = "3";
	Lettere[3][2] = "7";
	
	Lettere[4][0] = "E";
	Lettere[4][1] = "4";
	Lettere[4][2] = "9";
	
	Lettere[5][0] = "F";
	Lettere[5][1] = "5";
	Lettere[5][2] = "13";
	
	Lettere[6][0] = "G";
	Lettere[6][1] = "6";
	Lettere[6][2] = "15";
	
	Lettere[7][0] = "H";
	Lettere[7][1] = "7";
	Lettere[7][2] = "17";
	
	Lettere[8][0] = "I";
	Lettere[8][1] = "8";
	Lettere[8][2] = "19";
	
	Lettere[9][0] = "J";
	Lettere[9][1] = "9";
	Lettere[9][2] = "21";
	
	Lettere[10][0] = "K";
	Lettere[10][1] = "10";
	Lettere[10][2] = "2";
	
	Lettere[11][0] = "L";
	Lettere[11][1] = "11";
	Lettere[11][2] = "4";
	
	Lettere[12][0] = "M";
	Lettere[12][1] = "12";
	Lettere[12][2] = "18";
	
	Lettere[13][0] = "N";
	Lettere[13][1] = "13";
	Lettere[13][2] = "20";
	
	Lettere[14][0] = "O";
	Lettere[14][1] = "14";
	Lettere[14][2] = "11";
	
	Lettere[15][0] = "P";
	Lettere[15][1] = "15";
	Lettere[15][2] = "3";
	
	Lettere[16][0] = "Q";
	Lettere[16][1] = "16";
	Lettere[16][2] = "6";
	
	Lettere[17][0] = "R";
	Lettere[17][1] = "17";
	Lettere[17][2] = "8";
	
	Lettere[18][0] = "S";
	Lettere[18][1] = "18";
	Lettere[18][2] = "12";
	
	Lettere[19][0] = "T";
	Lettere[19][1] = "19";
	Lettere[19][2] = "14";
	
	Lettere[20][0] = "U";
	Lettere[20][1] = "20";
	Lettere[20][2] = "16";
	
	Lettere[21][0] = "V";
	Lettere[21][1] = "21";
	Lettere[21][2] = "10";
	
	Lettere[22][0] = "W";
	Lettere[22][1] = "22";
	Lettere[22][2] = "22";
	
	Lettere[23][0] = "X";
	Lettere[23][1] = "23";
	Lettere[23][2] = "25";
	
	Lettere[24][0] = "Y";
	Lettere[24][1] = "24";
	Lettere[24][2] = "24";
	
	Lettere[25][0] = "Z";
	Lettere[25][1] = "25";
	Lettere[25][2] = "23";
	
	Lettere[26][0] = "0";
	Lettere[26][1] = "0";
	Lettere[26][2] = "1";
	
	Lettere[27][0] = "1";
	Lettere[27][1] = "1";
	Lettere[27][2] = "0";
	
	Lettere[28][0] = "2";
	Lettere[28][1] = "2";
	Lettere[28][2] = "5";
	
	Lettere[29][0] = "3";
	Lettere[29][1] = "3";
	Lettere[29][2] = "7";
	
	Lettere[30][0] = "4";
	Lettere[30][1] = "4";
	Lettere[30][2] = "9";
	
	Lettere[31][0] = "5";
	Lettere[31][1] = "5";
	Lettere[31][2] = "13";
	
	Lettere[32][0] = "6";
	Lettere[32][1] = "6";
	Lettere[32][2] = "15";
	
	Lettere[33][0] = "7";
	Lettere[33][1] = "7";
	Lettere[33][2] = "17";
	
	Lettere[34][0] = "8";
	Lettere[34][1] = "8";
	Lettere[34][2] = "19";
	
	Lettere[35][0] = "9";
	Lettere[35][1] = "9";
	Lettere[35][2] = "21";
	
	for(I=0; I<=25; I++){
		ConfrontoCarattereControllo[I] = String.fromCharCode(65 + I);
		}
	
	Carattere=0;
	ValorePari=1;
	ValoreDispari=2;
	SommaCaratteri=0;
	
	CarattereControllo=CodiceFiscale.charAt(CodiceFiscale.length-1);
	for(I=0; I<(CodiceFiscale.length)-1; I++){
		if (((I+1) % 2)==0){
			PariDispari="P";
			}
		else{
			PariDispari="D";
			}
		Temp=CodiceFiscale.substr(I,1);
		J=0;
		do{
			Test=Lettere[J][Carattere];
			J++;
			} while(Temp!=Test);
		J--;
	  
		if (PariDispari=="P"){
			SommaCaratteri = SommaCaratteri + parseInt(Lettere[J][ValorePari]);
			}
		else{
			SommaCaratteri = SommaCaratteri + parseInt(Lettere[J][ValoreDispari]);
			}
		}
	
	Risultato = (SommaCaratteri % 26);
	
	Risultato = ConfrontoCarattereControllo[Risultato];
	
	if (Risultato!=CarattereControllo){
		return false;
		}
	else{
		return true;
		}
}