//  ####################################
//  Validazione reg utente Fotobelle.it
//  NB inserire nel root principale
//	v. 30-05-05
//  ####################################



// espressioni regolari 

var re_emptyall = new RegExp("^[ ]*$");
var re_emptyfirst = new RegExp("^[ ]");
var re_emptylast = new RegExp("[ ]$");
var re_empty = new RegExp("[ ]");
var re_number = new RegExp("[0-9]");
var re_not_number = new RegExp("[^0-9]");
var re_login_pwd = new RegExp("[^a-zA-Z0-9\_\.]");
var re_year = new RegExp("[0-9]{4}");
var re_prov = new RegExp("([a-z]|[A-Z]){2}");
var re_numcell1 = new RegExp("[0-9]{7}");
var re_numcell2 = new RegExp("[0-9]{8}");
var re_not_isAlpha = new RegExp("[^a-zA-Z ]");
var re_not_isAlphaNum = new RegExp("[^a-zA-Z0-9 ]");
var re_cf = new RegExp("[^a-zA-Z0-9]");


// rif: http://www.aspcode.it/forum/forum.asp?tab=2&cod=50
//




function validate_registra_utente()
{ 


// validazione dati personali
if (document.form_registra_utente.nome_persona.value=="")
{ alert ("Attenzione, campo obbligatorio: nome."); document.form_registra_utente.nome_persona.focus(); return false }

if (document.form_registra_utente.cognome_persona.value=="")
{ alert ("Attenzione, campo obbligatorio: cognome."); document.form_registra_utente.cognome_persona.focus(); return false }

if (document.form_registra_utente.telefono_persona.value=="")
{ alert ("Attenzione, campo obbligatorio: Telefono."); document.form_registra_utente.telefono_persona.focus(); return false }

if (document.form_registra_utente.mail_persona.value=="")
{ alert ("Attenzione, campo obbligatorio: indirizzo email."); document.form_registra_utente.mail_persona.focus(); return false }



// ulteriore valdazione mail 

EmailAddr = document.form_registra_utente.mail_persona.value;
Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (Filtro.test(EmailAddr)){
// return true;
}else{
alert("Controlla l'indirizzo di email inserito");
document.form_registra_utente.mail_persona.focus();
return false;
}



//
//



// data nascita
if (document.form_registra_utente.data_nascita_giorno.value=="")
{ alert ("Attenzione, campo obbligatorio: data di nascita (giorno)."); document.form_registra_utente.data_nascita_giorno.focus(); return false }

if (document.form_registra_utente.data_nascita_mese.value=="")
{ alert ("Attenzione, campo obbligatorio: data di nascita (mese)."); document.form_registra_utente.data_nascita_mese.focus(); return false }

if (document.form_registra_utente.data_nascita_anno.value=="")
{ alert ("Attenzione, campo obbligatorio: data di nascita (anno)."); document.form_registra_utente.data_nascita_anno.focus(); return false }


// codice fiscale


var CodiceFiscale = document.form_registra_utente.cf_persona;


// test vuoto
if (document.form_registra_utente.cf_persona.value=="")
{ alert ("Attenzione, inserisci il tuo codice fiscale."); document.form_registra_utente.cf_persona.focus(); return false 
}

// test alfanumerico
if(re_cf.test(CodiceFiscale.value)){
alert("Il codice fiscale puo\' contenere solo lettere e numeri");
CodiceFiscale.focus();
return false;
}


// test lunghezza
if (CodiceFiscale.value.length < 16 || CodiceFiscale.value.length > 16) {
alert("Lunghezza codice fiscale non corretta");
CodiceFiscale.focus();
return false;
}

// verifica ripetizione
if (document.form_registra_utente.cf_persona.value!=document.form_registra_utente.verifica_cf_persona.value)
{ alert ("Attenzione, controlla il codice fiscale ed inseriscilo anche nel campo di controllo."); document.form_registra_utente.verifica_cf_persona.focus(); return false }





// password utente

// passwod vuota
if (document.form_registra_utente.password_utente.value=="")
{ alert ("Attenzione, devi scegliere una password per accedere alla tua area riservata."); document.form_registra_utente.password_utente.focus(); return false 
}


// Controllo lunghezza da 6 10 caratteri alfanum
var password = document.form_registra_utente.password_utente;
if (re_empty.test(password.value) || password.value.length < 6 || password.value.length > 10) {
alert("La password deve essere min 6 max 10 caratteri non vuoti");
password.focus();
return false;
}

if(re_login_pwd.test(password.value)){
alert("La password puo\' contenere solo lettere, numeri, \"_\" o \".\"");
password.focus();
return false;
};

// ripetizione password
if (document.form_registra_utente.password_utente.value!=document.form_registra_utente.verifica_password.value)
{ alert ("Attenzione, le password non coincidono."); document.form_registra_utente.verifica_password.focus(); return false }










// end validazione dati personali



// validazione azienda, test secondo radio button

if (document.form_registra_utente.privato_azienda[1].checked)
{ 

if (document.form_registra_utente.ragione_sociale.value=="")
{ alert ("Attenzione, inserisci la Ragione Sociale."); document.form_registra_utente.ragione_sociale.focus(); return false }

if (document.form_registra_utente.piva_azienda.value=="")
{ alert ("Attenzione, inserisci la Partita IVA."); document.form_registra_utente.piva_azienda.focus(); return false }

if (document.form_registra_utente.tel_azienda.value=="")
{ alert ("Attenzione, inserisci il numero di telefono dell'azienda."); document.form_registra_utente.tel_azienda.focus(); return false }


if (document.form_registra_utente.mail_azienda.value=="")
{ alert ("Attenzione, inserisci l'indirizzo email dell'azienda."); document.form_registra_utente.mail_azienda.focus(); return false }

// validazione settore appartenenza

if (document.form_registra_utente.settore_attivita.selectedIndex <= 0)
{ alert ("Indica un settore di attivita"); return false }


}// end validazione azienda





// indirizzo fatturazione
if (document.form_registra_utente.ind_fatt_via.value=="")
{ alert ("Attenzione, campo obbligatorio: indirizzo (via)."); document.form_registra_utente.ind_fatt_via.focus(); return false }

if (document.form_registra_utente.ind_fatt_civico.value=="")
{ alert ("Attenzione, campo obbligatorio: indirizzo (n° civico)."); document.form_registra_utente.ind_fatt_civico.focus(); return false }

if (document.form_registra_utente.ind_fatt_citta.value=="")
{ alert ("Attenzione, campo obbligatorio: indirizzo (Citta')."); document.form_registra_utente.ind_fatt_citta.focus(); return false }

if (document.form_registra_utente.ind_fatt_cap.value=="")
{ alert ("Attenzione, campo obbligatorio: indirizzo (CAP)."); document.form_registra_utente.ind_fatt_cap.focus(); return false }

// end indirizzo fatturazione


// validazione metodo pagamento
if (document.form_registra_utente.modo_pagamento.selectedIndex <= 0)
{ alert ("Scegli una metodo di pagamento"); return false }



// fine delle condizioni
else { return true }

}



