function verificaBrowser(){
  var versao = window.navigator.userAgent;
  // CHECA O NAVEGADOR
  if(versao.indexOf("MSIE")!= -1){
//    window.alert("Internet Explorer");
    var browser = "MSIE";
  }else if(versao.indexOf("Firefox")!= -1){
//    window.alert("Mozzila Firefox");
    var browser = "Firefox";
  }else if(versao.indexOf("Chrome")!= -1){
//    window.alert("Google Chrome");
    var browser = "Chrome";
  }else if(versao.indexOf("Safari")!= -1){
    if(versao.indexOf("Chrome")!= -1){
    }else{
//      window.alert("Apple Safari");
      var browser = "Safari";
    }
  }
  return browser;
}

function larguraBrowser(){
     return window.innerWidth ? window.innerWidth : /* For non-IE */
            document.documentElement ? document.documentElement.clientWidth : /* IE 6+ (Standards Compilant Mode) */
            document.body ? document.body.clientWidth : /* IE 4 Compatible */
            window.screen.width; /* Others (It is not browser window size, but screen size) */
}

function alturaBrowser(){
     return window.innerHeight ? window.innerHeight : /* For non-IE */
            document.documentElement ? document.documentElement.clientHeight : /* IE 6+ (Standards Compilant Mode) */
            document.body ? document.body.clientHeight : /* IE 4 Compatible */
            window.screen.height; /* Others (It is not browser window size, but screen size) */
}

function verificaTamanhoJanela(){
  largura = larguraBrowser().toString();
  altura = alturaBrowser().toString();

  var tamanho = new Array(2);
  tamanho[0] = largura;
  tamanho[1] = altura;
  
  return tamanho;
}

function ajustaCamada(camada,posx,posy,sinal_top,top,sinal_left,left){
  var obj = document.getElementById(camada);

  if(sinal_top == '+'){
    obj.style.top   = posy + top + 'px';
  }else if(sinal_top == '-'){
    obj.style.top   = posy - top + 'px';
  }
  if(sinal_left == '+'){
    obj.style.left  = posx + left + 'px';
  }else if(sinal_left == '-'){
    obj.style.left  = posx - left + 'px';
  }
}

function pegarPosicaoX(objeto){
  var atual_left = 0;
  if (objeto.offsetParent) {
    while (objeto.offsetParent) {
      atual_left += objeto.offsetLeft
      objeto = objeto.offsetParent;
    }
  }
  return atual_left;
}

function pegarPosicaoY(objeto){
  var atual_top = 0;
  if (objeto.offsetParent) {
    while (objeto.offsetParent) {
      atual_top += objeto.offsetTop
      objeto = objeto.offsetParent;
    }
  }
  return atual_top;
}

function visibilidade(camada,acao){
  document.getElementById(camada).style.visibility = acao;
}

/*Verifica se o email é um email válido*/
function verificaEmail(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{
      return false;
    }
  }else if(typeof(mail) == "object"){
    if(er.test(mail.value)){
      return true;
    }
  }else{
    return false;
  }
}

/* FUNÇÃO QUE EXIBE UM ELEMENTO E OCULTA ELE QUANDO OCORRE UM CLICK FORA DELE. */
/* document.onclick=evento; */
function evento(e){
  var target = (e && e.target) || (event && event.srcElement);
    if(target.id == 'clica'){
      habilitaAlertaProblema('alertar_problema',target.id,'descricao_problema');
    }else if(target.id == 'alertar_problema' || target.id == 'registra_problema' || target.id == 'descricao_problema' || target.id == 'enviar_problema'){
    }else{
      desabilitaAlertaProblema('alertar_problema');
    }
}
function habilitaAlertaProblema(camada,clique,campo){
  ajustaCamada(camada,pegarPosicaoX(document.getElementById(clique)),pegarPosicaoY(document.getElementById(clique)),'+',12,'-',370);
  visibilidade(camada,'visible');
  document.getElementById(campo).focus();
}
function desabilitaAlertaProblema(camada){
  visibilidade(camada,'hidden');
}

