﻿//***************************************************************************************************
//Invoca o método inicial do Robô de acessibilidade(Projeto: Deficiente Visual).
$(document).ready(function() {
   Acessibilidade.executar();
   FixMenuFlutuantePortalSeguranca();
});






//***************************************************************************************************
//Classe base do projeto de Acessilibidade
function Acessibilidade() {
   //
   //----- Inicio - Atributos -----
   //

   this.elementos = null;
   this.indiceElemento = -1;
   this.tabIndex = 0;

   //
   //------- Fim - Atributos ------
   //

   //*********************************************

   //
   // ----- Inicio - Métodos -----
   //

   // Método Iniciar
   // Responsável por iniciar processo de ajuste de acessibilidade na página atual.
   this.iniciar = function() {

      //Inicia o DedoDuro(OuterHTML do objeto selecionado).
      //DedoDuro.executar();

      //Remove todos os atributos tabIndex pré existentes.
      $("*").removeAttr("tabIndex");

      //Ajusta todos os elementos que nao tinha como ser tabuláveis.
      this.trataElementosSolto();

      //Captura todos os elementos da página.
      this.elementos = document.getElementsByTagName('*');

      //Vai de elemento a elemento do documento
      for (this.indiceElemento = 0; this.indiceElemento < this.elementos.length; this.indiceElemento++) {

         //Verifica se o elemento ja não foi tratado, caso não tenha sido tratado aceita elemento.
         elementoAceito = !this.elementoFoiTratado();

         if (elementoAceito) {
            elementoAtual = this.getElementoAtual();

            //Verifica se trata ou invalida o elemento.
            if (this.tagElementoATratar()) {
               this.trataElemento(this);
            }
            else {
               this.invalidaElementoSeNecessario();
            }
         }
      }
   }

   // Método elementoFoiTratado
   // Responsável por retornar se o elemento ja foi tratado.
   this.elementoFoiTratado = function() {
      var elementoAtual = this.getElementoAtual();
      return Auxiliar.elementoFoiTratado(elementoAtual);
   }

   // Método invalidaElemento
   // Responsável por invalidar o elemento da vez.
   this.invalidaElemento = function() {
      var elementoAtual = this.getElementoAtual();
      Auxiliar.setTabIndexInvalido(elementoAtual);
   }

   // Método invalidaElementoSeNecessario
   // Responsável por invalidar o elemento da vez se necessário.
   this.invalidaElementoSeNecessario = function() {
      var elementoAtual = this.getElementoAtual();
      Auxiliar.setSePrecisarInvalidarElemento(elementoAtual);
   }

   // Método getTabIndexValido
   // Responsável por retornar um tabIndex sequencial.
   this.getTabIndexValido = function() {
      this.tabIndex++;
      return this.tabIndex;
   }

   // Método setTabIndex
   // Seta o tabIndex do elemento recebido,
   this.setTabIndex = function(pValido, pElementoAtual) {
      if (pValido) {
         //valida o tabIndex do elemento.
         pElementoAtual.tabIndex = this.getTabIndexValido();
         if (pElementoAtual.tabIndex == 1) {
            try {
               pElementoAtual.focus();
            }
            catch (err) {

            }
         }
      }
      else {

         //invalida o elemento, dessa forma o mesmo não sera selecionável via tab.
         this.invalidaElementoSeNecessario();
      }
   }

   // Método trataElementosSolto
   // Responsável por ajustar todos os elemento que nao tem tag e deveriam ter para serem acessíveis via tab.
   this.trataElementosSolto = function() {
      //Captura todos os elementos da página.
      this.elementos = document.getElementsByTagName('*');

      var tagsNaoAceita = " !, META, SCRIPT, HTML, BODY, LINK, TITLE, HEAD, SPAN"

      for (var i = 0; i < this.elementos.length; i++) {
         elementoAtual = this.elementos[i];

         if (tagsNaoAceita.indexOf(elementoAtual.nodeName) < 0) {
            if (AjustaTagLI.LISomenteTextoETagBR(elementoAtual)) {
               continue;
            }

            if (AjustaTagLI.LIMaisDeUmTextoEUmaTagA(elementoAtual)) {
               continue;
            }

            if (elementoAtual.nodeName != "TD") {
               if (elementoAtual.childNodes.length > 1) {
                  j = 0;

                  while (j < elementoAtual.childNodes.length) {

                     if ((elementoAtual.childNodes[j].nodeName == "#text")) {

                        var conteudoElemento = Auxiliar.getTextSemEspacos(elementoAtual.childNodes[j]);
                        //elementoAtual.childNodes[j].data.replace(/ /gi, "");

                        if ((conteudoElemento != "") && (conteudoElemento != "|")) {
                           var newDiv = document.createElement("DIV");
                           newDiv.setAttribute("innerHTML", elementoAtual.childNodes[j].data)
                           retirar = elementoAtual.childNodes[j];
                           elementoAtual.insertBefore(newDiv, retirar);
                           elementoAtual.removeChild(retirar);
                        }
                     }

                     j++;
                  }
               }
            }
            else {
               if ((elementoAtual.childNodes.length == 1) && (elementoAtual.childNodes[0].nodeName == "#text") && (elementoAtual.innerHTML.replace(/ /gi, "").replace(/&nbsp;/gi, "") != "")) {
                  var newDiv = document.createElement("DIV");
                  newDiv.setAttribute("innerHTML", elementoAtual.innerText);
                  retirar = elementoAtual.childNodes[0];
                  elementoAtual.insertBefore(newDiv, retirar);
                  elementoAtual.removeChild(retirar);
               }
            }
         }
      }
   }

   // Método trataElemento
   // Responsável por chamar o método responsável por ajustar o elemento da vez.
   this.trataElemento = function(pAcessibilidade) {

      //variável de validação
      //responsável por apontar se o elemento receberá
      //um tabIndex ou se o mesmo será invalidado para o tabIndex.
      var valido = false;
      var elementoAtual = this.getElementoAtual();
      switch (elementoAtual.tagName) {

         case "TD":
            {
               valido = AjustaTagTD.regras(elementoAtual);
               break;
            }
         case "A":
            {
               valido = AjustaTagA.regras(elementoAtual);
               break;
            }
         case "IMG":
            {
               valido = AjustaTagIMG.regras(elementoAtual);
               break;
            }
         case "IFRAME":
            {
               valido = true;
               break;
            }
         case "H1":
            {
               valido = AjustaTagH1.regras(elementoAtual);
               break;
            }
         case "H2":
            {
               valido = AjustaTagH2.regras(elementoAtual);
               break;
            }
         case "H3":
            {
               valido = AjustaTagH3.regras(elementoAtual);
               break;
            }
         case "H4":
            {
               valido = AjustaTagH4.regras(elementoAtual);
               break;
            }
         case "H5":
            {
               valido = AjustaTagH5.regras(elementoAtual);
               break;
            }
         case "LI":
            {
               valido = AjustaTagLI.regras(elementoAtual);
               break;
            }
         case "P":
            {
               valido = AjustaTagP.regras(elementoAtual);
               break;
            }
         case "SMALL":
            {
               valido = AjustaTagSMALL.regras(elementoAtual);
               break;
            }
         case "DIV":
            {
               valido = AjustaTagDIV.regras(elementoAtual, pAcessibilidade);
               break;
            }
         case "STRONG":
            {
               valido = AjustaTagSTRONG.regras(elementoAtual);
               break;
            }
         case "B":
            {
               valido = AjustaTagB.regras(elementoAtual);
               break;
            }
         case "U":
            {
               valido = AjustaTagU.regras(elementoAtual);
               break;
            }
         case "SPAN":
            {
               valido = AjustaTagSPAN.regras(elementoAtual);
               break;
            }
         case "INPUT":
            {
               valido = AjustaTagINPUT.regras(elementoAtual);
               break;
            }
         case "SELECT":
            {
               valido = AjustaTagSELECT.regras(elementoAtual);
               break;
            }
         default:
            {
               valido = false;
               break;
            }
      }

      this.setTabIndex(valido, elementoAtual);
   }

   // Método tagElementoATratar
   // Responsável por retornar se o elemento vai ser tratado ou não.
   this.tagElementoATratar = function() {
      var elementoAtual = this.getElementoAtual();
      return (Acessibilidade.tagNameValidas.indexOf(" " + elementoAtual.tagName) >= 0)
   }

   // Método getElementoAtual
   // Responsável por retornar o elemento da vez.
   this.getElementoAtual = function() {
      return this.elementos[this.indiceElemento];
   }

   //
   // ------- Fim - Métodos ------
   //
}

