function validate() {

	var email = document.getElementById("email");
	var condition = document.getElementById("condition");
	var dob = document.getElementById("dob");
	var nonuk = document.getElementById("nonUK");
	var name = document.getElementById("enquirername");
	var telephone = document.getElementById("enquirerphone");
	var address = document.getElementById("enquireraddress");
	var enquiry = document.getElementById("enquiry");


	// Check for non empty email field
	if(email.value.length == 0) {
		alert("Please enter an email address");
		return false;
	}

	// Check for valid email address
	var reEmail = new RegExp(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/);
  	if(reEmail.test(email.value) == false) {
		alert("Please enter a valid email address");
		return false;
	}

	// Check the condition for non-alphanumeric characters, allowing white space and amphersands
	// This would prevent any code being executed within the fields
   var reNonalpha = new RegExp(/[^\w\/\&\s\']+/);
   if (reNonalpha.test(condition.value)) {
      alert("The condition must contain alphanumeric characters, spaces or amphersands only");
      return false;
   }

	// Check the date of birth for any characters other than numbers and hyphens
	// This would prevent any code being executed within the field
	var reNonalpha = new RegExp(/[^\d\-]+/);
	if (reNonalpha.test(dob.value)) {
		alert("The date of birth must contain digits and hypens only");
		return false;
	}

	// Check the nonUK for non-alphanumeric characters, allowing white space, hypens and amphersands
	// This would prevent any code being executed within the fields
   var reNonalpha = new RegExp(/[^\w\/\-\&\s]+/);
   if (reNonalpha.test(nonuk.value)) {
      alert("The country outside of the UK must contain alphanumeric characters, spaces, hypens or amphersands only");
      return false;
   }

	// Check the name for letters, allowing white space, hypens and amphersands
	// This would prevent any code being executed within the fields
   var reNonalpha = new RegExp(/[^\w\/\-\&\s]+/);
   if (reNonalpha.test(name.value)) {
      alert("The name must contain alphanumeric characters, spaces, hypens or amphersands only");
      return false;
   }
	
	// Check the telephone number for any characters besides digits and spaces
	// This would prevent any code being executed within the fields
   var reNonalpha = new RegExp(/[^\d\s\-]+/);
   if (reNonalpha.test(telephone.value)) {
      alert("The telephone number must contain numbers, spaces or hyphens only");
      return false;
   }

	// Check the address for any characters besides alphanumeric characters, spaces, hyphens, amphersands, commas and full stops. 
	// This would prevent any code being executed within the fields
   var reNonalpha = new RegExp(/[^\w\&\-\.\,\s\']+/);
   if (reNonalpha.test(address.value)) {
      alert("The address must contain alphanumeric characters, full stops, commas, spaces, amphersands or hyphens only");
      return false;
   }
   if (reNonalpha.test(enquiry.value)) {
      alert("The enquiry must contain alphanumeric characters, full stops, commas, spaces, amphersands or hyphens only");
      return false;
   }

	return true;

}

function submitForm() {
	if(validate()) {	
	   var obj = createObject('query');
   	obj.submit();
	}	
}

function resetForm() {
   var obj = createObject('query');
   obj.reset();
}


