this.Nav = "IE";
navegador = navigator.appName;
if (navegador != "Microsoft Internet Explorer"){
  document.write("<link href='estilos/open.css' rel='stylesheet' type='text/css'/>");
  this.Nav = "OS";
};

function acessarContexto(Contexto){
  location.href = Contexto;
}

function addElement(oForm, Tipo, Name, Type, Value){
  var oTextAction = document.createElement(Tipo);
  oTextAction.setAttribute("type",Type);
  oTextAction.setAttribute("name",Name);
  oTextAction.setAttribute("value",Value);
  oForm.appendChild(oTextAction);
}

function formataCPF(campo, teclapres){
  var tecla = teclapres.keyCode;
  var vr = new String(campo.value);
  vr = vr.replace(".", "");
  vr = vr.replace("/", "");
  vr = vr.replace("-", "");
  tam = vr.length + 1;
  if (tecla != 14){
    if (tam == 4)
      campo.value = vr.substr(0, 3) + '.';
    if (tam == 7)
      campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 6) + '.';
    if (tam == 11)
      campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(7, 3) + '-' + vr.substr(11, 2);
  };
}

function imprimeData(){
  DataToda = new Date();
  DiaHoje = DataToda.getDay();
  MesHoje = DataToda.getMonth();
  HoraHoje = DataToda.getHours();

  NomeDia = new Array(7)
  NomeDia[0] = "Dom";
  NomeDia[1] = "Seg";
  NomeDia[2] = "Ter" ;
  NomeDia[3] = "Qua";
  NomeDia[4] = "Qui";
  NomeDia[5] = "Sex";
  NomeDia[6] = "Sáb";
  
  NomeMes = new Array(12)
  NomeMes[0] = "Janeiro";
  NomeMes[1] = "Fevereiro";
  NomeMes[2] = "Março";
  NomeMes[3] = "Abril";
  NomeMes[4] = "Maio";
  NomeMes[5] = "Junho";
  NomeMes[6] = "Julho";
  NomeMes[7] = "Agosto";
  NomeMes[8] = "Setembro";
  NomeMes[9] = "Outubro";
  NomeMes[10] = "Novembro";
  NomeMes[11] = "Dezembro";

  if(HoraHoje > 5 && HoraHoje < 12){
    var turno = ' - Bom dia !';
  }
  else if(HoraHoje > 11 && HoraHoje < 18){
    var turno = ' - Boa tarde !';
  }
  else{
    var turno = ' - Boa noite !';
  };
  document.write (NomeDia[DiaHoje] + ', ' + DataToda.getDate() + ' de ' + NomeMes[MesHoje] + ' de ' + DataToda.getYear() + ' ' + turno);
}

function jsConfirmSubmitForm(pMsg, pTipo, pAction, pDados) {
  Parameters = "";
  var Texto = pMsg;
  var Tam = Texto.length;
  for(x = 0; x <= Tam; x++){
    if (Texto.charAt(x) == "|"){
      Parameters += " ";
      continue;
    };
    Parameters += Texto.charAt(x);
  }
  pMsg = Parameters;
  if (confirm(pMsg) == 1) {
    return jsSubmit(pTipo, pAction, pDados);
  };
}

function jsRedirect(pTipo, pFormulario, pParametros){
  var oForm = document.formWeb;
  if(pTipo == 'RETURN'){
    history.back(-1);
  };
  if (pParametros != ''){
    Parameters = new Array();
    var Texto = pParametros;
    var Tam = Texto.length;
    var Chave = "";
    var Valor = "";
    var Igual = false;
    for(x = 0; x <= Tam; x++){
      if (Texto.charAt(x) == "|"){
        Igual = true;
        continue;
      };
      if ( (Texto.charAt(x) != '&') && (x < Tam) ){
        if (!Igual){
          Chave += Texto.charAt(x);
        }
        else{
          Valor += Texto.charAt(x);
        };
      }
      else{
        //Adiciono os Parametros no Form um a um para uso posterior
        addElement(oForm, "input", "Parameters["+Chave+"]", "hidden", Valor);
        Chave = "";
        Valor = "";
        Igual = false;
      };
    }
  };
  addElement(oForm, "input", "FWAplicacao", "hidden", pFormulario);
  addElement(oForm, "input", "FWTipo", "hidden", pTipo);
  oForm.action = pFormulario;
  oForm.method = 'POST';
  oForm.submit();
  return true;
}

