
jQuery(document).ready(function(){

//CRIA A BARRA DE ROLAGEM PERSONALIZADA
//$('.produtos_aba').jScrollPane();

//
//FUNÇÃO QUE CHAMA O CARROCEL DE IMAGENS DOS CONCURSOS E FAQ
//

//setTimeout(function(){
//   $.post("exibir_flash.php",
//
//                    function(valor)
//                    {
//                            $("#boxflash").html(valor);
//                    }
//    )
//},5000);

//var relogio = setInterval(ocultarDivFlash, 21000);
//
//function ocultarDivFlash(){
//    alert('.');
//    
//}

$(".campos").keypress(verificaNumero);

setInterval(function() {
      
      //alert('.');
      // Do something every 2 seconds
      //$("#boxflash2").hide();
      $(".boxflash_home").html(" ");
      $(".boxflash_home").css("display", "none");
      
}, 28000);



$("#btn_fecharbanner").click(function(){
    $("#bannerhome").hide(500);
});

//AJAX PARA VERIFICAR O LINK DE DESTINO DO CADASTRO
$(".botao_sacola").click(function(){
    $("#link_cadastro").html("<a href='/cadastro2.php' id='cadastre-se'>cadastre-se</a>");
    $("#link_cadastro2").html("<a href='/cadastro2.php' class='links'>Cadastre-se</a>");
});

$(".botao-sacola").click(function(){
    $("#link_cadastro").html("<a href='/cadastro2.php' id='cadastre-se'>cadastre-se</a>");
    $("#link_cadastro2").html("<a href='/cadastro2.php' class='links'>Cadastre-se</a>");
});


jQuery('.carrocel').jcarousel();//RESPONSÁVEL PELOS NOVOS CARROCÉIS
jQuery('#conteudo-lista').carousel('.anterior', '.proximo');//CARROCEL DOS HOTSITES
jQuery('#viewport').carousel('#simplePrevious', '#simpleNext');//CARROCEL DE FAQ

$("#btn_fechar_popup").click(function(){
    $("#divbanner_popup").hide("slow");
    $("#imgbanner_popup").hide("slow");
    $("#btn_fechar_popup").hide("slow");
});

//FUNÇÃO PARA QUANDO O USUÁRIO CLICAR NO TEXTO AO LADO DO CHECKBOX MARCAR E DESMARCAR AUTOMATICAMENTE O CHECK.
$("#txtchecar").click(function(){
    if(document.getElementById("checkcontrato").checked == false){
        $('#checkcontrato').attr('checked', true);
    }else{
         $('#checkcontrato').attr('checked', false);
    }
});


$("#fechar_flash").click(function(){
    $("#boxflash").html("");
    $("#boxflash").css("display", "none");
});

$("#boxflash").mouseover(function(){
    $("#fechar_flash").css("display",'block');
    $("#fechar_flash").css("z-index",'21');
});

$("#boxflash").mouseout(function(){
    $("#fechar_flash").css("display",'none');
    $("#fechar_flash").css("z-index",'19');
});

$("#btnapresentacaovideo").click(function(){
    
    $.post("/exibirVideoapresentacao.php",
                    {
                            produto:$("#idproduto").val()
                    },
                    function(valor)
                    {
                            $("#video-curso-perfil").html(valor);
                    }
    )

});

$("#formloginafiliado").submit(function(){
    
    if($("#email_afiliado").val() == ""){
        alert('Digite o e-mail');
        $("#email_afiliado").focus();
        return false;
    }
    
    if($("#senhal_afiliado").val() == ""){
        alert('Digite a senha');
        $("#senhal_afiliado").focus();
        return false;
    }
    
})

$("#formcadastroemail").submit(function(){
    
    if($("#email_cadsimples").val() == ""){
        alert('Por favor, digite um E-MAIL');
        $("#email_cadsimples").focus();
        return false;
    }
    
    email = $("#email_cadsimples").val();
    er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;

    if(er.exec(email))
        {
          return true;
        } else {
          alert('E-mail Inválido!');
          $("#email_cadsimples").focus();
          return false;
    }
    
    return true;
    
})

$("#btndemonstracaovideo").click(function(){

    $.post("/exibirVideodemonstracao.php",
                    {
                            produto:$("#idproduto").val()
                    },
                    function(valor)
                    {
                            $("#video-curso-perfil").html(valor);
                    }
    )

});

$("#btnapresentacaosimulado").click(function(){

    $.post("/exibirapresentacaoSimulado.php",
                    {
                            produto:$("#idproduto").val()
                    },
                    function(valor)
                    {
                            $("#video-curso-perfil").html(valor);
                    }
    )

});

$("#btndemonstracaosimulado").click(function(){

    $.post("/exibirdemonstracaoSimulado.php",
                    {
                            produto:$("#idproduto").val()
                    },
                    function(valor)
                    {
                            $("#video-curso-perfil").html(valor);
                    }
    )

});

//FUNÇÃO DE CHAMADA DO LIGHTBOX DA INDICAÇÃO DO AMIGO
//

$("#depoimentos-conteudo").jCarouselLite({
			btnNext: "#direita",
			btnPrev: "#esquerda",
			circular: false,
			visible: 1,
			scroll:1
});

$("#ver_todos_institu").click(function(){

   $.post("/exibirTodasinstituicoes.php",
                    function(valor)
                    {
                            $("#busca_instituicoes_result").html(valor); //select recebe o valor dos produtos
                    })

});

//FAZENDO O CONTROLE DE EXIBIÇÃO DA SETA DO CARROUSEL DA PÁGINA video-aulas.php
$(".lista-proximo").click(function(){

    //OBTENDO O id DA CATEGORIA
    config_id = this.id;
    quebra_id = config_id.split("-");
    id = quebra_id[2];

    //OBTENDO OS VALORES DOS inputs DESTA CATEGORIA
    total_itens = parseInt($("#total_itens"+id).val());
    itens_cat = parseInt($("#itens_cat_"+id).val());
    itens_cat += 1;
    
    if(itens_cat == total_itens){
        $("#img-right-"+id).css("display","none");
        $("#lista-proximo-"+id).css("display","none");
        $("#itens_cat_"+id).val(itens_cat);
    }else{
        $("#itens_cat_"+id).val(itens_cat);
    }

    if(itens_cat > 3){
        $("#img-left-"+id).css("display","block");
        $("#lista-anterior-"+id).css("display","block");
    }else{
        $("#img-left-"+id).css("display","none");
        $("#lista-anterior-"+id).css("display","none");
    }

});

//FAZENDO O CONTROLE DE EXIBIÇÃO DA SETA DO CARROUSEL DA PÁGINA video-aulas.php
$(".lista-anterior").click(function(){

    //OBTENDO O id DA CATEGORIA
    config_id = this.id;
    quebra_id = config_id.split("-");
    id = quebra_id[2];

    //OBTENDO OS VALORES DOS inputs DESTA CATEGORIA
    total_itens = parseInt($("#total_itens"+id).val());
    itens_cat = parseInt($("#itens_cat_"+id).val());
    itens_cat -= 1;
    
    if(itens_cat == 3){
        $("#img-left-"+id).css("display","none");
        $("#lista-anterior-"+id).css("display","none");
        $("#itens_cat_"+id).val(itens_cat);
    }else{
        $("#itens_cat_"+id).val(itens_cat);
        $("#img-left-"+id).css("display","block");
        $("#lista-anterior-"+id).css("display","block");
    }

    if(itens_cat != total_itens){
        $("#img-right-"+id).css("display","block");
        $("#lista-proximo-"+id).css("display","block");
    }

});



$('a[name=modal]').click(function(e) {
        e.preventDefault();

        var id = $(this).attr('href');

        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $('#mask').css({'width':maskWidth,'height':maskHeight});

        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow",0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);

        $(id).fadeIn(2000);

});

$("#busca-orgao").keyup(function(){

    $.post("/listarInstituicoes.php",
                    {
                            orgao:$("#busca-orgao").val()
                    },
                    function(valor)
                    {
                            $("#busca_instituicoes_result").html(valor); //select recebe o valor dos produtos
                    }
    )
        
});

$('.window .close').click(function (e) {
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
});

$('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
});

//FUNÇÃO QUE CHAMA O SLIDER DO DESTAQUE
$('#slider').nivoSlider({
    effect:'fade',
    animSpeed:500,
    pauseTime:2000 // Velocidade de rotação dos banners da home

});


$("#btn_fecharaba").click(fecharAba);


$("#btn_abriraba").click(abrirAba);


$("#email_cadastro").blur(function(){

        $.post("/veririficarEmail.php",
                    {
                            email:$("#email_cadastro").val()
                    },
                    function(valor)
                    {
                            $("#validacao_email").html(valor); //select recebe o valor dos produtos
                    }
               )

});


$(".aba-interna:first").show();

//ABAS
$("#art-mat-com #abas ul li a").click(function(){
   $(".aba-interna").hide();
   var div = $(this).attr('href');
   $(div).show();
   return false;

});


$(".adicionar-a-sacola-pacote").click(function(){

    //OBTENDO O id DO PRODUTO
    id_imagem = this.id;

    //RETORNANDO O VALOR SOMENTE DO id DO PRODUTO
    var quebra_id = id_imagem.split("_");

    //ID DO PRODUTO
    id_pacote = quebra_id[1];

    config_preco = $("#pacote_"+id_pacote).val();
    var quebra_preco = config_preco.split("-");
    preco_final = quebra_preco[1];
    pacote = quebra_preco[0];

    abrirAba()

    $.post("/carregarPacotesaba.php",
                    {
                            pacote:pacote,
                            preco_final:preco_final
                    },
                    function(valor)
                    {
                            $("#contet_abarodape").html(valor); //select recebe o valor dos produtos
                    }
    )

})


//FUNÇÃO PARA ADICIONAR EM AJAX O PRODUTO NA ABA
$(".adicionar-a-sacola").click(function(){

    //OBTENDO O id DO PRODUTO
    id_imagem = this.id;

    //RETORNANDO O VALOR SOMENTE DO id DO PRODUTO
    var quebra_id = id_imagem.split("_");

    //ID DO PRODUTO
    id_produto = quebra_id[1];

    abrirAba()

    $.post("/carregarProdutosaba.php",
                    {
                            produto:$("#produto_"+id_produto).val()
                    },
                    function(valor)
                    {
                            $("#contet_abarodape").html(valor); //select recebe o valor dos produtos
                    }
    )

//    $.post("atualizarItens.php",
//
//                    function(valor)
//                    {
//                            $(".itens_rodape").html(valor);
//                    }
//    )
//
//    $.post("atualizarValor.php",
//
//                    function(valor)
//                    {
//                            $(".preco_rodape").html(valor);
//                    }
//    )


});

$("#conteudo-lista").jCarouselLite({
    btnNext: "#anterior",
    btnPrev: "#proximo",
    circular: true,
    visible: 5,
    scroll: 2,
    auto: 4500 //Aqui altera a velocidade da rotação, quanto maior o valor, mais lento.
});


$(".video-aulas").jCarouselLite({
    btnNext: ".lista-proximo",
    btnPrev: ".lista-anterior",
    circular: false,
    visible: 3,
    scroll:5
});


////LIMPA A BUSCA DE ÓRGÃOS
//$("#busca-orgao").focus(function(){
//        valor = $("#busca-orgao").val();
//        if(valor == "Buscar"){
//                $("#busca-orgao").val("");
//        }
//});
//
////COLOCA O VALOR DE NOVO NO CAMPO
//$("#busca-orgao").blur(function(){
//        valor = $("#busca-orgao").val();
//        if(valor == ""){
//                $("#busca-orgao").val("Buscar");
//        }
//});



function fecharAba(){
    $("#aba_compras").hide("slow");
    $("#rodape").css("padding", "0 0 0px 0");
    $("#rodape").css("background-image", "/images/fundo_rodape2.png");
}

function abrirAba(){
    $("#aba_compras").show("slow");
    $("#aba_compras").css("z-index",'2000');
    $("#aba_compras").css("position",'fixed');
    $("#rodape").css("padding", "0 0 80px 0");
    $("#rodape").css("background-image", "/images/rodape2.png");
}

//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.titulo-videos').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.titulo-videos').removeClass('menos');

		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.slide-videos').slideUp('normal');

		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {

			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('menos');

			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 }

	 });

	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/
	$('.slide-videos').hide();

    $("#combo-estado").change(function(){
                  $("#combo-cidade").html('Carregando...');
                  $.post("/exibirCidades.php",
                                    {
                                            estado:$(this).val()
                                    },
                                    function(valor)
                                    {
                                            $("#combo-cidade").html(valor); //select recebe o valor dos produtos
                                    }
                   )
    });

