// JavaScript Document

    function getDocAnexo(id,idInd) {
        
        location.href="#"
        var option = {
                
                onShow: function(dialog){
                    
                    jQuery(dialog.data).load("pub_getAnexo.php",{fn:'doc', id:id},
                            function()
                            {
                                jQuery(dialog.data).jScrollPane({showArrows:true})
                            })},
                            
                    closeTitle:'Fechar',
                    onClose:function(dialog){scrollTo(idInd); $.modal.close()}
        };
        
        jQuery("#basicModalContent").html('<img src="img/loader.gif" />');
        jQuery('#basicModalContent').modal(option);
        
    };

    function alternar(elemento,id) {
        
        jQuery(".serie" + id).hide('slow');
        jQuery("#serie" + elemento + id).show('slow');
    };

    function alternarGraficoClasse(exibir,ocultar) {
        
        jQuery(ocultar).hide();
        jQuery(exibir).show();
        
    };

    function showGraficoGlobal (id, ano, exclusivo) {
        
		
        if (undefined == exclusivo)exclusivo = 'nao';
        if (undefined == idDistrito) {
        	distrito = 0;
        } else {
        	distrito = idDistrito;
        }
        location.href="#"
        
        var option = {
            
            onShow: function(dialog){
                
                jQuery(dialog.data).load("pub_getAnexo.php",{fn:'grafico', ano:ano, id:id, exclusivo:exclusivo, distrito:distrito},
                            function(){
                                //jQuery(dialog.data).jScrollPane({showArrows:true})
                                $("#scrollGrafico").jScrollPane({showArrows:true})
                              })},
                            
                closeTitle:'Fechar',
                onClose:function(dialog){scrollTo(id); $.modal.close()}
        };
        
        jQuery("#basicModalContent").html('<img src="img/loader.gif" />');
        jQuery('#basicModalContent').modal(option);
        
    };

    function iniciarLinks(id) {
        
        return ;
        jQuery('a.goto').click(function (e){
        var href = jQuery(this).attr('href');
        href = href + "&ind=" + id;
       
        jQuery(this).attr('href', href);
        return true;
        
        });
        jQuery.unblockUI();
        
    };

    function scrollTo(ancora, msg) {
        
        var seletor ='#ancora' + ancora;
        if (!jQuery(seletor))return;
        
        jQuery.scrollTo(seletor, 800,{offset:-300});
        
        seletor = '.info' + ancora;
        if (!jQuery(seletor))return;
        jQuery(seletor).css({'background-color':'#EFEFEF'});
        
        setTimeout(function(){jQuery(seletor).css({'background-color':'white'});},3000);
        if (msg) aguardar();
        
    };

    function preloads() {
        
        for (i = 1; i < 34; i++){
            
            jQuery.preload('s' + i + '.gif', 'img/nomes');
        }
       
        for (i = 0; i < 10; i++){
            
            jQuery.preload('v' + i + '.jpg', 'img/numeros');
        }
        
        for (i = 1; i < 16; i++){
            
            jQuery.preload('b' + i + '.jpg', 'img/assets');
            jQuery.preload('c' + i + '.jpg', 'img/assets');
            jQuery.preload('t' + i + '.jpg', 'img/assets');
        }
        
    };

    function download(idIndicador) {
       
        $.post('pub_getAnexo.php', {fn:'download', id:idIndicador}, function (response, status) {
           
            $.clipboard(response) ;
            $.blockUI('<div id="boxClipboard" style="cursor:pointer;"><a onclick ="$.unblockUI()">Fechar</a><h5>Dados copiados para a sua &Aacute;rea de Transfer&ecirc;ncia.<p> Abra uma planilha e cole. <p/>(control + V ).</h5></div>') ; 
            
        });
        
    }; 

    function downloadDistritos(idIndicador) {
        $.post('pub_getAnexo.php', {fn:'downloadDistritos', id:idIndicador}, function (response, status) {
            $.clipboard(response) ;
            $.blockUI('<div id="boxClipboard" style="cursor:pointer;"><a onclick ="$.unblockUI()">Fechar</a><h5>Dados copiados para a sua &Aacute;rea de Transfer&ecirc;ncia.<p> Abra uma planilha e cole. <p/>(control + V ).</h5></div>') ; 
            
        });
        
    }; 

    /**
    *
    *  URL encode / decode
    *  http://www.webtoolkit.info/
    *
    **/

    var Url = {
        
        // public method for url encoding
        encode : function (string) {
            return escape(this._utf8_encode(string));
        },
        
        // public method for url decoding
        decode : function (string) {
            return this._utf8_decode(unescape(string));
        },
        
        // private method for UTF-8 encoding
        _utf8_encode : function (string) {
            string = string.replace(/\r\n/g,"\n");
            var utftext = "";
            
            for (var n = 0; n < string.length; n++) {
                
                var c = string.charCodeAt(n);
                
                if (c < 128) {
                    utftext += String.fromCharCode(c);
                }
                else if((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
                else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
                
            }
            
            return utftext;
        },
        
        // private method for UTF-8 decoding
        _utf8_decode : function (utftext) {
            var string = "";
            var i = 0;
            var c = c1 = c2 = 0;
            
            while ( i < utftext.length ) {
                
                c = utftext.charCodeAt(i);
                
                if (c < 128) {
                    string += String.fromCharCode(c);
                    i++;
                }
                else if((c > 191) && (c < 224)) {
                    c2 = utftext.charCodeAt(i+1);
                    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                    i += 2;
                }
                else {
                    c2 = utftext.charCodeAt(i+1);
                    c3 = utftext.charCodeAt(i+2);
                    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                    i += 3;
                }
                
            }
            
            return string;
        }
        
    }  