//Método estático para iniciar procedimento de ajuste acessibilidade.
Acessibilidade.executar = function() {

   //Instância objeto que conter todos as informações necessárias para ajustar a página atual para acessibilidade.
   var acessibilidade = new Acessibilidade();

   //Inicia processo de ajuste de acessibilidade.
   acessibilidade.iniciar();
}

//Campo estático constante com as tags aceitas.
Acessibilidade.tagNameValidas = " A, IMG, IFRAME, H1, H2, H3, H4, H5, P, LI, DIV, STRONG, B, U, SPAN, INPUT, SELECT, SMALL, TD";
//PRE, H5, SUB, SUP, HR, OL, UL";






















//***************************************************************************************************

function Auxiliar() { }

//Campo estático;
Auxiliar.elementosTabulaveis = " A, SPAN";


// Método estático elementoNaoTratado
// Responsável por retornar se o elemento foi tratrado.
Auxiliar.elementoFoiTratado = function(pElementoAtual) {
   return (pElementoAtual.tabIndex > 0 || pElementoAtual.tabIndex == -1);
}




// Método estático elementoNaoTratado
// Responsável por retornar se o elemento foi tratrado.
Auxiliar.getTextSemEspacos = function(pElementoAtual) {

   var conteudo;

   if (pElementoAtual.nodeValue) {
      conteudo = pElementoAtual.nodeValue;
   }
   else {
      conteudo = pElementoAtual.innerText;
   }

   while (conteudo.indexOf(" ") >= 0 || conteudo.indexOf("&nbsp;") >= 0 || conteudo.indexOf(String.fromCharCode(160)) >= 0) {
      conteudo = conteudo.replace(/ /, "").replace(/&nbsp;/, "").replace(String.fromCharCode(160), "");
   }

   return conteudo;
}

