// JavaScript Document

// SAIR DO GERENCIADFOR
function sairGerenciador(){
	if(confirm("Deseja sair do gerenciador?")){
		window.location='sair.php'	
	}
}

// TROCA IMGEME
function trocaImgSair1(){
	document.all.sair.src='imagens/sair1.jpg'
}

// SAIR NORMAL
function trocaImgSair2(){
	document.all.sair.src='imagens/sair.jpg'
}

// TROCA IMGEME
function trocaImgHome1(){
	document.all.inicial.src='imagens/home1.gif'
}

// SAIR NORMAL
function trocaImgHome2(){
	document.all.inicial.src='imagens/home.gif'
}

// LINHA SELECIONA
function M_over(src,clrOver) {
 if (!src.contains(event.fromElement)) {
  src.style.cursor = 'default';
  src.bgColor = clrOver;
 }
}
function M_out(src,clrIn) {
 if (!src.contains(event.toElement)) {
  src.style.cursor = 'default';
  src.bgColor = clrIn;
 }
}

// NOVA JANELA
function NovaJanela(mypage, myname, w, h, scroll, status) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+', status='+status+''
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus();
}
}

// janela menu
function JanelaMenu(mypage, myname, w, h, scroll, status, menu) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+', status='+status+', menubar='+menu+''
win = window.open(mypage, myname, winprops)
	if(parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}

// FAVORITOS
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

// RELOGIO
function atualizarelogio(){
var hoje=new Date()
var hora=hoje.getHours()
var minuto=hoje.getMinutes()
var seconds=hoje.getSeconds()

  if(hora<10){hora="0" + hora}
  if(minuto<10){minuto="0" + minuto}
  if(seconds<10){seconds="0" + seconds}

relog.innerText = hora + ":" + minuto // + ":" + seconds

setTimeout("atualizarelogio()",1000)
}

// RELOGIO
function atualizarelogio1(){
var hoje=new Date()
var hora=hoje.getHours()
var minuto=hoje.getMinutes()
var seconds=hoje.getSeconds()

  if(hora<10){hora="0" + hora}
  if(minuto<10){minuto="0" + minuto}
  if(seconds<10){seconds="0" + seconds}

relog.innerText = hora + ":" + minuto

setTimeout("atualizarelogio1()",1000)
}

// FRASE DO RODAPE
var hellotext=""
var thetext=""
var started=false
var step=0
var times=1
 function welcometext()
    {
      times--
      if (times==0)
      {
        if (started==false)
        {
          started = true;
          window.status = hellotext;
          setTimeout("anim()",1);
        }
        thetext = hellotext;
      }
    }
 function showstatustext(txt)
    {
      thetext = txt;
      setTimeout("welcometext()",4000)
      times++
    }
 function anim()
    {
     step++
      if (step==7) {step=1}
      if (step==1) {window.status='>==='+thetext+'===<'}
      if (step==2) {window.status='=>=='+thetext+'==<='}
      if (step==3) {window.status='>=>='+thetext+'=<=<'}
      if (step==4) {window.status='=>=>'+thetext+'<=<='}
      if (step==5) {window.status='==>='+thetext+'=<=='}
      if (step==6) {window.status='===>'+thetext+'<==='}
      setTimeout("anim()",200);
    }
//welcometext();

// MASCARA MOEDA
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // PRECO para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

// tira o controle do flash
function flash(arqflash,largura,altura) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
	document.write('<param name="movie" value="' + arqflash + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="' + arqflash + '" width="' + largura + '" height="' + altura + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" wmode="transparent"></embed>');
	document.write('</object>');
}

// MOSTRA LAYER DO GERENCIADOR
var top = ((screen.height-95)/3)-20;
var left = (screen.width-228)/2;
function show(){ 
	Layer1.style.visibility="visible";
	Layer1.style.top=top;
	Layer1.style.left=left;
}

function hide(){ 
	Layer1.style.visibility="hidden"; 
}

// EMAIL
function mail(email){
	var email = decode64(email);
	document.location.href='mailto:'+email;
}

// 
function decode64(input) {

   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

// TROCA ENTRE
function trocaEnter(campo, evt) {
    var e = evt || event;
    k = e.keyCode;
    
    if(k == 13) {
		buscar();
        return false;
    }
}


// POSIÇÃO LAYER INICIAL
function pos(){
	document.getElementById("logo").style.left = ((screen.width - 520) / 2);
	document.getElementById("logo").style.top = 60;

	document.getElementById("logoPortal").style.left = 10;
	document.getElementById("logoPortal").style.bottom = 10;
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                    return true; 
                }
    }else{
        return false;
        }
}
function cancelarContato(){
	if(confirm("Deseja realmente cancelar seu contato?")){
		window.top.location = "index.php";
	}
}
function confirmarContato(){
	nome = document.frmContato.NOME.value;
	empresa = document.frmContato.EMPRESA.value;
	cidade = document.frmContato.CIDADE.value;
	estado = document.frmContato.ESTADO.value;
	assunto = document.frmContato.ASSUNTO.value;
	mensagem = document.frmContato.MENSAGEM.value;
	retorno = document.frmContato.RETORNO.value;
	telefone = document.frmContato.TELEFONE.value;
	email = document.frmContato.EMAIL.value;
	motivo = document.frmContato.MOTIVO.value;
		
		if((nome != "") && (cidade != "") && (assunto != "") && (mensagem != "") && (telefone != "") && (email != "")){
			if(checkMail(email)) {
				document.frmContato.submit();
			} else {
				alert("O email informado não é válido!")
			}
		} else {
			alert("Preencha todos os campos marcados com asterisco (*)!")
		}
}

