function validateFields(frm)
{
  var elements = frm.elements;
  var emailPattern = /^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/;
  var integerPattern = /(^-?\d\d*$)/;
  var currencyPattern = /-?[0-9]+\.[0-9]{2}$/;
  for (var i = 0; i < elements.length; i++)
  {
    if (/(^| )checkRequired( |$)/.test(elements[i].className) && elements[i].value == "")
    {
      elements[i].focus();
      alert("Please fill out this field.");
      return false;
    }
    
    if (/(^| )checkOther( |$)/.test(elements[i].className) && elements[i].value == "Other")
    {
      if (elements['other'].value == ""){
        elements['other'].focus();
        alert("Please enter a value in the 'If other please state' field.");
        return false;
      }
    }

    if (/(^| )checkEmail( |$)/.test(elements[i].className) && !emailPattern.test(elements[i].value))
    {
      elements[i].focus();
      alert("Please fill in a valid e-mail address.");
      return false;
    }
    
    if (/(^| )checkInteger( |$)/.test(elements[i].className) && !integerPattern.test(elements[i].value))
    {
      elements[i].focus();
      alert("Please enter a whole number value in this field.");
      return false;
    }
    
    if (/(^| )checkCurrency( |$)/.test(elements[i].className) && !currencyPattern.test(elements[i].value))
    {
      elements[i].focus();
      alert("Please enter a currency value eg 2.99.");
      return false;
    }
  }

  return true;
}
function checkEmail(){
    var el = document.getElementById("s_email");
    var uName = el.value;
    if (uName != ""){
      var url = "check_email.php?e="+uName;
      var xmlhttp=false; //Clear our fetching variable
      try {
        xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
      } catch (e) {
        try {
          xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
        } catch (E) {
          xmlhttp = false;
        }
      }
      if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
      }
      xmlhttp.open('GET', url, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
      xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
          var content = xmlhttp.responseText; //The content data which has been retrieved ***
          if (content == "Used"){
            alert("The email address "+uName+ " is currently being used by an existing account holder, please check you have typed in your email address correctly before continuing. If you already have an account please login by using the form at the top of this page. If this is your email address and you don't have an account please contact us for more information.");
            el.value = "";
            el.focus();
          }
        }
      }
      xmlhttp.send(null) //Nullify the XMLHttpRequest
    }
  }
