﻿/* *********************************************** */
//  Funções relacionadas ao carrinho
    function addLivro(CodLivro)
    {
        location.href = "../compras/?COD=" + CodLivro;
    }
    
    function validaQtde(OBJ)
    {
        var cQuantidade;
        cQuantidade = document.getElementById( OBJ );
        if( parseInt( cQuantidade.value ) <= 0 || cQuantidade.value == "" )
        {
            alert("A quantidade digitada é inválida.");
            cQuantidade.focus();
            return false;
        }
    }
    
    function validaCalculoFrete()
    {
        if( document.getElementById("ctl00_cph_txtCEP1").value == "" || document.getElementById("ctl00_cph_txtCEP2").value == "" )
        {
            alert("Informe corretamente seu CEP.");
            return false;
        }
    }

/* *********************************************** */
// Funções relacionadas ao busca rapida mini
    YAHOO.example.Colecoes = [
        ["Arte","0001"],
        ["Bíblia","0002"],
        ["Biografias","0003"],
        ["Comunicação","0004"],
        ["Coração de Jesus","0005"],
        ["Direito Canônico","0006"],
        ["Economia e Empresa","0007"],
        ["Educação","0008"],
        ["Filosofia","0009"],
        ["História","0010"],
        ["Jesuítas","0011"],
        ["Literatura","0012"],
        ["Literatura Infanto-Juvenil","0013"],
        ["Livros Didáticos","0014"],
        ["Magistério da Igreja","0015"],
        ["Multimídia","0016"],
        ["Diversos","0017"],
        ["Parapsicologia","0018"],
        ["Pastoral","0019"],
        ["Psicologia","0020"],
        ["Renovação Carismática","0021"],
        ["Revistas","0022"],
        ["Saúde","0023"],
        ["Sociologia e Política","0024"],
        ["Teologia","0025"],
        ["Vida Interior","0026"],
        ["Bioetica","0027"],
        ["Ecologia e meio ambiente","0028"]
    ];
    var clkBuscaRapidaMini = function(Type, Args)
    {
        location.href = "../livraria/?AR=" + Args[2][1];
    }
/* *********************************************** */
// Funções relacionadas ao cadastro

    function comparaSenhaAlteracao(src, args)
    {
        var _form = document.forms[0];
        var NovaSenha = _form.ctl00_cph_txtNovaSenha;
        var ConfirmeSenha = _form.ctl00_cph_txtConfirmeSenha;
        
        if( NovaSenha.value != ConfirmeSenha.value ) args.IsValid = false;
    }

    function validaCPF(src, args)
    {
        var _form = document.forms[0];
        var CPF   = _form.ctl00_cph_txtCPF;
        
        if( CPF.value != "" )
        {
            if( !isCpf(CPF.value) ) args.IsValid = false;
        }
    }


