﻿npPags = {};
npPags.Config = {};

npPags.Topo = {
    img: function(){
        ValidarPng();
    },
    menu: function(){
        
        limpaTexto("#txtBusca","Buscar",'#898989');
        
        $(".filho ul li").hover(
            function(){
                if(this.innerHTML.indexOf('filho_dir') == -1)
                    this.style.backgroundColor = '#4f97dc';
            },
            function(){
                if(this.innerHTML.indexOf('filho_dir') == -1)
                    this.style.backgroundColor = '';
            }
        );
        
        obj_abaixo = $('.flash_curso_int');
        obj_sobre = $('#escondeDdl');
        var navegadorIE = navigator.appVersion.split("MSIE")[1];       
                
        $("li[id*='mn_']").hover(
            function(){
                animaMenu(this,"on");   
                /* erro do ie com ddl e div */
                if(navegadorIE != null && obj_abaixo.get(0) != null && obj_sobre.get(0) != null)
                {
                    var i = parseInt(this.id.substring(3,4));
                    if (i >= 1 && i <= 3)
                    {
                        obj_sobre.css('height', obj_abaixo.get(0).offsetHeight + 'px'); 
                        obj_sobre.css('width', (obj_abaixo.get(0).offsetWidth ) + 'px'); 
                        obj_sobre.show();
                    }
                }                        
            },
            function(){
                animaMenu(this,"off");  
                /* erro do ie com ddl e div */
                if(navegadorIE != null && obj_abaixo.get(0) != null && obj_sobre.get(0) != null)
                {
                    var i = parseInt(this.id.substring(3,4));
                    if (i >= 1 && i <= 3)
                    {
                        obj_sobre.hide();              
                        obj_abaixo.show();
                    }
                }
            }
        );
    },
    data : function(){
       topoLabels();
    }
};

npPags.Rodape = {
    init: function(){
        var obj_divsRodape = $('.rodape_Inferior ul li div');
        var altura = 0;
        obj_divsRodape.each(function(){
               if(this.offsetHeight > altura)
                    altura = this.offsetHeight;
        });
        $('.separador_rodape').css('height',(altura + 10) + 'px');
    }
};

npPags.FlashDestaque = {
    init: function (){
        
        /*carregaFlash('flash_destaque','flashPrincipal',
        npPags.Config.ApplicationPath + 'flash/destaque/destaque_full.swf', 740, 185, "opaque");*/

        carregaFlash('flash_destaque', 'flashPrincipal',
        npPags.Config.ApplicationPath + 'banner.swf', 740, 185, "opaque");
        
    }
};

npPags.Rollover = {
    init: function (){
        rollover();  
    }
};

