//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.mail_form.email_addr.value))
	{
		document.mail_form.email_addr.focus();
		alert ("Please enter your email address");
		return false;
	}
	if (!emailCheck(document.mail_form.email_addr.value) || hasWhitespace(document.mail_form.email_addr.value))
	{
		alert ("The email address appears to be invalid - please check and re-enter");
		document.mail_form.email_addr.focus();
		return false;
	}
	if (isEmpty(document.mail_form.name.value))
	{
		document.mail_form.name.focus();
		alert ("Please enter your first name");
		return false;
	}
	if (isEmpty(document.mail_form.family_name.value))
	{
		document.mail_form.family_name.focus();
		alert ("Please enter your family name");
		return false;
	}
	if (document.mail_form.is_a.value == "-1")
	{
		document.mail_form.is_a.focus();
		alert ("Please select either Investor, Student, Job Seeker or Employer from the pulldown list");
		return false;
	}
	if (document.mail_form.department.value == "-1")
	{
		document.mail_form.department.focus();
		alert ("Please select the area you are interested in from the pulldown list");
		return false;
	}
}
