function Limpa(S)
{
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<S.length; i++){
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0) {
			temp = temp + digito;
		}
	}
	return temp;
}
function Inverte(S)
{
	var temp = "";
	for (var i=0; i<S.length; i++) {
		temp = S.charAt(i) + temp;
	}
    return temp;
}

function Resto(S)
{
	var invertido = Inverte(Limpa(S));
	var soma = 0;
	for (var i=0; i<invertido.length; i++) {
		soma = soma + (i+2) * eval(invertido.charAt(i));
	}
	soma *= 10;
	return ((soma % 11) % 10);
}

function Validar_CPF12()
{
	if ((document.form2.cpf_candidato.value == "000.000.000-00") || (document.form2.cpf_candidato.value == "111.111.111-11") || (document.form2.cpf_candidato.value == "222.222.222-22") || (document.form2.cpf_candidato.value == "333.333.333-33") || (document.form2.cpf_candidato.value == "444.444.444-44") || (document.form2.cpf_candidato.value == "555.555.555-55") || (document.form2.cpf_candidato.value == "666.666.666-66") || (document.form2.cpf_candidato.value == "777.777.777-77") || (document.form2.cpf_candidato.value == "888.888.888-88") || (document.form2.cpf_candidato.value == "999.999.999-99")) {
		return (false);
	}
	var result = "";
	var OK = false;
	var temp = Limpa(document.form2.cpf_candidato.value);
	if (temp.length>10) {
		var work = temp.substring(0,(temp.length)-2);
		var resto = Resto(work);
		OK = (resto == eval(temp.charAt((temp.length)-2)));
		if (OK){
			work = work + resto;
			resto = Resto(work);
			OK = (resto == eval(temp.charAt((temp.length)-1)));
		}
	}
	if (OK){
		return (true);
	}
	else 
	{
		return (false);
	}
}
function Validar_CPF11()
{
	if ((document.form1.cpf_candidato.value == "000.000.000-00") || (document.form1.cpf_candidato.value == "111.111.111-11") || (document.form1.cpf_candidato.value == "222.222.222-22") || (document.form1.cpf_candidato.value == "333.333.333-33") || (document.form1.cpf_candidato.value == "444.444.444-44") || (document.form1.cpf_candidato.value == "555.555.555-55") || (document.form1.cpf_candidato.value == "666.666.666-66") || (document.form1.cpf_candidato.value == "777.777.777-77") || (document.form1.cpf_candidato.value == "888.888.888-88") || (document.form1.cpf_candidato.value == "999.999.999-99")) {
		return (false);
	}
	var result = "";
	var OK = false;
	var temp = Limpa(document.form1.cpf_candidato.value);
	if (temp.length>10) {
		var work = temp.substring(0,(temp.length)-2);
		var resto = Resto(work);
		OK = (resto == eval(temp.charAt((temp.length)-2)));
		if (OK){
			work = work + resto;
			resto = Resto(work);
			OK = (resto == eval(temp.charAt((temp.length)-1)));
		}
	}
	if (OK){
		return (true);
	}
	else 
	{
		return (false);
	}
}

function Validar_CPF()
{
	if ((document.form.cpf_cliente.value == "000.000.000-00") || (document.form.cpf_cliente.value == "111.111.111-11") || (document.form.cpf_cliente.value == "222.222.222-22") || (document.form.cpf_cliente.value == "333.333.333-33") || (document.form.cpf_cliente.value == "444.444.444-44") || (document.form.cpf_cliente.value == "555.555.555-55") || (document.form.cpf_cliente.value == "666.666.666-66") || (document.form.cpf_cliente.value == "777.777.777-77") || (document.form.cpf_cliente.value == "888.888.888-88") || (document.form.cpf_cliente.value == "999.999.999-99")) {
		return (false);
	}
	var result = "";
	var OK = false;
	var temp = Limpa(document.form.cpf_cliente.value);
	if (temp.length>10) {
		var work = temp.substring(0,(temp.length)-2);
		var resto = Resto(work);
		OK = (resto == eval(temp.charAt((temp.length)-2)));
		if (OK){
			work = work + resto;
			resto = Resto(work);
			OK = (resto == eval(temp.charAt((temp.length)-1)));
		}
	}
	if (OK){
		return (true);
	}
	else 
	{
		return (false);
	}
}

function Mascarar_CPF(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 3 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 7 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 11 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '-';
		}
	}
}