//onBlur="verCPF(this)"
function verCPF(objCPF){
   if (objCPF.value != ""){
      if(validarCPF(objCPF) == false){
         objCPF.focus();
      }
   }
}

//if (validarCPF(document.forms[0].CAMPO) == false){
//    document.forms[0].CAMPO.focus();
//    return false;
//}

function validarCPF(objCPF) {

  if (objCPF.value == "")
  {
    alert("Digite um valor para o campo \"CPF\".");
    return (false);
  }
  else if (objCPF.value == "00000000000" || objCPF.value == "11111111111" || objCPF.value == "22222222222" || objCPF.value == "33333333333" || objCPF.value == "44444444444" || objCPF.value == "55555555555" || objCPF.value == "66666666666" || objCPF.value == "77777777777" || objCPF.value == "88888888888" || objCPF.value == "99999999999"){
    alert("CPF inválido. Favor redigitar.");
    return (false);
  }  
  else if (objCPF.value.length  != 11){
    alert("O campo do \"CPF\" deve ser preenchido com 11 dígitos sem vírgula, espaço ou qualquer outro tipo de caracter. Ex: 22250960809");
    return (false);
  }
  else
  {
    cpf = objCPF.value;
    somaux = (cpf.charAt(0) * 10);
    somaux = somaux + (cpf.charAt(1) * 9);
    somaux = somaux + (cpf.charAt(2) * 8);
    somaux = somaux + (cpf.charAt(3) * 7);
    somaux = somaux + (cpf.charAt(4) * 6);
    somaux = somaux + (cpf.charAt(5) * 5);
    somaux = somaux + (cpf.charAt(6) * 4);
    somaux = somaux + (cpf.charAt(7) * 3);
    somaux = somaux + (cpf.charAt(8) * 2);
 
    if (somaux == 0){
      alert("CPF inválido. Favor redigitar.");
      return (false);
    }
 
    resto = (somaux % 11);
    div = somaux - resto;
    soma = (11 - (somaux - div));
    
    if (soma > 9){ soma = 0; }
    
    if (soma != (cpf.charAt(9))){
      alert("CPF inválido. Favor redigitar.");
      return (false);
    }
    
    somaux = (cpf.charAt(0) * 11);
    somaux = somaux + (cpf.charAt(1) * 10);
    somaux = somaux + (cpf.charAt(2) * 9);
    somaux = somaux + (cpf.charAt(3) * 8);
    somaux = somaux + (cpf.charAt(4) * 7);
    somaux = somaux + (cpf.charAt(5) * 6);
    somaux = somaux + (cpf.charAt(6) * 5);
    somaux = somaux + (cpf.charAt(7) * 4);
    somaux = somaux + (cpf.charAt(8) * 3);
    somaux = somaux + (cpf.charAt(9) * 2);
    
    resto = (somaux % 11);
    div = (somaux - resto);
    soma = (11 - (somaux - div));
    
    if (soma > 9) { soma = 0; }
    
    if (soma != cpf.charAt(10)){
      alert("CPF inválido. Favor redigitar.");
      return (false);
    }
  }
}
  // Fim da validacao do CPF