// Método estático elementoNaoTratado
// Responsável por retornar se o elemento foi tratrado.
Auxiliar.getTextSemEspacosFromText = function(pText) {

   var conteudo = pText;

   while (conteudo.indexOf(" ") >= 0 || conteudo.indexOf("&nbsp;") >= 0 || conteudo.indexOf(String.fromCharCode(160)) >= 0) {
      conteudo = conteudo.replace(/ /, "").replace(/&nbsp;/, "").replace(String.fromCharCode(160), "");
   }

   return conteudo;
}



// Método estático setSePrecisarInvalidarElemento
// Responsável por setar no atributo tabIndex do objeto um valor que invalida o elemento via tabulação.
Auxiliar.setSePrecisarInvalidarElemento = function(pElementoAtual) {
   tagsQueTemDeInvalidar = " A, BODY, OBJECT, DIV";

   if (tagsQueTemDeInvalidar.indexOf(pElementoAtual.tagName) > -1) {
      Auxiliar.setTabIndexInvalido(pElementoAtual);
   }
}


// Método estático setTabIndexInvalido
// Responsável por setar no atributo tabIndex do objeto um valor que invalida o elemento via tabulação.
Auxiliar.setTabIndexInvalido = function(pElementoAtual) {
   $(pElementoAtual).attr("tabIndex", "-1");
}

// Método estático validaQuandoSoTexto
// Responsável por retornar 'true', caso o elemento só contenha texto entre as tags de inicio e fim, caso contrário 'false'.
Auxiliar.validaQuandoSoTexto = function(pElementoAtual) {

   var saida = true;

   if (pElementoAtual.childNodes.length > 0) {
      for (var i = 0; i < pElementoAtual.childNodes.length; i++) {
         if (pElementoAtual.childNodes[i].nodeName != "#text") {
            saida = false;
         }
         else {
            if (Auxiliar.getTextSemEspacos(pElementoAtual.childNodes[i]) == "") {
               saida = false;
            }
         }
      }
   }
   else {
      saida = false;
   }

   return saida;
}


Auxiliar.validaQuandoElementosViramTexto = function(pElementoAtual) {
   var saida = false;

   if (("<".indexOf(pElementoAtual.innerHTML) < 0) && (">".indexOf(pElementoAtual.innerHTML) < 0)) {
      //invalida filhos.
      for (var i = 0; i < pElementoAtual.childNodes.length; i++) {
         Auxiliar.setTabIndexInvalido(pElementoAtual.childNodes[i]);
      }

      saida = true;
   }

   return saida;
}



