/* Javascript for Contact Form */

function validateForm() {
	//Validate the form
	
	//Compose the array of elements to pass to the form checker
	var els=Array('name','telemail','enquiry');
	
	//Get objects
	objTelephone=document.getElementById('telephone');
	objEmail=document.getElementById('email');
	objTelEmail=document.getElementById('telemail');
	
	if (objTelephone && objEmail) {
		//Set the combined telephone/email field
		if (objEmail.value) {
			objTelEmail.value=objEmail.value;
		} else {
			objTelEmail.value=objTelephone.value;
		}
		
		//Check the form
		var theResult=checkForm(els);
		if (theResult) {
			//We have a result - that means an error
			alert("You must complete the following fields:\n\n"+theResult);	
			return false;
		} else if (!isValidEmail(objEmail.value) && objEmail.value) {
			//Invalid e-mail address
			alert("You must supply a valid e-mail address!");
			return false;
		} else {
			//OK
			return true;
		}
	} else {
		//Oops
		alert("Unfortunately your browser does not support this contact form.");
		return false;
		
	}
}