// MENU
function mudaOn(src,cor){
	src.style.background = cor;
	src.style.cursor = 'pointer';
	src.style.textDecoration = 'underline';
}
function mudaOff(src,cor){
	src.style.background = cor;
	src.style.cursor = 'default';
	src.style.textDecoration = 'none';
}
function ir(destino){
	window.location = destino;
}


// FILTRAR NTOICIAS
function filtroNoticias(destino){
	var mes = document.frmNot.mes.value;
	var ano = document.frmNot.ano.value;
	window.location='index.php?action='+destino+'&mes='+mes+'&ano='+ano;
}

function validaLogin(){
	
	// FORM
	f = document.frmLogin;
		
		if(f.CNPJ.value == ""){
			alert("Preencha o campo CNPJ!");
			document.frmLogin.CNPJ.focus();
			return false;
		}
		if(f.CNPJ.value == ""){
			alert("Preencha o campo com sua SENHA!");
			document.frmLogin.CNPJ.focus();
			return false;
		}
			
	return true; // ok
}

// LIMPA CAMPO
function limpaCampo(){
	if(document.getElementById("BUSCA").value == "Busca livre"){
		document.getElementById("BUSCA").value = "";
		document.getElementById("BUSCA").style.fontSize = "12px";
		document.getElementById("BUSCA").style.color = "#000000";
		document.getElementById("BUSCA").style.padding = "1 0 0 5";
	}
}
function mostraCampo(){
	if(document.getElementById("BUSCA").value == ""){
		document.getElementById("BUSCA").value = "Busca livre";
		document.getElementById("BUSCA").style.fontSize = "10px";
		document.getElementById("BUSCA").style.color = "#999999";
	}
}

// VALIDA BUSCA
function validaBusca(){
	if(document.getElementById("BUSCA").value == "Busca livre"){
		alert("Informe no campo busca a palavra que deseja buscar!");		
	} else {
		if(document.getElementById("BUSCA").value == ""){
			alert("Informe no campo busca a palavra que deseja buscar!");		
		} else {
			window.location='index.php?action=busca&b='+document.getElementById("BUSCA").value;
		}
	}
}

// TROCA ENTRE
function trocaEnterBusca(campo, evt) {
    var e = evt || event;
    k = e.keyCode;
    
    if(k == 13) {
		validaBusca();
        return false;
    }
}

// FORÇA DA SENHA
function checa_seguranca(pass, campo){ 

        var senha = document.getElementById(pass).value; 
        var entrada = 0; 
        var resultado; 
        
        if(senha.length < 6){ 
                entrada = entrada - 1; 
        } 
        
        if(!senha.match(/[a-z_]/i) || !senha.match(/[0-9]/)){ 
                entrada = entrada - 1; 
        } 
        
        if(!senha.match(/\W/)){ 
                entrada = entrada - 1; 
        } 
        
        if(entrada == 0){ 
//			resultado = 'A Segurança de sua senha é: <font color=\'#99C55D\'>EXCELENTE</font>'; 
			resultado = '<img src="http://www.suachave.com.br/senha/forte.jpg">';
        } else if(entrada == -1){ 
//			resultado = 'A Segurança de sua senha é: <font color=\'#7F7FFF\'>BOM</font>'; 
			resultado = '<img src="http://www.suachave.com.br/senha/boa.jpg">';
        } else if(entrada == -2){ 
//			resultado = 'A Segurança de sua senha é: <font color=\'#FF5F55\'>BAIXA</font>'; 
			resultado = '<img src="http://www.suachave.com.br/senha/fraca.jpg">';
        } else if(entrada == -3){ 
//			resultado = 'A Segurança de sua senha é: <font color=\'#A04040\'>MUITO BAIXA</font>'; 
			resultado = '<img src="http://www.suachave.com.br/senha/mfraca.jpg">';
        } 
        
        document.getElementById(campo).innerHTML = resultado; 
        
        return; 
}

// NOVA SENHA
function validaNovaSenha(){

	senha = document.frmCadastro.SENHA_ATUAL.value;
	senha1 = document.frmCadastro.SENHA_NOVA.value;
	senha2 = document.frmCadastro.SENHA_CONF.value;
	
		if((senha != "") && (senha1 != "") && (senha2 != "")){
			if(senha1 == senha2){
				document.frmCadastro.submit();
			} else {
				alert("A nova senha e a confirmação da senha são diferentes!");
			}
		} else {
			alert("Preencha todos os campos!");
		}

}

