// JavaScript Document

// 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"; 
}

// FILTRA
function filtro(destino){
	var mes = document.frmNot.mes.value;
	var ano = document.frmNot.ano.value;
	window.location='index.php?meio='+destino+'&mes='+mes+'&ano='+ano;
}


// 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;
}