/* *********************************************** */
// Funções relacionadas a livraria
    
    
    
    function PaginarLivraria(P)
    {
        var URL;
        var Parametros;
        var Saida;
        var AUX;
        
        if( location.href.indexOf("?") != -1 )
        {
            URL = location.href.split("?");            
            Parametros = URL[1].split("&");
            Saida = "";
            for( AUX = 0; AUX <= Parametros.length-1; AUX++ )
            {
                if( Parametros[AUX].split("=")[0] != "P" ) Saida += Parametros[AUX] + "&";
            }
            Saida += "P="+ P ;
            location.href = URL[0] + "?"+ Saida;
        };
    }
    
    function ondeComprar(ISBN)
    {
        location.href = "../ondecomprar?COD=" + ISBN;
    }
    
    function AddTip(OBJ)
    {
        $(OBJ).ToolTip( { className: 'tooltipcapa', position: 'mouse', delay: 400 } );
    }
    
    function Avalia(NOTA)
    {
        var Retorno;
        var Ajax;
        var CodLivro = "LIV." + document.getElementById("ctl00_cph_hfCodLivro").value;

        Ajax = CriaAJAX();
        Ajax.onreadystatechange = function()
        {
            if( Ajax.readyState == 4 )
            {
                if( Ajax.status == 200 )
                {
                    Retorno = unescape(Ajax.responseText.replace(/\+/g," "));
                    document.getElementById("ctl00_cph_imgAvaliacaoClientes").src = "../imgs/img-avalia-"+ Retorno +".gif";
                };
            };
        }
		Ajax.open("GET", "../ajax/set-avaliacao.aspx?CodLivro=" + CodLivro +"&NOTA="+ NOTA +"&c=" + Math.random(), true);
		Ajax.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1" );
		Ajax.send( null );        
    }

    function habilitaFormOpine(COD)
    {
        window.open('comentario.aspx?COD='+ COD, '_comentario', 'width=400, height=500, left=10, top=10, scrollbars=yes');
    }

    function onOffDesavalie(OBJ)
    {
        var DESC  = document.getElementById("desc-nota");        
        if( OBJ.src.indexOf("off") != -1)
        {
            OBJ.src = "../imgs/desavaliar-on.gif";
            DESC.innerHTML = "Desavalie";
        }
        else
        {
            OBJ.src = "../imgs/desavaliar-off.gif";
            DESC.innerHTML = "";
        }
    }


    function selNota(NOTA)
    {
        var NOTAS = document.getElementById("avaliacao-notas");
        var DESC  = document.getElementById("desc-nota");
        NOTAS.src = "../imgs/img-avalia-"+ NOTA +".gif";
        switch(NOTA)
        {
            case 0:
                DESC.innerHTML = "";
                break;
            case 1:
                DESC.innerHTML = "Ruim";
                break;
            case 2:
                DESC.innerHTML = "Regular";
                break;
            case 3:
                DESC.innerHTML = "Bom";
                break;
            case 4:
                DESC.innerHTML = "Ótimo";
                break;
            case 5:
                DESC.innerHTML = "Excelente";
                break;
        }
    }

    function controleTamanhoFonteLivro(Acao)
    {
        var Intervalo  = 2;
        var Titulo     = document.getElementById("ctl00_cph_lblLivro_Titulo");
        var DadosLivro = document.getElementById("dados_livro");
        var Sinopse    = document.getElementById("ctl00_cph_lblLivro_Sinopse");
        var Autores    = document.getElementById("autores");
        var TamanhoAtual;

        if( Acao == "+" )
        {
            // AUMENTANDO O TITULO
            if( Titulo.style.fontSize == "" )
            {
                Titulo.style.fontSize = "20px";
            }
            else
            {
                TamanhoAtual = Titulo.style.fontSize.replace("px", "");
                TamanhoAtual = parseInt(TamanhoAtual) + Intervalo;            
                if( parseInt(TamanhoAtual) <= 30 ) Titulo.style.fontSize = TamanhoAtual + "px";
            }
            // AUMENTANDO OS OUTROS DADOS DO LIVRO
            if( DadosLivro.style.fontSize == "" )
            {
                DadosLivro.style.fontSize = "13px";
            }
            else
            {
                TamanhoAtual = DadosLivro.style.fontSize.replace("px", "");
                TamanhoAtual = parseInt(TamanhoAtual) + Intervalo;            
                if( parseInt(TamanhoAtual) <= 21 ) DadosLivro.style.fontSize = TamanhoAtual + "px";
            }
            
            // AUMENTO A SINOPSE DO LIVRO
            if( Sinopse.style.fontSize == "" )
            {
                Sinopse.style.fontSize = "13px";
            }
            else
            {
                TamanhoAtual = Sinopse.style.fontSize.replace("px", "");
                TamanhoAtual = parseInt(TamanhoAtual) + Intervalo;
                if( parseInt(TamanhoAtual) <= 21 ) Sinopse.style.fontSize = TamanhoAtual + "px";
            }

            // AUMENTO OS AUTORES DO LIVRO
            if( Autores.style.fontSize == "" )
            {
                Autores.style.fontSize = "13px";
            }
            else
            {
                TamanhoAtual = Autores.style.fontSize.replace("px", "");
                TamanhoAtual = parseInt(TamanhoAtual) + Intervalo;
                if( parseInt(TamanhoAtual) <= 21 ) Autores.style.fontSize = TamanhoAtual + "px";
            }
        }
        else
        {
            // DIMINUINDO O TITULO
            if( Titulo.style.fontSize != "" && parseInt( Titulo.style.fontSize.replace("px", "") ) >= 18 )
            {
                TamanhoAtual = parseInt(Titulo.style.fontSize.replace("px", ""));
                TamanhoAtual = TamanhoAtual - Intervalo;
                if( TamanhoAtual >= 18 ) Titulo.style.fontSize = TamanhoAtual + "px";
            }
            // DIMINUINDO OS OUTROS DADOS DO LIVRO
            if( DadosLivro.style.fontSize != "" && parseInt( DadosLivro.style.fontSize.replace("px", "") ) >= 11 )
            {
                TamanhoAtual = parseInt( DadosLivro.style.fontSize.replace("px", "") );
                TamanhoAtual = TamanhoAtual - Intervalo;
                if( TamanhoAtual >= 11 ) DadosLivro.style.fontSize = TamanhoAtual + "px";
            }
            // DIMINUINDO A SINOPSE
            if( Sinopse.style.fontSize != "" && parseInt( Sinopse.style.fontSize.replace("px", "") ) >= 11 )
            {
                TamanhoAtual = parseInt( Sinopse.style.fontSize.replace("px", "") );
                TamanhoAtual = TamanhoAtual - Intervalo;
                if( TamanhoAtual >= 11 ) Sinopse.style.fontSize = TamanhoAtual + "px";
            }
            // DIMINUINDO OS AUTORES
            if( Autores.style.fontSize != "" && parseInt( Autores.style.fontSize.replace("px", "") ) >= 11 )
            {
                TamanhoAtual = parseInt( Autores.style.fontSize.replace("px", "") );
                TamanhoAtual = TamanhoAtual - Intervalo;
                if( TamanhoAtual >= 11 ) Autores.style.fontSize = TamanhoAtual + "px";
            }
        }
    }

    function controleTamanhoFonteLivros(Acao)
    {
        var Livros = document.getElementById("ctl00_cph_dtlLivros");
        var DIVs = Livros.getElementsByTagName("div");
        var DIVsAUX;
        var Livro;
        var Titulo, Colecao, Serie, Autores;
        var X;

        for(AUX = 0; AUX <= DIVs.length-1; AUX++)
        {
            if( DIVs[AUX].id == "livro-clipping" )
            {
                Titulo = DIVs[AUX].getElementsByTagName("h4");
                auxAumentaDiminui(Titulo[0], Acao);
                /*
                DIVsAUX = DIVs[AUX].getElementsByTagName("div");
                for(X = 0; X <= DIVsAUX.length-1; X++)
                {
                    if( DIVsAUX[X].title == "Coleção" || DIVsAUX[X].title == "Serie" || DIVsAUX[X].title == "Autores" )
                    {
                        auxAumentaDiminui(DIVsAUX[X], Acao);
                    }
                }
                */
            }
        }    
    }

    function auxAumentaDiminui(OBJ, Acao)
    {
        var Intervalo = 2;
        if( Acao == "+" )
        {
            if( OBJ.style.fontSize == "" )
            {
                OBJ.style.fontSize = "13px";
            }
            else
            {
                X = OBJ.style.fontSize.replace("px", "");
                X = parseInt(X) + Intervalo;
                if( X <= 21 ) OBJ.style.fontSize = X + "px";
            }
        }
        else
        {
            if( OBJ.style.fontSize != "" )
            {
                X = OBJ.style.fontSize.replace("px", "");
                X = parseInt(X) - Intervalo;
                if( X >= 11 ) OBJ.style.fontSize = X + "px";
            }
        }
    }

    function verLivro(iCOD)
    {
        location.href = "../livraria/detalhes.aspx?COD=" + iCOD;
    }
    function verLivroAutor(iCOD)
    {
        location.href = "../busca/?P=" + iCOD;
    }

    function verColecao(iCOL, iAREA)
    {
        location.href = "../livraria/?AR="+ iAREA +"&COL="+ iCOL;
    }

    function verArea(iCOD)
    {
        location.href = "../livraria/?AR=" + iCOD;
    }
