function $K(id) { return document.getElementById(id); }
function handleKeyPress(evt) { var nbr;  var nbr = (window.event)?event.keyCode:evt.which;  return nbr; }


/* Javascript de aumentar e diminuir a fonte dos textos */
var tam = 12;
function mudaFonte(tipo,elemento){
	if (tipo=="mais") {
		if(tam<=22) tam+=1;
	} else {
		if(tam>=13) tam-=1;
	}
	$K('texto').style.fontSize = tam+'px';
}
/* =================================================================== */
function ValidarNoticia(theForm) {
	if(theForm.palavra.value=="") { alert("Digite uma busca Válida!"); theForm.palavra.focus(); return (false); }
	return (true);
}
function ReplaceCaracteres(valor) {
	var txt = valor.replace(/\W\#| /g,"-");
	var txt2 = txt.replace(/\W\!|\º|\ª|@|\$|%|¨|&|\*|\(|\)|\+|´|`|\{|\[|\^|~|\}|\]|\<|\>|:|\?|\,|\.|\;|\/|\|/g,"");
	com_acento = "áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ";  
	sem_acento = "aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC";  
	nova="";
	for(i=0;i<txt2.length;i++) {  
		if (com_acento.search(txt2.substr(i,1))>=0) {  
			nova+=sem_acento.substr(com_acento.search(txt2.substr(i,1)),1);  
		} else {  
			nova+=txt2.substr(i,1).toLowerCase();  
		}  
	}
	return nova;
}
function bodyOnReady(func){
//by Micox - based in jquery bindReady and Diego Perini IEContentLoaded
        //flag global para indicar que já rodou e function que roda realmente
        done = false
        init = function(){ if(!done) { done=true; func() } }
        var d=document; //apelido para o document
        //pra quem tem o DOMContent (FF)
        if(document.addEventListener){ d.addEventListener("DOMContentLoaded", init, false );}
        
        if( /msie/i.test( navigator.userAgent ) ){ //IE
                (function () {
                        try { // throws errors until after ondocumentready                              
                                d.documentElement.doScroll("left");
                        } catch (e) {
                                setTimeout(arguments.callee, 10); return;
                        }
                        // no errors, fire
                        init();
                })();
        }
        if ( window.opera ){
                d.addEventListener( "DOMContentLoaded", function () {
                        if (done) return;
                        //no opera, os estilos só são habilitados no fim do DOMready
                        for (var i = 0; i < d.styleSheets.length; i++){
                                if (d.styleSheets[i].disabled)
                                        setTimeout( arguments.callee, 10 ); return;
                        }
                        // fire
                        init();
                }, false);
        }
        if (/webkit/i.test( navigator.userAgent )){ //safari's
                if(done) return;
                //testando o readyState igual a loaded ou complete
                if ( /loaded|complete/i.test(d.readyState)===false ) {
                        setTimeout( arguments.callee, 10 );     return;
                }
                init();
        }
        //se nada funfou eu mando a velha window.onload lenta mesmo
        if(!done) window.onload = init
}
function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    
    str_data += '';
    
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }

    return tmp_arr.join('');
}
function base64_decode (data) {
    // http://kevin.vanzonneveld.net
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Thunder.m
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_decode
    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'

    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof this.window['btoa'] == 'function') {
    //    return btoa(data);
    //}

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];

    if (!data) {
        return data;
    }

    data += '';

    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;

        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);

    dec = tmp_arr.join('');
    dec = this.utf8_decode(dec);

    return dec;
}

function Pooopup(pagina, largura, altura) {
	w = screen.width;
	h = screen.height;
	meio_w = w/2;
	meio_h = h/2;

	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;

	if(screen.width <= 1024) {
		window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+'');
	} else {
		window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+'');
	}
}
function PooopupGaleriaEventos(pagina, largura, altura) {
	w = screen.width;
	h = screen.height;
	meio_w = w/2;
	meio_h = h/2;

	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;

	if(screen.width <= 1024) {
		window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+'');
	} else {
		window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+'');
	}
}
function PopupManifestacao(pagina, largura, altura) {
	w = screen.width;
	h = screen.height;
	meio_w = w/2;
	meio_h = h/2;

	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;

	if(screen.width <= 1024) {
		window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+', scrollbars=1');
	} else {
		window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+', scrollbars=1');
	}
}
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}
function barraGestao(objeto) {
	if(objeto.value.length==4) {
		objeto.value = objeto.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 soNumeros(v){
    return v.replace(/\D/g,"")
}

function itelefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function icpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function icep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

