//	Javascript Document
//	validateForm.jp
//	Checks that required form fields have been completed correctly
//	Date Created: 2 Nov 2005
//	Author:	Kris McDougall kris@decorate.com.au

//alert("validate form");

var errorMessage; //	prints out error message if form has not been completed correctly
var submitform;		//	specifies whether or not the form should be submitted.

/*	Function checkform()
	Checks that the user has completed all mandatory fields
	If all mandatory fields have not been completed - pop up alert message will appear
	Date Created: 2 Nov 2005
		Author: Kris McDougall kris@decorate.com.au
*/

function checkform()
{	
	errorMessage = "Error:  \n";	
	submitform = true;
	validateTextField(document.forms[0].name.value, 'name');
	validateTextField(document.forms[0].phone.value, 'phone');
	validateTextField(document.forms[0].email.value, 'email');

	if(submitform == false){
		alert(errorMessage);
	}
	if(submitform == true){
		document.forms[0].submit();
	}
}


/* 	function validateTextField('textField', 'fieldName')
	Parameters:	textField - value of input text field
				fieldName -	name of the field this name will be printed in the error message
	Checks to make sure the user has entered information in the field
	If no information has been entered, the submit form variable is set to false and error message is set.
	Date Created:	2 Nov 2005
	Author:	Kris McDougall kris@decorate.com.au
*/

function validateTextField(textField, fieldName)
{
	if(textField == ""){
		submitform = false;
		errorMessage += fieldName + " must be completed\n";
	}
}

/* 	function validateSelectList('selectList', 'fieldName')
	Parameters: selectList - value of select list
				fieldName - name of field this name will be printed in the error message
	Checkes to make sure the user has selected an option from the select list
	If no selection has been made, the submitform variable is set to false and an error message is displayed
	Date Created: 2 Nov 2005
	Author: Kris McDougall@decorate.com.au
*/

function validateSelectList(selectList, fieldName)
{
		if(selectList.selectedIndex == 0){
			submitform = false;
			errorMessage +=  fieldName + " must be selected\n";
		}
}