var good;

function checkEmailAddress(field) {
  var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

  if (goodEmail) {
    good = true
  }
  else {
    alert('Inserisci un indirizzo email valido. Esempio: xx@xx.xx')
    field.focus()
    field.select()
    good = false
  }
}

function sendOff() {
  tNomecheck = document.fContatto.tNome.value
  if (tNomecheck.length <1) {
    alert('Inserire il nome!');
    document.fContatto.tNome.focus()
    document.fContatto.tNome.select()
    return
  }
  
  tMessaggiocheck = document.fContatto.tMessaggio.value
  if (tMessaggiocheck.length <1) {
    alert('Inserire il messaggio!');
    document.fContatto.tMessaggio.focus()
    document.fContatto.tMessaggio.select()
    return
  }
  
  good = false
  checkEmailAddress(document.fContatto.tMail)
  if ((document.fContatto.tNome.value && document.fContatto.tMessaggio.value)&&(good)) {
    //alert("Controllo superato!")
    //window.location= 'http://www.html.it'
    document.fContatto.submit();
    
  }
  /*
  if ((document.fContatto.em.value != document.fContatto.emx.value)&&(good)) {
    alert('Gli indirizzi email non coincidono')
  }
  */
}
