// Confere se o CPF dado esta' OK
function isCPF( cpf)
{
	var result = "";
	var OK = false;
	var temp = justNumbersStr(trim(cpf));
	if( onlySameNumber( temp))
		return false;

	if (temp.length>10)
	{
		var work=temp.substring(0,(temp.length)-2)
		var resto = getVerificationDigit(work);
		OK = (resto==parseInt(temp.charAt((temp.length)-2)));
		if (OK)
		{
			work=work+resto;
			resto= getVerificationDigit(work);
			OK = (resto==parseInt(temp.charAt((temp.length)-1)));
		}
	}
	return (OK)
}

//----- Funcoes auxiliares ------//

function getVerificationDigit(S)
{
	// Retorna o digito verificador (entrar com S "limpo")
	var invertido = invertStr(justNumbersStr(S));
	var soma = 0;
   for (var i=0; i<invertido.length; i++){
        soma=soma+(i+2)*parseInt(invertido.charAt(i))
   }
   soma*=10;
   return ((soma % 11) % 10)
}