function jsSubmit(pTipo, pAction, pParametros){
  var oForm = document.formWeb;
  if (pTipo == 'POPUP'){
    if (pParametros != ''){
      Parameters = new Array();
      var Texto = pParametros;
      var Tam = Texto.length;
      var Chave = "";
      var Valor = "";
      var Igual = false;
      for(x = 0; x <= Tam; x++){
        if (Texto.charAt(x) == "|"){
          Igual = true;
          continue;
        };
        if ( (Texto.charAt(x) != '&') && (x < Tam) ){
          if (!Igual){
            Chave += Texto.charAt(x);
          }
          else{
            Valor += Texto.charAt(x);
          };
        }
        else{
          //Adiciono os Parametros no Form um a um para uso posterior
          addElement(oForm, "input", "Parameters["+Chave+"]", "hidden", Valor);
          Chave = "";
          Valor = "";
          Igual = false;
        };
      }
    }
    PopUp('','PopUp');
    oForm.method = 'GET';
    oForm.action = pAction;
    oForm.target = 'PopUp';
    oForm.submit();
    oForm.action = '';
    oForm.target = '';
    return;
  }
  else if (pTipo == 'MENU'){
    addElement(oForm, "input", "FWAplicacao", "hidden", pAction);
  }
  else if(pTipo == 'LOGIN'){
    addElement(oForm, "input", "FWAplicacao", "hidden", pAction);
  }
  else if(pTipo == 'LOGOUT'){
    addElement(oForm, "input", "FWAplicacao", "hidden", pAction);
  }
  else if(pTipo == 'SUBMIT'){
    addElement(oForm, "input", "Action", "hidden", pAction);
    if (pParametros != ''){
      Parameters = new Array();
      var Texto = pParametros;
      var Tam = Texto.length;
      var Chave = "";
      var Valor = "";
      var Igual = false;
      for(x = 0; x <= Tam; x++){
        if (Texto.charAt(x) == "|"){
          Igual = true;
          continue;
        };
        if ( (Texto.charAt(x) != '&') && (x < Tam) ){
          if (!Igual){
            Chave += Texto.charAt(x);
          }
          else{
            Valor += Texto.charAt(x);
          };
        }
        else{
          //Adiciono os Parametros no Form um a um para uso posterior
          addElement(oForm, "input", "Parameters["+Chave+"]", "hidden", Valor);
          Chave = "";
          Valor = "";
          Igual = false;
        };
      }
    };
  };
  addElement(oForm, "input", "FWTipo", "hidden", pTipo);
  oForm.method = 'POST';
  oForm.submit();
  return true;
}

function lerConteudo(Contexto,Id){
  location.href = Contexto + '?id=' + Id;
}

function navegar(page,elementDIV){
  ajax = new objAjax();
  var div = document.getElementById(elementDIV);

  ajax.onreadystatechange = function(){
    if(ajax.readyState == 1){
      div.innerHTML="Carregando...";
    };
    if(ajax.readyState == 4){
      div.innerHTML=ajax.responseText;
    };
  }
  ajax.open("GET",page,true);
  ajax.send(null);
}

function objAjax(){
  try{
    return new XMLHttpRequest();
  }
  catch(e){
    try{
      return new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
      return new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return null;
}


function PopUp(sArquivo,w,h){
  if(!eval(w)){
    var w = 740;
  };
  if(!eval(h)){
    var h = 460;
  };
  var left = (screen.width - w) / 2;
  var top = (screen.height - h) / 2;
  Opcoes = 'width='+w+',height='+h+',top='+top+',left='+left+',toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1'
  win = window.open(sArquivo,'PopUp',Opcoes);
  if (parseInt(navigator.appVersion) >= 4) { 
    win.window.focus(); 
  };
}

function setFocus(pCampoForm){
  document.getElementById(pCampoForm).focus();
}

function verificaCPF(Form) {
  var CPF = Form.CPF.value; // Recebe o valor digitado no campo
  // Verifica se o campo é nulo
  if (CPF == '') {
    alert('Este campo é de preenchimento obrigatório!');
    return false;
  };
  CPF = CPF.replace(/\./gi,"").replace("-","");
  // 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');
    Form.CPF.value = '';
    Form.CPF.focus();
    return false;
  }; 
}