var isCpoEdit = 0;
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
var isIE = (navigator.appName == "Microsoft Internet Explorer") ? 1 : 0;
var TeclaAnt = 0;
var evt = 0;

function BotaoDireito() {
  return false;
}
document.oncontextmenu = BotaoDireito;

function VerificaTecla() {
  var Evento = (evt) ? evt : ((window.event) ? event : 1);
  if (Evento) return true;
  var Tecla = Evento.keyCode;
  if ((Tecla == 8)) {
    if (!isCpoEdit) {
      if (isNS) {
        Evento.preventDefault();
        Evento.stopPropagation();
      }
      else {
        Evento.keyCode = 0;
        Evento.returnValue = true;
      }
    }
  }
  if (((Tecla >= 112) && (Tecla <= 123))) {
    if (isNS) {
      Evento.preventDefault();
      Evento.stopPropagation();
    }
    else {
      Evento.keyCode = 0;
      Evento.returnValue = false;
    }
  }
  if (isNS) {
    if ((Tecla == 37) || (Tecla == 39)) {
      alert('Tecla não permitida !');
      Evento.preventDefault();
      Evento.stopPropagation();
    }
  }
  else {
    if ((TeclaAnt == 18) && ((Tecla == 37) || (Tecla == 39))) {
      alert('Tecla não permitida !');
      Evento.keyCode = 0;
      Evento.returnValue = false;
    }
    TeclaAnt = Tecla;
  }
  return true;
}

if (isNS) {
  document.onkeypress = VerificaTecla;
}
else {
  document.onkeydown = VerificaTecla;
}

function inicio() {
  self.defaultStatus="www.controlaobra.com.br";
  TimeOut=setTimeout('inicio()',1);
  clearTimeout(TimeOut);
  TimeOut=setTimeout('prossegue()',0);
}

function prossegue() {
  self.defaultStatus="www.controlaobra.com.br";
}

function SomenteNumero(e){
  var tecla=(window.event)?event.keyCode:e.which;
  if ((tecla > 47 && tecla < 58)) {
    return true;
  } else {
    if (tecla != 8) {
      return false;
    } else {
      return true;
    }
  }
}

function MudaBotao(tipo, OpcaoMenu) {
  OpcaoAtual = parent.frames[1].document.forms[0].elements[1].value;
  switch (tipo) {
    case "0":
      document.getElementById(OpcaoMenu).style.background="#FFFFFF";
      break;
    case "1":
      document.getElementById(OpcaoMenu).style.background="#99EEFF";
      break;
    case "2":
      if (OpcaoMenu == OpcaoAtual) {
        document.getElementById(OpcaoMenu).style.background="#FFFFFF";
      } else {
        document.getElementById(OpcaoMenu).style.background="#C0C0C0";
      }
      break;
  }
}
function MudaPagina(OpcaoClicada, Programa, CheckLogado) {
  Logado = parent.frames[1].document.forms[0].elements[0].value;
  OpcaoAtual = parent.frames[1].document.forms[0].elements[1].value;
  if (CheckLogado == "S" && Logado == "N") {
    alert('Você somente terá acesso a esta página,\n  entrando com o seu Usuário e Senha !');
    return true;
  }
  parent.frames[1].document.getElementById(OpcaoAtual).style.background="#C0C0C0";
  parent.frames[1].document.getElementById(OpcaoClicada).style.background="#FFFFFF";
  parent.frames[1].document.forms[0].elements[1].value = OpcaoClicada;
  window.parent.frames[3].location=Programa;
}
function formataValor(valorIn) {
  posVirgula = valorIn.indexOf(",");
  if (posVirgula == -1) {
    if (valorIn == "") {
      inteiros = "0";
    }
    else {
      inteiros = valorIn;
    }
    centavos = "00";
  }
  else {
    inteiros = valorIn.substring(0,posVirgula);
    centavos = valorIn.substring(posVirgula+1,valorIn.length);
    if (centavos.length < 2) {
      centavos = centavos + "0";
    }
  }
  valorOut = inteiros + "," + centavos;
  return valorOut;
}
function openModalWindow(strURL, strArgument, intWidth, intHeight){
  var intTop = ((screen.height - intHeight) / 2);
  var intLeft = ((screen.width - intWidth) / 2);
  var strEnderec = strURL;
  var strAjustesIE = 'status=0; help=0; center:yes; dialogWidth:'+intWidth+'px; dialogHeight:'+intHeight+'px';
  var strAjustesNS = 'width='+intWidth+',height='+intHeight+',status=0,scrollbars=1,menubar=0,modal=1,left='+intLeft+',top='+intTop;
  with (window.navigator){
  switch (appName){
    case 'Microsoft Internet Explorer':
      var x = window.showModalDialog(strEnderec, strArgument ,strAjustesIE);
      break;
    case 'Netscape':
      try {
        //netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
        window.open(strEnderec, 'Default', strAjustesNS);
        return true;
      }
      catch (e) {
        alert("Seu navegador não permite abertura de janela modal.");
        return false;
      }
      break;
    }
  }
}

