// JavaScript Document
  
  function submitForm() {
  	return validateFields();
  	}
  
  function validateFields() {
  	var strErrorMsg='';	
  	  
  var selObj = document.getElementById('pref4');
	var txtIndexObj = document.getElementById('txtIndex');
	var txtValueObj = document.getElementById('txtValue');

	
	var selIndex = selObj.selectedIndex;
	
        	  
  //if (document.form.pref4.selectedIndex == 0) {
  if(selObj.options[selIndex].value=="nd"){
      strErrorMsg+='      * E\' necessario selezionare un corso di studi\n';
     }
  
  	
  		var strpref1=document.form.pref1.value;
  	if (strpref1 == "00")
    {
      strErrorMsg+='* E\' necessario indicare un orario di inizio reperibilità\n';
    }
  
    	var strpref2=document.form.pref2.value;
    if (strpref2 == "00")
    {
      strErrorMsg+='* E\' necessario un orario di fine reperibilità\n';
    }
  
  
  	var strnome=document.form.nome.value;
  	if ((strnome.length < 1) || (strnome.length > 50))  {
  		strErrorMsg+='      * Nome \n';
  	}
  	var strcognome=document.form.cognome.value;
  	if ((strcognome.length < 1) || (strcognome.length > 50))  {
  		strErrorMsg+='      * Cognome\n';
  	}
  
  	var strvia=document.form.via.value;
  	if ((strvia.length < 1) || (strvia.length > 100))  {
  		strErrorMsg+='      * Indirizzo\n';
  	}
  	
  	var strcap=document.form.cap.value;
  	if (!verifyCap(strcap)) {
  		strErrorMsg+='      * CAP\n';
  	}
  	
  	var strcitta=document.form.comune.value;
  	if ((strcitta.length < 1) || (strcitta.length > 40))  {
  		strErrorMsg+='      * Città \n';
  	}
  
  	if (document.form.prov.selectedIndex == 0) {
  		strErrorMsg+='      * Provincia \n';
  	}
  ////////
  	var strtelf=document.form.telf.value;
  	var strtelm=document.form.telm.value;
  	
  	if(!strtelf && !strtelm){
  	 strErrorMsg+='      * Inserire Telefono fisso o telefono cellulare\n';
    }
    else{
      if(!strtelf && (strtelm.length<6)){
        strErrorMsg+='      * Telefono fisso o telefono cellulare errato o incompleto\n';
      }
      else{
        if(!strtelm && (strtelf.length<6)){
          strErrorMsg+='      * Telefono fisso o telefono cellulare errato o incompleto\n';
        }
      }
    }  
  ////////	
  	var stremail=document.form.email.value;
  	if (!verifyEmail(stremail)) {
  		strErrorMsg+='      * E-mail \n';
  	}
  	
  	radio_button_checker();
  
  function radio_button_checker()
  {
  var radio_choice = false;
  var radio_posta = false;
  	for (counter = 0; counter < 2; counter++)
  	{
  	if (document.form.privacy[counter].checked) radio_choice = true; 
   	if (document.form.postadiretta[counter].checked) radio_posta = true; 
  	}
  
  if (!radio_choice)
  	{
  	strErrorMsg+='      * Il tuo consenso all\'informativa al trattamento dei dati\n'; 
  	}
  else
  {
  	for (var i=0; i < 2; i++)
     	{
     	if (document.form.privacy[i].checked)
        {
  	 	var rad_val = document.form.privacy[i].value;
  		if(rad_val!= 's') 
  				{
  				strErrorMsg+='      * Il tuo consenso all\'informativa al trattamento dei dati\n'; 
  				}
        }	
  	}
  }
  
  if (!radio_posta)
  	{
  	strErrorMsg+='      *Consenso all’iscrizione a PostaDiretta.com \n'; 
  	}
  
  
  }
  	if (strErrorMsg!='') {
  		strErrorMsg='I campi di seguito non sono stati compilati correttamente\n'+strErrorMsg;
  		alert(strErrorMsg);
  		return false;
  	} else {
  		return true;
  	}
  }
  
  function get_radio_value()
  {
  for (var i=0; i < 2; i++)
     {
     if (document.form.privacy[i].checked)
        {
       	 var rad_val = document.form.privacy[i].value;
  		if(rad_val!= 's') 
  					{
  					alert('NO');	
  					strErrorMsg+='      * Il tuo consenso all\'informativa al trattamento dei dati\n'; 
  					}
        }
     }
  }
  
  function verifyEmail(s) {
  	var chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-@';
  	var sLen = s.length; var i=0, c=0, cCnt=0, step=0;
  	if (sLen < 6) 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;
  	}
  
  function verifyNumeric(strInput) {
  	if (strInput != '') {
  		if (!strInput.match(/[^0-9]/)) return true;
  	}
  	}
  
  function verifyCap(strCap) {
  	var bValid = false;
  	var intLength = strCap.length;
  	if (verifyNumeric(strCap) && intLength ==5)
  		bValid = true;
  
  
  	return bValid;
  	}
  

