  var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
  var checkOK = "0123456789-";
  var checkStr
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";

function Valida(theForm){

  if (theForm.nome.value == ""){
    alert("Enter a value for the field \"Full Name of Applicant\".");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.nome.value.length < 1){
    alert("Insert at least 1 character in \"Full Name of Applicant\".");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.nome.value.length > 150)
  {
    alert("Insert a maximum 150 characters in \"Full Name of Applicant\".");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.Indir.value == "")
  {
    alert("Enter a value for the field \"Address\".");
    theForm.Indir.focus();
    return (false);
  }

  if (theForm.Indir.value.length < 1)
  {
    alert("Insert at least 1 character in \"Address\".");
    theForm.Indir.focus();
    return (false);
  }

  if (theForm.Indir.value.length > 100)
  {
    alert("Insert a maximum 100 characters in \"Address\".");
    theForm.Indir.focus();
    return (false);
  }

  if (theForm.Loc.value == "")
  {
    alert("Enter a value for the field \"City\".");
    theForm.Loc.focus();
    return (false);
  }

  if (theForm.Loc.value.length < 1)
  {
    alert("Insert at least 1 character in \"City\".");
    theForm.Loc.focus();
    return (false);
  }

  if (theForm.Loc.value.length > 100)
  {
    alert("Insert a maximum 100 characters in \"Località\".");
    theForm.Loc.focus();
    return (false);
  }

  if (theForm.Tel.value == "")
  {
    alert("Enter a value for the field \"Phone\".");
    theForm.Tel.focus();
    return (false);
  }

  if (theForm.Tel.value.length < 1)
  {
    alert("Insert at least 1 character in \"Phone\".");
    theForm.Tel.focus();
    return (false);
  }

  if (theForm.Tel.value.length > 50)
  {
    alert("Insert a maximum 50 characters in \"Phone\".");
    theForm.Tel.focus();
    return (false);
  }

  checkStr = theForm.Tel.value;
  allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Enter only numbers in \"Phone\".");
    theForm.Tel.focus();
    return (false);
  }  

  if (theForm.Mail.value == "")
  {
    alert("Enter a value for the field \"E-Mail\".");
    theForm.Mail.focus();
    return (false);
  }else{
	var returnval=emailfilter.test(theForm.Mail.value)
	if (returnval==false){
		alert("Please enter an address valid E-Mail!")
		theForm.Mail.focus()
		return (false);
	}
  }

  if (theForm.Mail.value.length < 1)
  {
    alert("Insert at least 1 character in \"E-Mail\".");
    theForm.Mail.focus();
    return (false);
  }

  if (theForm.Mail.value.length > 50)
  {
    alert("Insert a maximum 50 characters in \"E-Mail\".");
    theForm.Mail.focus();
    return (false);
  }
  
  if (theForm.NPers.value.length > 3)
  {
    alert("Insert a maximum 3 characters in \"Number of people in the group\".");
    theForm.npers.focus();
    return (false);
  }

  checkStr = theForm.npers.value;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Enter only numbers in \"Number of people in the group\".");
    theForm.npers.focus();
    return (false);
  }

  if (theForm.Ling.selectedIndex < 0)
  {
    alert("Select one of the options \"Spoken language\".");
    theForm.Ling.focus();
    return (false);
  }
  
  if (theForm.data.value == "")
  {
    alert("Enter a value for the field \"Book for the day\".");
    theForm.data.focus();
    return (false);
  }else{
    var di=theForm.data.value;
    var df="dd/mm/yyyy"
    var y4=df.search(/yyyy/i), y=di.substring(y4, y4+4)-0;
    var m2=df.search(/mm/i), m=di.substring(m2, m2+2)-1;
    var d2=df.search(/dd/i), d=di.substring(d2, d2+2)-0;
    var dd=new Date(y, m, d);
    if (y==dd.getFullYear() && m==dd.getMonth() && d==dd.getDate()) {
    }else {
	    alert("Enter a valid date in \"Book for the day\".");
	    theForm.data.focus();
	    return (false);
    }
  }

  if (theForm.data.value.length < 1)
  {
    alert("Insert at least 1 character in \"Book for the day\".");
    theForm.data.focus();
    return (false);
  }

  if (theForm.data.value.length > 10)
  {
    alert("Insert a maximum 10 characters in \"Book for the day\".");
    theForm.data.focus();
    return (false);
  } 
  
  if (theForm.Msg.value.length > 200)
  {
    alert("Insert a maximum 200 characters in \"Message\".");
    theForm.Msg.focus();
    return (false);  
  }

  if (theForm.Cons[1].checked){
  	alert('Without permission to the processing of personal data we can not receive data!')
  	theForm.Cons[1].focus();
  	return (false)
  }
  return (true);
}

