	// Validation functions to check user input

	// Check whether a string is empty
	function isEmpty(s)
	{
		return( (s == null) || (s.length == 0) )
	}

	// Check email address validity
	function isEmailAddr(email)
	{
		var check = /^.+@.+\..{2,4}$/;

		if ( check.test(email) )
			return true;
		else
			return false;
	}

	// Validate the form values
	function FormValidator(theForm)
	{
		var errMsg = "";

		var commentsStr = theForm.comments.value;
		commentsStr = commentsStr.replace(/^\s+/,''); //Trim white spaces
		if ( isEmpty(commentsStr) )
		{
			errMsg = " - enter Comments\n" + errMsg;
			theForm.comments.focus();
		}

//		if ( theForm.product_name.selectedIndex == 0 )
//		{
//			errMsg = " - select a Product\n" + errMsg;
//			theForm.product_name.focus();
//		}

		if ( theForm.subject.selectedIndex == 0 )
		{
			errMsg = " - select a Subject\n" + errMsg;
			theForm.subject.focus();
		}

		var emailAddr = theForm.email_address.value;
		if ( (isEmpty(emailAddr)) || (!isEmailAddr(emailAddr)) )
		{
			errMsg = " - enter a valid Email Address\n" + errMsg;
			theForm.email_address.focus();
		}
		else if ( (emailAddr.indexOf('|')>-1) || (emailAddr.indexOf('~')>-1) || (emailAddr.indexOf('!')>-1) )
		{
				errMsg = " - invalid character in Email Address\n" + errMsg;
				theForm.email_address.focus();
		}

		var lastName = theForm.last_name.value;
		if ( isEmpty(lastName) )
		{
			errMsg = " - enter Last Name\n" + errMsg;
			theForm.last_name.focus();
		}
		else if ( (lastName.indexOf('|')>-1) || (lastName.indexOf('~')>-1) || (lastName.indexOf('!')>-1) )
		{
			errMsg = " - invalid character in Last Name\n" + errMsg;
			theForm.last_name.focus();
		}

		var firstName = theForm.first_name.value;
		if ( isEmpty(theForm.first_name.value) )
		{
			errMsg = " - enter First Name\n" + errMsg;
			theForm.first_name.focus();
		}
		else if ( (firstName.indexOf('|')>-1) || (firstName.indexOf('~')>-1) || (firstName.indexOf('!')>-1) )
		{
			errMsg = " - invalid character in First Name\n" + errMsg;
			theForm.first_name.focus();
		}


		if ( isEmpty(errMsg) )
		{
			return true;
		}
		else
		{
			errMsg = "Please correct the following error(s): \n" + errMsg;
			alert( errMsg );
			return false;
		}
	}

