var errors = [];
errors[0] = 'The Honoree\'s <a href="#FirstName">first name</a> is required.';
errors[1] = 'The Honoree\'s <a href="#LastName">last name</a> is required.';
errors[2] = 'Please enter the Honoree\'s <a href="#Rank">rank</a>.';
errors[3] = 'Please enter the Honoree\'s <a href="#Division">military division</a>.';
errors[4] = 'The Honoree\'s <a href="#ReturnDate">return date</a> is required.';
errors[5] = 'Please enter your <a href="#ContactFirstName">first name</a>.';
errors[6] = 'Please enter your <a href="#ContactLastName">last name</a>.';
errors[7] = 'Please enter your <a href="#RelationToHonoree">relation to the honoree</a>.';
errors[8] = 'You must enter a valid <a href="#Email">email address</a>.';
errors[9] = 'You must enter a valid <a href="#DayPhone">phone number</a>.';
errors[10] = 'Please enter a <a href="#ReceptionDate">desired reception date</a>.';
errors[11] = 'Please enter a <a href="#StartTime">desired start time</a>.';
errors[12] = 'Please specify your <a href="#Restaurant">Gold Star Chili restaurant location</a>.';
errors[13] = 'Please specify <a href="#Guest">how many guests</a> will be attending.';

function checkRequired() {
	var returnme = true;
	focused = false;
	// first name
	if(checkempty('FirstName', false)) {
		focusFirst($("input[name='FirstName']"));
		throwError(0);
		$("input[name='FirstName']").bind('validate', function() {
			hideError(0);
		});
		$("a[href='#FirstName']").click(function () {
			$("input[name='FirstName']").focus();
			return false;
		});
		returnme = false;
	}
	// last name
	if(checkempty('LastName', false)) {
		focusFirst($("input[name='LastName']"));
		throwError(1);
		$("input[name='LastName']").bind('validate', function() {
			hideError(1);
		});
		$("a[href='#LastName']").click(function () {
			$("input[name='LastName']").focus();
			return false;
		});
		returnme = false;
	}
	// rank
	if(checkempty('Rank', false)) {
		focusFirst($("input[name='Rank']"));
		throwError(2);
		$("input[name='Rank']").bind('validate', function() {
			hideError(2);
		});
		$("a[href='#Rank']").click(function () {
			$("input[name='Rank']").focus();
			return false;
		});
		returnme = false;
	}
	// division
	if(checkempty('Division', false)) {
		focusFirst($("input[name='Division']"));
		throwError(3);
		$("input[name='Division']").bind('validate', function() {
			hideError(3);
		});
		$("a[href='#Division']").click(function () {
			$("input[name='Division']").focus();
			return false;
		});
		returnme = false;
	}
	// ReturnDate
	if(checkempty('ReturnDate', false)) {
		focusFirst($("input[name='ReturnDate']"));
		throwError(4);
		$("input[name='ReturnDate']").bind('validate', function() {
			hideError(4);
		});
		$("a[href='#ReturnDate']").click(function () {
			$("input[name='ReturnDate']").focus();
			return false;
		});
		returnme = false;
	}
	// contact first name
	if(checkempty('ContactFirstName', false)) {
		focusFirst($("input[name='ContactFirstName']"));
		throwError(5);
		$("input[name='ContactFirstName']").bind('validate', function() {
			hideError(5);
		});
		$("a[href='#ContactFirstName']").click(function () {
			$("input[name='ContactFirstName']").focus();
			return false;
		});
		returnme = false;
	}
	// contact last name
	if(checkempty('ContactLastName', false)) {
		focusFirst($("input[name='ContactLastName']"));
		throwError(6);
		$("input[name='ContactLastName']").bind('validate', function() {
			hideError(6);
		});
		$("a[href='#ContactLastName']").click(function () {
			$("input[name='ContactLastName']").focus();
			return false;
		});
		returnme = false;
	}
	// RelationToHonoree
	if(checkempty('RelationToHonoree', false)) {
		focusFirst($("input[name='RelationToHonoree']"));
		throwError(7);
		$("input[name='RelationToHonoree']").bind('validate', function() {
			hideError(7);
		});
		$("a[href='#RelationToHonoree']").click(function () {
			$("input[name='RelationToHonoree']").focus();
			return false;
		});
		returnme = false;
	}
	// email
	if (!checkValidEmail()) {
		focusFirst($("input[name='Email']"));
		throwError(8);
		$("input[name='Email']").bind('validate', function() {
			hideError(8);
		});
		$("a[href='#Email']").click(function () {
			$("input[name='Email']").focus();
			return false;
		});
		returnme = false;
	}
	// phone
	if(checkempty('DayPhone', false)) {
		focusFirst($("input[name='DayPhone']"));
		throwError(9);
		$("input[name='DayPhone']").bind('validate', function() {
			hideError(9);
		});
		$("a[href='#DayPhone']").click(function () {
			$("input[name='DayPhone']").focus();
			return false;
		});
		returnme = false;
	}
	// ReceptionDate
	if(checkempty('ReceptionDate', false)) {
		focusFirst($("input[name='ReceptionDate']"));
		throwError(10);
		$("input[name='ReceptionDate']").bind('validate', function() {
			hideError(10);
		});
		$("a[href='#ReceptionDate']").click(function () {
			$("input[name='ReceptionDate']").focus();
			return false;
		});
		returnme = false;
	}
	// StartTime
	if(checkempty('StartTime', false)) {
		focusFirst($("input[name='StartTime']"));
		throwError(11);
		$("input[name='StartTime']").bind('validate', function() {
			hideError(11);
		});
		$("a[href='#StartTime']").click(function () {
			$("input[name='StartTime']").focus();
			return false;
		});
		returnme = false;
	}
	// Restaurant
	if(checkempty('Restaurant', false)) {
		focusFirst($("input[name='Restaurant']"));
		throwError(12);
		$("input[name='Restaurant']").bind('validate', function() {
			hideError(12);
		});
		$("a[href='#Restaurant']").click(function () {
			$("input[name='Restaurant']").focus();
			return false;
		});
		returnme = false;
	}
	// Guest
	if(checkempty('Guest', false)) {
		focusFirst($("input[name='Guest']"));
		throwError(13);
		$("input[name='Guest']").bind('validate', function() {
			hideError(13);
		});
		$("a[href='#Guest']").click(function () {
			$("input[name='Guest']").focus();
			return false;
		});
		returnme = false;
	}
	
	return returnme;
}