npPags.Login = {
    init: function() {
        limpaTexto("input[id$=txtLogin]", "RA", '#C9C9C9');
        limpaTexto("input[id$=txtReenvioSenha_Email]", "Informe seu e-mail", '#C9C9C9');

        // Função que abre o div de reenvio de senha.
        $('span[id$=linkEsqueciMinhaSenha]').click(function() {
            var obj = $('div[id*=divEsqueciMinhaSenha]');
            if (obj.get(0).style.display == 'block')
                obj.get(0).style.display = 'none'
            else
                obj.get(0).style.display = 'block'
        });
    },
    // Função criada para testar solução do preenchimento do txtLogin com o texto "RA ou e-mail", pois mesmo recompi-
    // lando a aplicação o textbox assume o mesmo valor.
    DivReenvioSenha: function() {
        limpaTexto("input[id$=txtLogin]", "RA", '#C9C9C9');
        limpaTexto("input[id$=txtReenvioSenha_Email]", "Informe seu e-mail", '#C9C9C9');
        alert('teste limpatexto');
        // Função que abre o div de reenvio de senha.
        $('span[id$=linkEsqueciMinhaSenha]').click(function() {
            var obj = $('div[id*=divEsqueciMinhaSenha]');
            if (obj.get(0).style.display == 'block')
                obj.get(0).style.display = 'none'
            else
                obj.get(0).style.display = 'block'
        });
    },
    confirmacao: function() {
        limpaTexto("input[id$=txtEmail_ReenvioRegistro]", "Informe seu e-mail", '#C9C9C9');
        $('span[id$=lbtnReenviarRegistroAutenticacao]').click(function() {
            var obj = $('#boxReenviarRegistroAutenticacao');
            if (obj.get(0).style.display == 'block')
                obj.get(0).style.display = 'none'
            else
                obj.get(0).style.display = 'block'
        });
    },
    Logar: function() {
        var obj_login = $("input[id$=txtLogin]");
        var obj_senha = $("input[id$=txtSenha]");

        PageMethods.Logar(obj_login.get(0).value, obj_senha.get(0).value
                          , npPags.Login.LogarReturnSucced
                          , npPags.Login.WebMethodReturnError);
    },
    ReenvioSenha: function() {
        var obj_reenvioSenha = $("input[id$=txtReenvioSenha_Email]");

        PageMethods.ReenvioSenha(obj_reenvioSenha.get(0).value
                                , npPags.Login.ReenvioSenhaReturnOk
                                , npPags.Login.WebMethodReturnError);

    },
    /*Erro WebMethod padrao : imprime a exceção*/
    WebMethodReturnError: function(result) {
        if (result != null && result != 'undefined' && result.get_message() != '')
            alert(result.get_message());
    },
    /*sucesso WebMethod padrao : imrpime o retorno*/
    WebMethodReturnOk: function(result) {
        if (result != null && result != 'undefined')
            alert(result);
    },
    LogarReturnSucced: function(result) {
        if (result != null && result != 'undefined')
            location.href = '../Index.aspx';
    },
    ReenvioSenhaReturnOk: function(result) {
        if (result != null && result != 'undefined') {
            if (result.indexOf("true.") > -1) {
                $('#divEsqueciMinhaSenha').hide();
                $("input[id$=txtReenvioSenha_Email]").get(0).value = "";
                alert(result.replace("true.", ""));
            }
            else if (result.indexOf("false.") > -1) {
                alert(result.replace("false.", ""));
            }
        }
    }
};