// Método estático setTitle
// Responsável por retornar setar o title do elemento, caso o elemento não tenha title.
Auxiliar.setTitleSeNecessario = function(pElementoAtual) {
   if (pElementoAtual.childNodes.length > 0) {
      if (pElementoAtual.childNodes[0].nodeName == "#text") {
         if (pElementoAtual.title == "") {
            pElementoAtual.title = pElementoAtual.innerHTML;
         }
      }
   }
}


Auxiliar.validaSeTextETagsNaoTabulaveis = function(pElementoAtual) {
   var saida = true;

   for (var i = 0; i < pElementoAtual.childNodes.length; i++) {
      if (pElementoAtual.childNodes[i].nodeName != "#text") {
         if (Auxiliar.elementosTabulaveis.indexOf(pElementoAtual.childNodes[i].tagName) > 0) {
            saida = false;
            break;
         }
      }
   }

   if (saida == true)
      Auxiliar.invalidaTagsNaoTabulaveis(pElementoAtual);

   return saida;
}


Auxiliar.invalidaTagsNaoTabulaveis = function(pElementoAtual) {
   for (var i = 0; i < pElementoAtual.childNodes.length; i++) {
      if (Auxiliar.elementosTabulaveis.indexOf(pElementoAtual.childNodes[i].nodeName) < 0) {
         Auxiliar.setTabIndexInvalido(pElementoAtual.childNodes[i]);
      }
   }
}




//***************************************************************************************************

function AjustaTagA() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagA.regras = function(pElementoAtual) {

   saida = true;

   //Implementação de regras aqui.
   if (AjustaTagA.invalidaFilhos(pElementoAtual)) {
      saida = true;
      return saida;
   }

   if (AjustaTagA.invalidaSeConteudoVazio(pElementoAtual)) {
      saida = false;
      return saida;
   }

   return saida;
}


// Método estático invalidaFilhos
// Responsável por invalidar os filhos do elemento da vez.
AjustaTagA.invalidaFilhos = function(pElementoAtual) {

   var saida = false;

   for (j = 0; j < pElementoAtual.childNodes.length; j++) {

      palavrasNaoAceitas = " #text, BR, FONT";

      if (palavrasNaoAceitas.indexOf(pElementoAtual.childNodes[j].nodeName) < 0) {
         pElementoAtual.childNodes[j].tabIndex = -1;
         saida = true;
      }
   }

   if (pElementoAtual.childNodes.length == 1) {
      if (pElementoAtual.childNodes[0].nodeName == "IMG") {
         if (Auxiliar.getTextSemEspacosFromText(pElementoAtual.childNodes[0].alt) != "") {
            pElementoAtual.title = pElementoAtual.childNodes[0].alt;
         }
         else {
            pElementoAtual.title = "Imagem"
         }
      }
   }

   return saida;
}


// Método estático invalidaFilhos
// Responsável por invalidar os filhos do elemento da vez.
AjustaTagA.invalidaSeConteudoVazio = function(pElementoAtual) {

   var saida = false;

   var conteudoElemento = Auxiliar.getTextSemEspacos(elementoAtual);

   saida = conteudoElemento == "";

   return saida;
}



function AjustaTagTD() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagTD.regras = function(pElementoAtual) {

   var saida = true;

   for (var i = 0; i < elementoAtual.childNodes.length; i++) {
      if (elementoAtual.childNodes[i].nodeName != "BR" && elementoAtual.childNodes[i].nodeName != "#text") {
         saida = false;
         return saida;
      }
   }

   if (Auxiliar.getTextSemEspacos(pElementoAtual) == "") {
      saida = false;
      return saida;
   }

   return saida;
}










//***************************************************************************************************

function AjustaTagLI() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagLI.regras = function(pElementoAtual) {

   saida = true;

   saida = Auxiliar.validaQuandoSoTexto(pElementoAtual);

   return saida;
}


// Método estático LISomenteTextoETagBR
// Responsável por retorna se o elemento atual é contém somente texto e/ou quebra de linha.
AjustaTagLI.LISomenteTextoETagBR = function(pElementoAtual) {

   saida = false;

   if (pElementoAtual.tagName == "LI") {

      saida = true;

      for (j = 0; j < pElementoAtual.childNodes.length; j++) {
         if (pElementoAtual.childNodes[j].nodeName != "#text" && pElementoAtual.childNodes[j].nodeName != "BR") {
            saida = false;
            break;
         }
      }
   }

   return saida;
}