//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href');
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
        $('#mask').css("z-index",'100')
        //transition effect
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow",0.8);
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top',  (winH/2-$(id).height()/2) - 70);
        $(id).css('left', winW/2-$(id).width()/2);
        //transition effect
        $(id).fadeIn(2000);
});

//if close button is clicked
$('.window .close').click(function (e) {
    //Cancel the link behavior
    e.preventDefault();
    $('#mask').hide();
    $('.window').hide();
});

//if mask is clicked
$('#mask').click(function () {
    $(this).hide();
    $('.window').hide();
});


//
//FUNÇÃO QUE CHAMA O MENU ACCORDION
//

	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');

		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');

		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {

			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');

			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 }

	 });


	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/

	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');

	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');
	});

	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/


	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/
	$('.accordionContent').hide();


//
//FUNÇÃO DAS ABAS DOS VIDEOS
//
        $(".aba:first").show();

        $("#nav-aba a").click(function(){
           $(".aba").hide();
           var div = $(this).attr('href');
           $(div).show();
           return false;
        });

//
//FUNÇÃO QUE LIMPA OS CAMPOS AO CLICAR
//


	//VERIFICA O PREENCHIMENTO DO E-MAIL NA CAMPANHA DO MPE(APOSTILA)
	$("#emailcampanha").blur(function(){
		valor = $("#emailcampanha").val();
		if(valor == ""){
			$("#emailcampanha").val("Digite seu e-mail");
		}
	});

        //VERIFICA O PREENCHIMENTO DO E-MAIL NA CAMPANHA DO MPE(APOSTILA)
	$("#emailcampanha").focus(function(){
		valor = $("#emailcampanha").val();
		if(valor == "Digite seu e-mail"){
			$("#emailcampanha").val("");
		}
	});

	//LIMPA O NOME DO LOGIN
	$("#nome-login").focus(function(){
		valor = $("#nome-login").val();
		if(valor == "E-mail"){
			$("#nome-login").val("");
		}
	});

	//COLOCA O VALOR DE NOVO NO CAMPO
	$("#nome-login").blur(function(){
		valor = $("#nome-login").val();
		if(valor == ""){
			$("#nome-login").val("E-mail");
		}
	});

	//LIMPA O NOME DO LOGIN
	$("#login-login").focus(function(){
		valor = $("#login-login").val();
		if(valor == "Senha"){
			$("#login-login").val("");
		}
	});

	//COLOCA O VALOR DE NOVO NO CAMPO
	$("#login-login").blur(function(){
		valor = $("#login-login").val();
		if(valor == ""){
			$("#login-login").val("Senha");
		}
	});

	//LIMPA O NOME DA NEWSLETTER
	$("#nome-newsletter").focus(function(){
		valor = $("#nome-newsletter").val();
		if(valor == "Seu nome"){
			$("#nome-newsletter").val("");
		}
	});

	//COLOCA O VALOR DE NOVO NO CAMPO DA NEWSLETTER
	$("#nome-newsletter").blur(function(){
		valor = $("#nome-newsletter").val();
		if(valor == ""){
			$("#nome-newsletter").val("Seu nome");
		}
	});

	//LIMPA O NOME DO LOGIN
	$("#email-newsletter").focus(function(){
		valor = $("#email-newsletter").val();
		if(valor == "Seu e-mail"){
			$("#email-newsletter").val("");
		}
	});

	//COLOCA O VALOR DE NOVO NO CAMPO
	$("#email-newsletter").blur(function(){
		valor = $("#email-newsletter").val();
		if(valor == ""){
			$("#email-newsletter").val("Seu e-mail");
		}
	});

        $("#formnewsletter").submit(function(){

                if($("input[name=nome-newsletter]").val() == "Seu nome" || $("input[name=nome-newsletter]").val() == ""){
                    alert('ATENCAO. Entre com o campo NOME.');
                    $("input[name=nome-newsletter]").focus()
                    return false;
                }

                if($("input[name=e-mail-newsletter]").val() == "Seu e-mail" || $("input[name=e-mail-newsletter]").val() == ""){
                    alert('ATENCAO. Entre com o campo E-MAIL.');
                    $("input[name=e-mail-newsletter]").focus()
                    return false;
                }

                email = $("input[name=e-mail-newsletter]").val();
                er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;

                if(er.exec(email))
                    {
                      return true;
                    } else {
                      alert('ATENÇÃO. E-mail INVÁLIDO');
                      $("input[name=e-mail-newsletter]").focus();
                      return false;
                }

                return true;

	});

        $("#formduvidas").submit(function(){

                if($("#duvida_nome").val() == ""){
                    alert('ATENCAO. Entre com o campo NOME.');
                    $("#duvida_nome").focus();
                    return false;
                }

                if($("#duvida_email").val() == ""){
                    alert('ATENCAO. Entre com o campo E-MAIL.');
                    $("#duvida_email").focus();
                    return false;
                }

                if($("#duvida_mensagem").val() == ""){
                    alert('ATENCAO. Entre com o campo MENSAGEM.');
                    $("#duvida_mensagem").focus();
                    return false;
                }

                email = $("#duvida_email").val();
                er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;

                if(er.exec(email))
                    {
                      return true;
                    } else {
                      alert('ATENÇÃO. E-mail INVÁLIDO');
                      $("#duvida_email").focus();
                      return false;
                }

                return true;

        })

        $("#formcontato").submit(function(){

                if($("#contato_nome").val() == ""){
                    alert('ATENCAO. Entre com o campo NOME.');
                    $("#contato_nome").focus();
                    return false;
                }

                if($("#contato_email").val() == ""){
                    alert('ATENCAO. Entre com o campo E-MAIL.');
                    $("#contato_email").focus();
                    return false;
                }
				
				if($("#contato_telefone").val() == ""){
                    alert('ATENCAO. Entre com o campo TELEFONE.');
                    $("#contato_telefone").focus();
                    return false;
                }

                if($("#contato_assunto").val() == ""){
                    alert('ATENCAO. Entre com o campo ASSUNTO.');
                    $("#contato_assunto").focus();
                    return false;
                }

                if($("#contato_mensagem").val() == ""){
                    alert('ATENCAO. Entre com o campo MENSAGEM.');
                    $("#contato_mensagem").focus();
                    return false;
                }

                email = $("#contato_email").val();
                er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;

                if(er.exec(email))
                    {
                      return true;
                    } else {
                      alert('ATENÇÃO. E-mail INVÁLIDO');
                      $("#contato_email").focus();
                      return false;
                }


        })

        

});