/* *********************************************** */
// Funções relacionadas ao Quiz

    function responderQuiz(iCOD)
    {
        if( iCOD != "" )
        {
            location.href = "../quiz/?COD="+ iCOD;
        }
    }

/* *********************************************** */
// Funções relacionadas a busca rapida

    var JaAbriu = false;
    var arrBR   = Array();

    function travaEnter(e)
    {
        if (navigator.appName == 'Microsoft Internet Explorer') { Code = e.keyCode; } else if (navigator.appName == 'Netscape') { Code = e.which; };
        var EL = document.activeElement || e.explicitOriginalTarget;
        if( EL.id == "cBusca" )
        {
            if( Code == 13 ) return false;
        }
    }

    function buscaRapida(Expressao, e)
    {
        posicionaBaseResultado();
        
	    // Tratando para resgatar o código correta da tecla
	    if (navigator.appName == 'Microsoft Internet Explorer') { Code = e.keyCode; } else if (navigator.appName == 'Netscape') { Code = e.which; };

	    // Filtrando as teclas Enter, Shift, Contrl
	    if( (Code != 13) && (Code != 16) && (Code != 17) )
	    {
	        if( Expressao.length > 0 )
	        {
                arrBR[Expressao.length] = CriaAJAX();
                arrBR[Expressao.length].onreadystatechange = function()
                {
                    document.getElementById("load-br").style.display = "";
                    if( arrBR[Expressao.length].readyState == 4 )
                    {
                        if( arrBR[Expressao.length].status == 200 )
                        {
                            Retorno = unescape(arrBR[Expressao.length].responseText.replace(/\+/g," "));
                            document.getElementById("BASE_RESULTADO").style.display = "";
                            document.getElementById("BASE_RESULTADO").innerHTML     = Retorno;
                            document.getElementById("load-br").style.display        = "none";
                            //if( !JaAbriu ) $('#BASE_RESULTADO').BlindDown(600);
                            
                            // Variavel utilizada para saber se preciso utilizar o efeito ou não mais
                            // No cenário que cada letra é feita uma nova busca
                            JaAbriu = true;
                        };
                    };
                }
		        arrBR[Expressao.length].open("GET", "../ajax/get-buscarapida.aspx?T=" + Expressao, true);
		        arrBR[Expressao.length].setRequestHeader("Content-Type", "text/html; charset=iso-8859-1" );
		        arrBR[Expressao.length].send( null );
	        }
	        else
	        {
	            if( JaAbriu )
	            {
                    document.getElementById("BASE_RESULTADO").style.display = "none";
                    document.getElementById("load-br").style.display        = "none";
                    //$('#BASE_RESULTADO').BlindUp(600);
                    JaAbriu = false;
                }
	        }
	    }
	    //document.getElementById("cBusca").focus();
    }

    function buscaRapidaMais(Ancora)
    {
        if( Ancora != "" )
        {
            location.href = "../busca/?P="+ document.getElementById("cBusca").value + "#" + Ancora;
        }
        else
        {
            location.href = "../busca/?P="+ document.getElementById("cBusca").value;
        }
    }

    function posicionaBaseResultado()
    {
        BaseResultado = document.getElementById("BASE_RESULTADO");
        if( BaseResultado.style.top != "56px" )
        {
            var Campo;
            var Pos;
            var BaseResultado

            Campo         = document.getElementById("cBusca");
            Pos = YAHOO.util.Dom.getXY( Campo );
            BaseResultado.style.left = (Pos[0] - 310) +"px";
            BaseResultado.style.top  = "56px";
        }
    }

    function ocultaBuscaRapida()
    {
        BaseResultado = document.getElementById("BASE_RESULTADO");
        if( BaseResultado.style.display == "" )
        {
            BaseResultado.style.display = "none";
            BaseResultado.innerHTML = "";
        }
    }

    function limparCampoBuscaRapida(Campo)
    {
        if( Campo.value == "Buscar" ) Campo.value = "";
    }