// Método estático LIMaisDeUmTextoEUmaTagA
// Responsável por retorna se o elemento atual é contém mais de um texto e apenas um link.
AjustaTagLI.LIMaisDeUmTextoEUmaTagA = function(pElementoAtual) {

   saida = false;

   if (pElementoAtual.tagName == "LI") {

      saida = true;
      numeroLinks = 0
      numeroTextos = 0
      indicePrimeiroLink = -1;

      for (j = 0; j < pElementoAtual.childNodes.length; j++) {

         if (pElementoAtual.childNodes[j].nodeName != "#text" && pElementoAtual.childNodes[j].nodeName != "A") {
            saida = false;
            break;
         }

         if (pElementoAtual.childNodes[j].nodeName == "A") {
            numeroLinks++;
            indicePrimeiroLink = j;
         }

         if (pElementoAtual.childNodes[j].nodeName == "#text") {
            numeroTextos++;
         }
      }

      if (numeroLinks = 1 && numeroTextos == 1) {
         saida = false;
      }
      else if (numeroLinks = 1 && numeroTextos > 1) {
         saida = true;
      }
   }

   return saida;
}






//***************************************************************************************************

function AjustaTagIMG() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagIMG.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   AjustaTagIMG.setAltDefaultSeNecessario(pElementoAtual);

   return saida;
}

// Método estático setAltDefaultSeNecessario
// Responsável por setar o atributo alt com o texto 'Imagem', quando a imagem não tiver um texto pré-definido.
AjustaTagIMG.setAltDefaultSeNecessario = function(pElementoAtual) {
   if (pElementoAtual.alt == "") {
      pElementoAtual.alt = "Imagem";
   }
}








//***************************************************************************************************

function AjustaTagSELECT() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagSELECT.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   return saida;
}






//***************************************************************************************************

function AjustaTagINPUT() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagINPUT.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   palavrasAceitas = " text, button, image";

   if (palavrasAceitas.indexOf(pElementoAtual.type) < 0) {
      saida = false;
   }

   return saida;
}







//***************************************************************************************************

function AjustaTagH1() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagH1.regras = function(pElementoAtual) {

   saida = true;

   if (AjustaTagH1.invalidaElementoSeFilhoForSPAN(pElementoAtual)) {
      saida = false;
      return saida;
   }


   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.
   if (AjustaTagH1.invalidaElementoSeFilhoForLink(pElementoAtual)) {
      saida = false;
      return saida;
   }
   else {
      AjustaTagH1.setTitle(pElementoAtual);
   }

   return saida;

}

AjustaTagH1.invalidaElementoSeFilhoForLink = function(pElementoAtual) {

   saida = false;

   if (pElementoAtual.hasChildNodes()) {
      if (pElementoAtual.childNodes[0].nodeName == "A") {
         saida = true;
      }
   }

   return saida;
}


AjustaTagH1.invalidaElementoSeFilhoForSPAN = function(pElementoAtual) {

   saida = false;

   if (pElementoAtual.childNodes.length == 1) {
      if (pElementoAtual.childNodes[0].nodeName == "SPAN") {
         saida = true;
      }
   }

   return saida;
}

AjustaTagH1.setTitle = function(pElementoAtual) {

   saida = true;

   Auxiliar.setTitleSeNecessario(pElementoAtual);

   return saida;
}










//***************************************************************************************************

function AjustaTagH2() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagH2.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.
   if (AjustaTagH2.invalidaElementoSeFilhoForLink(pElementoAtual)) {
      saida = false;
      return saida;
   }


   if (AjustaTagH3.invalidaElementosSePrimeiroFilhoForTabObjectESegundoFilhoForTagSpan(pElementoAtual)) {
      saida = false;
      return saida;
   }

   return saida;
}

AjustaTagH2.invalidaElementoSeFilhoForLink = function(pElementoAtual) {

   saida = true;

   if (pElementoAtual.hasChildNodes()) {
      if (pElementoAtual.childNodes[0].nodeName == "A") {
         saida = false;
      }
   }

   return saida;
}