/**************************************************
*** VALIDA EMAIL
***************************************************/
function validaEmail(email) {
	//Checando se o endereço de e-mail é válido
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
		return false;
	}else{
		return true;
	}
}

/**************************************************
*** VALIDA EMAIL
***************************************************/
function validaCPF(cpf){
	var valido = true;
	var CPF = "";

	CPF = cpf.substr(0,3);
	CPF = CPF+cpf.substr(4,3);
	CPF = CPF+cpf.substr(8,3);
	CPF = CPF+cpf.substr(12,2);

	// Aqui começa a checagem do CPF
	var POSICAO, I, SOMA, DV, DV_INFORMADO;
	var DIGITO = new Array(10);
	DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado

	// Desemembra o número do CPF na array DIGITO
	for (I=0; I<=8; I++) {
	  DIGITO[I] = CPF.substr( I, 1);
	}

	// Calcula o valor do 10º dígito da verificação
	POSICAO = 10;
	SOMA = 0;

	for (I=0; I<=8; I++) {
	  SOMA = SOMA + DIGITO[I] * POSICAO;
	  POSICAO = POSICAO - 1;
	}

	DIGITO[9] = SOMA % 11;

	if (DIGITO[9] < 2) {
	   DIGITO[9] = 0;
	}else{
	   DIGITO[9] = 11 - DIGITO[9];
	}

	// Calcula o valor do 11º dígito da verificação
	POSICAO = 11;
	SOMA = 0;

	for (I=0; I<=9; I++) {
	  SOMA = SOMA + DIGITO[I] * POSICAO;
	  POSICAO = POSICAO - 1;
    }

	DIGITO[10] = SOMA % 11;
    if (DIGITO[10] < 2) {
		DIGITO[10] = 0;
    }else {
		DIGITO[10] = 11 - DIGITO[10];
    }

	// Verifica se os valores dos dígitos verificadores conferem
	DV = DIGITO[9] * 10 + DIGITO[10];
	if (DV != DV_INFORMADO) {
		CPF = '';
		valido = false
	}

     if(valido){
		return true;
	 }else{
		alert('CPF inválido');
	 }
}

