//JS stuff for the Age Verification Splash.

var themePath = "/wp-content/themes/beerville_1.0";

jQuery(document).ready(function($){
	
	$("#verificationForm").submit(function(evt) {
		evt.preventDefault();
		
		$month = $('#month').val();
		$day = $('#day').val();
		$year = $('#year').val();
		
		//console.log("Month: " + $month + " Day: " + $day + " Year: " + $year);
		
		$.getJSON(themePath+'/time.php', function (data) {
			//console.log(data.serverTime);
			$theTime = data.serverTime;
			$theDate = getToday($theTime);
			//console.log($theDate);
			
			//console.log("Month: " + $month + " Day: " + $day + " Year: " + $year);
			
			$theirDate = new Date($year, $month - 1, $day );
			//console.log($theirDate);
			
			$adjustedDate = new Date();
			$adjustedDate.setDate($theDate.getDate());
			//console.log($adjustedDate);
			$adjustedDate.setFullYear($adjustedDate.getFullYear() - 21);
			//console.log($adjustedDate);
			
			if($theirDate <= $adjustedDate)
			{
				window.location.href = '/home/';
			}else{
				$('#errorBox').html('<p>Sorry, you\'re not old enough.  Check this place out.</p>');
				setTimeout( "window.location.href = 'http://www.centurycouncil.org/'", 5*1000 );
			}
		});
		
	});

});



function getToday($theTime)
{
	$theDate = new Date($theTime);
	return $theDate;
}