AjustaTagH3.invalidaElementosSePrimeiroFilhoForTabObjectESegundoFilhoForTagSpan = function(pElementoAtual) {

   saida = true;

   if (pElementoAtual.childNodes.length > 1) {
      if ((pElementoAtual.childNodes[0].nodeName == "OBJECT") && (pElementoAtual.childNodes[1].nodeName == "SPAN")) {
         Auxiliar.setTabIndexInvalido(pElementoAtual.childNodes[0]);
         Auxiliar.setTabIndexInvalido(pElementoAtual.childNodes[1]);

         saida = false;
      }
   }

   return saida;

}








//***************************************************************************************************

function AjustaTagH3() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagH3.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.
   if (AjustaTagH3.invalidaElementoSeFilhoForLink(pElementoAtual)) {
      saida = false;
      return saida;
   }

   if (AjustaTagH3.invalidaElementosSePrimeiroFilhoForTabObjectESegundoFilhoForTagSpan(pElementoAtual)) {
      saida = false;
      return saida;
   }

   return saida;
}

AjustaTagH3.invalidaElementoSeFilhoForLink = function(pElementoAtual) {

   saida = false;

   if (pElementoAtual.hasChildNodes()) {
      if (pElementoAtual.childNodes[0].nodeName == "A") {
         saida = true;
      }
   }

   return saida;
}

AjustaTagH3.invalidaElementosSePrimeiroFilhoForTabObjectESegundoFilhoForTagSpan = function(pElementoAtual) {

   saida = true;

   if (pElementoAtual.childNodes.length > 1) {
      if ((pElementoAtual.childNodes[0].nodeName == "OBJECT") && (pElementoAtual.childNodes[1].nodeName == "SPAN")) {
         Auxiliar.setTabIndexInvalido(pElementoAtual.childNodes[0]);
         Auxiliar.setTabIndexInvalido(pElementoAtual.childNodes[1]);

         saida = false;
      }
   }

   return saida;

}







//***************************************************************************************************

function AjustaTagH4() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagH4.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.
   saida = AjustaTagH4.invalidaElementoSeFilhoForLink(pElementoAtual);

   return saida;
}

AjustaTagH4.invalidaElementoSeFilhoForLink = function(pElementoAtual) {

   saida = true;

   if (pElementoAtual.hasChildNodes()) {
      if (pElementoAtual.childNodes[0].nodeName == "A") {
         saida = false;
      }
   }

   return saida;
}







//***************************************************************************************************

function AjustaTagH5() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagH5.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.
   saida = AjustaTagH5.invalidaElementoSeFilhoForLink(pElementoAtual);

   return saida;
}

AjustaTagH5.invalidaElementoSeFilhoForLink = function(pElementoAtual) {

   saida = true;

   if (pElementoAtual.hasChildNodes()) {
      if (pElementoAtual.childNodes[0].nodeName == "A") {
         saida = false;
      }
   }

   return saida;
}




//***************************************************************************************************

function AjustaTagP() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagP.regras = function(pElementoAtual) {

   saida = false;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   if (AjustaTagP.validaQuandoSoTextoTagBReTagA(pElementoAtual)) {
      saida = true;
      return saida;
   }

   if (Auxiliar.validaQuandoSoTexto(pElementoAtual)) {
      saida = true;
      return saida;
   }

   if (Auxiliar.validaSeTextETagsNaoTabulaveis(pElementoAtual)) {
      saida = true;
      return saida;
   }

   if (AjustaTagP.invalidaSeTemTagsTabulaveis(pElementoAtual)) {
      saida = false;
      return saida;
   }

   if (pElementoAtual.childNodes.length > 1) {
      // se somente o filho a for tabulavel valida
      for (var i = 0; i < pElementoAtual.childNodes.length; i++) {
         if (pElementoAtual.childNodes[i].nodeName != "B" && pElementoAtual.childNodes[i].nodeName != "FONT" && pElementoAtual.childNodes[i].nodeName != "A" && pElementoAtual.childNodes[i].nodeName != "#text") {
            saida = false;
            return saida;
         }
      }

      //saida = true;
   }

   return saida;
}

AjustaTagP.invalidaSeTemTagsTabulaveis = function(pElementoAtual) {
   var saida = true;

   for (var i = 0; i < pElementoAtual.childNodes.length; i++) {
      if (pElementoAtual.childNodes[i].nodeName == "B" || pElementoAtual.childNodes[i].nodeName == "FONT") {
         saida = false;
         break;
      }
   }

   return saida;
}