function verificaNumero(e) {
    if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        return false;
    }
}

function excluir_carrinho(id_carrinho){

    $.post("/excluirItemcarrinho.php",
                    {
                            id_carrinho:id_carrinho
                    },
                    function(valor)
                    {
                            $("#contet_abarodape").html(valor);
                    }
    )
}

function excluir_carrinho_pacote(id_pacote){
    $.post("/excluirItemcarrinho.php",
                    {
                            pacote:id_pacote
                    },
                    function(valor)
                    {
                            $("#contet_abarodape").html(valor);
                    }
    )
}

function finalizar_pedido(valor_total){
    var pergunta;
    pergunta = confirm('DESEJA REALMENTE FINALIZAR A SUA COMPRA?');
    if(pergunta == true){
        window.location.href="/config/finalizarPedido.php?valor_total=" + valor_total;
    }
}

/**************************************************
*** SOMENTE NUMEROS
***************************************************/
function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
	if(tecla > 47 && tecla < 58){
		return true;
	}else{
		if(tecla == 8 || tecla == 0){
			return true;
		}else{
			return false;
		}
	}
}

/**************************************************
*** Máscaras de dados para textfields
***************************************************/
function Mascara(tipo, campo, teclaPress) {
	if (window.event){
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}

	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
	tam = s.length + 1;


	if (tecla != 9 && tecla != 8) {
		if(SomenteNumero(teclaPress)){
				switch (tipo){

				case 'CPF' :
					if (tam > 3 && tam < 7)
						campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
					if (tam >= 7 && tam < 10)
						campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
					if (tam >= 10 && tam < 13)
						campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
				break;

				case 'CNPJ' :

					if (tam > 2 && tam < 6)
						campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
					if (tam >= 6 && tam < 9)
						campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
					if (tam >= 9 && tam < 13)
						campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
					if (tam >= 13 && tam < 15)
						campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
				break;

				case 'CEP' :
					if (tam > 5 && tam < 9)
						campo.value = s.substr(0,5) + '-' + s.substr(5,tam);
				break;

				case 'TEL' :
					if (tam > 2 && tam < 4)
						campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
					if (tam >= 7 && tam < 11)
						campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
				break;

				case 'DATA' :
					if (tam > 2 && tam < 4)
						campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
					if (tam > 4 && tam < 11)
						campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
				break;
			}
		}else{
			return false;
		}
	}
}

