// Faz um layer acompanhar o cursor do mouse
// Uso: na seção body -> onmousemove="cursortogether(layer_cursor)"


var ie = ( (navigator.appName.substr(0,27) == "Microsoft Internet Explorer") );
var ns = ( !ie );



// Centraliza layer
// Uso: na seção body -> onload="vhcenter(layer)" onresize="vhcenter(layer)"
function vhcenter(obj, largura, altura) {

  if (obj==null) return false;
  if (largura==null) largura=100;
  if (altura==null)  altura=100;

  if (ie) { 
    layerheight = obj.style.height;
    layerwidth  = obj.style.width;
  } else {
    layerheight = altura;
    layerwidth  = largura;
  }

  layerheight = parseInt(layerheight);
  layerheight = unescape(layerheight);
  layerwidth  = parseInt(layerwidth);
  layerwidth  = unescape(layerwidth);

  docmiddle    = (layerheight/2);
  if (ie) screenmiddle = (document.body.offsetHeight/2);
  else    screenmiddle = (innerHeight/2);
  screenmiddle = parseInt( screenmiddle );
  newoffset = (screenmiddle - docmiddle);
  newoffset -= 50;
  if (newoffset < 0) {
    newoffset = 0;
  }
  if (ie) obj.style.top = newoffset + "px";
  else obj.top = newoffset ;

  docmiddle = (layerwidth/2);
  if (ie) screenmiddle = (document.body.offsetWidth/2);
  else screenmiddle = (innerWidth/2);
  screenmiddle = parseInt( screenmiddle );
  newoffset = (screenmiddle - docmiddle);
  newoffset -= 10   // Centering correction
  if (newoffset < 0) {
    newoffset = 0;
  }
  if (ie) obj.style.left = newoffset + "px";
  else {
    obj.left = unescape(newoffset);
  }

}


function center_h(obj, largura, altura) {

  if (obj==null) return false;
  if (largura==null) largura=100;
  if (altura==null)  altura=100;

  if (ie) { 
//    layerheight = obj.style.height;
    layerwidth  = obj.style.width;
  } else {
//    layerheight = altura;
    layerwidth  = largura;
  }

//  layerheight = parseInt(layerheight);
//  layerheight = unescape(layerheight);
  layerwidth  = parseInt(layerwidth);
  layerwidth  = unescape(layerwidth);

//  docmiddle    = (layerheight/2);
//  if (ie) screenmiddle = (document.body.offsetHeight/2);
//  else    screenmiddle = (innerHeight/2);
//  screenmiddle = parseInt( screenmiddle );
//  newoffset = (screenmiddle - docmiddle);
//  newoffset -= 50;
//  if (newoffset < 0) {
//    newoffset = 0;
//  }
//  if (ie) obj.style.top = newoffset + "px";
//  else obj.top = newoffset ;

  docmiddle = (layerwidth/2);
  if (ie) screenmiddle = (document.body.offsetWidth/2);
  else screenmiddle = (innerWidth/2);
  screenmiddle = parseInt( screenmiddle );
  newoffset = (screenmiddle - docmiddle);
  newoffset -= 10   // Centering correction
  if (newoffset < 0) {
    newoffset = 0;
  }
  if (ie) obj.style.left = newoffset + "px";
  else {
    obj.left = unescape(newoffset);
  }

}



function semacento( variavel ) {
  if ( variavel.length <= 0 ) return "";

  var comac = "áãàâéèêíìîóõòôúùûçñÁÃÀÂÉÈÊÍÌÎÓÕÒÔÚÙÛÇÑ";
  var semac = "aaaaeeeiiioooouuucnAAAAEEEIIIOOOOUUUCN";
  var base  = variavel;
  var novabase = "";

  for (x=0; x <= (variavel.length-1); ++x ) {
    var caracter = variavel.substring( (x+1), x );
    var posicao = comac.indexOf( caracter );
    if ( posicao > -1 ) caracter = semac.substring( (posicao+1), posicao );
    novabase = novabase + caracter;
    caracter = "";
  }
  return novabase;
}