function iniciaGaleriaInicial(total_fotos,foto_proxima,atual_foto){
  var _global = this;
  if(foto_proxima && atual_foto){
    var foto_atual = 'foto_rotativa_' + atual_foto;
    var proxima_foto = 'foto_rotativa_' + foto_proxima;
    document.getElementById(foto_atual).style.visibility = 'hidden';
    document.getElementById(foto_atual).style.zIndex = 1;
    document.getElementById(proxima_foto).style.visibility = 'visible';
    document.getElementById(proxima_foto).style.zIndex = 10;
    clearInterval(_global.atualizaGaleria);
    _global.atualizaGaleria = setInterval(function(){
      loopingGaleriaInicial(total_fotos,foto_proxima,1);
    }, 10000);
  }else{
    document.getElementById('foto_rotativa_1').style.zIndex = 10;
    for(i=2;i<=total_fotos;i++){
      var camada_galeria_inicial = 'foto_rotativa_' + i;
      document.getElementById(camada_galeria_inicial).style.visibility = 'hidden';
    }
    document.getElementById('foto_visivel').value = 1;
    _global.atualizaGaleria = setInterval(function(){
      loopingGaleriaInicial(total_fotos);
    }, 10000);
  }
}

function loopingGaleriaInicial(total_fotos,foto,ativo){
  var _global = this;

  if(ativo == 1){
    clearInterval(_global.atualizaGaleria);
    _global.atualizaGaleria = setInterval(function(){
      loopingGaleriaInicial(total_fotos);
    }, 10000);
  }

  if(foto){
    var foto_visivel = foto;
  }else{
    var foto_visivel = document.getElementById('foto_visivel').value;
  }
  var foto_atual = 'foto_rotativa_' + foto_visivel;
  if(foto_visivel == total_fotos){
    var foto_seguinte = 1;
  }else{
    var foto_seguinte = parseInt(parseInt(foto_visivel)+1);
  }
  var proxima_foto = 'foto_rotativa_' + foto_seguinte;

  document.getElementById(foto_atual).style.visibility = 'hidden';
  document.getElementById(foto_atual).style.zIndex = 1;
  document.getElementById(proxima_foto).style.visibility = 'visible';
  document.getElementById(proxima_foto).style.zIndex = 10;
  if(foto_seguinte > total_fotos){
    document.getElementById('foto_visivel').value = 1;
  }else{
    document.getElementById('foto_visivel').value = foto_seguinte;
  }
}


function iniciaBannerRotativo(total_banners){
  document.getElementById('banner_1').style.zIndex = 5;
  for(i=2;i<=total_banners;i++){
    var camada_banner_inicial = 'banner_' + i;
    document.getElementById(camada_banner_inicial).style.visibility = 'hidden';
  }
  document.getElementById('banner_visivel').value = 1;
  var atualizaBanner = setInterval(function(){
    loopingBannerInicial(total_banners);
  }, 6000);
}

function loopingBannerInicial(total_banners){
  var banner_visivel = document.getElementById('banner_visivel').value;
  var banner_atual = 'banner_' + banner_visivel;
  if(banner_visivel == total_banners){
    var banner_seguinte = 1;
  }else{
    var banner_seguinte = parseInt(parseInt(banner_visivel)+1);
  }
  var proximo_banner = 'banner_' + banner_seguinte;

  document.getElementById(banner_atual).style.visibility = 'hidden';
  document.getElementById(banner_atual).style.zIndex = 1;
  document.getElementById(proximo_banner).style.visibility = 'visible';
  document.getElementById(proximo_banner).style.zIndex = 5;
  if(banner_seguinte > total_banners){
    document.getElementById('banner_visivel').value = 1;
  }else{
    document.getElementById('banner_visivel').value = banner_seguinte;
  }
}

function visualizaPaginaSubmenu(pagina,total_paginas){
  for(i=1;i<=total_paginas;i++){
    var coluna_submenus = 'pagina_submenu_' + i;
    document.getElementById(coluna_submenus).style.position = 'absolute';
    document.getElementById(coluna_submenus).style.visibility = 'hidden';
  }
  document.getElementById('pagina_submenu_'+pagina).style.position = 'relative';
  document.getElementById('pagina_submenu_'+pagina).style.visibility = 'visible';
}

