/***************************************************
 funzioni di controllo della form prima dell'invio
***************************************************/ 

function controlla(form)
{

    var err=0;
	var msg='Sono stati riscontrati i seguenti errori di inserimento:\n\n';
    var msg2='Attenzione\n\n';
	if (form.nome.value == "")
		{
			var err=1;
			//colora di giallo l'input
			var elem = document.getElementById("nome");
			elem.style.background = 'Yellow' ;
			//fine
			var msg=msg+'- Nome non indicato'+'\n';
		}
    if (form.cognome.value == "")
		{
			var err=1;
				//colora di giallo l'input
			var elem = document.getElementById("cognome");
			elem.style.background = 'Yellow' ;
			//fine
			var msg=msg+'- Cognome non indicato'+'\n';
		}
	
	if (form.email.value == "")
		{
			var err=1;
			//colora di giallo l'input
			var elem = document.getElementById("email");
			elem.style.background = 'Yellow' ;
			//fine
			var msg=msg+'- E-mail non indicata'+'\n';
		}
		
	if (form.testo.value == "")
		{
			var err=1;
			//colora di giallo l'input
			var elem = document.getElementById("testo");
			elem.style.background = 'Yellow' ;
			//fine
			var msg=msg+'- Inserire testo'+'\n';
		}	
	

     if (err == 0)
	    {
	 	  if(form.privacy[1].checked == true){
			alert("Per poter eseguire la registrazione si deve dare il proprio consenso al trattamento dei dati personali cliccando sulla voce 'Accetto'");
					return;
					}	
					form.submit();
		}
     if (err == 1)
		   {
			var msg=msg+'\n'+'Correggere i dati prima di procedere';
	    	alert(msg);
			return;
		   }
     if (err == 2)
	       {
			var msg=msg2+'\n'+'Inserire la stessa password nei campi "PASSWORD" e "CONFERMA PASSWORD"';
			alert(msg);
			return;
		   }
}

/*******************************
permette di cambiare classe css
*******************************/
function cambiaClasse(id){
var section = document.getElementById(id);
section.className="active";
}
/*******************************
permette di cambiare classe css
*******************************/

/***********************
 controllo se il formato 
  della mail è esatta
*************************/

function emailAlert(emailInput)
   {
   // se il formato dell'indirizzo e-mail è errato da un alert
   var checkEmail=emailControl(emailInput);
   if (checkEmail==false)
      {
      alert ('Attenzione : Formato indirizzo errato !'+'\n'+'Correggere indirizzo prima di procedere')
      //emailInput.focus();
	  //form.email.focus();
      return (false);
      }   
   }

function emailControl(emailInput)
   {
   // Controllo il formato dell'indirizzo e-mail. restituisce true o false
   var StrMail;
   //StrMail=emailInput.value;
   StrMail=emailInput;
   if (StrMail.length>6)
      {
      var pos;
      var dotpos;
      pos = StrMail.indexOf("@");
      if ( (pos >= (StrMail.length-3) ) || (pos < 2) )
         {
         //emailInput.focus();
         return (false);
         }
      pos=pos+1;
      dotpos = StrMail.indexOf(".", pos);
      if (dotpos > (StrMail.length-3) )
         {
         //emailInput.focus();
         return (false);
         }
      Strmail=StrMail.substr(pos);
      if ( (StrMail.length < 5) || (dotpos <= 0) )
         {
         //emailInput.focus();
         return (false);
         }
      }
   else
      {
      //emailInput.focus();
      return (false);
      }
   return true;
   }
/***********************
 controllo se il formato 
  della mail è esatta
*************************/