$(document).ready(function () {
	$("input[name='FirstName']").blur(function() {checkempty('FirstName', false)});	
	$("input[name='LastName']").blur(function() {checkempty('LastName', false)});
	$("input[name='Rank']").blur(function() {checkempty('Rank', false)});
	$("input[name='Division']").blur(function() {checkempty('Division', false)});
	$("input[name='ReturnDate']").blur(function() {checkempty('ReturnDate', false)});
	$("input[name='ContactFirstName']").blur(function() {checkempty('ContactFirstName', false)});
	$("input[name='ContactLastName']").blur(function() {checkempty('ContactLastName', false)});
	$("input[name='RelationToHonoree']").blur(function() {checkempty('RelationToHonoree', false)});
	$("input[name='Email']").blur(function() {checkValidEmail()});
	$("input[name='DayPhone']").blur(function() {checkempty('DayPhone', false)});
	$("input[name='ReceptionDate']").blur(function() {checkempty('ReceptionDate', false)});
	$("input[name='StartTime']").blur(function() {checkempty('StartTime', false)});
	$("input[name='Restaurant']").blur(function() {checkempty('Restaurant', false)});
	$("input[name='Guest']").blur(function() {checkempty('Guest', false)});
	
	$("form#welcomehome").submit(function() {return checkRequired();});
});