function checkSampleForm(){
	
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var enquiry = document.getElementById('enquiry');
	var enquiry_type = document.forms["SampleForm"]["enquiry_type"];
		
	if (alphaNumField(name, "name.")) {
		if (emailField(email, "email address.")) {
			if (radioButtons(enquiry_type, "Please provide the nature of your enquiry (joining, your membership, something else)")) {
				if (textArea(enquiry, "Please enter the nature of your enquiry.")) {
					return true;
				}
			}
		}
	}
	return false;
}
		
// function for checking alpha-only text fields
function alphaField(element, fieldDesc) {
	var alphaExp = /^[-a-zA-Z ']+$/;
	if (element.value.length < 2) {
		var shortStub = 'Please enter your ';
		alert(shortStub + fieldDesc);
		element.focus(); // set the focus to this input
		return false;
	} else if ((element.value.length > 1) && (!element.value.match(alphaExp))) {
		var wrongStub = 'Please enter only letters for your ';
		alert(wrongStub + fieldDesc);
		element.focus();
		return false;
	} else {
		return true;
	}
}
	
// function for checking alphanumeric text fields
function alphaNumField(element, fieldDesc) {
	var alphaNumExp = /^[-0-9a-zA-Z' /]+$/;
	if (element.value.length < 2) {
		var shortStub = 'Please enter your ';
		alert(shortStub + fieldDesc);
		element.focus(); // set the focus to this input
		return false;
	} else if ((element.value.length > 1) && (!element.value.match(alphaNumExp))) {
		var wrongStub = 'Please enter only letters and numbers for your ';
		alert(wrongStub + fieldDesc);
		element.focus();
		return false;
	} else {
		return true;
	}
}
	
// function for checking post and zip code fields (needs letters for uk and nz)
function postCodeField(element, fieldDesc) {
	var alphaNumExp = /^[0-9a-zA-Z]+$/;
	if (element.value.length < 4) {
		var shortStub = 'Please enter your ';
		alert(shortStub + fieldDesc);
		element.focus(); // set the focus to this input
		return false;
	} else if ((element.value.length > 1) && (!element.value.match(alphaNumExp))) {
		var wrongStub = 'Please enter only letters and numbers for your ';
		alert(wrongStub + fieldDesc);
		element.focus();
		return false;
	} else {
		return true;
	}
}
	
// function for checking  telephone number fields. we allow numbers and spaces.
function PhoneField(element, fieldDesc) {
	var NumExp = /^[- 0-9]+$/;
	if (element.value.length < 7) {
		var shortStub = 'Please enter your ';
		alert(shortStub + fieldDesc);
		element.focus(); // set the focus to this input
		return false;
	} else if ((element.value.length > 1) && (!element.value.match(NumExp))) {
		var wrongStub = 'Please enter only numbers for your ';
		alert(wrongStub + fieldDesc);
		element.focus();
		return false;
	} else {
		return true;
	}
}

// function for quickly checking email format (check again on server side)	
function emailField(element, fieldDesc){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if (element.value.length < 6) {
		var shortStub = 'Please enter your ';
		alert(shortStub + fieldDesc);
		element.focus(); // set the focus to this input
		return false;
	} else if (element.value.match(emailExp)) {
		return true;
	} else {
		var wrongStub = 'Please check the format of your ';
		alert(wrongStub + fieldDesc);
		element.focus();
		return false;
	}
}

// function for checking text areas
function textArea(element, message){
	if (element.value.length < 10) {
		alert(message);
		element.focus();
		return false;
	} else {
		return true;
	}
}

// function for checking radio buttons for one select
function radioButtons(element, message){
	var picked = 0;
	for (var i=0; i < element.length; i++) {
		if (element[i].checked == true) {
			picked = picked+1;
			break;
		}
	}
	if (picked < 1) {
		alert(message);
		return false;
	} else {
		return true;
	}
}
