function checkEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){	return true;	}else{		return false;	}
}		
function subme(modulo) {

  mama=modulo;
 
  ook=true;
  if (mama.firstname.value=="") {
    alert("Inserire Nome");
    ook=false;
  };
  
 if (ook && mama.realname.value=="") {
    alert("Inserire Cognome");
    ook=false;
  };
  
 if (ook && !checkEmail(mama.elements['email'].value)) {;	
    alert("Inserire un indirizzo di e-mail valido");
    ook=false;    
  };

 if (mama.sesso.value=="") {
    alert("Selezionare il sesso");
    ook=false;
  };

  if (ook && mama.gg.selectedIndex == 0) {
    alert("Inserire Giorno nascita");
    ook=false;
  };

 if (ook && mama.mm.selectedIndex == 0) {
    alert("Inserire il mese di nascita");
    ook=false;
  };

 if (ook && mama.aa.selectedIndex == 0) {
    alert("Inserire l'anno di nascita");
    ook=false;
  };
  
 if (ook && mama.localita.value=="") {
    alert("Inserire citta");
    ook=false;
  };
  
 if (ook && mama.provincia.selectedIndex == 0) {
    alert("Inserire provincia");
    ook=false;
  };  
  

if ( ook) {
    var len = mama.titolostudio.length;
    for(var i=0;i<len;i++){
        if (mama.titolostudio[i].checked == true){
          if(i==1){
              if(mama.diploma.value==""){
                 alert("Specificare il diploma");
                 ook=false;
              }
          }
           if(i==2){
              if(mama.laurea.value==""){
                 alert("Specificare laurea");
                 ook=false;
              }
          }
           if(i==3){
              if(mama.laureaspe.value==""){
                 alert("Specificare tipo di specializzazione");
                 ook=false;
              }
          }
           if(i==4){
              if(mama.master.value==""){
                 alert("Specificare il master");
                 ook=false;
              }
          }
        } 
         
    }
    
  }

    /*
  if (mama.titolo_studio.value=="") {
    alert("Selezionare il titolo di studio");
    ook=false;
  };
  */
  
   if (ook && mama.settore.value=="") {
    alert("Inserire Settore");
    ook=false;
  };
  
   if (ook && mama.sede.value=="") {
    alert("Inserire Sede");
    ook=false;
  };


  if (ook && !verificaImg(mama.curriculum)) {
    alert("Inserire il Curriculum Vitae");
    ook=false;
  };
 
  if (ook && !(mama.tratt_dati.checked)) {
    alert("E' necessario acconsentire al trattamento dei dati personali");
    ook=false;
  };

// if (ook) {
  //  mama.submit();
  // };
  
  return ook;
} 

var extFile = Array("pdf","rtf","doc","txt");

function verificaImg(fileInput){
   var file = fileInput.value;
   var temp = file.split(".");
   var numPunti = temp.length;
   if(numPunti < 2)
       return false;
   numPunti = numPunti-1;
   var ext = temp[numPunti].toLowerCase();
   
   if(ext.length != 3)
      return false;
   // Verifichiamo l'estensione
   
   var lenExt = extFile.length;
   
   for(var i=0;i<lenExt;i++){
       
   if(extFile[i] == ext){
        return true;
   }
   }
   return false;
}