/* *********************************************** */
// Funções relacionadas a notícias


    function linkNoticias()
    {
        var BASE_TEXTO = document.getElementById("noticia").value;
        var Links = BASE_TEXTO.getElementsByTagName("a");
        for(AUX = 0; AUX <= Links.length-1; AUX++)
        {
            Links[AUX].target = "_blank";
            Links[AUX].title = Links[AUX].href;
        }
    }

    function Comentar(iCOD)
    {
        if( iCOD )
        {
            var Topo, Left;
            var Largura, Altura;
            
            Largura = 380;
            Altura  = 450;
            Left    = (window.screen.width / 2) - (Largura / 2);
            Topo    = (window.screen.height / 2) - (Altura / 2);
            window.open("comentario.aspx?COD=" + iCOD, "_comentario", "width="+ Largura +", height="+ Altura +", scrollbars=yes, top="+ Topo +", left="+ Left);
        }
    }

    function versaoImpressao(iCOD)
    {
        if( iCOD != "" )
        {
            var Topo, Left;
            
	        Topo = (window.screen.height / 2) - (500 / 2);
	        Left = (window.screen.width / 2) - (700 / 2);

            window.open("print.aspx?COD=" + iCOD, "_print", "width=700, height=500, scrollbars=yes, top="+ Topo +", left="+ Left);
        }
    }

    function ampliarFoto(iFoto)
    {
        var Topo, Left;

	    Topo = (window.screen.height / 2) - (500 / 2);
	    Left = (window.screen.width / 2) - (600 / 2);
        window.open("ampliar.aspx?COD="+ iFoto, "_foto", "width=600, height=500, top="+ Topo +", left="+ Left);
    }

    function downAnexo(iArquivo)
    {
        location.href = "../downloads/down.aspx?" + iArquivo;
    }

    function enviarEmail(iCOD)
    {
        if( iCOD != "" )
        {
            var Topo, Left;
            
	        Topo = (window.screen.height / 2) - (450 / 2);
	        Left = (window.screen.width / 2) - (340 / 2);

            window.open("enviar.aspx?COD="+ iCOD, "_enviar", "width=340, height=450, top="+ Topo +", left="+ Left);
        }
    }

 
    function controleFonteNoticia(Acao)
    {
        var Intervalo = 2;
        var AUX;
        var Noticia = document.getElementById("noticia");
        
        if( Acao == "+" ) {
            if (Noticia.style.fontSize == "") {
                Noticia.style.fontSize = "13px";
            }
            else {
                AUX = parseInt(Noticia.style.fontSize.replace("px", ""));
                AUX = AUX + Intervalo;
                if( AUX <= 25 ) Noticia.style.fontSize = AUX.toString() + "px";
            };
        }
        else {
            if( Noticia.style.fontSize != "" ) {
                AUX = parseInt(Noticia.style.fontSize.replace("px", ""));
                AUX = AUX - Intervalo;
                if( AUX >= 11 ) Noticia.style.fontSize = AUX.toString() + "px";
            };
        };
    }

    function lerNoticia(iCOD)
    {
        location.href = "../noticias/?COD=" + iCOD;
    }

