function isEmail (s)
{     
    // is s whitespace?
    // if (ContainsWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function Form_Validator(theForm)
{
//  if (theForm.Media.value=="0") { alert("How did you find out about this website?"); theForm.Media.focus();  return (false);  }
  
  if (theForm.Title.value=="not specified")  { alert("Please select your title, Mr, Mrs etc"); theForm.Title.focus();  return (false);  }
  if (theForm.FirstName.value=="")  { alert("Please enter your first name"); theForm.FirstName.focus();  return (false);  }
  if (theForm.Surname.value=="")  { alert("Please enter your surname"); theForm.Surname.focus();  return (false);  }
//  if (theForm.HouseNumber.value=="")  { alert("Please enter your house/flat number"); theForm.HouseNumber.focus();  return (false);  }
//  if (theForm.PostCode.value=="")  { alert("Please enter your post code"); theForm.PostCode.focus();  return (false);  }
  if  (theForm.Email.value=="" || (!isEmail(theForm.Email.value)) )
  {
    alert("Please enter a valid email address");
    theForm.Email.focus();
    return (false);
  } 
//  if ((theForm.DaytimePhone.value=="")  && (theForm.MobilePhone.value==""))  { alert("Please enter a phone number so that we can contact you"); theForm.DaytimePhone.focus();  return (false);  }

 // if ((theForm.DaytimePhone.value!="") && (theForm.DaytimePhone.value.length<7)) { alert("Please don't forget to enter the area code of your phone number so that we can contact you"); theForm.DaytimePhone.focus();  return (false);  }
 // if ((theForm.MobilePhone.value!="") && (theForm.MobilePhone.value.length<7)) { alert("Please make sure you have entered all the digits of your phone number so that we can contact you"); theForm.MobilePhone.focus();  return (false);  }


//  if ((theForm.BranchID.value=="0")) { alert("Please select a branch"); theForm.BranchID.focus(); return(false); }
  if ((theForm.EmailList.checked==false) &&	(theForm.MailingList.checked==false) && (theForm.OptOut.checked==false)) { alert("Please select your mailing preference - if you prefer not to be contacted with future promotional mailings please tick the opt-out box"); theForm.EmailList.focus(); return(false); }

    return (true);
}
