jQuery.fn.validateCPF=function(a){var b=this;var c=b.val().replace('.','').replace('.','').replace('-','');if(c.length!=11){return false}else{var d=/1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}/;if(d.test(c)){return false}else{var x=0;var y=0;var e=0;var f=0;var g=0;var h="";var k="";var l=c.length;x=l-1;for(var i=0;i<=l-3;i++){y=c.substring(i,i+1);e=e+(y*x);x=x-1;h=h+y}f=11-(e%11);if(f==10){f=0}if(f==11){f=0}k=c.substring(0,l-2)+f;x=11;e=0;for(var j=0;j<=(l-2);j++){e=e+(k.substring(j,j+1)*x);x=x-1}g=11-(e%11);if(g==10){g=0}if(g==11){g=0}if((f+""+g)==c.substring(l,l-2)){return true}else{return false}}}};

function validarCPF(txtCpf){
   var cpf = txtCpf;
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
     window.alert("Por favor, confirme e digite novamente seu CPF.");
	 return false;
   }
   
   cpf = cpf.replace('.', '');
   cpf = cpf.replace('.', '');
   cpf = cpf.replace('-', '');
   //cpf = remove(cpf, ".");
   //cpf = remove(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"){
	  window.alert("Por favor, confirme e digite novamente seu CPF.");
	  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))){
	 window.alert("Por favor, confirme e digite novamente seu CPF.");
	 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))){
     window.alert("Por favor, confirme e digite novamente seu CPF.");
	 return false;
   }
   return true;
 }
 

