var link;

jQuery(document).ready(function(){
	jQuery('#nascimentoDia').autotab({ target: 'nascimentoMes', format: 'numeric' });
	jQuery('#nascimentoMes').autotab({ target: 'nascimentoAno', format: 'numeric', previous: 'nascimentoDia' });
	jQuery('#nascimentoAno').autotab({ previous: 'nascimentoMes', format: 'numeric' });

	jQuery("#escolha").hide();

	jQuery("#underageban").submit(function(){
		var url = baseUrl + "/index.json";
		var data = {
			dia: parseInt(jQuery("#underageban .dia input").val(), 10),
			mes: parseInt(jQuery("#underageban .mes input").val(), 10),
			ano: parseInt(jQuery("#underageban .ano input").val(), 10)
		}
		if (isNaN(data['dia']) || data['dia'] < 1 || data['dia'] > 31) {
			showAlert("Insira um <strong>dia</strong> válido");
			jQuery("#underageban .dia input").focus();
			return false;
		}
		if (isNaN(data['mes']) || data['mes'] < 1 || data['mes'] > 12) {
			showAlert("Insira um <strong>mês</strong> válido");
			jQuery("#underageban .mes input").focus();
			return false;
		}
		if (isNaN(data['ano'])) {
			showAlert("Insira um <strong>ano</strong> válido");
			jQuery("#underageban .ano input").focus();
			return false;
		}

		jQuery.post(url, data, function(data){
			if(parseInt(data['status']) == 1) {
				//jQuery("#idade").hide('slow');
				//jQuery("#escolha").show('slow');
				top.location.href = "http://www.caipiry.com.br/site/";
				return;
			}
			//top.location.href = "http://twitter.com/semalcool";
			top.location.href = "http://www.kaly.com.br/";
		}, "json");

		return false;
	});

	jQuery("#dialog").dialog({
		autoOpen: false,
		modal: true,
		buttons: {
			Ok: function() {
				jQuery(this).dialog('close');
			}
		}
	});

	jQuery(".acessarjogo a").click(function(){
		if(!jQuery(this).hasClass("popup")) {
			link = jQuery(this).attr("href");
			jQuery(this).attr("href", "javascript:void(0);");
			window.open(link, "jogo", "status=1,location=0,menubar=0,toolbar=0,resizable=1,scrollbars=1,width=970,height=630");
			jQuery(this).addClass("popup");
			return false;
		} else {
			window.open(link, "jogo", "status=1,location=0,menubar=0,toolbar=0,resizable=1,scrollbars=1,width=970,height=630");
			return false;
		}
	});
});

function showAlert(msg)
{
	jQuery("#dialog").find("p").html(msg);
	jQuery("#dialog").dialog('open');
}
