function validateField(theField, errorMessage)
{
	with (theField)
	{
		if (value==null||value=="")
		{
			alert(errorMessage);
			return false;
		}
		else
		{
			return true;
		}
	}
}

function validateEmail(theEmail, errorMessage)
{
	with (theEmail)
	{
		var atPosition = value.indexOf("@");
		var periodPosition = value.lastIndexOf(".");
		var emailLength = value.length;
		if (atPosition < 1 || periodPosition - atPosition < 2 || emailLength < 5)
		{
			alert(errorMessage);
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function validateForm(theForm)
{
	with (theForm)
	{
		var allValid = true;
		allValid = allValid && validateField(firstName, "You must enter your first name.");
		allValid = allValid && validateField(emailAddress, "You must enter an email address.");
		allValid = allValid && validateField(message, "You must enter a message.");
		allValid = allValid  && validateEmail(emailAddress, "Your email address is incorrect");
		return allValid;
	}
}