$(function() {
	$('#submit').bind('click', function() {
		try {
			$('#first_name, #last_name, #location, #eligibility_date, #email, #email_confirmation').each(function() {
				if (this.value == '') {				
					var elementLabelText = $('label[for=' + this.id + ']').text().replace(/[ ]*:[ ]*/g, '');
					throw('Please fill out the "' + elementLabelText + '" field.');
					return false;
				}
			});
			
			if ($.trim($('#email').get(0).value) != $.trim($('#email_confirmation').get(0).value)) {
				throw ('Error: email address mismatch.'); 			
			}
			
			if ($.trim($('#email').get(0).value).search(/^[A-Z0-9.+]+@[A-Z0-9.+]+$/gi)==-1) {
				throw ('Please enter a valid email address.');			
			}
			
			if ($('#consent').get(0).checked == false) {
				throw ('Error: You must check the box to continue.');			
			}

		}
		catch (e) {
			alert(e);
			return false;
		}
		return true;
	});
});