function ValidaMod(theForm){

  if (theForm.nome.value == ""){
    alert("Enter a value for the field \"Full Name of Applicant\".");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.nome.value.length < 1){
    alert("Insert at least 1 character in \"Full Name of Applicant\".");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.nome.value.length > 150)
  {
    alert("Insert a maximum 150 characters in \"Full Name of Applicant\".");
    theForm.nome.focus();
    return (false);
  }

  if (theForm.Indir.value == "")
  {
    alert("Enter a value for the field \"Address\".");
    theForm.Indir.focus();
    return (false);
  }

  if (theForm.Indir.value.length < 1)
  {
    alert("Insert at least 1 character in \"Address\".");
    theForm.Indir.focus();
    return (false);
  }

  if (theForm.Indir.value.length > 100)
  {
    alert("Insert a maximum 100 characters in \"Address\".");
    theForm.Indir.focus();
    return (false);
  }

  if (theForm.Loc.value == "")
  {
    alert("Inserire un valore per il campo \"Località\".");
    theForm.Loc.focus();
    return (false);
  }

  if (theForm.Loc.value.length < 1)
  {
    alert("Insert at least 1 character in \"City\".");
    theForm.Loc.focus();
    return (false);
  }

  if (theForm.Loc.value.length > 100)
  {
    alert("Insert a maximum 100 characters in \"Località\".");
    theForm.Loc.focus();
    return (false);
  }

  if (theForm.Tel.value == "")
  {
    alert("Enter a value for the field \"Phone\".");
    theForm.Tel.focus();
    return (false);
  }

  if (theForm.Tel.value.length < 1)
  {
    alert("Insert at least 1 character in \"Phone\".");
    theForm.Tel.focus();
    return (false);
  }

  if (theForm.Tel.value.length > 50)
  {
    alert("Insert a maximum 50 characters in \"Phone\".");
    theForm.Tel.focus();
    return (false);
  }

  checkStr = theForm.Tel.value;
  allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Enter only numbers in \"Phone\".");
    theForm.Tel.focus();
    return (false);
  }

  if (theForm.Mail.value == "")
  {
    alert("Enter a value for the field \"E-Mail\".");
    theForm.Mail.focus();
    return (false);
  }else{
	var returnval=emailfilter.test(theForm.Mail.value)
	if (returnval==false){
		alert("Please enter an address valid E-Mail!")
		theForm.Mail.focus()
		return (false);
	}
  }

  if (theForm.Mail.value.length < 1)
  {
    alert("Insert at least 1 character in \"E-Mail\".");
    theForm.Mail.focus();
    return (false);
  }

  if (theForm.Mail.value.length > 50)
  {
    alert("Insert a maximum 50 characters in \"E-Mail\".");
    theForm.Mail.focus();
    return (false);
  }
  
  if (theForm.NPers.value.length > 3)
  {
    alert("Insert a maximum 3 characters in \"Number of people in the group\".");
    theForm.npers.focus();
    return (false);
  }

  checkStr = theForm.npers.value;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Enter only numbers in \"Number of people in the group\".");
    theForm.npers.focus();
    return (false);
  }

  if (theForm.Ling.selectedIndex < 0)
  {
    alert("Select one of the options \"Spoken language\".");
    theForm.Ling.focus();
    return (false);
  }
  
  if (theForm.data.value == "")
  {
    alert("Enter a value for the field \"Book for the day\".");
    theForm.data.focus();
    return (false);
  }else{
    var di=theForm.data.value;
    var df="dd/mm/yyyy"
    var y4=df.search(/yyyy/i), y=di.substring(y4, y4+4)-0;
    var m2=df.search(/mm/i), m=di.substring(m2, m2+2)-1;
    var d2=df.search(/dd/i), d=di.substring(d2, d2+2)-0;
    var dd=new Date(y, m, d);
    if (y==dd.getFullYear() && m==dd.getMonth() && d==dd.getDate()) {
    }else {
	    alert("Enter a valid date in \"Book for the day\".");
	    theForm.data.focus();
	    return (false);
    }
  }

  if (theForm.data.value.length < 1)
  {
    alert("Insert at least 1 character in \"Book for the day\".");
    theForm.data.focus();
    return (false);
  }

  if (theForm.data.value.length > 10)
  {
    alert("Insert a maximum 10 characters in \"Book for the day\".");
    theForm.data.focus();
    return (false);
  } 
  
  if (theForm.Msg.value.length > 200)
  {
    alert("Insert a maximum 200 characters in \"Message\".");
    theForm.Msg.focus();
    return (false);  
  }

  if (theForm.DataMailConferma.value != "")
  {
    var di=theForm.DataMailConferma.value;
    var df="dd/mm/yyyy"
    var y4=df.search(/yyyy/i), y=di.substring(y4, y4+4)-0;
    var m2=df.search(/mm/i), m=di.substring(m2, m2+2)-1;
    var d2=df.search(/dd/i), d=di.substring(d2, d2+2)-0;
    var dd=new Date(y, m, d);
    if (y==dd.getFullYear() && m==dd.getMonth() && d==dd.getDate()) {
    }else {
	    alert("Inserire una data valida nel campo \"Data di invio Mail\".");
	    theForm.DataMailConferma.focus();
	    return (false);
    }
  }

  if (theForm.DataMailConferma.value.length > 10)
  {
    alert("Inserire al massimo 10 caratteri nel campo \"Data di invio Mail\".");
    theForm.DataMailConferma.focus();
    return (false);
  }
  
  if (theForm.DataEsecuzione.value != "")
  {
    var di=theForm.DataEsecuzione.value;
    var df="dd/mm/yyyy"
    var y4=df.search(/yyyy/i), y=di.substring(y4, y4+4)-0;
    var m2=df.search(/mm/i), m=di.substring(m2, m2+2)-1;
    var d2=df.search(/dd/i), d=di.substring(d2, d2+2)-0;
    var dd=new Date(y, m, d);
    if (y==dd.getFullYear() && m==dd.getMonth() && d==dd.getDate()) {
    }else {
	    alert("Inserire una data valida nel campo \"Visita eseguita in data\".");
	    theForm.DataEsecuzione.focus();
	    return (false);
    }
  }

  if (theForm.DataEsecuzione.value.length > 10)
  {
    alert("Inserire al massimo 10 caratteri nel campo \"Visita eseguita in data\".");
    theForm.DataEsecuzione.focus();
    return (false);
  } 

  if (theForm.DataAnnullamento.value != "")
  {
    var di=theForm.DataAnnullamento.value;
    var df="dd/mm/yyyy"
    var y4=df.search(/yyyy/i), y=di.substring(y4, y4+4)-0;
    var m2=df.search(/mm/i), m=di.substring(m2, m2+2)-1;
    var d2=df.search(/dd/i), d=di.substring(d2, d2+2)-0;
    var dd=new Date(y, m, d);
    if (y==dd.getFullYear() && m==dd.getMonth() && d==dd.getDate()) {
    }else {
	    alert("Inserire una data valida nel campo \"Visita Annullata in data\".");
	    theForm.DataAnnullamento.focus();
	    return (false);
    }
  }

  if (theForm.DataAnnullamento.value.length > 10)
  {
    alert("Inserire al massimo 10 caratteri nel campo \"Visita Annullata in data\".");
    theForm.DataAnnullamento.focus();
    return (false);
  } 

  if (theForm.DataEsecuzione.value != "" && theForm.DataAnnullamento.value != ""){
    alert("Attenzione!"+String.fromCharCode(10)+"Non potete Annullare una vista eseguita."+String.fromCharCode(10)+"Operazione cancellata.");
    theForm.DataAnnullamento.focus();
    return (false);
  }

  return (true);
}

function btnAnn(){
var strURL = "http://www.cedomis-scalabriniane.org/en/visite/default.asp";
document.forms[0].action=strURL;
document.forms[0].submit();
}

function contaMsg(){
  var nMsg = document.forms[0].Msg.value.length;
  cntCar.innerText=nMsg;
  if (nMsg > 200){
    cntCar.style.color="#FF0000"
  }else{
    cntCar.style.color="#000000"
  }
}