function valida()
{
	var i;
	var trovato=0;

     if (document.form.rubriche_id_nuovo.value.length == 0) {
		alert("Prego selezionare la RUBRICA");
		document.form.rubriche_id_nuovo.focus();
		return false;
	}
	
	
	if (document.form.annuncio.value.length == 0) {
		alert("Prego inserire l\'ANNUNCIO");
		document.form.annuncio.focus();
		return false;
	}
	
	
	
var conta=0
	
	for(var i=0;i<form.elements['pubblica_id_nuovo[]'].length;i++)
		if(form.elements['pubblica_id_nuovo[]'][i].checked)conta++
	if(conta==0){
		alert('Selezionare almeno una testata DOVE pubblicare l\'ANNUNCIO')
		return false
	}


//CONTROLLI PER IL CAMPO NOME
     if (document.form.nome.value.length == 0) {
		alert("Prego inserite il Vs NOME");
		document.form.nome.focus();
		return false;
	}

	

//CONTROLLI PER IL CAMPO COGNOME
   if (document.form.cognome.value.length == 0)
    {
		alert("Prego inserite il Vs COGNOME");
		document.form.cognome.focus();
		return false;
	}
	

//CONTROLLI TELEFONO
    if (document.form.telefono.value.length == 0)
    {
     alert("Prego inserite il Vs TELEFONO");
     document.form.telefono.focus();
     return false;
    }  
    if(isNaN(document.form.telefono.value))
    {
      alert("Non inserite spazi bianchi nel numero es:054224242");
      document.form.telefono.focus();
      return false;
    }
//FINE CONTROLLI TELEFONO



//CONTROLLI PER IL CAMPO Eemail
            
  var e_email;
  e_email=document.form.email.value;
  
  
     if (document.form.email.value.length == 0) {
		alert("Prego inserite la Vs E-email");
		document.form.email.focus();
		return false;
	}  

if (document.form.email.value.length > 0)
{
	
	for(i=0;i<document.form.email.value.length;i++)
	{
		if(document.form.email.value.lastIndexOf("@")<1)
		{
		alert("il carattere @ [chiocciola] deve essere presente nel campo E-email");
		document.form.email.focus();
		return false;
		}
	}

if (document.form.email.value.substring(0).charCodeAt()==45||document.form.email.value.substring(0).charCodeAt()==46||document.form.email.value.substring(0).charCodeAt()==64||document.form.email.value.substring(0).charCodeAt()==95) {
		alert("Il PRIMO carattere del campo E-email non può essere nessuno dei seguenti caratteri:\npunto [.], chiocciola [@], trattino [-], underscore [_].");
		document.form.email.focus();
		return false;
		}
		
		for(i=0;i<document.form.email.value.length;i++)  //visualizza l' alert se nel campo sono presenti caratteri non consentiti
		{
        if(document.form.email.value.charCodeAt(i)!=32&&document.form.email.value.charCodeAt(i)!=45&&document.form.email.value.charCodeAt(i)!=46&&document.form.email.value.charCodeAt(i)<48||document.form.email.value.charCodeAt(i)>57&&document.form.email.value.charCodeAt(i)< 64|| document.form.email.value.charCodeAt(i)>90 && document.form.email.value.charCodeAt(i)!=95&&document.form.email.value.charCodeAt(i)<97|| document.form.email.value.charCodeAt(i)>122)
	      {
        alert("Nel campo E-email il carattere ["+document.form.email.value.substring(i,i+1)+"] non è consentito");
         document.form.email.focus();
	return false;
	 }
	}
	
     for(i=0;i<document.form.email.value.length;i++)  //visualizza l' alert se nel campo è presente il carattere (spazio)
	{
        if(document.form.email.value.charCodeAt(i)==32)
        {
        alert("Il carattere [spazio] nel campo E-email non è consentito");
         document.form.email.focus();
         return false;
	 }
         }
   
   
  
         	
var chiocciolaCount = 0;
var foundatposition = 0;
while(foundatposition != -1)  {
	foundatposition = e_email.indexOf("@", foundatposition);
	if (foundatposition != -1) {
		chiocciolaCount++;
		foundatposition++;
	}
	}
	
	if (chiocciolaCount>1) {
	alert("Attenzione! Hai inserito " + chiocciolaCount + " volte il simbolo [@]. Negli indirizzi e-email ne puoi inserire solamente uno!");
	document.form.email.focus();
	return false;
	}


var lunghezza_email;
lunghezza_email = e_email.length;
punto_posizionez=(lunghezza_email-4);
punto_posizione=(lunghezza_email-3);
puntone =e_email.substring(punto_posizionez,punto_posizionez+1);
punto = e_email.substring(punto_posizione,punto_posizione+1);

if (e_email != "es. lorenzo.lovato@europamultimedia.it" && e_email == "") {
	e_email = "";
	}
	else {
		
	for(i=punto_posizione+1;i<lunghezza_email;i++) {

	if (e_email.charCodeAt(i) < 65 || e_email.charCodeAt(i) > 90 && e_email.charCodeAt(i) < 97 || e_email.charCodeAt(i) > 122)
	{
	alert("Nel campo E_email l'estensione (es: .it,.com) non è corretta oppure è mancante.");
	document.form.email.focus();
	return false;
	}
	}
	}

	if (e_email != "es. lorenzo.lovato@europamultimedia.it" && e_email == "") {
	e_email = "";
	}
	else {

	if (punto != "."&&puntone!=".") {
	alert("Nel campo E-email c'é un errore!\nControllare l'estensione.\n\nLe possibili cause sono:\n1. Manca il carattere punto.\n2. L'estensione è troppo lunga");
	document.form.email.focus();
	return false;
	}
	}
	
 	if (e_email.lastIndexOf("@.") > 0 || e_email.lastIndexOf(".@") > 0) {
		alert("Nel campo E-email c'é un errore!\nI caratteri [@] e [.] non sono consentiti consecutivamente");
		document.form.email.focus();
		return false;
	}
 		
	
	if (e_email.lastIndexOf("..") > 0) {
		alert("Nel campo E-email non sono ammessi i punti [..] consecutivi.");
		document.form.email.focus();
		return false;
		}


//FINE CONTROLLI Eemail
}


//CONTROLLI TELEFONO
   if (document.form.code.value.length == 0)
    {
     alert("Prego ricopiare il CODICE ANTISPAM!");
     document.form.code.focus();
     return false;
    }  


//CONTROLLI PER LA PRIVACY
   if(document.form.datipersonali.checked == false)
   {
     alert("Prego autorizzare il trattamento ai dati personali.");
     document.form.datipersonali.focus();
     return false; 
   }  
//FINE CONTROLLI PRIVACY

return true;
}	