function checkForm(myForm) {

	with (myForm) {
		if ((societa.value == "") && (cognome.value == "") && (nome.value == "")) {
			alert("Valorizzare i campi Cognome e Nome o Ragione Sociale (se azienda).");
			societa.focus();
			return;
		}
		if ((societa.value == "") && ((cognome.value == "") || (nome.value == ""))) {
			alert("Entrambi i campi Cognome e Nome sono obbligatori.");
			cognome.focus();
			return;
		}
		if (email.value == "") {
			alert("Il campo E-mail è obbligatorio.");
			email.focus();
			return;
		}
		if ((CF.value == "") || (PI.value == "")) {
			alert("Entrambi i campi Codice Fiscale e Partita IVA sono obbligatori.");
			CF.focus();
			return;
		} else {
			if (CF.value == "") CF.value = PI.value;
			if (PI.value == "") PI.value = CF.value;
		}
		if (username.value == "") {
			alert("Il campo UserName è obbligatorio.");
			username.focus();
			return;
		}
		if (password.value == "") {
			alert("Inserire la Password.");
			password.focus();
			return;
		}
		if (conferma.value == "") {
			alert("Reinserire la Password per la conferma.");
			conferma.focus();
			return;
		}
		if (password.value != conferma.value){
			conferma.value = "";
			alert("Password errata. Reinserire la Password per la conferma.");
			conferma.focus();
			return;
		}
		if (indirizzo.value == "") {
			alert("Il campo Indirizzo è obbligatorio.");
			indirizzo.focus();
			return;
		}
		if (comune.value == "") {
			alert("Selezionare un comune.");
			return;
		}
		if (tel.value == "") {
			alert("Inserire il Telefono.");
			tel.focus();
			return;
		}
		if (informativa[1].checked) {
			alert("Spiacenti, ma non dando il consenso, la registrazione non può essere effettuata.");
			return;
		}
		submit();
	}
}

function checkPaymentInfo(myForm) {
	with (myForm){
		if ((txtPaymentFirstName.value == '') && (txtPaymentLastName.value == '') && 
				(txtPaymentAddress1.value == '') && (txtPaymentCity.value == '') && 
				(txtPaymentPostalCode.value == '') && (txtPaymentCountry.value == '')) {
			setPaymentInfo(true);

			txtPaymentCity.disabled = false;
			txtPaymentPostalCode.disabled = false;
			txtPaymentCountry.disabled = false;
			
			submit();
		} 
		if ((txtPaymentFirstName.value != '') && (txtPaymentLastName.value != '') && 
				(txtPaymentAddress1.value != '') && (txtPaymentCity.value != '') && 
				(txtPaymentPostalCode.value != '') && (txtPaymentCountry.value != '')) {
			
			txtPaymentCity.disabled = false;
			txtPaymentPostalCode.disabled = false;
			txtPaymentCountry.disabled = false;

			submit();
		} else {
			alert("Compilare tutti i campi relativi alla spedizione");
		}
	}
}


function setPaymentInfo(isChecked)
{
	with (window.document.frmCheckout) {
		if (isChecked) {
			if (txtPaymentCountry.value != '' && txtPaymentCountry.value != hidShippingCountry.value) {
				alert("Adesso sarà fatto il reload della pagina.\nDopo il reload è possibile rieseguire l'operazione.");
				window.location.href = "checkoutConfirmation_en.php?shipment="+hidShipmentType.value;
			}
			txtPaymentFirstName.value  = hidShippingFirstName.value;
			txtPaymentLastName.value   = hidShippingLastName.value;
			txtPaymentAddress1.value   = hidShippingAddress1.value;
			txtPaymentCity.value       = hidShippingCity.value;
			txtPaymentIdCity.value     = hidShippingIdCity.value;
			txtPaymentCountry.value    = hidShippingCountry.value;
			txtPaymentPostalCode.value = hidShippingPostalCode.value;
		} else {
			txtPaymentFirstName.value  = '';
			txtPaymentLastName.value   = '';
			txtPaymentAddress1.value   = '';
			txtPaymentCity.value       = '';
			txtPaymentIdCity.value     = '';
			txtPaymentCountry.value    = '';
			txtPaymentPostalCode.value = '';
		}
	}
}


/**************************************
    Controllo del Codice Fiscale
    Linguaggio: JavaScript
***************************************/

function ControllaCF(cf)
{
    var validi, i, s, set1, set2, setpari, setdisp;
    if( cf == '' )  return true;
    cf = cf.toUpperCase();
    if( cf.length != 16 ) {
        alert("La lunghezza del codice fiscale non e' corretta:\n il codice fiscale dovrebbe essere lungo esattamente 16 caratteri.");
		return false;
	}
    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for( i = 0; i < 16; i++ ){
        if( validi.indexOf( cf.charAt(i) ) == -1 ) {
            alert("Il codice fiscale contiene un carattere non valido `" +
                cf.charAt(i) +
                "'.\nI caratteri validi sono le lettere e le cifre.\n");
			return false;
		}
    }
    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) ) {
        alert("Il codice fiscale non e' corretto:\n il codice di controllo non corrisponde.");
		return false;
	}
    return true;
}