
function isEUDate(objName)
{
   var sDD;
   var sMM;
   var sYY;
   var sS1;
   var sS2;
   var iDD;
   var iMM;
   var iYY;
   var iMMDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

   if (objName.value.length == 0) return true;
   if (objName.value.length != 10) return false;
   sDD = objName.value.substr(0, 2);
   sS1 = objName.value.substr(2, 1);
   sMM = objName.value.substr(3, 2);
   sS2 = objName.value.substr(5, 1);
   sYY = objName.value.substr(6, 4);
   iDD = parseInt(sDD, 10);
   iMM = parseInt(sMM, 10);
   iYY = parseInt(sYY, 10);
   
   // alert(sDD+sS1+sMM+sS2+sYY);
   // alert(''+iDD+''+sS1+''+iMM+''+sS2+''+iYY);

   if ((iYY % 4) == 0) iMMDays[1] = 29;

   if (isNaN(iDD)) return false;
   if (isNaN(iMM)) return false;
   if (isNaN(iYY)) return false;
   if (iYY.toString() != sYY) return false;

   if ((iMM > 12) || (iMM < 1)) return false;
   if ((iDD > iMMDays[iMM -1]) || (iMM < 1)) return false;
   if (sS1 != "/") return false;
   if (sS2 != "/") return false;
   return true;
}

function convalida()
{
	
   var lista = Array("NOME","COGNOME","CF","*DATA(DATA_NASC)","LUOG_NASC","INDIR","CAP","LOCAL","PROV","EMAIL","DIP_TIPO","DIP_ANNO","DIP_VOTO");
   var nomic = Array("NOME","COGNOME","CODICE FISCALE","DATA DI NASCITA","LUOGO DI NASCITA","INDIRIZZO","CAP","CITTA'","PROVINCIA","E-MAIL","DIPLOMA (TIPO)","DIPLOMA (ANNO)","DIPLOMA (VOTO)");
   var XALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var XNUME = "0123456789";
   var n = lista.length;
   var i = 0;
   var j = 0;
   var p = 0;
   var t;
   var c;
   
   for (i=0; i<n; i++)
   {
      p = 0;
      while (document.all(p).name != lista[i]) p++;
      if (document.all(p).value.length < 2)
      {
         alert('Per poter inviare il proprio curriculum\n\nè necessario compilare il campo\n\n' + nomic[i] + '\n\n');
         document.all(p).focus();
         return false;
      }
      
      if (i == 2) // Controllo sul codice fiscale
      {
         document.all(p).value = document.all(p).value.toUpperCase();
         if (document.all(p).value.length != 16)
         {
            alert('Codice fiscale non valido.\n');
            document.all(p).focus();
            return false;
         }
         else
         {
            for(j=0; j<16; j++)
            {
               c = document.all(p).value;
               if ((j == 6) || (j == 7) || (j == 9) || (j == 10) || (j == 12) || (j == 13) || (j == 14))
               {
                  if (XNUME.indexOf(c.charAt(j)) < 0)
                  {
                     alert('Codice fiscale non valido alla posizione ' + j + '[' + c.charAt(j) + '].\n');
                     document.all(p).focus();
                     return false;
                  }
               }
               else
               {
                  if (XALFA.indexOf(c.charAt(j)) < 0)
                  {
                     alert('Codice fiscale non valido\nalla posizione ' + j + ' [' + c.charAt(j) + '].\n');
                     document.all(p).focus();
                     return false;
                  }
               }
            }
         }
      }

      if (i == 3) // Controllo sulla data di nascita
      {
         if (isEUDate(document.all(p)) == false)
         {
            alert('Data non valida.\n');
            document.all(p).focus();
            return false;
         }
      }
   }
   
   p = 0;
   while (document.all(p).name != 'TEL') p++;
   t = document.all(p);

   p = 0;
   while (document.all(p).name != 'CELL') p++;
   c = document.all(p);
   if ((t.value.length < 2) && (c.value.length < 2))
   {
      alert('Per poter inviare il proprio curriculum\n\nè necessario dare un recapito telefonico\n\n');
      t.focus();
      return false;
   }

   p = 0;
   while (document.all(p).name != 'CF') p++;
   c = document.all(p);

   if ((c.value.length != 16))
   {
      alert('Per poter inviare il proprio curriculum\n\nè necessario inserire il codice fiscale\n\n');
      t.focus();
      return false;
   }



if (!document.cvform.CONSENSOS.checked) {
	alert ("CONSENSO AL TRATTAMENTO DEI DATI PERSONALI: per poter proseguire nella registrazione, è necessario consentire al trattamento dei dati personali.");
    return false;
   }



   return true;
}
