// PADRAO rev1110b
(function($){$.fn.blink=function(options){var defaults={delay:500};var options=$.extend(defaults,options);return this.each(function(){var obj=$(this);setInterval(function(){if($(obj).css("visibility")=="visible"){$(obj).css('visibility','hidden');}else{$(obj).css('visibility','visible');}},options.delay);});}}(jQuery));
$(document).ready(function(){
// MÁSCARAS
jQuery(function($){$("#cad_cep").mask("99999999");$("#cad_telefone").mask("(99) 9999.9999");$("#cad_cpf").mask("99999999999");$("#telefone").mask("(99) 9999.9999");$("#cpf").mask("99999999999");});
	$("#formLogin").validate({
		rules: {
			log_email: {required: true, email:true},
			log_senha: {required: true}
		},
		messages: {
			log_email: {required: '<br />Informe seu e-mail', email:'<br />E-mail inválido'},
			log_senha: {required: '<br />Informe sua senha'}
		},
		submitHandler: function(form){
			// EXIBE IMAGEM
			$('#retornoLogin').html('<img src="gfx/blueload.gif" />').show().css('display','block');
			$('#erroLogin').html('').slideUp();
			$('#btLogar').hide();
			// ENVIA O FORMULARIO
			$.post('cliente/logar', $(form).serializeArray(), getRetorno, "json");
			return false;
		}
	});
	$("#form_senha").validate({
		errorPlacement: function(error, element) {
			error.appendTo(element.parent().find(".erro"));
		},
		rules: {
			senha_atual: {required: true },
			senha_nova: {required: true, minlength: 6},
			senha_nova2: {required: true, minlength: 6, equalTo: "#senha_nova"}
		},
		messages: {
			senha_atual: {required: 'Informe sua senha atual' },
			senha_nova: {required: 'Informe sua nova senha', minlength: 'Digite pelo menos 6 caracteres'},
			senha_nova2: {required: 'Repita a nova senha', minlength: 'Digite pelo menos 6 caracteres', equalTo: 'Informe a mesma senha'}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#formPreloader").css("display", "block");
			$("#btSubmit").css("display", "none");
			$("#retornoSenha").text("");
			// ENVIA O FORMULARIO
			$.post("cliente/alterar_senha", $(form).serializeArray(), getSenha, "json");
			return false;
		}
	});
	$("#form_esqsenha").validate({
		errorPlacement: function(error, element) {
			error.appendTo(element.parent().find(".erro"));
		},
		rules: {
			esq_email: {required: true, email:true}
		},
		messages: {
			esq_email: {required: 'Informe seu e-mail', email:'E-mail inválido'}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#formPreloader").css("display", "block");
			$("#btSubmit").css("display", "none");
			$("#retornoSenha").text("");
			// ENVIA O FORMULARIO
			$.post("cliente/lembrar_senha", $(form).serializeArray(), getEsqueci, "json");
			return false;
		}
	});
	$('#resgateForm').validate({
		errorPlacement: function(error, element) {
			error.appendTo(element.parent().find(".spacer"));
		},
		rules: {
			id_banco: {required: true},
			ag1: {required: true},
			ct1: {required: true},
			tipoconta: {required: true},
			cpf: {required: true, CPF: true},
			telefone: {required: true},
			valor: {required: true}
		},
		messages: {
			id_banco: {required: 'Selecione o banco'},
			ag1: {required: 'Digite a agência'},
			ct1: {required: 'Digite a conta'},
			tipoconta: {required: 'Selecione o tipo da conta'},
			cpf: {required: 'Digite o CPF', CPF: 'Digite um CPF válido'},
			telefone: {required: 'Digite o telefone'},
			valor: {required: 'Digite o valor'}
		},
		submitHandler: function(form){
			$('#btSubmit').hide();
			$('#retornoTexto').html('');
			$('#formPreloader').show();
			$.post('cliente/resgatar',$(form).serializeArray(), getResgate, 'json');
		}
	});
	// CONFIGURA A VALIDACAO DO FORMULARIO DE CONTATO
	$("#form_contato").validate({
		rules: {
			nome: {required: true, minlength: 5},
			email: {required: true, email:true},
			mensagem: {required: true, minlength: 10}
		},
		messages: {
			nome: {
				required: "Informe seu nome",
				minlength:"Informe pelo menos 5 caracteres"
			},
			email:{
				required: "Informe um e-mail",
				email: "Informe um e-mail válido"
			},
			mensagem: {
				required: "Informe a mensagem",
				minlength:"Informe pelo menos 10 caracteres"
			}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#form_contato .formPreloader").css("display", "block");
			$("#form_contato .btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			// ENVIA O FORMULARIO
			$.post("contato/envia", $(form).serializeArray(), getContato, "json");
			return false;
		}
	});
	// CONFIGURA A VALIDACAO DO FORMULARIO DE CADASTRO
	$("#form_cadastro").validate({
		errorPlacement: function(error, element) {
			error.appendTo(element.parent().find(".erro"));
		},
			rules: {
			cad_email: {required: true, email: true},
			cad_senha: {required: true, minlength: 5},
			cad_senha2: {equalTo: '#cad_senha'},
			cad_nome: {required: true, minlength: 5},
			cad_dia: {required: true},
			cad_mes: {required: true},
			cad_ano: {required: true},
			cad_telefone: {required: true},
			cad_cpf: {required: true, CPF: true},
			cad_rg: {required: true},
			cad_cep: {required: true, minlength: 8},
			cad_logradouro: {required: true, minlength: 5},
			cad_numero: {required: true},
			cad_bairro: {required: true, minlength: 5},
			cad_cidade: {required: true},
			cad_uf: {required: true},
			contrato: {required: true}
		},
		messages: {
			cad_email: {required: 'Digite seu email', email: 'Digite um email válido'},
			cad_senha: {required: 'Digite sua senha', minlength: 'Mínimo de 5 caracteres'},
			cad_senha2: {equalTo: 'Digite a mesma senha'},
			cad_nome: {required: 'Digite seu nome', minlength: 'Digite seu nome'},
			cad_dia: {required: 'Digite o dia'},
			cad_mes: {required: 'Digite o mes'},
			cad_ano: {required: 'Digite o ano'},
			cad_telefone: {required: 'Digite o telefone'},
			cad_cpf: {required: 'Digite seu CPF', CPF: 'Digite um CPF válido'},
			cad_rg: {required: 'Digite seu RG'},
			cad_cep: {required: 'Digite seu CEP', minlength: 'Digite um CEP válido'},
			cad_logradouro: {required: 'Digite seu endereço', minlength: 'Digite seu endereço'},
			cad_numero: {required: 'Digite o número'},
			cad_bairro: {required: 'Digite o bairro'},
			cad_cidade: {required: 'Digite a cidade'},
			cad_uf: {required: 'Digite a UF'},
			contrato: {required: 'Leia e aceite os Termos de Serviço'}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#formPreloader").css("display", "block");
			$("#btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			// ENVIA O FORMULARIO
			$.post("cliente/cadastrar", $(form).serializeArray(), getCadastro, "json");
			return false;
		}
	});
	$("#form_Depor").validate({
		rules: {
			texto: {required: true, minlength: 15},
			code: {required: true}
		},
		messages: {
			texto: {required: 'Digite o depoimento', minlength: 'Digite no minimo 15 caracteres'},
			code: {required: 'Digite o código'}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#formPreloader").css("display", "block");
			$("#btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			// ENVIA O FORMULARIO
			$.post("cliente/depor", $(form).serializeArray(), getDepoimento, "json");
			return false;
		}
	});
	$("#form_indique").validate({
		rules: {
			seu_nome: {required: true},
			seu_email: {required: true, email: true},
			amigo_nome: {required: true},
			amigo_email: {required: true, email: true},
			code: {required: true}
		},
		messages: {
			seu_nome: {required: 'Digite seu nome'},
			seu_email: {required: 'Digite seu email', email: 'Digite um email válido'},
			amigo_nome: {required: 'Digite o nome do amigo'},
			amigo_email: {required: 'Digite o email', email: 'Digite um email válido'},
			code: {required: 'Digite o código'}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#formPreloader").css("display", "block");
			$("#btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			// ENVIA O FORMULARIO
			$.post("cliente/indique", $(form).serializeArray(), getIndique, "json");
			return false;
		}
	});
	// CONFIGURA A VALIDACAO DO FORMULARIO DE atualizacao DE CADASTRO
	$("#form_meucadastro").validate({
		rules: {
			cad_email: {required: true, email: true},
			cad_nome: {required: true, minlength: 5},
			cad_dia: {required: true},
			cad_mes: {required: true},
			cad_ano: {required: true},
			cad_telefone: {required: true},
			cad_cpf: {required: true, CPF: true},
			cad_rg: {required: true},
			cad_cep: {required: true, minlength: 8},
			cad_logradouro: {required: true, minlength: 5},
			cad_numero: {required: true},
			cad_bairro: {required: true, minlength: 5},
			cad_cidade: {required: true},
			cad_uf: {required: true}
		},
		messages: {
			cad_email: {required: 'Digite seu email', email: 'Digite um email válido'},
			cad_nome: {required: 'Digite seu nome', minlength: 'Digite seu nome'},
			cad_dia: {required: 'Digite o dia'},
			cad_mes: {required: 'Digite o mes'},
			cad_ano: {required: 'Digite o ano'},
			cad_telefone: {required: 'Digite o telefone'},
			cad_cpf: {required: 'Digite seu CPF', CPF: 'Digite um CPF válido'},
			cad_rg: {required: 'Digite seu RG'},
			cad_cep: {required: 'Digite seu CEP', minlength: 'Digite um CEP válido'},
			cad_logradouro: {required: 'Digite seu endereço', minlength: 'Digite seu endereço'},
			cad_numero: {required: 'Digite o número'},
			cad_bairro: {required: 'Digite o bairro'},
			cad_cidade: {required: 'Digite a cidade'},
			cad_uf: {required: 'Digite a UF'}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#formPreloader").css("display", "block");
			$("#btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			// ENVIA O FORMULARIO
			$.post("cliente/alterar_cadastro", $(form).serializeArray(), getCadastro, "json");
			return false;
		}
	});
	$(".verifica_cep").keyup(function(){
		// RETORNA OS DADOS A PARTIR DE UM CEP
		var cep = $(this).val();
		var reDigits = /^\d+$/;// EXPRESSAO REGULAR PARA ACEITAR APENAS NUMEROS INTEIROS
		if(cep.length == 8 && reDigits.test(cep)){
			$('#txtCEP').html('<img src="gfx/mini_load.gif" /> &nbsp; Processando CEP...');
			$.post("cliente/cep", {'cep':cep}, retornEndereco, "json");
		} else {
			$(".logradouro").attr("value","");
			$(".bairro").attr("value","");
			$(".cidade").attr("value","");
			$(".id_cidade").attr("value","");
			$(".uf").attr("value","");
		}
	});
	$("#form_Login").validate({
		rules: {
			email: {required: true, email:true},
			senha: {required: true}
		},
		messages: {
			email: {required: 'Informe seu e-mail', email:'E-mail inválido'},
			senha: {required: 'Informe sua senha'}
		},
		submitHandler: function(form){
			// EXIBE IMAGEM
			$('#imgLoader').show();
			$('#loginErro').html('').slideUp();
			$('#btLogar2').hide();
			// ENVIA O FORMULARIO
			$.post('cliente/logar', $(form).serializeArray(), getRetorno, "json");
			return false;
		}
	});
	$("#formPagar").validate({
		rules: {
			radios: {required: true}
		},
		messages: {
			radios: {required: 'Selecione a opção'}
		},
		submitHandler: function(form){
			// EXIBE IMAGEM
			$('#imgLoader').show();
			$('.info').hide();
			// ENVIA O FORMULARIO
			$.post('jogos/pagar', $(form).serializeArray(), getApostas, "json");
			return false;
		}
	});
	

	$(".formPromocao").validate({
		submitHandler: function(form){
			$.post('jogos/jogar_promocao', $(form).serializeArray(), function(data){
				
				var cor = data.rs=='ok' ? 'Blue' : 'Red';
				var seta = data.rs=='ok' ? 'azul' : 'laranja';
				
				var html = '<div class="informacao info'+cor+'">'+
								'<img src="gfx/ico_'+data.ico+'.gif" alt="" />'+
								'<img src="gfx/seta_'+seta+'.gif" alt="" class="seta" />'+
								data.msg+'</div>';

				$('#retorno_concurso_'+data.numero).html(html).fadeIn();
				
				
				if(data.rs=='ok'){
					$('#cupom_'+data.numero).val('');
					
					setTimeout(function(){
						window.location = SITE_URL+'/promocoes/conclusao'
					}, 3000);
				}
				else
				{
					setTimeout(function(){
						$('#retorno_concurso_'+data.numero).fadeOut();
					}, 5000);
				}

			}, "json");
			return false;
		}
	});
	
	$('.precisaLogar').click(function(){
		var numero = $(this).attr('rel');
		$('#retorno_concurso_'+numero+' .infoBlue').fadeIn();
		
		setTimeout(function(){
			$('#retorno_concurso_'+numero+' .infoBlue').fadeOut();
		}, 5000);

	});
});
//////////////////////
// INICIA SHADOWBOX //
//////////////////////
function doInit(){
	Shadowbox.init();
};
function reloadCap()
{
	$('#target').html('<img src="css/blank.gif" height="45" width="135" />');
	$('#target').html('<img src="securimage_show.php?sid=' + Math.random() +'" />');
	//$('#target').src('/securimage/securimage_show.php?' + Math.random());
};
function moeda2float(moeda){
    moeda = moeda.replace(/\./gi, "");
    moeda = moeda.replace(",", ".");
    return parseFloat(moeda);
};
function roundNumber(rnum){
    return Math.round(rnum * Math.pow(10, 2)) / Math.pow(10, 2);
};
function float2moeda(num){
    x = 0;
    if (num < 0) {
        num = Math.abs(num);
        x = 1;
    }
    if (isNaN(num)) 
        num = "0";
    cents = Math.floor((num * 100 + 0.5) % 100);
    num = Math.floor((num * 100 + 0.5) / 100).toString();
    if (cents < 10) 
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) 
        num = num.substring(0, num.length - (4 * i + 3)) + '.' +
        num.substring(num.length - (4 * i + 3));
    ret = num + ',' + cents;
    if (x == 1) 
        ret = ' - ' + ret;
    return ret;
};
getRetorno = function(data)
{
	if(data.rs == 'ok' || data.rs == 'nao-liberado'){
		msg = 'Redirecionando, aguarde...';
		setTimeout(function(){ window.location = data.url_destino; }, 1000);
	}
	if(data.rs == 'erro_post'){
		msg = 'Informe seu login e senha';
	}
	if(data.rs == 'nao-encontrado'){
		msg = 'Login e/ou senha incorretos';
	}
	if (data.flag != 'on')
	{
		// EXIBE MENSAGEM
		$('#erroLogin').html(msg).fadeIn('slow');
		$('#retornoLogin').html('').hide();
	}
	else
	{
		// EXIBE MENSAGEM
		$('#loginErro').html(msg).fadeIn('slow');
		$('#imgLoader').hide();
		$('#btLogar2').show();
	}
	// AGUARDA UM TEMPO E MOSTRA O BOTÃƒO NOVAMENTE
	setTimeout(function(){ $('#btLogar').fadeIn(); }, 2000);
};
function retornEndereco(rs){
	// VALIDA O RESULTADO
	if(rs.resultado == "ok"){
		$("#txtCEP").text("");
		$("#cad_logradouro").attr("value",rs.endereco);
		$("#cad_bairro").attr("value",rs.bairro);
		$("#cad_cidade").attr("value",rs.cidade);
		$("#id_cidade").attr("value",rs.id_cidade);
		$("#cad_uf").attr("value",rs.uf);
	}else{
		$("#txtCEP").text("Digite um CEP válido");
		$("#cad_logradouro").attr("value","");
		$("#cad_bairro").attr("value","");
		$("#cad_cidade").attr("value","");
		$("#id_cidade").attr("value","");
		$("#cad_uf").attr("value","");
	}
};
getApostas = function(data){
	if(data.rs == "ok"){
		window.top.location = SITE_URL+'/jogos/apostaregistrada/credito';
	}
	if(data.rs == "erro"){
		$('#imgLoader').hide();
		$("#infoMsg").text(data.msg);
		$(".info").show();
	}
	if(data.rs == "pagseguro"){
		window.top.location = SITE_URL+'/jogos/pagseguro';
	}
};
getDepoimento= function(data){
	if(data.rs == "ok"){
		$("#aguardeContato").text('Depoimento enviado com êxito e aguarda moderação.');
		setTimeout(function(){
			window.top.location = window.top.location;
		}, 2500);
	}
	if(data.rs == "erro"){
		$("#formPreloader").css("display", "none");
		$("#btSubmit").css("display", "");
		$("#aguardeContato").text(data.msg);
	}
};
getIndique= function(data){
	if(data.rs == "ok"){
		$("#aguardeContato").text('Sua indicação foi enviada com êxito.');
		setTimeout(function(){
			window.top.location = window.top.location;
		}, 2500);
	}
	if(data.rs == "erro"){
		$("#formPreloader").css("display", "none");
		$("#btSubmit").css("display", "");
		$("#aguardeContato").text(data.msg);
	}
};
getEsqueci = function(data){
	if(data.rs == 'email_invalido'){
		msg = 'E-mail inválido';
		$("#btSubmit").css("display", "block");
	}
	if(data.rs == 'email_nao_encontrado'){
		msg = 'E-mail não encontrado';
		$("#btSubmit").css("display", "block");
	}
	if(data.rs == 'erro_envio_email'){
		msg = 'Erro ao enviar e-mail, por favor tente mais tarde';
		$("#btSubmit").css("display", "block");
	}
	if(data.rs == 'ok'){
		msg = 'Verifique seu e-mail para confirmar a alteração';
		setTimeout(function(){
			//window.top.location = SITE_URL;
		}, 2000);
	}
	$("#formPreloader").css("display", "none");
	$('#retornoSenha').html(msg).css('display','block');
};
getResgate = function(data){
	if(data.rs == "ok"){
		$('#retornoTexto').html('Seu resgate foi enviado e aguarda análise.');
		setTimeout(function(){
			window.top.location = window.top.location;
		}, 2500);
	}
	if(data.rs == "erro"){
		$('#retornoTexto').html(data.msg);
	}
	$("#formPreloader").hide();
	$("#btSubmit").show();
};
getContato = function(data){
	if(data.rs == "ok"){
		$("#aguardeContato").text("Mensagem enviada com sucesso");
		$("#aguardeContato").fadeIn("slow");
		setTimeout(function(){
			$("#formReset").click();
		}, 2000);
	}
	if(data.rs == "erro"){
		$("#aguardeContato").text(data.msg);
	}
	// MOSTRA O BOTAO
	$("#formPreloader").css("display", "none");
	$("#btSubmit").css("display", "");
};
getSenha = function(data)
{
	if(data.rs == 'erro'){
		$('#senha_atual').focus();
	}
	if(data.rs == 'ok'){
		$("#btReset").click();
	}
	$('#retornoSenha').text(data.msg).fadeIn();
	// MOSTRA O BOTAO
	$("#formPreloader").css("display", "none");
	$("#btSubmit").css("display", "");
};
getCadastro = function(data){
	if (data.site == "")
	{
		data.site = SITE_URL;
	}
	if(data.rs == "ok"){
		$("#aguardeContato").text(data.msg);
		$("#aguardeContato").fadeIn("slow");
		setTimeout(function(){
			window.location = data.site;
		}, 2000);
	}
	if(data.rs == "erro"){
		$("#aguardeContato").text(data.msg);
	}
	// MOSTRA O BOTAO
	$("#formPreloader").css("display", "none");
	$("#btSubmit").css("display", "");
};
getJogar = function(data)
{
	if(data.rs == 'ok'){
		window.location = SITE_URL+'/jogos/carrinho';
	}
	if(data.rs == 'erro'){
		alert(data.msg);
	}
};
showMenu = function () {
		$("#submenu").fadeIn();
		clearTimeout(menuTimer);
};
var menuTimer = 0;
var speed = 400;
function hideMenu() {
	$("#submenu").fadeOut(speed);
};
function marcar(numero)
{
	var sTmp = $('#numberSelecteds').html();
	sTmp = sTmp.replace('&nbsp;','');
	var aNum = new Array();
	var total = 0;
	if(sTmp.length == 0)
	{
		aNum.push(numero);
		$('#n'+numero).addClass('sobre');
	}
	else
	{
		aNum = sTmp.split(", ");
		total += $('.sobre').size();
			iPos = buscar(aNum, numero);
			if(iPos > -1) {
				aNum.splice(iPos, 1);
				$('#n'+numero).toggleClass('sobre');
			}
			else
			{
				if(total >= maxloteria) {
					alert('Máximo de dezenas selecionado!');
				}
				else
				{
					aNum.push(numero);
					$('#n'+numero).toggleClass('sobre');
				}
		}
	}
	aNum.sort();
	var numbs = aNum.length;
	if (aNum.length==0)
	{
		$('#numberSelecteds').html("&nbsp;");
		$('#numDezenas').html('0');
	}
	else
	{
		$('#numberSelecteds').html(aNum.join(", "));
		$('#numDezenas').html(numbs.toString());
	}
	var preco = 0;
	if(numbs >= minloteria)
		preco = valor[numbs - minloteria];
	$('#valorAposta').html('R$ ' + preco.toFixed(2));
};
function buscar(array, numero) {
	for(var j=0;j<array.length;j++) {
		if(array[j] == numero)
			return(j);
	}
	return(-1);
};
function start()
{
	$('#numberSelecteds').html("&nbsp;");
	$('#numDezenas').html('0');
	$('.sobre').removeClass('sobre');
};
function Palpite() {
	start();
	var arrNum = solTip($('#selectPalpite').val(), supermax);
	for (x=0; x<arrNum.length; x++) {
		marcar(arrNum[x]);
	}
};
var ra = new Array();
var max=0;
var sum=0;
function solTip(imax, isum) {
	var tmp = '';
	ra  = new Array();
	max = imax;
	sum = isum;
	sum-=1;
	for (x=0; x<max; x++){
		tmp = Math.round(Math.random() * sum);
		ra[x] = tmp;
		if(ra[x] == 0) ra[x]++;
		if(ra[x] < 10) ra[x] = '0' + ra[x].toString();
		if(ra[x] == 100) ra[x] = '00';
	}
	check();
	ra.sort();
	return(ra);
};
function troca(x){
	ra[x]=Math.random();
	ra[x]=ra[x]*sum;
	ra[x]=Math.round(ra[x]);
	ra[x]+=1;
	if(ra[x] < 10) ra[x] = '0' + ra[x].toString();
	if(ra[x] == 100) ra[x] = '00';
	check();
};
function check(){
	for (x=0; x<max; x++){
		for (y=x+1; y<max; y++){
			if (ra[x]==ra[y]){
				troca(x);
			}
		}
	}
};
novoJogo = function(alerta)
{
	var sTmp = $('#numberSelecteds').html();
	sTmp = sTmp.replace('&nbsp;','');
	var aNum = new Array();
	if(sTmp.length == 0)
	{
		alert('Selecione entre '+(minloteria)+' e '+ maxloteria +' dezenas.');
	}
	else
	{
		aNum = sTmp.split(", ");
		if (aNum.length < minloteria)
		{
			if ((minloteria-aNum.length)==1)
				alert('Selecione mais '+(minloteria-aNum.length)+' dezena.');
			else
				alert('Selecione mais '+(minloteria-aNum.length)+' dezenas.');
		}
		else
		{
			var idConcurso = $('#hd_idConcurso').val();
			if(idConcurso!='')
			{
			if (alerta == 1)
				alert('Atenção\nSeu jogo valerá apenas para o próximo concurso!');
			$('#btNovoJogo').hide();
			$('#novoLoad').show();
			var currentTime = new Date();
			var preco = $('#valorAposta').html();
			var idConcurso = $('#hd_idConcurso').val();
			$.post('jogos/incluir_jogo',
			{
				id_modalidade: $('#hd_idModalidade').val(),
				id_concurso: idConcurso,
				id_jogo: currentTime.getTime(),
				id_time: $('#timeCoracao').val(),
				quant: 1,
				concurso: $('#infoNumero'+idConcurso).html(),
				dataconcurso: $('#infoData'+idConcurso).html(),
				preco: valor[aNum.length - minloteria],
				modalidade: $('#infoModalidade').html(),
				sigla: $('#infoSigla').html(),
				jogo: sTmp,
				url: $('#infoUrl').html()
			}, getJogar, "json");
			}
			else
				alert('Atenção\nNão é possível realizar seu jogo!');
		}
	}
};
jogarPromocao = function(idJogo)
{
	$('#btCont'+idJogo).html('<img src="gfx/loader.gif" alt="" height="16" width="16" />');
	$.post('jogos/incluir_jogo', {id_jogo: idJogo, quant: 1}, getJogar, "json");
};
jogar = function(idJogo)
{
	var qtd = $('#quant'+idJogo).val();
	if (qtd == 0)
	{
		alert('Selecione as cotas desejadas.');
	}
	else
	{
		$('#btCont'+idJogo).html('<img src="gfx/loader.gif" alt="" height="16" width="16" />');
		$.post('jogos/incluir_jogo', {id_jogo: idJogo, quant: qtd}, getJogar, "json");
	}
};
removeJogo = function(idJogo)
{
	$('#btCont'+idJogo).html('<img src="gfx/loader.gif" alt="" height="16" width="16" />');
	$.post('jogos/remover_jogo', {id_jogo: idJogo}, getJogar, "json");
};
limparJogo = function()
{
	$.post('jogos/limpar_carrinho', {id_jogo: '0'}, getJogar, "json");
};
atualizaJogo = function(idJogo)
{
	$('#btCont'+idJogo).html('<img src="gfx/loader.gif" alt="" height="16" width="16" />');
	var quant= $('#quant'+idJogo).val();
	$.post('jogos/atualizar_jogo', {id_jogo: idJogo, quant: quant}, getJogar, "json");
};
ativaEntrega = function()
{
	var total = moeda2float($('.totalCont').html());
	var taxa = moeda2float($('#entrega').val());
	if ($('#entrega').is(':checked')) {
		var soma = (total+taxa); 
		$('.totalCont').html(float2moeda(soma));
		$.post('jogos/ativaFrete', {frete: taxa});
	}
	else
	{
		var soma = (total-taxa);
		$('.totalCont').html(float2moeda(soma));
		$.post('jogos/ativaFrete', {frete: -taxa});
	}
};

function FormataReais(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
		return true;
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1)
		return false; // Chave inválida
	len = fld.value.length;
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep))
			break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1)
			aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0)
		fld.value = '';
	if (len == 1)
		fld.value = '0'+ decSep + '0' + aux;
	if (len == 2)
		fld.value = '0'+ decSep + aux;
	if (len > 2)
	{
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3)
			{
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
};
