$(function(){
	
	$("#dateField").mask("99/99/9999");
	
	$("#submitAge").click(function(){
		verif();
	});
	
	$("#submitAgeForm").submit(function(event){
		verif();
		event.preventDefault();
	});
	
	function verif(){
		$("#dateField").trigger('blur');
		var date = $("#dateField").val().split('/');
		if(date!="")
		{
			var minAge = 18;
			
			var day = date[0];
			var month = date[1]-1;
			var year = date[2];
			if(day > 0 && day <=31 && month>0 && month<=12)
			{
				var theirDate = new Date((parseInt(year) + minAge), month, day);
				var today = new Date;
				
				if ( (today.getTime() - theirDate.getTime()) < 0) 
				{
					$(".hid-msg").slideDown();
					$(".hid-msg2").slideUp();
				}
				else 
				{
					$("#body").css('overflow','hidden');
					$("#body").animate({height:'0px',marginTop:'197px'},1000,function(){
						//$("#submitAgeForm").submit();
						location.href = '/historia';
					});
				}
			}
		}
		else
		{
			$(".hid-msg").slideUp();
			$(".hid-msg2").slideDown();
		}
	}
	
});
