/*
Author: Simone Volpini < www.simonevolpini.info >
This code is licensed under Creative Commons Attribution-ShareAlike License < http://creativecommons.org/licenses/by-sa/2.0/ >
*/

/**
 * Check modulo registrazione privati, email e pass
 */
function checkModRegPrivEmail(frm) {

    var email = frm.email.value;
    var password = frm.password.value;
	var password2 = frm.password2.value;
    
    var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
    
    if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
       alert("Inserire un indirizzo email corretto.");
       frm.email.select();
       return false;
    } else if (password.length < 6) {
       alert("La password è troppo corta (min. 6 caratteri).");
	   frm.password.value = "";
	   frm.password.focus();
	   return false;
    } else if (password != password2) {
	   alert("Le password non coincidono.");
	   frm.password2.value = "";
	   frm.password2.focus();
	   return false;
    
    //INVIA IL MODULO
    } else {
       frm.submit();
    }
	return false;
}

/**
 * Check modulo registrazione
 */
function checkModRegPrivDati(frm) {

	var cognome = frm.cognome.value;
    var nome = frm.nome.value;
    var indirizzo = frm.indirizzo.value;
    var citta = frm.citta.value;
    var cap = frm.cap.value;
    var nazione = frm.nazione.value; // n
    var telefono = frm.telefono.value;
    var informativa = frm.informativa;
    var newsletter = frm.newsletter[0]; // n   
    var n = $('#checkNewsletter input:checked').length; // n
    
    if ((nome == "") || (nome == "undefined")) {
       alert("Il campo Nome è obbligatorio.");
       frm.nome.focus();
       return false;
	} else if ((cognome == "") || (cognome == "undefined")) {
       alert("Il campo Cognome è obbligatorio.");
       frm.cognome.focus();
       return false;
    } else if ((indirizzo == "") || (indirizzo == "undefined")) {
       alert("Il campo Indirizzo è obbligatorio.");
       frm.indirizzo.focus();
       return false;
    } else if ((citta == "") || (citta == "undefined")) {
       alert("Il campo Città è obbligatorio.");
       frm.citta.focus();
       return false;
    } else if ((cap == "") || (cap == "undefined")) {
       alert("Il campo Cap è obbligatorio.");
       frm.cap.focus();
       return false;
    } else if ((nazione == "0") || (nazione == "undefined")) { // n
       alert("Il campo Nazione è obbligatorio");
       frm.nazione.focus();
       return false;
    } else if ((telefono == "") || (telefono == "undefined")) {
       alert("Il campo Telefono è obbligatorio.");
       frm.telefono.focus();
       return false;
    } else if ((newsletter.checked) && (n == 0)) { // n
  	   alert("Seleziona professione o interesse");
   	   return false;
    } else if (!informativa.checked) {
       alert("E' necessario accettare l'informativa sulla privacy");
       frm.telefono.focus();
       return false;
    }
    
    //INVIA IL MODULO
    else {
       frm.submit();
    }
	return false;
}

/**
 * Check modulo registrazione
 */
function checkModReg(frm) {

	var ragionesociale = frm.ragionesociale.value;
	var cognome = frm.cognome.value;
    var nome = frm.nome.value;
    var indirizzo = frm.indirizzo.value;
    var citta = frm.citta.value;
    var cap = frm.cap.value;
    var nazione = frm.nazione.value; // n
    var telefono = frm.telefono.value;
    var piva = frm.piva.value;
    var email = frm.email.value;
    var newsletter = frm.newsletter[0]; // n
    var informativa = frm.informativa;
    var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

    var n = $('#checkNewsletter input:checked').length; // n
    
    if ((ragionesociale == "") || (ragionesociale == "undefined")) {
       alert("Il campo Ragione sociale è obbligatorio.");
       frm.ragionesociale.focus();
       return false;
    } else if ((cognome == "") || (cognome == "undefined")) {
       alert("Il campo Cognome è obbligatorio.");
       frm.cognome.focus();
       return false;
    } else if ((nome == "") || (nome == "undefined")) {
       alert("Il campo Nome è obbligatorio.");
       frm.nome.focus();
       return false;
    } else if ((indirizzo == "") || (indirizzo == "undefined")) {
       alert("Il campo Indirizzo è obbligatorio.");
       frm.indirizzo.focus();
       return false;
    } else if ((citta == "") || (citta == "undefined")) {
      alert("Il campo Città è obbligatorio.");
      frm.citta.focus();
      return false;
    } else if ((nazione == "0") || (nazione == "undefined")) { // n
       alert("Il campo Nazione è obbligatorio");
       frm.nazione.focus();
       return false;
    } else if ((cap == "") || (cap == "undefined")) {
       alert("Il campo Cap è obbligatorio.");
       frm.cap.focus();
       return false;
    } else if ((telefono == "") || (telefono == "undefined")) {
       alert("Il campo Telefono è obbligatorio.");
       frm.telefono.focus();
       return false;
    } else if ((piva == "") || (piva == "undefined")) {
       alert("Il campo Partita Iva è obbligatorio.");
       frm.piva.focus();
       return false;
    } else if ((newsletter.checked) && (n == 0)) { // n
  	   alert("Seleziona professione o interesse");
   	   return false;
    } else if (!informativa.checked) {
       alert("Il campo Informativa è obbligatorio.");
       frm.telefono.focus();
       return false;
    } else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
       alert("Inserire un indirizzo email corretto.");
       frm.email.select();
       return false;
    }

    //INVIA IL MODULO
    else {
       frm.submit();
    }
	return false;
}

/**
 * Check modulo registrazione
 */
function checkModRegNewsletter(frm) {

	var cognome = frm.cognome.value;
    var nome    = frm.nome.value;
    var email   = frm.email.value;
    var nazione = frm.nazione.value;
    var informativa = frm.informativa;
    var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
    
	var n = $('#checkNewsletter input:checked').length;
	
    if ((cognome == "") || (cognome == "undefined")) {
       alert("Il campo Cognome è obbligatorio");
       frm.cognome.focus();
       return false;
    } else if ((nome == "") || (nome == "undefined")) {
       alert("Il campo Nome è obbligatorio");
       frm.nome.focus();
       return false;
    } else if ((nazione == "0") || (nazione == "undefined")) {
       alert("Il campo Nazione è obbligatorio");
       frm.nazione.focus();
       return false;
    } else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
       alert("Inserire un indirizzo email corretto");
       frm.email.select();
       return false;
    } else if (n == 0) {
       alert("Seleziona professione o interesse");
       return false;
    } else if (!informativa.checked) {
       alert("Il campo Informativa è obbligatorio");
       return false;
    }

    //INVIA IL MODULO
    else {
       frm.submit();
    }
	return false;
}
