function checkForm(form) {

  var eml1 = form.email;
  var eml2 = form.email2;

  if (eml1.value != eml2.value) {

  alert("Le due e-mail inserite non corrispondono!");
  return false;

  }

  var strErrorMsg='';

  if (form.name.value.length < 1)  {
        strErrorMsg+='      * Nome \n';
  }

  if (form.surname.value.length < 1)  {
        strErrorMsg+='      * Cognome \n';
  }

  if (form.mobile.value.length < 1)  {
        strErrorMsg+='      * N. di cellulare \n';
  }

  if (form.password.value.length < 6)  {
        strErrorMsg+='      * Password \n';
  }

  if (!verifyEmail(form.email.value)) {
        strErrorMsg+='      * E-mail \n';
  }

  if (form.id_nationality.selectedIndex == 0) {
        strErrorMsg+='      * Nazionalita\' \n';
  }

  if (form.id_prov.selectedIndex == 0) {
        strErrorMsg+='      * Provincia \n';
  }

  if (form.id_level.selectedIndex == 0) {
        strErrorMsg+='      * Titolo di studio \n';
  }

  //if (form.birth_date_day.selectedIndex == 0) {
  //      strErrorMsg+='      * Data di nascita - giorno \n';
  //}

  //if (form.birth_date_month.selectedIndex == 0) {
  //      strErrorMsg+='      * Data di nascita - mese \n';
  //}

  if (form.birth_date_year.selectedIndex == 0) {
        strErrorMsg+='      * Anno di nascita \n';
  }

  if (form.id_situation.selectedIndex == 0) {
        strErrorMsg+='      * Situazione attuale \n';
  }

  if (form.id_level.selectedIndex == 0) {
        strErrorMsg+='      * Titolo di studio \n';
  }

  if (!document.getElementById('id_genderM').checked && !document.getElementById('id_genderF').checked) {
        strErrorMsg+='      * Sesso \n';
  }

  if (strErrorMsg!='') {
        strErrorMsg='I campi di seguito non sono stati compilati correttamente\n'+strErrorMsg;
        alert(strErrorMsg);
        return false;
  }

  if (!document.getElementById('agreeyes').checked) {

  alert("Senza l'autorizzazione al trattamento dei dati non possiamo procedere alla registrazione!");
  return false;

  }

  if (!document.getElementById('optinyes').checked && !document.getElementById('optinno').checked) {

  alert("Devi scegliere se autorizzi il trattamento dei dati per finalita' di tipo B!");
  return false;

  }

  if (!document.getElementById('posdiryes').checked && !document.getElementById('posdirno').checked) {

  alert("Devi scegliere se desideri l'iscrizione a PostaDiretta!");
  return false;

  }

  return true;
}

function verifyEmail(s) {
        var chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-@';
        var sLen = s.length; var i=0, c=0, cCnt=0, step=0;
        if (sLen < 6) return false;
        if (s.indexOf('@.')>=0) return false;
        if (s.indexOf('.@')>=0) return false;
        while (i < sLen){
                c=s.charAt(i);
                if (!(chrs.indexOf(c)>=0 || (c=='_' && step<1))) return false;
                if (c=='.') { if (cCnt<1) return false; cCnt=0; }
                if (c=='@') { if (step>0) return false; if (cCnt<1) return false; step++; cCnt=0; }
                cCnt=cCnt+1; i++;
        }
        if (cCnt < 3 || cCnt > 5 || step==0 || (s.indexOf(".")<0) ) return false;
        return true;
}


