function isEmail(string) {
if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
return 1;
else
return 0;
}


function controlla(){

var errors = "";


if ((document.getElementById("contatti_ragione_sociale").value == "") && (document.getElementById("contatti_cognome").value == "")){
errors += "\n- Indica il tuo Cognome o Ragione Sociale";
}
if ((document.getElementById("contatti_email").value == "") && (document.getElementById("contatti_telefono").value == "")){
errors += "\n- Inserisci almeno un recapito tra Telefono ed e-mail";
}

if (document.getElementById("contatti_email").value != ""){ 
if (!isEmail(document.getElementById("contatti_email").value)){
errors += "\n- L'indirizzo e-Mail non e' valido";
}
}

if (document.getElementById("contatti_comune").value == ""){
errors += "\n- Indica la tua citta'";
}

if (document.getElementById("contatti_testo").value == ""){
errors += "\n- Non e' stato digitato il testo della richiesta";
}

if (errors != ""){
alert("Il modulo non puo' essere inviato, controlla quanto segue:\n" + errors);
return false;
} else {
return true;
}
}
