// validate.js - validates an comments form
// (c) James Gent 2003
	function ValidateForm()
	{
		// Submit the form as all fields are filled with
		// valid data
		
		// Check the txtName field has been filled in
		if (document.frmComments.txtName.value == "")
		{
			alert("Please fill in the Name field");
			document.frmComments.txtName.focus();
			return false;
		}
		
		// Check the txtEmail field has been filled in
		if (document.frmComments.txtEmail.value == "")
		{
			alert("Please fill in the Email field with a valid email address");
			document.frmComments.txtEmail.focus();
			return false;
		}
		// Check that there is an "@" in the email address
		// -1 means no "@" in the strng
		if (document.frmComments.txtEmail.value.indexOf("@") == -1)
		{
			alert("Please fill in the Email field with a valid email address");
			document.frmComments.txtEmail.focus();
			return false;
		}
		// Check the txtSubject field has been filled in
		if (document.frmComments.txtSubject.value == "")
		{
			alert("Please fill in the Subject field");
			document.frmComments.txtSubject.focus();
			return false;
		}
		// Check the txtComment field has been filled in
		if (document.frmComments.txtComment.value == "")
		{
			alert("Please fill in the Comments field");
			document.frmComments.txtComment.focus();
			return false;
		}
	
		// All data has been validated so post the form
		
		// First change all "=" signs and "&" signs to special markup to avoid
		// confusing the perl parser
		document.frmComments.txtName.value = 
			document.frmComments.txtName.value.replace("=", "[EQUALSSIGN]");
		document.frmComments.txtEmail.value = 
			document.frmComments.txtEmail.value.replace("=", "[EQUALSSIGN]");
		document.frmComments.txtSubject.value = 
			document.frmComments.txtSubject.value.replace("=", "[EQUALSSIGN]");
		document.frmComments.txtComment.value = 
			document.frmComments.txtComment.value.replace("=", "[EQUALSSIGN]");
		document.frmComments.txtName.value = 
			document.frmComments.txtName.value.replace("&", "[AMPERSAND]");
		document.frmComments.txtEmail.value = 
			document.frmComments.txtEmail.value.replace("&", "[AMPERSAND]");
		document.frmComments.txtSubject.value = 
			document.frmComments.txtSubject.value.replace("&", "[AMPERSAND]");
		document.frmComments.txtComment.value = 
			document.frmComments.txtComment.value.replace("&", "[AMPERSAND]");
		
		frmComments.submit();

		document.frmComments.txtName.value = 
			document.frmComments.txtName.value.replace("[EQUALSSIGN]", "=");
		document.frmComments.txtEmail.value = 
			document.frmComments.txtEmail.value.replace("[EQUALSSIGN]", "=");
		document.frmComments.txtSubject.value = 
			document.frmComments.txtSubject.value.replace("[EQUALSSIGN]", "=");
		document.frmComments.txtComment.value = 
			document.frmComments.txtComment.value.replace("[EQUALSSIGN]", "=");
		document.frmComments.txtName.value = 
			document.frmComments.txtName.value.replace("[AMPERSAND]", "&");
		document.frmComments.txtEmail.value = 
			document.frmComments.txtEmail.value.replace("[AMPERSAND]", "&");
		document.frmComments.txtSubject.value = 
			document.frmComments.txtSubject.value.replace("[AMPERSAND]", "&");
		document.frmComments.txtComment.value = 
			document.frmComments.txtComment.value.replace("[AMPERSAND]", "&");
		
		// Set the hidden hidValidated field to true to show
		// the form has been validated
		document.frmComments.hidValidated.value = 1;
		
		return true;
	} // EoFN ValidateForm