/* *********************************************** */
// Funções relacionadas aos clippings

    function ComentarClippings(iCOD)
    {
        if( iCOD )
        {
            var Topo, Left;
            var Largura, Altura;
            
            Largura = 380;
            Altura  = 450;
            Left    = (window.screen.width / 2) - (Largura / 2);
            Topo    = (window.screen.height / 2) - (Altura / 2);
            window.open("../clippings/comentario.aspx?COD=" + iCOD, "_comentario", "width="+ Largura +", height="+ Altura +", scrollbars=yes, top="+ Topo +", left="+ Left);
        }
    }

    function linkClippings()
    {
        var BASE_TEXTO = document.getElementById("clippings").value;
        var Links = BASE_TEXTO.getElementsByTagName("a");
        for(AUX = 1; AUX <= Links.length-1; AUX++)
        {
            Links[AUX].target = "_blank";
            Links[AUX].title = Links[AUX].href;
        }
    }
    function controleFonteClippings(Acao)
    {
        var Intervalo = 2;
        var AUX;
        var Noticia = document.getElementById("clippings");
        
        if( Acao == "+" ) {
            if (Noticia.style.fontSize == "") {
                Noticia.style.fontSize = "13px";
            }
            else {
                AUX = parseInt(Noticia.style.fontSize.replace("px", ""));
                AUX = AUX + Intervalo;
                if( AUX <= 25 ) Noticia.style.fontSize = AUX.toString() + "px";
            };
        }
        else {
            if( Noticia.style.fontSize != "" ) {
                AUX = parseInt(Noticia.style.fontSize.replace("px", ""));
                AUX = AUX - Intervalo;
                if( AUX >= 11 ) Noticia.style.fontSize = AUX.toString() + "px";
            };
        };
    }

    function lerClippings(iCOD)
    {
        location.href = "../clippings/default.aspx?COD=" + iCOD;
    }

