// JavaScript Document
function valida_contattaci()
{
var nome = document.contattaci.nome.value;
var telefono = document.contattaci.telefono.value;
var email = document.contattaci.email.value;
var oggetto = document.contattaci.oggetto.value;
var testo = document.contattaci.testo.value;

if(nome == '')
{
alert('Inserisci nome e cognome');
return false;
}
if(telefono == '')
{
alert('Inserisci il numero di telefono');
return false;
}
if(email == '')
{
alert('Inserisci l\'indirizzo email');
return false;
}
else
{
if(!checkemail(email))
{
return false;
}
}
if(oggetto == '' || oggetto == ' ')
{
alert('Inserisci l\'oggetto della email');
return false;
}
if(testo == '' || testo == ' ')
{
alert('Inserisci il testo della email');
return false;
}

return true;
}

//Contiene almeno un carattere prima di "@"
//Contiena il carattere "@" dopo uno o pi\371 caratteri
//Contiene almeno un carattere dopo "@", seguito da un punto (.), seguito da 2 o 4 caratteri
function checkemail(email) {
var str = email;
var filter = /^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+\.[a-zA-Z]{2,4}$/
if (filter.test(str))
testresults = true
else {
alert("Attenzione!\n L'indirizzo email che hai inserito non risulta valido.")
testresults = false
}
return (testresults)
}