//JavaScript

var whitespace = " \t\n\r";

function isEmpty(theField)
{
	// Check for nothing entered
	if ((theField == null || theField.length == 0))
		return true;
}
function hasWhitespace(theField)
{
	var x;
	// check that there are non-white space characters entered.
	for (x=0; x<theField.length; x++)
	{
		var y = theField.charAt(x);
		if (whitespace.indexOf(y) == -1)
			return false;
	}
	// if we get here we must have white space
	return true;
}
function emailCheck(emailAsEntered)
{
	var atSymbol = "@";
	var dot = ".";
	for (z=0; z<emailAsEntered.length; z++)
	{
		var c = emailAsEntered.charAt(z);
		var x = atSymbol.indexOf(c);
		if (x ==! -1)
		{
			for (y=0; y<emailAsEntered.length; y++)
			{
				var p = emailAsEntered.charAt(y);
				var q = dot.indexOf(p);
				if (q !== -1)
				{
					return true;
				}
			}
		}
	}
	return false; // if it reaches then at least one of the essential characters was missing
}
function contentPresent()
{
	if (isEmpty(document.mailForm.emailField.value))
	{
		alert ("Please complete the E-mail Address field");
		document.mailForm.emailField.focus();
		return false;
	}
	if (isEmpty(document.mailForm.subjectField.value))
	{
		alert ("Please complete the Subject field");
		document.mailForm.subjectField.focus();
		return false;
	}
	if (isEmpty(document.mailForm.messageField.value))
	{
		alert ("Please complete the Message field");
		document.mailForm.messageField.focus();
		return false;
	}
	if (!emailCheck(document.mailForm.emailField.value) || hasWhitespace(document.mailForm.emailField.value))
	{
		alert ("The email address appears to be invalid - please check and re-enter");
		document.mailForm.emailField.focus();
		return false;
	}
}
