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 all of the required fields marked with an asterix.");
      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_surname");
    var sName = el.value;
    var el = document.getElementById("s_email");
    var uName = el.value;
    if (uName != ""){
      var url = "/includes/functions/check-email.php?e="+uName+"&s="+sName;
      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
    }
  }

 
 
function howManyChecked(whichForm, whichCheckBoxArray, title, myMin, myMax)
{
	var _countChecked = 0;
	var err = 0;
	for(i=0;i<document[whichForm][whichCheckBoxArray].length;i++)
	{
		if(document[whichForm][whichCheckBoxArray][i].checked==true)
			{ _countChecked++; }
	}
	if(_countChecked > myMax)
		{ alert('Please make sure you have only selected '+myMax+' extra feature(s) for this item.');
			err = 1;}
	else if(_countChecked < myMin)
		{ alert('Please select at least '+myMin+' extra feature(s) from the "'+title+'" list displayed.');
			err = 1;}
	if (err == 1) { return false; }
}