/* 
 * Ensure field is not empty
 */
function checkField(inputField)
{
	var myField = document.getElementById(inputField);
	if (myField == null || myField.value == "") {
		myField.focus();
		return (false);
	} else {
		return (true);
	}
}

/* 
 * Get value of field and return its value
 */
function getField(inputField)
{
	var myField = document.getElementById(inputField);

	return (myField.value);
}

/*
 * Validate Email address supplied
 */
function checkEmail(emailAddress)
{
	var atIndex     = emailAddress.indexOf('@')
	var dotIndex    = emailAddress.indexOf('.',atIndex)
	
	// check 0 < atIndex < dotindex < length
	if( (0 < atIndex) && (atIndex < dotIndex) && (dotIndex < emailAddress.length-1) )
	{
	// first character is a letter and all other are not whitespace
		var firstChar = emailAddress.charAt(0);
	
		if( (firstChar>='a' && firstChar<='z') || (firstChar>='A' && firstChar<='Z') || (firstChar>='0' && firstChar<='9') )
		{
			for(var i=1; i<emailAddress.length; ++i)
			{
				if(emailAddress.charCodeAt(i) <= 0x20)
				{
					if(emailAddress.charAt(i) == ' ') {
						return("   Email address must not contain spaces");
					} else {
						return("   Email address must not contain the character \"" + emailAddress.charAt(i) + "\"")
					}
				}
			}
			return ("");
		}
		return("   Email address cannot start with the character \"" + firstChar + "\"")
	}
	return("   Email address invalid")
}


