
function check_mail(id_obj, msg_txt)
  {
  el = document.getElementById(id_obj);

  if(el)
    {
    address = el.value;

    if (msg_txt == null)
      msg_txt = "Attenzione, indirizzo e-mail non corretto.";
    re = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (!re.test(address))
      {
      if (msg_txt != "")
        alert(msg_txt);
      return false;
      }
    else
      return true;
    }
  else
    {
    alert("Errore: impossibile trovare ID="+id_obj);
    return false;
    }
  }

  
function MyReset(nome_id)
  {
  $$('#'+nome_id+' input[type=text]').each(function(el){
    el.setProperty('value', '');
  });

  $$('#'+nome_id+' option').each(function(el){
    el.removeProperty('selected');
  });

  $$('#'+nome_id+' input[type=radio]').each(function(el){
    if (el.getProperty('value') == '')
      el.setProperty('checked', 'checked');
    else
      el.removeProperty('checked');
  });

  document.getElementById(nome_id).submit();

  return false;
  }

//hide divs and link function-------------------------------
function tabDiv(show,hide1){
	if(document.getElementById(show).style.display == 'none'){
		document.getElementById(show).style.display = 'block';
		document.getElementById(hide1).style.display = 'none';
	}
	else{
		document.getElementById(show).style.display = 'block';
		document.getElementById(show).style.display = 'none';
	}
}

// controlla che la lunghezza del testo inserito in textarea id_campo
// NON superi i MAX  caratteri
// aggiorno il campo con id=contatore
function controlla_lunghezza(id_campo, maxchars)
  {
  var chars = document.getElementById(id_campo).value;
  if (chars.length > maxchars)
    {
    document.getElementById(id_campo).value=chars.substr(0,maxchars);
    document.getElementById(id_campo).blur();
    }
    document.getElementById('contatore').value = maxchars-document.getElementById(id_campo).value.length;
  }

 // controlla che i campi obbligatori NOME - COGNOME -PRIVACY - TELEFONO 
// e se inserita la mail deve essere corretta
function controlla_form(nome_form)
  {
  if (nome_form.nome.value=="" || nome_form.nome.value==" ")
    {
    alert("Il campo nome non è stato compilato");
    nome_form.nome.focus();
    return false;
    }

  if (nome_form.cognome.value=="" || nome_form.cognome.value==" ")
    {
    alert("Il campo cognome non è stato compilato");
    nome_form.cognome.focus();
    return false;
    }
    
  if (nome_form.telefono.value=="" || nome_form.telefono.value==" ")
    {
    alert("Il campo telefono non è stato compilato");
    nome_form.telefono.focus();
    return false;
    }
    
  // PRIVACY
  ck_privacy = document.getElementById('privacy').checked;
  if(!(ck_privacy))
    {
    alert("Per proseguire è necessario fornire il consenso al trattamento dei dati. \n");
    return false;
    }
  //  controllo EMAIL (se c'è)
  if(nome_form.email.value!="")
    {
    re = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (!re.test(nome_form.email.value))
      {
      alert("ATTENZIONE! \n  E_MAIL non valida");
      nome_form.email.focus();
      return false;
      }
     }

  return true;
  }



