$(document).ready(function() {	
	$.validator.addMethod('birthDate', function(value, element) {
		var day = $("#birthDay").val();
		var month = $("#birthMonth").val();
		var year = $("#birthYear").val();
		var age = 13;

		var myDate = new Date();
		myDate.setFullYear(year, month-1, day);

		var currDate = new Date();
		currDate.setFullYear(currDate.getFullYear() - age);
		
		//birthday invalid, display message
		if(checkBirthdayEntered()) {
			if(currDate - myDate < 0) {
				//alert('bday invalid');
				$("#signUpDiv").hide();
				$("#signUpSorryDiv").show();
				$.cookie('dda_age', '0');
				return false;
			} else {
				return true;
			}
		} else {
			return false;
		}
//		return (currDate - myDate < 0 ? false : true);
	});
	
	// check birthday entered
	$('#birthMonth').change(function() {
		checkBirthdayEntered();
	});
	$('#birthDay').change(function() {
		checkBirthdayEntered();
	});
	$('#birthYear').change(function() {
		checkBirthdayEntered();
	});

	function checkBirthdayEntered() {
		var day = $("#birthDay").val();
		var month = $("#birthMonth").val();
		var year = $("#birthYear").val();
		if((day != '') && (month != '') && (year != '')){
			$('#birthDateEntry').val('1');
			return true;
		} else {
			$('#birthDateEntry').val('');
			return false;
		}
	}
	
//	$("#submitButton").click(function(){	
		$("#signUpForm").validate({			
			rules: {
	        	firstName: "required",// simple rule, converted to {required:true}
				lastName: "required",
				birthDateEntry: "required",
				email: {// compound rule
					required: true,
					email: true
				},
				birthDateInvalid: {// functions as placeholder to position birthDateInvalid error message
					birthDate : true
				}
			},
			messages: {
				birthDateEntry: "Please select your birth date.",
				birthDateInvalid: "", // intentionally blank
				firstName: "First Name is Required",
				lastName: "Last Name is Required",
				email: "Please enter a valid email address."
			}
		});
//	});

});

