/***********************************************************************
 * 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 title is set
	if(frm.elements["name_title"].value == "other" && !frm.elements["name_titleother"].value) {
		alert("You must supply a title!");
		return false;
	}
	
	// Make sure last name supplied
	if(!frm.elements["name_last"].value) {
		alert("You must supply a last 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;
}