/* *********************************************** */
// Funções relacionadas aos releases


    function ComentarRelease(iCOD)
    {
        if( iCOD )
        {
            var Topo, Left;
            var Largura, Altura;
            
            Largura = 380;
            Altura  = 450;
            Left    = (window.screen.width / 2) - (Largura / 2);
            Topo    = (window.screen.height / 2) - (Altura / 2);
            window.open("../release/comentario.aspx?COD=" + iCOD, "_comentario", "width="+ Largura +", height="+ Altura +", scrollbars=yes, top="+ Topo +", left="+ Left);
        }
    }
    function lerRelease(iCOD)
    {
        location.href = "../release/default.aspx?COD=" + iCOD;
    }
    
    function controleFonteRelease(Acao)
    {
        var Intervalo = 2;
        var AUX;
        var Noticia = document.getElementById("release");
        
        if( Acao == "+" ) {
            if (Noticia.style.fontSize == "") {
                Noticia.style.fontSize = "13px";
            }
            else {
                AUX = parseInt(Noticia.style.fontSize.replace("px", ""));
                AUX = AUX + Intervalo;
                if( AUX <= 25 ) Noticia.style.fontSize = AUX.toString() + "px";
            };
        }
        else {
            if( Noticia.style.fontSize != "" ) {
                AUX = parseInt(Noticia.style.fontSize.replace("px", ""));
                AUX = AUX - Intervalo;
                if( AUX >= 11 ) Noticia.style.fontSize = AUX.toString() + "px";
            };
        };
    }
/* *********************************************** */

/* *********************************************** */
// Funções relacionadas aos eventos

    function exibeEventos(iData)
    {
        location.href = "../agenda/?" + iData;
    }
    
    
    
    function agendaEnviarAmigo(COD)
    {
        var Topo, Left;
        
        Topo = (window.screen.height / 2) - (370 / 2);
        Left = (window.screen.width / 2) - (340 / 2);

        window.open("../agenda/indique.aspx?COD="+ COD, "_enviar", "width=340, height=380, top="+ Topo +", left="+ Left);
    }

    function agendaVersaoImpressao(iCOD)
    {
        if( iCOD != "" )
        {
            var Topo, Left;
            
	        Topo = (window.screen.height / 2) - (500 / 2);
	        Left = (window.screen.width / 2) - (700 / 2);

            window.open("print.aspx?COD=" + iCOD, "_print", "width=700, height=500, scrollbars=yes, top="+ Topo +", left="+ Left);
        }
    }


