
function valid_email(email_address)
{
	if (email_address.length < 6) {return false};

	at_location = email_address.indexOf("@");
	dot_location = email_address.lastIndexOf(".");
	space_location = email_address.lastIndexOf(" ");

	if (at_location == -1 || space_location > 0 || dot_location == -1 || at_location > dot_location ) {return false};
	if (at_location == 0) {return false};
	if (dot_location - at_location < 3 ) {return false};
	if (email_address.length - dot_location < 3) {return false};
	return true
}

//Check for empty or only non visible characters in string

function its_not_visible(string_value)
{
	var not_visible = " \n\r\t"

	for (var counter = 0; counter < string_value.length; counter++)
	{
		current_char = string_value.charAt(counter)
		if (not_visible.indexOf(current_char) == -1)
		{
			return false
		}
	}
	return true
}

//Submit handler can be extended to many more fields

function submit_handler()
{
	if( its_not_visible(document.forms[0].Name.value) )
	{
		alert('You have not entered anything for your NAME!');
		document.forms[0].Name.focus() ;
		return false
	}
	if( !valid_email(document.forms[0].Email.value) )
	{
		alert('Please enter a valid email address so I can reply \n Hint: Check for leading or trailing spaces');
		document.forms[0].Email.focus() ;
		return false
	}

	if( its_not_visible(document.forms[0].Message.value) )
	{
		alert('You have not entered any message!');
		document.forms[0].Message.focus() ;
		return false
	}
	if( its_not_visible(document.forms[0].txtNumber.value) )
	{
		alert('You have not entered the 5 digit verification number!');
		document.forms[0].txtNumber.focus() ;
		return false
	}
	if( valid_email(document.forms[0].Email.value) )
	{
		return true
	}
}