npPags.Chamadas = {
    conhecaanewton: function(id) {
        FadeImg(id, 0.80);
    },
    boxImg: function(altura, largura, vetorImgs) {
        boxImg('[id$=boxImg_img]', '[id$=boxImg_link]', '[id$=boxImg_setaDir]', '[id$=boxImg_setaEsq]', altura, largura, vetorImgs);
    },
    destaqueCurso: function(vetorAlturas) {
        var maior = 0;
        var maiorCima = 0;
        var maiorBaixo = 0;

        for (var i = 0; i < vetorAlturas.length; i++) {
            var aux = $(vetorAlturas[i].id).get(0);
            if (i < (vetorAlturas.length + 1) / 2) {
                if (maiorCima < aux.offsetHeight)
                    maiorCima = aux.offsetHeight
            }
            else {
                if (maiorBaixo < aux.offsetHeight)
                    maiorBaixo = aux.offsetHeight
            }
        }

        $(".clearSeparadorV_DestaqueCurso_Cima").css('height', maiorCima + 'px');
        $(".clearSeparadorV_DestaqueCurso_Baixo").css('height', (maiorBaixo + 8) + 'px');

    },
    saibaMais_base: function() {
        var obj_box = $('.espaco_base_tamanho').get(0);
        if (obj_box != null)
            $('.clearSeparadorV_SaibaMais_Base').css('height', (obj_box.offsetHeight + 8) + 'px');
    },
    saibaMais_topo: function() {
        var obj_box = $('.espaco_topo_tamanho').get(0);
        if (obj_box != null)
            $('.clearSeparadorV_SaibaMais_Topo').css('height', (obj_box.offsetHeight + 8) + 'px');
    },
    AlturaDivs: function(divRecebe, vetorDivsRelacionado, acrecenta) {
        var maior = 0;

        for (var i = 0; i < vetorDivsRelacionado.length; i++) {
            var aux = $(vetorDivsRelacionado[i].id).get(0);
            if (maior < aux.offsetHeight)
                maior = aux.offsetHeight
        }

        $(divRecebe).css('height', (maior + (acrecenta)) + 'px');
    },
    exibeMenu: function(mn1, mn2, mn3, mn4, mn5, mn6) {
        if (!mn1)
            $('.filho_1').hide();
        if (!mn2)
            $('.filho_2').hide();
        if (!mn3)
            $('.filho_3').hide();
        if (!mn4)
            $('.filho_4').hide();
        if (!mn5)
            $('.filho_5').hide();
        if (!mn6)
            $('.filho_6').hide();
    },
    RodapeInterno_posicaoBox: function() {

        obj_box = $("#box_enviarNoticia");
        obj_chamaBox = $("img[id*='imgFecharBoxEncaminharNoticia']");

        obj_box.css({ 'left': '75px', 'top': '-305px' });

        obj_chamaBox.click(function() {
            npPags.Chamadas.RodapeInterno_abriFecharBox(false);
        });
    },
    RodapeInterno_posicaoBoxCurso: function() {
        npPags.Chamadas.RodapeInterno_posicaoBox();
        /*Enviar amigo - posicao diferente*/
        $("#box_enviarNoticia").css({ 'left': '90px', 'top': '-305px' });

        /*Info*/
        obj_box = $("#box_enviarInfo");
        obj_chamaBox = $("img[id*='imgFecharBoxEncaminharInfo']");

        obj_box.css({ 'left': '-75px', 'top': '-275px' });

        obj_chamaBox.click(function() {
            npPags.Chamadas.RodapeInterno_abriFecharBoxCurso(false);
        });

        $("input[id*='txtTelInfo']").setMask('(99)9999-9999');
        $("input[id*='txtTelCelular']").setMask('(99)9999-9999');
    },
    RodapeInterno_mensagem: function(msg) {
        alert(msg)
        npPags.Chamadas.RodapeInterno_abriFecharBox(false);
    },
    RodapeInterno_abriFecharBox: function(exibe) {
        obj_box = $("#box_enviarNoticia");
        if (exibe) {
            if (obj_box.get(0).style.display != 'block')
                obj_box.show("fast");
            else
                npPags.Chamadas.RodapeInterno_abriFecharBox(false);
        }
        else {
            $("input[id*='txtNomeRemetente']").get(0).value = "";
            $("input[id*='txtEmailRemetente']").get(0).value = "";
            $("input[id*='txtNomeDestinatario']").get(0).value = "";
            $("input[id*='txtEmailDestinatario']").get(0).value = "";
            obj_box.hide("fast");
        }
    },
    RodapeInterno_abriFecharBoxCurso: function(exibe) {
        obj_box = $("#box_enviarInfo");
        if (exibe) {
            if (obj_box.get(0).style.display != 'block')
                obj_box.show("fast");
            else
                npPags.Chamadas.RodapeInterno_abriFecharBoxCurso(false);
        }
        else {
            $("input[id*='txtNomeInfo']").get(0).value = "";
            $("input[id*='txtEmailInfo']").get(0).value = "";
            $("input[id*='txtTelInfo']").get(0).value = "";
            $("input[id*='txtTelCelular']").get(0).value = "";
            obj_box.hide("fast");
        }
    }
};

npPags.Default = {
    init: function (id){
        setarTamanho("#separadorV_novidade","#boxAbaixoPrincipal",0.05,0.05);
        setarTamanho("#novidade_cen","#divNovidade",0.05,0);
        
        $('.conteudo').css({
            'background-color':'white', 
            'background-image':'url('+ npPags.Config.ApplicationPath + 'App_Themes/estiloPadrao/img/controles/conteudo_bg.jpg)',
            'background-repeat':'repeat-x',
            'background-position': '0px 4px'
        });
    }
};

npPags.Conteudo = {
    init: function (qtd){
        subMenuConteudo(qtd);
    }
};


npPags.Extensao = {
    init: function (){
        $('.ddl_e').change(function(){
            window.location.replace("Default.aspx?e=" + this.value); 
        });
        
        $('.ddl_c').change(function(){
            window.location.replace(npPags.Config.ApplicationPath + "cursos/Curso.aspx?cID=" + this.value); 
        });
    }
};