/* ************************************************* */
// Funções relacionadas aos cursos

    function indiqueCurso(COD)
    {
        var Topo, Left;
        
        Topo = (window.screen.height / 2) - (500 / 2);
        Left = (window.screen.width / 2) - (700 / 2);

        window.open("../cursos/indique.aspx?COD=" + COD, "_indique", "width=350, height=430, scrollbars=yes, top="+ Topo +", left="+ Left);
    }
    function listaCursos(DATA)
    {
        location.href = "../cursos/listar.aspx?DATA=" + DATA;
    }
    function verCurso(COD)
    {
        location.href = "../cursos/detalhes.aspx?COD=" + COD;
    }
    function cursosInscricao(COD)
    {
        location.href = "../cursos/inscricao.aspx?COD=" + COD;
    }

/* *********************************************** */
// Funções relacionadas a liturgia diaria
    function listaLiturgia(DATA)
    {
        location.href = "../liturgiadiaria/listar.aspx?DATA=" + DATA;
    }

/* *********************************************** */
// Funções relacionadas a galeria de fotos
    
    function verFoto(OBJ)
    {
        initLightbox();
        myLightbox.start(OBJ);
    }

    function verGaleria(COD)
    {
        location.href = "../galeria/fotos.aspx?COD=" + COD;
    }
    
/* *********************************************** */
// Funções relacionadas ao mensageiro

    function listarTodasMensageiro(ANO)
    {
        location.href = "../mensageiro/edicoes.aspx?ANO=" + ANO;
    }

    function selAnoMensageiro(OBJ)
    {
        location.href = "../mensageiro/?ANO=" + OBJ.value;
    }

    function verEdicao(iCOD)
    {
        if( iCOD != "" )
        {
            location.href = "../mensageiro/?ED=" + iCOD;
        }
    }
    
    function lerMateria(iCOD)
    {
        if( iCOD != "" )
        {
            location.href = "../mensageiro/?COD="+ iCOD;
        }
    }

/********************************************************/
// funções relacionadas a liturgia diaria

    function listarTodasLiturgia(ANO)
    {
        location.href = "../liturgiadiaria/?ANO=" + ANO;
    }
    
    function selAnoLiturgia(OBJ)
    {
        location.href = "../liturgiadiaria/?ANO=" + OBJ.value;
    }

    function verEdicaoLiturgia(iCOD)
    {
        if( iCOD != "" )
        {
            location.href = "../liturgiadiaria/?ED=" + iCOD;
        }
    }
    
    function lerMateriaLiturgia(iCOD)
    {
        if( iCOD != "" )
        {
            location.href = "../liturgiadiaria/?COD="+ iCOD;
        }
    }

    function controleFonteLiturgia(Acao)
    {
        var Intervalo = 2;
        var AUX;
        var Noticia = document.getElementById("codigo");
        
        if( Acao == "+" ) {
            if (Noticia.style.fontSize == "") {
                Noticia.style.fontSize = "13px";
            }
            else {
                AUX = parseInt(Noticia.style.fontSize.replace("px", ""));
                AUX = AUX + Intervalo;
                if( AUX <= 25 ) Noticia.style.fontSize = AUX.toString() + "px";
            };
        }
        else {
            if( Noticia.style.fontSize != "" ) {
                AUX = parseInt(Noticia.style.fontSize.replace("px", ""));
                AUX = AUX - Intervalo;
                if( AUX >= 11 ) Noticia.style.fontSize = AUX.toString() + "px";
            };
        };
    }
/* *********************************************** */
// Funções relacionadas a pesquisa

    function vldCheckBoxPesquisa(src, args)
    {
        var Tabela = document.getElementById(src.id.replace("cvAlternativa", "cblAlternativa"));
        var Controles = Tabela.getElementsByTagName("input");
        var Retorno = false;
        for(AUX = 0; AUX <= Controles.length-1; AUX++)
        {
            if( Controles[AUX].checked ) Retorno = true;
        }
        args.IsValid = Retorno;
    }

    

/* *********************************************** */

