<!--

// Não permite que sejam lançados possíveis erros de JavaScript ao usuário final
function stopErrors()
{
  return true;
}
window.onerror = stopErrors;

// Muda a cor de um Campo Input
function js_mudaCorCampo( campo, cor ) {
  campo.style.backgroundColor = cor;
}

// Muda a cor de um objeto
function js_mudaCorFundo( objeto, cor ) {
  objeto.style.bgColor = cor;
}

// Abre uma Janela a partir de um clique em um combobox
function js_abreJanelaCombo( objeto )
{
  var item = objeto.selectedIndex;
  
  var url = objeto.options[item].value;
  
  if(url != "")
    NovaJanela = window.open(url,"NewPage");
}

// Pula para o próximo campo depois de atingido um total de caracteres especificado
// Exemplo: onKeyUp='autoTab(this, form.campodestino, 10, event)'
function js_autoTab(campoAtual, campoDestino, limite, event)
{
  var intTecla = event.keyCode;
  
  if ( (campoAtual.value.length >= limite) && (intTecla != 37 && intTecla != 36)  )
    campoDestino.focus();
}

// Verifica se um CPF é válido
// Exemplo: if( !js_verificaCPF(campocpf.value) ) ...
function js_verificaCPF(CPF) 
{
  if(
     CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
     CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
     CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
     CPF == "88888888888" || CPF == "99999999999"
    )
    return false;
  
  soma = 0;
  for (i=0; i < 9; i ++)
  	soma += parseInt(CPF.charAt(i)) * (10 - i);
  
  resto = 11 - (soma % 11);
  
  if (resto == 10 || resto == 11)
  	resto = 0;
  if (resto != parseInt(CPF.charAt(9)))
    return false;
  
  soma = 0;
  
  for (i = 0; i < 10; i ++)
    soma += parseInt(CPF.charAt(i)) * (11 - i);
   
   resto = 11 - (soma % 11);
   
   if (resto == 10 || resto == 11)
     resto = 0;
   if (resto != parseInt(CPF.charAt(10)))
     return false;
   
   return true;
}

// Permite que sejam digitados somente números em um campo
// onkeyPress='return js_somenteNumeros(event, this)'
function js_somenteNumeros(event, campoAtual, intPos)
{ 
  var tecla = event.keyCode;
  
  if ((tecla > 47 && tecla < 58) || tecla == 46 || tecla == 13 ) // numeros de 0 a 9 e enter
    return true;
  else 
  {
    if(typeof(campoAtual) != "undefined" && typeof(intPos) != "undefined" && campoAtual.value.length == intPos)
    {
      if (tecla != 8 && tecla != 45) // backspace
        event.keyCode = 0;
      else
        return true;
    }
    else 
    {
      if (tecla != 8) // backspace
        event.keyCode = 0;            
      else
        return true;
    }
  }
}

// Troca uma imagem por outro - Deve-se usar o atributo 'name' na imagem
function cambiaImagem( nome_imagem, src ) {
  document.images.nome_imagem.src = src;
}

-->

