// JavaScript Document

  function FormValidator(theForm)
  {	  
	if (theForm.name.value == "" || theForm.name.value == "Name") 
    {
      alert("Please provide your name.");
      theForm.name.focus();
      return (false);
    }      
    if ((theForm.telephone.value == "" || theForm.telephone.value == "Telephone") && (theForm.email.value == "" || theForm.email.value == "Email") ) 
    { 
	  alert("Please provide at least one method for us to contact you by.");
      theForm.name.focus();
	  return (false);
    }
    else 
	{
	  if(theForm.email.value != "" && theForm.email.value != "Email"){
		if(check_email(theForm.email.value)==false){
		  return(false);
		}
	  }
	  if(theForm.telephone.value != "" && theForm.telephone.value != "Telephone"){
		if(check_tel(theForm.telephone.value)==false){
		  return(false);
		}
	  }
    }
    if (theForm.captcha.value == "" || theForm.captcha.value == "Enter code above") 
    {
      alert("Please enter the validation code.");
      theForm.captcha.focus();
      return (false);
    }
	else
    {
	  return(true);
	}

  }
  
  
  function QuestionnaireValidator(theForm)
  {	  
	if (theForm.name.value == "") 
    {
      alert("Please provide your name.");
      theForm.name.focus();
      return (false);
    }      
    if ((theForm.telephone_day.value == "") && (theForm.telephone_evening.value == "") && (theForm.email.value == "") ) 
    { 
	  alert("Please provide at least one method for us to contact you by.");
      theForm.name.focus();
	  return (false);
    }
    else 
	{
	  if(theForm.email.value != ""){
		if(check_email(theForm.email.value)==false){
		  return(false);
		}
	  }
	  if(theForm.telephone_day.value != ""){
		if(check_tel(theForm.telephone_day.value)==false){
		  return(false);
		}
	  }
	  if(theForm.telephone_evening.value != ""){
		if(check_tel(theForm.telephone_evening.value)==false){
		  return(false);
		}
	  }
    }
    if (theForm.captcha.value == "") 
    {
      alert("Please enter the validation code.");
      theForm.captcha.focus();
      return (false);
    }
	else
    {
	  return(true);
	}

  }
  
  
  
  
  function check_tel(tel){
	var checkOK = "0123456789 ";
	var checkStr = arguments[0];
	var allValid = true;
	for (i = 0;  i < tel.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;
	  }
	}
	if (!allValid)
	{
	  alert("You seem to have entered an invalid character in your telephone number");
	  return (false);
	}
  }

  function check_email(email){
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
	var checkStr = arguments[0];
	var 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;
	  }
	}
	if (!allValid)
	{
	  alert("You seem to have entered an invalid character in your email address");
	  return (false);
	}
	if ((checkStr.indexOf ('@',0) == -1 ||
	checkStr.indexOf ('.',0) == -1) &&
	checkStr != "")
	{
	  alert("The email address you have entered is not a valid email address");
	  return (false);
	} 
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(checkStr))) { 
	  alert("The email address you have entered is not a valid email address");
	  return (false);
	}
  }


