$(document).ready(function() {
    if ($("body").attr("rel")) {
	$val = $("body").attr("rel");
	_gaq.push(['_trackPageview', $val]);
    } else {
	_gaq.push(['_trackPageview']);
    }
    
    $(".boxAge input").keypress(function(event) {
	var controlKeys = [8, 9, 13, 35, 36, 37, 39];
	var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
	if (!event.which || // Control keys in most browsers. e.g. Firefox tab is 0
	    (49 <= event.which && event.which <= 57) || // Always 1 through 9
            (48 == event.which && $(this).attr("value")) || // No 0 first digit
            isControlKey) { // Opera assigns values for control keys.
	    return;
        } else {
	    event.preventDefault();
        }
    });

    $('.boxAge .submit').click(function(e){
	e.preventDefault();
	if($('.boxAge input').val()!=""){
	    if(parseInt($('.boxAge input').val())>=18){
		$('.boxAge .age .submit').removeClass('submit').addClass('redir').html('Redirecionando');
		jQuery.cookie('Skol.CookieMaiorIdade', '1', { path: '/', expires: 1 , domain: '.skol.com.br' });
	    	_gaq.push(['_trackPageview', '/skol/prehome/sim']);
		var url = $('.boxAge .age a').attr('href');
	    	window.location = jQuery.trim(url);
	    }else{
	    	_gaq.push(['_trackPageview', '/skol/prehome/nao']);
	    	$('.boxAge .age').fadeOut(function(){
		    $('.boxAge #erro1').fadeIn(function(){
	    		window.location = 'http://www.ambev.com.br/';
		    });
	    	});
	    }
	}else{
	    $('.boxAge .age').fadeOut(function(){
		$('.boxAge #erro2').fadeIn();
		window.setTimeout("$('.boxAge #erro2').fadeOut(function(){ $('.boxAge .age').fadeIn();$('.boxAge input').focus(); })", 2000);
	    });
	}
    });
    
    $('.boxAge input').keypress(function(e){
	if(e.which == 13){
	    $('.boxAge .submit').click();
	}
    });
});
