function valid_cpf(cpf)
{
	cpf = cpf.replace(/\/|\.|-/g, "");
	
	if (cpf.length != 11 || cpf.match(/\D/)) {
		return false;
	}
	if (cpf.match(/(\d)\1{10}/)) {
		return false;
	}
	var pesos = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2];
	var total = 0;
	var i;
	var digit;
	var rest;
	
	for (i = 1; i < 10; ++i) {
		total += pesos[i] * parseInt(cpf.charAt(i - 1));
	}
	digit = ( (rest = total % 11) < 2) ? 0 : 11 - rest;
	
	if (parseInt(cpf.charAt(9)) != digit) {
		return false;
	}
	
	total = 0;
	
	for (i = 0; i < 10; ++i) {
		total += pesos[i] * parseInt(cpf.charAt(i));
	}
	digit = ( (rest = total % 11) < 2) ? 0 : 11 - rest;
	
	return parseInt(cpf.charAt(10)) == digit;
}

function valid_cnpj(cnpj)
{
	cnpj = cnpj.replace(/\/|\.|-/g, "");
	
	if (cnpj.length != 14 || cnpj.match(/\D/)) {
		return false;
	}
	if (cnpj.match(/(\d)\1{13}/)) {
		return false;
	}
	var pesos = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
	var total = 0;
	var i;
	var digit;
	var rest;
	
	for (i = 1; i < 13; ++i) {
		total += pesos[i] * parseInt(cnpj.charAt(i - 1));
	}
	digit = ( (rest = total % 11) < 2) ? 0 : 11 - rest;
	
	if (parseInt(cnpj.charAt(12)) != digit) {
		return false;
	}
	total = 0;
	
	for (i = 0; i < 13; ++i) {
		total += pesos[i] * parseInt(cnpj.charAt(i));
	}
	digit = ( (rest = total % 11) < 2) ? 0 : 11 - rest;
	
	return parseInt(cnpj.charAt(13)) == digit;
}

function evita_letra2(tecla) {
	if (tecla.keyCode < 48 || tecla.keyCode > 57) 
		tecla.returnValue = false;
}
