/*	
	validateform.js
	contains all validation functions for all form fields
	date created: 16 July 2005
	author ari rizos webology www.webology.net.au
*/

/*	GLOBAL VARIABLES */
var submitform;
var errormessage;

/*	
	function validatetextfield(textfield, textfieldname)
	checks to make sure that the text field contains information
	parameters:		textfield - form field
					textfieldname - name of form field
	author ari rizos www.webology.net.au info@webology.net.au
*/

function validatetextfield(textfield, textfieldname)
{
	if(textfield.value == "" || textfield.value == "PLEASE COMPLETE"){
			textfield.value = "PLEASE COMPLETE";
			submitform = false;
			errormessage += textfieldname + " must be completed\n";
	}
}

/*
	function verification(textfieldOne, textfieldTwo)
	compares the values of two form fields and checks that the values are the same
	if not the same sets the submit value to false and adds an errormessage
	parameters		textfieldOne	first form field
					textfieldTwo	second form field
					textfieldname	name of the form field
	author			ari rizos www.webology.net.au info@webology.net.au
*/

function verification(textfieldOne, textfieldTwo, textfieldname){
	if(textfieldOne.value != textfieldTwo.value){
		submitform = false;
		errormessage += textfieldname + " do not match\n";
	}		
}	

/*	function validateselectlist(textfield, texfieldname)
	checks to make sure that the user has selected an option from the select list
*/
function validateselectlist(textfield, textfieldname)
{
	if(textfield.selectedIndex == 0){
		submitform = false;
		errormessage += textfieldname + " must be selected\n";
	}
}

/*	checks that all mandatory fields have been completed before
	submitting
	date created: 20 September 2005
	author: ari rizos info@webology.net.au www.webology.net.au
*/



function checkForm()
{
	errormessage = "Error: \n";
	submitform = true;
	validatetextfield(document.forms[0].realname, "Name");
	validatetextfield(document.forms[0].address, "Address");
	validatetextfield(document.forms[0].phone, "Phone");
	validatetextfield(document.forms[0].email, "Email");
	validateselectlist(document.forms[0].interest, "Interest");
	
	if(submitform == false){
		alert(errormessage);
	}
	if(submitform == true){
		document.forms[0].submit();
	}
}