function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_requiredOneOfTwo(field,field2,alerttxt)
{
  if ((field.value==null||field.value=="")&&(field2.value==null||field2.value==""))
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
}

function validate_requiredOneOfThreeChecked(field,field2,field3,alerttxt)
{
  if (field.checked==false&&field2.checked==false&&field3.checked==false)
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
}

function validate_requiredChecked(field, alerttxt)
{
  if (field.checked==false)
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(Name,"Please fill in the 'Name' box")==false)
  {Name.focus();return false;}
  if (validate_required(Address,"Please fill in the 'Address' box")==false)
  {Address.focus();return false;}
  if (validate_required(Email,"Please fill in the 'Email' box")==false)
  {Email.focus();return false;}
  if (validate_email(Email,"Please supply a valid email address")==false)
    {Email.focus();return false;}
  if (validate_requiredOneOfTwo(HomeTelephone, MobileTelephone, "Please supply at least one telephone number")==false)
    {HomeTelephone.focus();return false;}
  if (validate_requiredOneOfThreeChecked(LilacCottage, OakTreeBarn, TheStables, "Please tick at least one property")==false)
    {LilacCottage.focus();return false;}
  if (validate_required(DateFrom,"Please fill in the 'Date from' box")==false)
  {DateFrom.focus();return false;}
  if (validate_required(DateTo,"Please fill in the 'Date to' box")==false)
  {DateTo.focus();return false;}
  if (validate_requiredChecked(ConditionsAccepted,"Please tick the box at the bottom of the form to accept the Terms and Conditions")==false)
  {ConditionsAccepted.focus();return false;}
  alert("Thank you.\n\nWhen you click 'OK', your form will be submitted to\nEdward and Sue Clark at Les Chênes Gîtes.\n\nA summary of the information which you have supplied will be sent to you by email shortly at your email address\n"+Email.value+"\n\nShould you not receive that email, please contact us as soon as possible.")
  }
}

