/***********************************************************************
 * Routines to validate contact form input.
 *
 * Copyright (c) 2004 TOLRA Micro Systems Limited. All rights reserved.
 **********************************************************************/

function fxGetObject(obj) {
	var theObj;
	if(typeof obj == "string") {
		if(document.getElementById != null) { 
			theObj = document.getElementById(obj);
		} else if(document.all != null) {
			theObj = document.all(obj);
		}
	} else {
		theObj = obj;
	}
	return theObj;
}

function validateForm() {
	var frm = fxGetObject("contact");
	if(!frm) {
		return false;
	}

	// Make sure name supplied
	if(!frm.elements["name"].value) {
		alert("You must supply a name!");
		return false;
	}
	
	// Validate email
	var email = frm.elements["email"].value;
	if(!email || (email.indexOf("@") == -1) || (email.indexOf(".") == -1)) {
		alert("You must supply a valid email address!");
		return false;
	}
	
	// Make sure message supplied
	if(!frm.elements["enquiry"].value) {
		alert("You must supply enquiry text!");
		return false;
	}

	// Submit the form
	return true;
}