// Troca imagens
// Uso: swapImage('id_da_imagem','nova_imagem.gif')
function swapImage(imgName,newImg){
  if ((navigator.appName == 'Netscape' && parseFloat(navigator.appVersion) >= 3) || (parseFloat(navigator.appVersion) >= 4))
     { eval('document.' + imgName + '.src = "' + newImg + '"');
     }
}

// Executa pre-load em imagens
// Uso: preloadImages('imagem1.gif','imagem2.gif','imagem3.jpg')">

function preloadImages() { 
  if (document.images) {
    var imgFiles = preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

// Verifica a validade de data (com ano bissexto)
// Uso: 
//   if (!dataok(document.forms[0].nascimento) ) {
//       return false;
//   }

function dataok(dataObj) {

  temp = new String(dataObj.value);

  dia = temp.substring(0,2);
  if ((dia>31) || (dia<1)) {
    alert("Dia inválido !");
    return false;
  }

  if (temp.indexOf("/") == -1) {
    var mes = temp.substring(2,4);
    var ano = temp.substring(4,8);
  } else {
    var mes = temp.substring(3,5);
    var ano = temp.substring(6,10);
  }

  if ((mes>12) || (mes<1)) {
    alert("Mês inválido !");
    return false;
  }

  if ( (mes==4) || (mes==6) || (mes==9) || (mes==11) ) {
    if (dia>30) {
      alert("Dia inválido para este mês !");
      return false;
    }
  }

  if (mes==2) {
    // extrai módulo
    ano = parseInt(ano);
    ano = unescape(ano);
    divinteiro = Math.floor(ano/4);
    divisao    = (ano/4);
    resto = (divisao-divinteiro);

    if (resto>0) { // Não é ano bissexto
      if (dia>28) {
        alert("Neste ano fevereiro tem 28 dias !");
        return false;
      } else {
        if (dia>29) {
          alert("Fevereiro não pode ter mais que 29 dias !");
          return false;
        }
      }
    }
  }
  return true;
}


// Verifica a validade de hora
// Uso: 
//   if (!horaok(document.forms[0].horario) ) {
//       return false;
//   }

function horaok(horaObj) {

  temp = new String(horaObj.value);

  hora = temp.substring(0,2);
  if ((hora>23) || (hora<0)) {
    alert("Hora inválida !");
    return false;
  }

  if (temp.indexOf(":") == -1) {
    var minuto  = temp.substring(2,4);
    var segundo = temp.substring(4,6);
  } else {
    var minuto  = temp.substring(3,5);
    var segundo = temp.substring(6,8);
  }

  if ((minuto>59) || (minuto<0)) {
    alert("Minuto inválido !");
    return false;
  }

  if ((segundo>59) || (segundo<0)) {
    alert("Segundo inválido !");
    return false;
  }

  return true;
}

// Testa uma string para saber se é CPF ou CGC
function CPFouCNPJ( valor ) {
  if ( valor.length <= 12 ) {
     retorno = CPFOK( valor );
  } else {
     retorno = CNPJOK( valor );
  }
  return retorno;
}

// Extrai o módulo de uma string
function modulo(str) {
  soma=0;
  ind=2;
  for(pos=str.length-1;pos>-1;pos=pos-1) {
    soma = soma + (parseInt(str.charAt(pos)) * ind);
    ind++;
    if(str.length>11) {
      if(ind>9) ind=2;
    }
  }
  resto = soma - (Math.floor(soma / 11) * 11);
  if(resto < 2) {
    return 0;
  } else {
    return 11 - resto;
  }
}
    	

function CPFOK(cpf) {
// Verifica se o campo é nulo
if (cpf == '') {
//  alert('Este campo é de preenchimento obrigatório!');
  return false;
}

  cpfAux=new String(cpf);
  // para limpeza de caracteres
//  var limpar = " +-*/qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_=[]{};:?,<>~`|" + '".';
  var limpar = " +-*/.";
  var tamanho = (limpar.length );
  // limpa qualquer ocorrência
  for (vezes=1;vezes<=cpf.length;++vezes) {
    for (conta=0; conta<=tamanho; ++conta ) { cpf=cpf.replace((limpar.substr(conta,1)),""); }
  }

// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = cpf.substr(9, 2); // Retira os dois últimos dígitos do número informado

// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
  DIGITO[I] = cpf.substr( I, 1);
}

// Calcula o valor do 10º dígito da verificação
POSICAO = 10;
SOMA = 0;
for (I=0; I<=8; I++) {
  SOMA = SOMA + DIGITO[I] * POSICAO;
  POSICAO = POSICAO - 1;
}
DIGITO[9] = SOMA % 11;
if (DIGITO[9] < 2) {
  DIGITO[9] = 0;
} else {
  DIGITO[9] = 11 - DIGITO[9];
}

// Calcula o valor do 11º dígito da verificação
POSICAO = 11;
SOMA = 0;
for (I=0; I<=9; I++) {
  SOMA = SOMA + DIGITO[I] * POSICAO;
  POSICAO = POSICAO - 1;
}
DIGITO[10] = SOMA % 11;
if (DIGITO[10] < 2) {
  DIGITO[10] = 0;
} else {
  DIGITO[10] = 11 - DIGITO[10];
}

// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
if (DV != DV_INFORMADO) {
//  alert('CPF inválido');
//  formulario.CPF.value = '';
//  formulario.CPF.focus();
   return false;
  } 
  return true;
}


// Verifica a validade de CGC
function CNPJOK( valor ) {
  if (valor.length < 14) {
    return false;
  }

  cgcAux=new String(valor);

  pos=cgcAux.indexOf(" ");
  while (pos>0) {
    valor=cgcAux.replace(" ",'');
    cgcAux=valor;
    pos=cgcAux.indexOf(" ");
  }

  pos=cgcAux.indexOf(".");
  while (pos>0) {
    valor=cgcAux.replace(".",'');
    cgcAux=valor;
    pos=cgcAux.indexOf(".");
  }
	
  pos=cgcAux.indexOf("/");
  while (pos>0) {
    valor=cgcAux.replace("/",'');
    cgcAux=valor;
    pos=cgcAux.indexOf("/");
  }

  pos=cgcAux.indexOf("-");
  while (pos>0) {
    valor=cgcAux.replace("-",'');
    cgcAux=valor;
    pos=cgcAux.indexOf("-");
  }

  primeiro=valor.substr(1,1);
  falso=true;
  size=valor.length;
  size--;
  for (i=2; i<size-1; ++i) {
    proximo=(valor.substr(i,1));
    if (primeiro!=proximo) {
      falso=false;
    }
  }

  if (falso) {
    return false;
  }
		
  if( modulo( valor.substring( 0, valor.length - 2 ) ) + "" + modulo( valor.substring( 0, valor.length - 1) ) != valor.substring( valor.length - 2, valor.length ) ) {
    return false;
  }
  return true;
}

// Coloca o dia e hora no rodapé
// Uso: na seção body -> onload="startclock()"

var timerID = null;
var timerRunning = false;
function startclock () {
   stopclock();
   time();
}

function stopclock () {
   if(timerRunning)
      clearTimeout(timerID);
   timerRunning = false;
}

function time () {
   var now = new Date();
   var yr = now.getYear();
   var mName = now.getMonth() + 1;
   var dName = now.getDay() + 1;
//   var dayNr = ((now.getDate()<10) ? "0" : "")+ now.getDate();
   var dayNr = now.getDate();
   var ampm = (now.getHours() >= 12) ? "pm" : "am"
   var hours = now.getHours();

   hours = ((hours > 12) ? hours - 12 : hours);

   var minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
   var seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();

   if(dName==1) Day = "Domingo";
   if(dName==2) Day = "Segunda-feira";
   if(dName==3) Day = "Terça-feira";
   if(dName==4) Day = "Quarta-feira";
   if(dName==5) Day = "Quinta-feira";
   if(dName==6) Day = "Sexta-feira";
   if(dName==7) Day = "Sábado";

   if(mName==1) Month="janeiro";
   if(mName==2) Month="fevereiro";
   if(mName==3) Month="março";
   if(mName==4) Month="abril";
   if(mName==5) Month="maio";
   if(mName==6) Month="junho";
   if(mName==7) Month="julho";
   if(mName==8) Month="agosto";
   if(mName==9) Month="setembro";
   if(mName==10) Month="outubro";
   if(mName==11) Month="novembro";
   if(mName==12) Month="dezembro";

//   var DayDateTime=(" Hoje é " 
   var DayDateTime=( Day + ", " + dayNr + " de " + Month + " de " + yr
                     + " - " + hours + minutes + ampm );

   window.status=DayDateTime;
   timerID = setTimeout("time()",1000);
   timerRunning = true;
}

function clearStatus() {
   if(timerRunning)
      clearTimeout(timerID);
   timerRunning = false;
   window.status=" ";   
}


function escrevedata() {
   var now = new Date();
   var yr = now.getYear();
   var mName = now.getMonth() + 1;
   var dName = now.getDay() + 1;
   var dayNr = ((now.getDate()<10) ? "0" : "")+ now.getDate();
   var ampm = (now.getHours() >= 12) ? " pm" : " am"
   var hours = now.getHours();

   hours = ((hours > 12) ? hours - 12 : hours);

   var minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
   var seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();

   if(dName==1) Day = "Domingo";
   if(dName==2) Day = "Segunda-feira";
   if(dName==3) Day = "Terça-feira";
   if(dName==4) Day = "Quarta-feira";
   if(dName==5) Day = "Quinta-feira";
   if(dName==6) Day = "Sexta-feira";
   if(dName==7) Day = "Sábado";

   if(mName==1) Month="janeiro";
   if(mName==2) Month="fevereiro";
   if(mName==3) Month="março";
   if(mName==4) Month="abril";
   if(mName==5) Month="maio";
   if(mName==6) Month="junho";
   if(mName==7) Month="julho";
   if(mName==8) Month="agosto";
   if(mName==9) Month="setembro";
   if(mName==10) Month="outubro";
   if(mName==11) Month="novembro";
   if(mName==12) Month="dezembro";

   var DayDateTime=( Day
       + ", "
       + dayNr
       + " de "
       + Month
       + " de "
       + ""
       + yr
       + "." );
  document.writeln( DayDateTime );
  return true;
}

// document.onmousedown=right;
// if (document.layers) window.captureEvents(Event.MOUSEDOWN);
// window.onmousedown=right;


function enviapagina( novolocal ) {
  doclocal = location.hostname;
  if ( doclocal == "" ) doclocal = document.location;
  msgemail = "mailto:\?subject\=Veja este site que encontrei.&body=É muito bom! O endereço é "+doclocal;
  window.location = msgemail;
}

var menuskin = "skin1"; // skin0, or skin1
var display_url = 0; // Show URLs in status bar?
function showmenuie5() {
  var rightedge  = document.body.clientWidth-event.clientX;
  var bottomedge = document.body.clientHeight-event.clientY;
  if (rightedge < ie5menu.offsetWidth) ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;
  else                                 ie5menu.style.left = document.body.scrollLeft + event.clientX;
  if (bottomedge < ie5menu.offsetHeight) ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;
  else                                   ie5menu.style.top = document.body.scrollTop + event.clientY;
  ie5menu.style.visibility = "visible";
  return false;
}
function hidemenuie5() {
  ie5menu.style.visibility = "hidden";
}
function highlightie5() {
  if (event.srcElement.className == "menuitems") {
    event.srcElement.style.backgroundColor = "highlight";
    event.srcElement.style.color = "white";
    if (display_url) window.status = event.srcElement.url;
   }
}
function lowlightie5() {
  if (event.srcElement.className == "menuitems") {
    event.srcElement.style.backgroundColor = "";
    event.srcElement.style.color = "black";
    window.status = "";
   }
}
function jumptoie5() {
  if (event.srcElement.className == "menuitems") {
    if (event.srcElement.getAttribute("target") != null)
      window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
    else
      top.main.location = event.srcElement.url;
//      window.location = event.srcElement.url;
   }
}

// controla o menu com o botão direito do mouse
// vê qual é o endereço onde está a página...
endereco = location.hostname;  // vai informar www.endereco.com.br
// if ( endereco != "" ) endereco = "http://" + endereco + "/main.php";
if ( endereco != "" ) endereco = "http://" + endereco ;
document.write( '<style>\n' );
document.write( '.skin0 { z-index:0; position:absolute; text-align:left; width:200px; border:2px solid black; background-color:menu; font-family:Verdana; line-height:20px; cursor:default; visibility:hidden; }\n');
document.write( '.skin1 { cursor:default; font:menutext; position:absolute; text-align:left; font-family: Arial, Helvetica, sans-serif; font-size: 9pt; width:150px; background-color:menu; border:1 solid buttonface; visibility:hidden; border:2 outset buttonhighlight; }\n');
document.write( '.menuitems { padding-left:5px; padding-right:5px; }\n');
document.write( '</style>\n');
document.write( '<div id="ie5menu" class="skin0" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5();">\n');
document.write( '  <div class="center">MENU</div>\n');
document.write( '  <hr>\n');
// document.write( '  <div class="menuitems" url="javascript:history.back();">Voltar</div>\n');
// document.write( '  <div class="menuitems" url="javascript:document.location=document.location;">Reler a página</div>\n');
// document.write( '  <div class="menuitems" url="javascript:document.location.reload();">Reler a página</div>\n');
if ( endereco != "" ) document.write( '  <div class="menuitems" url="'+endereco+'/index.html" target="_top">Página Principal</div>\n');
document.write( '  <hr>\n');
document.write( '  <div class="menuitems" url="http://www.genios.com.br/download/" target="_top">Dowloads</div>\n');
document.write( '  <div class="menuitems" url="http://www.genios.com.br/sugestoes.html" target="_top">Sugestões</div>\n');
// document.write( '  <div class="menuitems" url="/servicos/eventos.php" target="main">Eventos</div>\n');
// document.write( '  <div class="menuitems" url="http://www.hpg.com.br/guestbook/guestbook.php3?user=aumbandan&action=write">Assinar Livro de Visitas</div>\n');
// testa os servidores...
// if ( endereco.indexOf( ".hpg.")>0  )    document.write( '  <div class="menuitems" url="http://www.globo.com/Globo.com/Top10/glb_top10_votar/1,12361,,00.html?site_id=7601" target="_blank">Votar no site</div>\n');
// document.write( '  <hr>\n');
// document.write( '  <div class="menuitems" url="http://www.genios.com.br/sugestoes.html" target="_top">Sugestões</div>\n');
// document.write( '  <div class="menuitems" url="mailto:genios@genios.com.br">Entrar em contato</div>\n');
// document.write( '  <div class="menuitems" url=javascript:enviapagina()>Indicar este site</div>\n');
document.write( '</div>\n');
document.write( '<scr' + 'ipt language="JavaScript1.2">\n');
document.write( 'if (document.all && window.print) {\n');
document.write( 'ie5menu.className = menuskin;\n');
document.write( 'document.oncontextmenu = showmenuie5;\n');
document.write( 'document.body.onclick = hidemenuie5;\n');
document.write( '}\n');
document.write( '</scr' + 'ipt>\n');
// Início da função imprimir!

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage() 
{
       gotoURL_ENDERECO(document.forms[0].ENDERECO.value);
//       window.alert("O documento está sendo impresso.\n\nAo término pressione CONFIRMA.");
//     SetDefaultFocus();
       return false;

}

function Print() 
{
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // outros browsers
   {
    alert("Seu browser não suporta esta função de impressão.")
    alert("Utilize o botão de imprimir do browser.")
   } 
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}
