function valida_cpf (objeto, msg)
{
 
 var numcpf = objeto.value;
        x = 0;
        soma = 0;
        dig1 = 0;
        dig2 = 0;
        texto = "";
        numcpf1="";
 
       if (numcpf == "00000000000" || numcpf == "11111111111" ||
  numcpf == "22222222222" || numcpf == "33333333333" || numcpf == "44444444444" ||
  numcpf == "55555555555" || numcpf == "66666666666" || numcpf == "77777777777" ||
  numcpf == "88888888888" || numcpf == "99999999999") {
  return (false);
       } 
        len = numcpf.length; x = len -1;
        // var numcpf = "12345678909";
        for (var i=0; i <= len - 3; i++) {
                y = numcpf.substring(i,i+1);
                soma = soma + ( y * x);
                x = x - 1;
                texto = texto + y;
        }
        dig1 = 11 - (soma % 11);
        if (dig1 == 10) dig1=0 ;
        if (dig1 == 11) dig1=0 ;
        numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
        x = 11; soma=0;
        for (var i=0; i <= len - 2; i++) {
                soma = soma + (numcpf1.substring(i,i+1) * x);
                x = x - 1;
        }
        dig2= 11 - (soma % 11);
        if (dig2 == 10) dig2=0;
        if (dig2 == 11) dig2=0;
        if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
                return (true);
        }
  else
  {
  alert(msg);
  objeto.select();
  return (false);
  }
}
 
 