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 = 14;
function mudaFonte(tipo,elemento){
	if (tipo=="mais") {
		if(tam<=22) tam+=1;
	} else {
		if(tam>=13) tam-=1;
	}

	$K('textoNoticias').style.fontSize = tam+'px';
}

/* =================================================================== */



/* Javascript de Nivel de segurança da senha */

function SegurancaSenha(val, tamanho) {

	$K('nivelSeguranca').style.borderBottom = '4px solid #a80000';

	$K('nivelSegurancaTxt').innerHTML = "Baixo";

	$K('nivelSegurancaTxt').style.color = "#a80000";



	if(val=="") {

		$K('nivelSeguranca').style.borderBottom = '4px solid #a80000';

		$K('nivelSegurancaTxt').style.color = "#a80000";

		return;   

	}

	if(val.length<tamanho ) {

		$K('nivelSeguranca').style.borderBottom = '4px solid #a80000';

		$K('nivelSegurancaTxt').style.color = "#a80000";

		return;   

	}



	if( val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) != -1 ||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) ||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1 && val.search(/[0-9]/) ||val.length >= tamanho  && val.search(/[@!#$%&*+=?|-]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) ) {

		$K('nivelSeguranca').style.borderBottom = '4px solid #6aaa1a';

		$K('nivelSegurancaTxt').innerHTML = "Forte";

		$K('nivelSegurancaTxt').style.color = "#6aaa1a";

	} else {

		if( val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 ||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[0-9]/) != -1 ||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1||val.length >= tamanho && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) != -1 ||val.length >= tamanho && val.search(/[A-Z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1 ||val.length >= tamanho && val.search(/[0-9]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1) {

			$K('nivelSeguranca').style.borderBottom = '4px solid #ffa507';

			$K('nivelSegurancaTxt').innerHTML = "Moderada";

			$K('nivelSegurancaTxt').style.color = "#ffa507";

		} else {

			if(val.length >= tamanho) {

				$K('nivelSeguranca').style.borderBottom = '4px solid #ff2f19';

				$K('nivelSegurancaTxt').style.color = "#ff2f19";

				$K('nivelSegurancaTxt').innerHTML = "Fraco";

			}

		}

	}

}

// Verifica as senhas

verificaSenhas = function(verifica) {

	var strSenha = $K('novaSenha');



	if(strSenha.value != ''){

		if(strSenha.value == verifica.value) {

			strSenha.style.background	= '#f1f1f6';

			strSenha.style.border		= '1px solid';

			strSenha.style.borderTopColor = '#d4d4d4';

			strSenha.style.borderBottomColor = '#edeaea';

			strSenha.style.borderLeftColor = '#d4d4d4';

			strSenha.style.borderRightColor = '#eeebeb';

			verifica.style.background	= '#f1f1f6';

			verifica.style.border		= '1px solid';

			verifica.style.borderTopColor = '#d4d4d4';

			verifica.style.borderBottomColor = '#edeaea';

			verifica.style.borderLeftColor = '#d4d4d4';

			verifica.style.borderRightColor = '#eeebeb';



		} else {

			strSenha.style.background = '#FFB0B7';

			strSenha.style.border= '1px solid #FF0000';

			verifica.style.background = '#FFB0B7';

			verifica.style.border= '1px solid #FF0000';			

		}

	}

}

/* =================================================================== */



function validarEnquete(theForm) {

	var controle = 0;

	for(i=0;i<document.EnqueteForm.elements.length;i++) {

		if(document.EnqueteForm.elements[i].type=="radio") {

			if(document.EnqueteForm.elements[i].checked==true) { controle++; }

		}

	}

	if(controle <= 0) { alert("Selecione uma opção para votar!"); return false; }



	ajaxForm('enqueteAjax', 'EnqueteForm');

	return(true);

}











function VarlidarNoticia(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 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 PooopupLojaonline(pagina) { 

	w = screen.width;

	h = screen.height;

	window.open(pagina,'','height='+h+', width='+w+', top=0, left=0, scrollbars=yes, status=yes, toolbar=yes, location=yes, directories=yes, menubar=yes, resizable=yes, fullscreen=yes');

}

function barra(objeto){

	if (objeto.value.length == 2 || objeto.value.length == 5 ){

	objeto.value = objeto.value+"/";

	}

}

function barraDataHora(objeto) {

	// 23/09/2010 14:39:00

	if(objeto.value.length==2 || objeto.value.length==5) {

	objeto.value = objeto.value+"/";

	}

	if(objeto.value.length==10) {

		objeto.value = objeto.value+" ";

	}

	if(objeto.value.length==13 || objeto.value.length==16) {

		objeto.value = objeto.value+":";

	}

}





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 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

}


