function validaCPF(cpf){ // Verifica a validade do CPF informado
	var msg = "CPF válido";
	var sch;
	var nRecebeCPF, nSoma, nresultado1, nresultado2, ns, nx;
	var arrNumero = Array(11);

	nRecebeCPF = cpf;
	ns = "";
	for(nx=0;nx<nRecebeCPF.length;nx++){
		sch = nRecebeCPF.substring(nx,nx+1);
		sch = parseInt(sch);
		sch = new String(sch);

		if (sch != "NaN") {
			ns += sch;

		}

	}

	nRecebeCPF = ns

	tudoIgual = 1; // Verifica se todos os números são iguais
	for (i = 1; i < nRecebeCPF.length; i++) {
		if (nRecebeCPF.substring(i-1, i) != nRecebeCPF.substring(i, i+1)){
			tudoIgual = 0;
		}
	}

	if (nRecebeCPF.length == 0) {

	} else if(nRecebeCPF.length != 11){
		msg = "A quantidade de dígitos do CPF é inferior a quantidade de dígitos requerida!";
		resultado = false;
	}
	else if(tudoIgual == 1){
		msg = "Os números do CPF não podem ser todos iguais!";
		resultado = false;
	}
	else if(nRecebeCPF == "12345678909"){
		msg = "Número de CPF inexistente!";
		resultado = false;
	}
	else{
		arrNumero[0] = nRecebeCPF.substring(0,1);
		arrNumero[1] = nRecebeCPF.substring(1,2);
		arrNumero[2] = nRecebeCPF.substring(2,3);
		arrNumero[3] = nRecebeCPF.substring(3,4);
		arrNumero[4] = nRecebeCPF.substring(4,5);
		arrNumero[5] = nRecebeCPF.substring(5,6);
		arrNumero[6] = nRecebeCPF.substring(6,7);
		arrNumero[7] = nRecebeCPF.substring(7,8);
		arrNumero[8] = nRecebeCPF.substring(8,9);
		arrNumero[9] = nRecebeCPF.substring(9,10);
		arrNumero[10] = nRecebeCPF.substring(10,11);

		nSoma = 10 * arrNumero[0] + 9 * arrNumero[1] + 8 * arrNumero[2] + 7 * arrNumero[3] + 6 * arrNumero[4] + 5 * arrNumero[5] + 4 * arrNumero[6] + 3 * arrNumero[7] + 2 * arrNumero[8]
		nSoma = nSoma-(11*parseInt(nSoma/11));

		if(nSoma == 0 || nSoma == 1){
			nresultado1 = 0;
		}
		else{
			nresultado1 = 11-nSoma;
		}

		if(nresultado1 == arrNumero[9]){
			nSoma = arrNumero[0] * 11 + arrNumero[1] * 10 + arrNumero[2] * 9 + arrNumero[3] * 8 + arrNumero[4] * 7 + arrNumero[5] * 6 + arrNumero[6] * 5 + arrNumero[7] * 4 + arrNumero[8] * 3 + arrNumero[9] * 2
			nSoma = nSoma-(11*parseInt(nSoma/11));
			if(nSoma == 0 || nSoma == 1){
				nresultado2 = 0;
			}
			else{
				nresultado2 = 11 - nSoma;
			}

			if(nresultado2 == arrNumero[10]){
				resultado = true;
			}
			else{
				msg = "CPF inválido!";
				resultado = false;
			}
		}
		else{
			msg = "CPF inválido!";
			resultado = false;
		}
	}
	resultado = msg;
	return resultado;
}