﻿// JScript File

        var conta_click = 0;
        var ultimo_tipo = "";
        
        function popup(url,name,windowWidth,windowHeight){
            myleft=(screen.width)?(screen.width-windowWidth)/2:100;	
            mytop=(screen.height)?(screen.height-windowHeight)/2:100;
            properties = "width="+windowWidth+",height="+windowHeight+",scrollbars=yes, top="+mytop+",left="+myleft;
            window.open(url,name,properties);            
        }
        
        function encodeMyHtml() {
            encodedHtml = escape(document.getElementById("estrutura").value);
            encodedHtml = encodedHtml.replace(/\//g,"%2F");
            encodedHtml = encodedHtml.replace(/\?/g,"%3F");
            encodedHtml = encodedHtml.replace(/=/g,"%3D");
            encodedHtml = encodedHtml.replace(/&/g,"%26");
            encodedHtml = encodedHtml.replace(/@/g,"%40");
            document.getElementById("estrutura").value = encodedHtml;
        } 

        function carregaImagens(cod,imagem,botao)
        {   
            var conteudo = "";
            conteudo = document.getElementById('conteudo_caixa04').innerHTML;  
            var estrutura = "";
            var arrayCod = cod.split(",");
            var arrayImagem = imagem.split(",");
            var z = 0;
            for (z = 0; z < arrayCod.length; z++){ 
                estrutura = "<DIV ID='" + arrayCod[z] + "' style=\"text-align:left;margin-left:auto;margin-right:auto;width:120px;height:79px;position:relative;background-image:url("+arrayImagem[z]+");\"><span style=\"position:absolute;margin-top:0px;margin-left:5px;\">2007/"+arrayCod[z]+"</span><img src='img/moldura.gif' width='120' height='79' border='0' /><img src='img/icone_x.jpg' border='0' style=\"position:absolute;margin-top:57px;margin-left:-25px\" id=\"btnExcluir"+arrayCod[z]+"\" onclick=\"EXCLUI(" + arrayCod[z] + ",'" + botao + "');\" /></DIV><br />" + estrutura;
                //estrutura = "<DIV ID='" + arrayCod[z] + "'><img src=" + arrayImagem[z] + " width=120 height=79 border=0 /><br /><input type=\"button\" value='X' id=\"btnExcluir"+arrayCod[z]+"\" onclick=\"EXCLUI(" + arrayCod[z] + ",'" + botao + "');\" /></DIV><BR />" + estrutura;
                document.getElementById('conteudo_caixa04').innerHTML = estrutura + conteudo;
            }
            abreDiv();
            return true;
        }
        
        function imagemImpressao(idioma)
        {
            var conteudo = document.getElementById("conteudo_caixa04").innerHTML;
            var pos_inicial;
            var recorte;
            var cod = "";
            for (var i=0;i < conteudo.length;i++){
                conteudo = conteudo.replace("\"","");
            }
            conteudo = conteudo.toUpperCase();
            while (conteudo.indexOf('<DIV ID=') != -1){
                pos_inicial = conteudo.indexOf('<DIV ID=') + 8;
                conteudo = conteudo.substr(pos_inicial,conteudo.length);
                var pos_espaco = conteudo.indexOf(' ');                
                cod = conteudo.substr(0,pos_espaco) + "," + cod;
                
            }
            cod = cod.substr(0,cod.length -1);
            if (cod == ""){
                alert("Selecione alguma imagem para impressão.");
            }
            else
            {
                if (document.getElementById("chkFicha").checked)
                {
                    location.href="imprimir.aspx?cod=" + cod + "&desc=ok&idioma=" + idioma;
                }
                else
                {
                    location.href="imprimir.aspx?cod=" + cod + "&idioma=" + idioma;
                }
            }
        }
        
        function imagemZoom(imagem,classe,idioma)
        {
            var conteudo = document.getElementById("conteudo_caixa04").innerHTML;
            var pos_inicial;
            var recorte;
            var cod = "";
            for (var i=0;i < conteudo.length;i++){
                conteudo = conteudo.replace("\"","");
            }
            conteudo = conteudo.toUpperCase();
            while (conteudo.indexOf('<DIV ID=') != -1){
                pos_inicial = conteudo.indexOf('<DIV ID=') + 8;
                conteudo = conteudo.substr(pos_inicial,conteudo.length);
                var pos_espaco = conteudo.indexOf(' ');
                cod = conteudo.substr(0,pos_espaco) + "," + cod;
            }
            cod = cod.substr(0,cod.length -1);
            if (cod == ""){
                location.href="zoom.aspx?classe=" + classe + "&cod=" + imagem + "&idioma=" + idioma;   
            }
            else
            {
                location.href="zoom.aspx?classe=" + classe + "&cod=" + imagem + "&lista=" + cod + "&idioma=" + idioma;
            }
        }

        function adicionaImagem(cod,imagem,botao)
        {   
            var conteudo = "";
            var conteudo_original = "";
            conteudo = document.getElementById('conteudo_caixa04').innerHTML;
            conteudo_original = document.getElementById('conteudo_caixa04').innerHTML;
            for (var i=0;i < conteudo.length;i++){
                conteudo = conteudo.replace("\"","");
            }
            conteudo = conteudo.toUpperCase();
            if (conteudo.indexOf('<DIV ID='+cod + ' ') != -1) {
            alert("Imagem já foi incluída na lista para impressão.");
            return false;
            }
            else
            {            
            var estrutura = "";
            estrutura = "<DIV ID='" + cod + "' style=\"text-align:left;margin-left:auto;margin-right:auto;width:120px;height:79px;position:relative;background-image:url("+imagem+");\"><span style=\"position:absolute;margin-top:0px;margin-left:5px;\">2007/"+cod+"</span><img src='img/moldura.gif' width='120' height='79' border='0' /><img src='img/icone_x.jpg' border='0' style=\"position:absolute;margin-top:57px;margin-left:-25px\" id=\"btnExcluir"+cod+"\" onclick=\"EXCLUI(" + cod + ",'" + botao + "');\" /></DIV><br />";
            document.getElementById('conteudo_caixa04').innerHTML = estrutura + conteudo_original;
            abreDiv();
            return true;
            }
        }
        
        function EXCLUI(codigo,botao)
        {  
            var browser = navigator.appName; 
            var div_string = "</DIV><BR>";
            var div_ff_string = "</div><br>";
            var conteudo = "";
            conteudo = document.getElementById('conteudo_caixa04').innerHTML;
            var pos_inicial = "";
            var pos_final = "";
            if (browser == "Microsoft Internet Explorer"){
                pos_inicial = conteudo.indexOf('<DIV id='+codigo + ' '); 
                    
            }else{
                pos_inicial = conteudo.indexOf('<div id=\"'+codigo+'\"'+ ' ');    
            }
            var captura_string = conteudo.substring(pos_inicial,conteudo.length);
            if (browser == "Microsoft Internet Explorer"){
                pos_final = captura_string.indexOf('</DIV>') + pos_inicial + div_string.length;  
                    
            }else{
                pos_final = captura_string.indexOf('</div>') + pos_inicial + div_ff_string.length;  
            }
            var recorte = "";
            recorte = conteudo.substring(pos_inicial,pos_final);
            document.getElementById('conteudo_caixa04').innerHTML = conteudo.replace(recorte,""); 
            if (document.getElementById('conteudo_caixa04').innerHTML.length < 34)
            {
                fechaDiv();
            }
        }
              
        function fechaDiv()
        {
            document.getElementById("coluna03").style.visibility = 'hidden';
            document.getElementById("coluna03").style.display = 'none';
        }
        
        function abreDiv()
        {
            document.getElementById("coluna03").style.visibility = 'visible';
            document.getElementById("coluna03").style.display = 'block';     
        }
        
        function detalhes(conteudo)
        {
            document.getElementById("lblDetalhes").innerHTML = conteudo;
            document.getElementById("lblDetalhes").style.display = 'inline';
            document.getElementById("lblDetalhes").style.visibility = 'visible';
        }
        
        function esconde_detalhes()
        {
            if (conta_click != 1){
                document.getElementById("lblDetalhes").style.visibility = 'hidden';
                document.getElementById("lblDetalhes").style.display = 'none';              
            }
            else
            {
                if (document.getElementById("opcao_atual").value != "")
                {
                    document.getElementById("lblDetalhes").innerHTML = document.getElementById("opcao_atual").value; 
                }
            }
        }
        
        function set_detalhes(conteudo, tipo)
        {
            document.getElementById("lblDetalhes").innerHTML = conteudo;
            document.getElementById("opcao_atual").value = conteudo;
            conta_click = 1;
            ultimo_tipo = tipo;            
            document.getElementById("ultima_opcao_sel").value = ultimo_tipo;
        }
        
        function limpa_detalhes()
        {
            if (ultimo_tipo == "")
            {
                conta_click = 0;
                document.getElementById("opcao_atual").value = "";
                esconde_detalhes();
            }
            else
            {
                document.getElementById("lblDetalhes").style.display = 'inline';
                document.getElementById("lblDetalhes").style.visibility = 'visible';
                document.getElementById("lblTituloDetalhes").style.visibility = 'visible';
                document.getElementById("lblTituloDetalhes").style.display = 'inline';
                conta_click = 1;
            }                       
        }
        
        function abrirZoom()
        {
                document.getElementById("div_zoom").style.display = 'inline';
                document.getElementById("div_zoom").style.visibility = 'visible';
                document.getElementById("estado_zoom").value = 'visibility:visible;display:inline;';
        }
        
        function fecharZoom()
        {
                document.getElementById("div_zoom").style.display = 'none';
                document.getElementById("div_zoom").style.visibility = 'hidden';        
                document.getElementById("estado_zoom").value = 'visibility:hidden;display:none;';
        }        