npPags.Curso = {
    init: function (){
        var obj_li = $('.curso_int_menu li');
        
        /*ativa primeira aba*/
        subMenuInternoCurso(obj_li.get(0),"on",aberto);
        var aberto = 1;
        
        /*ativa o hover no menu*/
        obj_li.hover(function(){
            subMenuInternoCurso(this,"on",aberto);
        },
        function(){
            subMenuInternoCurso(this,"off",aberto);
        });
        
        /*ativa o click no*/
        obj_li.click(function(){        
            var id = this.id.substring(this.id.length-1);
            if(aberto != id)
            {
                var ultimo_aberto = aberto;
                /*atualiza o estado do aberto*/
                subMenuInternoCurso(this,"on",aberto);
                aberto = id;
                subMenuInternoCurso_fechar(ultimo_aberto);
                
                var obj_div = $('.div_int')
                for (var i = 0; i<= obj_div.length;i++)
                {   
                    if((i+1) != id)
                        $("div[id*='div_int_"+ (i+1) + "']").hide();
                    else
                        $("div[id*='div_int_"+ (i+1) + "']").show();      
                }
            }
        });
        
        /*verifica tamanho do topo interno*/
        var obj_topo = $('.titulo_int_cen');
        var obj_topo_int = $('.div_titulo_int');
        //obj_topo.css('height',obj_topo_int.get(0).offsetHeight + 'px');
        
    },
   saibaMais: function (){
        $('.ddl_c').change(function(){
            window.location.replace("Curso.aspx?cID=" + this.value); 
        });        
   }, 
   habilitaMenuInterno: function( mn2 , mn3 , mn4 , mn5 , mn6){
        if (mn2 == 0)
            $("#curso_int_menu_esq_2 , #curso_int_menu_cen_2 , #curso_int_menu_dir_2").hide();    
        if (mn3 == 0)
            $("#curso_int_menu_esq_3 , #curso_int_menu_cen_3 , #curso_int_menu_dir_3").hide();    
        if (mn4 == 0)
            $("#curso_int_menu_esq_4 , #curso_int_menu_cen_4 , #curso_int_menu_dir_4").hide();    
        if (mn5 == 0)
            $("#curso_int_menu_esq_5 , #curso_int_menu_cen_5 , #curso_int_menu_dir_5").hide();    
        if (mn6 == 0)
            $("#curso_int_menu_esq_6 , #curso_int_menu_cen_6 , #curso_int_menu_dir_6").hide();    
   }
};

npPags.NewtonPraVoce = {
    init: function (flash , googleMaps){
       if(flash != null)
          carregaFlash('flash_unidade','id_flash_unidade','tourVirtual.swf?unidade=' + flash,495,200,"transparent");
       
       if(googleMaps != null)
       {
          var mapa = CriarMapa('googleMaps',0,0,13); 
          var gMapsSimple = new GoogleMapsSimple(mapa); 
          gMapsSimple.adicionarMarcador_doEndereco(googleMaps);
       }
    }
};