function SoN(e)
{
	var Code;
	
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		Code = e.keyCode;
	}
	else if (navigator.appName == 'Netscape')
	{
		Code = e.which;
	}
	
	if( (Code != 8) && (Code != 0) )
	{
		if( (Code < 48) || (Code > 57) )
		{
			if (navigator.appName == 'Microsoft Internet Explorer')
			{
				e.returnValue = false;
			}
			else if (navigator.appName == 'Netscape')
			{
				e.preventDefault();
			};
		};
	};
}

function buscaCEP(iCEP)
{
    var CEP = document.getElementById(iCEP);
    if( (CEP.length != 8) && (CEP.value != "") )
    {
        var Retorno;
        var Ajax;
        var P;
        var Form;

        Ajax = CriaAJAX();
        Ajax.onreadystatechange = function()
        {
            document.getElementById("load-cadastro").style.display = "";
            if( Ajax.readyState == 4 )
            {
                if( Ajax.status == 200 )
                {
                    document.getElementById("load-cadastro").style.display = "none";
                    Form    = document.aspnetForm;
                    Retorno = unescape(Ajax.responseText.replace(/\+/g," "));
                    if( Retorno != "" )
                    {
                        P = Retorno.split(";");
                        if( P[0] == "1" )
                        {
                            Form.ctl00_cph_txtEndereco.value = P[1];
                            Form.ctl00_cph_txtBairro.value   = P[2];
                            Form.ctl00_cph_txtCidade.value   = P[3];
                            Form.ctl00_cph_txtEstado.value   = P[4];
                            Form.ctl00_cph_txtNumero.focus();
                        }
                        else
                        {
                            Form.ctl00_cph_txtEndereco.disabled = false;
                            Form.ctl00_cph_txtBairro.disabled   = false;
                            Form.ctl00_cph_txtCidade.value      = P[3];
                            Form.ctl00_cph_txtEstado.value      = P[4];
                            Form.ctl00_cph_txtEndereco.focus();
                        };
                    }
                    else
                    {
                        document.getElementById("load-cadastro").style.display = "none";
                        alert("Não foi possível encontrar o endereço deste CEP!");
                        CEP.focus();                    
                    };
                }
                else
                {
                    document.getElementById("load-cadastro").style.display = "none";
                    alert("Ocorreu um erro inesperado ao buscar o endereco, tente novamente!");
                    CEP.value = "";
                    CEP.focus();
                };
            };
        }
		Ajax.open("GET", "../ajax/get-endereco.aspx?CEP=" + CEP.value +"&c=" + Math.random(), true);
		Ajax.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1" );
		Ajax.send( null );
    }
    else
    {
        alert("O CEP digitado é inválido!");
        CEP.focus();
    };
}
window.onload = posicionaBaseResultado;
/* *********************************************** */
//  Funções relacionadas ao carrinho
function addLivro(CodLivro)
{
	location.href = "../compras/?COD=" + CodLivro;
}

function validaQtde(OBJ)
{
	var cQuantidade;
	cQuantidade = document.getElementById( OBJ );
	if( parseInt( cQuantidade.value ) <= 0 || cQuantidade.value == "" )
	{
		alert("A quantidade digitada é inválida.");
		cQuantidade.focus();
		return false;
	}
}

function validaCalculoFrete()
{
	if( document.getElementById("ctl00_cph_txtCEP1").value == "" || document.getElementById("ctl00_cph_txtCEP2").value == "" )
	{
		alert("Informe corretamente seu CEP.");
		return false;
	}
}

/*************************************************/

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function datanasc(v){
    v=v.replace(/\D/g,"")                	//Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"$1/$2") 	//Coloca barra apos os 2 primeiros digitos
    v=v.replace(/(\d\d)(\d)/,"$1/$2")		//Coloca barra apos os 2 segundos digitos
    return v
}


function SoNumero(v){
    return v.replace(/\D/g,"")
}

function SoLetra(v){
    v=v.toUpperCase()             //Maiúsculas
	v=v.replace(/[^asdfghjklçqwertyuiopzxcvbnmASDFGHJKLÇQWERTYUIOPZXCVBNM]/g,"") //Remove tudo o que não Letra
    return v
}