AjustaTagP.validaQuandoSoTextoTagBReTagA = function(pElementoAtual) {
   for (var i = 0; i < pElementoAtual.childNodes.length; i++) {

      var hasText = false;

      if (pElementoAtual.childNodes[i].nodeName != "BR" && pElementoAtual.childNodes[i].nodeName != "A") {
         if (pElementoAtual.childNodes[i].nodeName == "#text") {
            if (Auxiliar.getTextSemEspacosFromText(pElementoAtual.childNodes[i].nodeValue) != "") {
               hasText = true;
            }
            else {
               hasText = false;
               break;
            }
         }
         saida = true;
      }
      else {
         saida = false;
      }
   }

   return saida && hasText;
}




//***************************************************************************************************

function AjustaTagSMALL() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagSMALL.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   saida = Auxiliar.validaQuandoSoTexto(pElementoAtual);

   return saida;
}







//***************************************************************************************************

function AjustaTagSPAN() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagSPAN.regras = function(pElementoAtual) {

   var saida = false;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   saida = Auxiliar.validaSeTextETagsNaoTabulaveis(pElementoAtual);

   if (saida) {
      saida = Auxiliar.validaQuandoSoTexto(pElementoAtual);
   }

   return saida;
}








//***************************************************************************************************

function AjustaTagSTRONG() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagSTRONG.regras = function(pElementoAtual) {

   saida = false;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   if (Auxiliar.validaQuandoSoTexto(pElementoAtual)) {
      saida = true;
      return saida;
   }

   if (Auxiliar.validaQuandoElementosViramTexto(pElementoAtual)) {
      saida = true;
      return saida;
   }

   return saida;
}









//***************************************************************************************************

function AjustaTagB() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagB.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   saida = Auxiliar.validaQuandoSoTexto(pElementoAtual);

   return saida;
}










//***************************************************************************************************

function AjustaTagU() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagU.regras = function(pElementoAtual) {

   saida = true;

   //se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.

   saida = Auxiliar.validaQuandoSoTexto(pElementoAtual);

   return saida;
}








function AjustaTagDIV() { }

// Método estático regras
// Responsável por submeter o elemento da vez as regras para validar ou invalidar o elemento.
AjustaTagDIV.regras = function(pElementoAtual, pAcessibilidade) {

   saida = true;

   // Se houver implementação posterior fazer aqui.
   // alterando a variável saída olhando se o elemento é ou não válido.
   if (pElementoAtual.childNodes.length > 0) {

      if (pElementoAtual.childNodes[0].nodeName != "#text") {
         saida = false;
      }
   }

   saida = Auxiliar.validaSeTextETagsNaoTabulaveis(pElementoAtual);

   if (saida) {
      saida = Auxiliar.validaQuandoSoTexto(pElementoAtual);
   }

   return saida;
}













//***************************************************************************************************
function DedoDuro() { }

DedoDuro.conteudo = "";

DedoDuro.executar = function() {

   if (document.activeElement != null) {
      if (this.conteudo != document.activeElement.outerHTML) {
         this.conteudo = document.activeElement.outerHTML
         alert(this.conteudo);
      }
   }

   setTimeout(DedoDuro.executar, 8000);
}








function FixMenuFlutuantePortalSeguranca() {
   //*****************************************************************************************************
   //conteudo criado para suprir problemas nas páginas do portal de segurança em relação ao menu flutuante.
   // --- Passo1 ---
   var objeto = $('#menu_seguro_juridica').children("a:last-child")[0];
   var contadorDivs = 0;
   if (objeto) {
      while (!$(objeto).find("div table").length) {
         objeto = objeto.parentNode;
         contadorDivs++;
      }

      $("#menu_seguro_juridica").children("a:last-child")[0].onblur = function() { UltimoItemFechaMenu(this, event, contadorDivs - 1) };
   }
   // --- Passo1 ---


   // --- Passo2 ---    
   var objetos = $("div[id*='table'] div");

   for (var i = 0; i < objetos.length; i++) {
      var objetoFim = $(objetos[i]).find("a:last-child");

      $(objetoFim).removeAttr("onblur");
   }

   // --- Passo2 ---
}