npPags.Servico = {
    cadastro_Init: function(ddlPerfilId, divRaSenhaId) {
        var obj = $('#' + divRaSenhaId);
        $('#' + ddlPerfilId).change(function() {
            if (this.value == '2' || this.value == '4')
                obj.show();
            else {
                obj.hide();
                $("input[id*='txtRaAlunoColaborador']").get(0).value = "";
                $("input[id*='txtSenhaAlunoColaborador']").get(0).value = "";
            }
        });

        $("input[id$=ibtnCancelar]").click(function() {
            location.href = '../meuEspaco/Default.aspx'; return false;
        });
    },
    cadastroDefault: function() {
        /*Mascaras*/
        $('input[id*="txtCpf"]').setMask('cpf');
        $('input[id*="txtCep"]').setMask('cep');
        $('input[id*="txtData"]').setMask('date');
        $('input[id*="txtTelF"]').setMask('phone');
        $('input[id*="txtTelC"]').setMask('phone');
        $('input[id*="txtNumero"]').setMask('999999999');

        /*ddlPerfil*/
        $('.ddlPerfil').change(function() {
            if (this[this.value].innerText == "Aluno" || this[this.value].innerText == "Colaborador") {
                var novaJanela = window.open("BuscaDadosAcademico.aspx?tipo=" + this.value, "wndModal", "width=300,height=200,resizable=no");
                novaJanela.focus();
            }
        });

        /*ToolTips*/
        $('.jTip').hover(function() { this.style.borderColor = '#0067AE'; }, function() { this.style.borderColor = '#F8F8F8'; });
        var jtip_perfil, jtip_email, jtip_senhaAtual, jtip_senha, jtip_csenha, jtip_data, jtip_cpf = "";

        jtip_perfil = "<p>Selecione o perfil que você pertence.</p>";
        $("#jtip_perfil")
	           .hover(function() { JT_show("200", jtip_perfil, this.id, "Ajuda no preenchimento") }, function() { $('#JT').remove() });

        jtip_email = "<p>Pontos e Hífens não podem iniciar nem terminar o email.</p>";
        $("#jtip_email")
	           .hover(function() { JT_show("200", jtip_email, this.id, "Ajuda no preenchimento") }, function() { $('#JT').remove() });

        jtip_senhaAtual = "<p>Senha Atual do usuário.</p>";
        $("#jtip_senha")
	           .hover(function() { JT_show("200", jtip_senha, this.id, "Ajuda no preenchimento") }, function() { $('#JT').remove() });

        jtip_senha = "<p>É bom lembrar a senha deve ter de 5 a 10 caracteres, misturando letras e números.</p>";
        $("#jtip_senha")
	           .hover(function() { JT_show("200", jtip_senha, this.id, "Ajuda no preenchimento") }, function() { $('#JT').remove() });

        jtip_csenha = "<p>Confirmação da senha digitada no campo anterior.</p>";
        $("#jtip_csenha")
	           .hover(function() { JT_show("200", jtip_csenha, this.id, "Ajuda no preenchimento") }, function() { $('#JT').remove() });

        jtip_data = "<p>Digite aqui sua data de nascimento da seguinte forma: dia/mês/ano. <br/> Exemplo: 20/05/1981</p>";
        $("#jtip_data")
	           .hover(function() { JT_show("200", jtip_data, this.id, "Ajuda no preenchimento") }, function() { $('#JT').remove() });

        jtip_cpf = "<p>Digite só os números. Hífens, traços e espaços não são bem-vindos! </p>";
        $("#jtip_cpf")
	           .hover(function() { JT_show("200", jtip_cpf, this.id, "Ajuda no preenchimento") }, function() { $('#JT').remove() });

        $("#jtip_cep")
	           .hover(function() { JT_show("200", jtip_cpf, this.id, "Ajuda no preenchimento") }, function() { $('#JT').remove() });

    },
    retornoDefault: function(usu) {
        if (window.opener != null && !window.opener.closed) {
            var form1 = window.opener.document.getElementsByTagName("form")[0]
            /*popup alterando dados do parent*/
            form1.ctl00_ContentPlaceHolder1_txtNome.value = usu.nome;
            form1.ctl00_ContentPlaceHolder1_txtEmail.value = usu.email;
            if (usu.sexo == "F") {
                form1.ctl00_ContentPlaceHolder1_rbSexoF.checked = true;
                form1.ctl00_ContentPlaceHolder1_rbSexoM.checked = false;
            }
            else {
                form1.ctl00_ContentPlaceHolder1_rbSexoF.checked = false;
                form1.ctl00_ContentPlaceHolder1_rbSexoM.checked = true;
            }
            form1.ctl00_ContentPlaceHolder1_txtData.value = usu.data;
            form1.ctl00_ContentPlaceHolder1_txtCpf.value = usu.cpf;
            
            form1.ctl00_ContentPlaceHolder1_txtRa.value = usu.ra;
        }
        window.close();
    }
};

npPags.ResultadoVest = {
    init: function(ddlPerfilId, divRaSenhaId) {
        var obj = $('input[id*="btnLetra"]');
        obj.hover(
            function() { this.style.backgroundColor = '#D38E11'; },
            function() { this.style.backgroundColor = '#3770A0'; }
        );
    }
};