function exibePopUp(largura,altura,timer){
  margem_superior = (-1) * parseInt(altura/2) + 'px';
  margem_esquerda = (-1) * parseInt(largura/2) + 'px';

  document.getElementById('popup').style.marginTop = margem_superior;
  document.getElementById('popup').style.marginLeft = margem_esquerda;
  
  mostraPopup();
  
  var timer_popup = parseInt(timer) * 1000;
  var esconde = setInterval(function(){
    escondePopup();
  }, timer_popup);
}

function mostraPopup(){
  document.getElementById('popup').style.visibility = 'visible';
}

function escondePopup(){
  document.getElementById('popup').style.visibility = 'hidden';
}

function exibeMesCalendario(){
  for(i=1;i<=12;i++){
    var mes_calendario = 'calendario_agenda_' + i;
    document.getElementById(mes_calendario).style.visibility = 'hidden';
    document.getElementById(mes_calendario).style.position = 'absolute';
    document.getElementById(mes_calendario).style.zIndex = 1;
  }

  var mes_exibicao = 'calendario_agenda_' + document.getElementById('mes_exibicao').value;

  document.getElementById(mes_exibicao).style.visibility = 'visible';
  document.getElementById(mes_calendario).style.position = 'relative';
  document.getElementById(mes_exibicao).style.zIndex = 10;
}

function proximoMesCalendario(){
  for(i=1;i<=12;i++){
    var mes_calendario = 'calendario_agenda_' + i;
    document.getElementById(mes_calendario).style.visibility = 'hidden';
    document.getElementById(mes_calendario).style.position = 'absolute';
    document.getElementById(mes_calendario).style.zIndex = 1;
  }

  var mes_exibicao = 'calendario_agenda_' + parseInt(parseInt(document.getElementById('mes_exibicao').value) + 1);

  document.getElementById(mes_exibicao).style.visibility = 'visible';
  document.getElementById(mes_calendario).style.position = 'relative';
  document.getElementById(mes_exibicao).style.zIndex = 10;

  if(parseInt(parseInt(document.getElementById('mes_exibicao').value) + 1) < 12){
    document.getElementById('mes_exibicao').value = parseInt(parseInt(document.getElementById('mes_exibicao').value) + 1);
    document.getElementById('esquerda_calendario').style.visibility = 'visible';
    document.getElementById('esquerda_calendario').style.display = 'table';
    document.getElementById('direita_calendario').style.visibility = 'visible';
    document.getElementById('direita_calendario').style.display = 'table';
  }else{
    document.getElementById('mes_exibicao').value = parseInt(parseInt(document.getElementById('mes_exibicao').value) + 1);
    document.getElementById('direita_calendario').style.visibility = 'hidden';
    document.getElementById('direita_calendario').style.display = 'none';
  }
}

function anteriorMesCalendario(){
  for(i=1;i<=12;i++){
    var mes_calendario = 'calendario_agenda_' + i;
    document.getElementById(mes_calendario).style.visibility = 'hidden';
    document.getElementById(mes_calendario).style.position = 'absolute';
    document.getElementById(mes_calendario).style.zIndex = 1;
  }

  var mes_exibicao = 'calendario_agenda_' + parseInt(parseInt(document.getElementById('mes_exibicao').value) - 1);

  document.getElementById(mes_exibicao).style.visibility = 'visible';
  document.getElementById(mes_calendario).style.position = 'relative';
  document.getElementById(mes_exibicao).style.zIndex = 10;
  
  if(parseInt(parseInt(document.getElementById('mes_exibicao').value) - 1) > 1){
    document.getElementById('mes_exibicao').value = parseInt(parseInt(document.getElementById('mes_exibicao').value) - 1);
    document.getElementById('esquerda_calendario').style.visibility = 'visible';
    document.getElementById('esquerda_calendario').style.display = 'table';
    document.getElementById('direita_calendario').style.visibility = 'visible';
    document.getElementById('direita_calendario').style.display = 'table';
  }else{
    document.getElementById('mes_exibicao').value = parseInt(parseInt(document.getElementById('mes_exibicao').value) - 1);
    document.getElementById('esquerda_calendario').style.visibility = 'hidden';
    document.getElementById('esquerda_calendario').style.display = 'none';
  }
}