function excluir_produto_sacola(id_carrinho){
    var pergunta;
    pergunta = confirm("Deseja realmente excluir?");
    if(pergunta == true){
        window.location.href="/config/excluir_item_sacola.php?id_carrinho=" + id_carrinho;
    }
}

function excluir_pacote_sacola(id_pacote){
    var pergunta;
    pergunta = confirm("Deseja realmente excluir?");
    if(pergunta == true){
        window.location.href="/config/excluir_item_sacola.php?pacote=" + id_pacote;
    }
}


//
//TOOLTIP COM VIDEO DO YOUTUBE
//

   // Use each method to gain access to all youtube links
   $('a[name="video"]').each(function()
   {
	  // Grab video ID from the url
	  var videoID = $(this).attr('href').match(/watch\?v=(.+)+/);
	  videoID = videoID[1];

	  // Create content using url as base
	  $(this).qtip(
	  {
		 // Create content DIV with unique ID for swfObject replacement
		 content: '<div id="youtube-embed-'+videoID+'">You need Flash player 8+ to view this video.</div>',
		 position: {
			corner: {
			   tooltip: 'bottomMiddle', // ...and position it center of the screen
			   target: 'topMiddle' // ...and position it center of the screen
			}
		 },
		 show: {
			when: 'click', // Show it on click...
			solo: true // ...and hide all others when its shown
		 },
		 hide: 'unfocus', // Hide it when inactive...
		 style: {
			width: 432,
			height: 264,
			padding: 0,
			tip: true,
			name: 'dark'
		 },
		 api: {
			onRender: function()
			{
			   // Setup video paramters
			   var params = {allowScriptAccess: 'always', allowfullScreen: 'false'};
			   var attrs = {id: 'youtube-video-'+videoID};

			   // Embed the youtube video using SWFObject script
			   swfobject.embedSWF('http://www.youtube.com/v/'+videoID+'&enablejsapi=1&playerapiid=youtube-api-'+videoID,
								 'youtube-embed-'+videoID, '425', '264', '8', null, null, params, attrs);
			},

			onHide: function(){
			   // Pause the vide when hidden
			   var playerAPI = this.elements.content.find('#youtube-video-'+videoID).get(0);
			   if(playerAPI && playerAPI.pauseVideo) playerAPI.pauseVideo();
			}
		 }
	  }
	  ).attr('href', '#video');
   });

function abrir_contrato(){
    window.open('/contrato.php?id_categoria=12','page','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=750,height=450');
}


function mostrarDiv() {
	//$('#teste').show();
        //$('#tudo_conteudo').fadeIn(500);

        //CSS PARA O Internet Explorer
        var browser = navigator.appName;
        
        if(navigator.appName == 'Microsoft Internet Explorer'){
            $('#tudo_conteudo').css("top",'0px');
        }
        
        $('#tudo_conteudo').fadeIn(1000);
        //$('#tudo_conteudo').show("slow");
        $('#loginlightbox').fadeIn(1000);
        //$("#aba_compras").show("slow");
	$('#fechar').hide();
}



function fecharDiv() {
	$('#loginlightbox').hide();
        $('#tudo_conteudo').fadeOut(1200);
	//$('#tudo_conteudo').hide("slow");
	$('#fechar').show();
}

function mostrarContato() {
	$('.caixa_contato').show("slow");
	//$('.caixa_contato').show();
	//$('.caixa_contato').show();
}

function fecharContato() {
	$('.caixa_contato').hide("slow");	
}

