	$(document).ready(function(){
		
		// check for cookies
		if($.cookie('BACARDI_AGE_VALIDATION_D')){
			$('#dob_d').val($.cookie('BACARDI_AGE_VALIDATION_D'));
			$('#dob_m').val($.cookie('BACARDI_AGE_VALIDATION_M'));
			$('#dob_y').val($.cookie('BACARDI_AGE_VALIDATION_Y'));
		}
		
		// remember me checkbox
		$('#dob_remember').change(function(){
			if($(this).is(':checked')){
				$('.dob_remember').addClass('selected')
			}else{
				$('.dob_remember').removeClass('selected')
			}
		});
		
		$(".number").keypress(function (e){
		  
		  //if the letter is not digit then display error and don't type anything
		  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
		  {
			//display error message
			$("#errmsg").html("Digits Only").show().animate({opacity:1},1000,function(){
				$(this).fadeOut("slow");
			});
			return false;
		  }
		});
		
		$('#dob_d').keyup(function(){
			if($(this).val() > 31){
				$(this).addClass('error');
			}else{
				$(this).removeClass('error');
			}
		});
		$('#dob_m').keyup(function(){
			if($(this).val() > 12){
				$(this).addClass('error');
			}else{
				$(this).removeClass('error');
			}
		});	
		$('#dob_y').keyup(function(){
			if($(this).val().length < 4){
				$(this).addClass('error');
			}else{
				$(this).removeClass('error');
			}
		});
		
		$('#check_age').submit(function(){
			if(checkAge() && validateForm() ){
				if($('#dob_remember').is(':checked')){
					// store cookies
					var options = { path: '/', expires: 10 };
					$.cookie('BACARDI_AGE_VALIDATION_D', $('#dob_d').val(), options);
					$.cookie('BACARDI_AGE_VALIDATION_M', $('#dob_m').val(), options);
					$.cookie('BACARDI_AGE_VALIDATION_Y', $('#dob_y').val(), options);
				}
				
				return true;			
			}else{
				return false;
			}
		});
		$('#dob_exit').click(function(){
			
			// redirect to EXIT PAGE
			window.location.replace("http://www.centurycouncil.org/landing")
			
			return false;		
		});	
		
		
	})
	
	function checkAge()
		{
			/* the minumum age you want to allow in */
			var min_age = 18;

			var year = parseInt($('#dob_y').val());
			var month = parseInt($('#dob_m').val()) - 1;
			var day = parseInt($('#dob_d').val());

			var theirDate = new Date((year + min_age), month, day);
			var today = new Date;

			if ( (today.getTime() - theirDate.getTime()) < 0) {
				
				//display error message
				$("#errmsg").html("Helaas, deze website is niet geschikt voor mensen onder de 18 jaar.").show()				
				return false;
			}
			else {
				return true;
			}
		}
		
	function validateForm()
		{
			if($(".number").hasClass('error')){
				//display error message
				$("#errmsg").html("De gegevens graag correct invoeren.").show().animate({opacity:1},1000,function(){
					$(this).fadeOut("slow");
				});
				return false;
			}else{
				return true;
			}
		}
