function formatar(src, mask)
//funcao para formatar qualquer campo.Ex.:cep,cpf,telefone,cnpj.
{
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida)
	{
		src.value += texto.substring(0,1);
	}
}

function limpa_string(S){
	// Deixa so' os digitos no numero
	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 }
	} //for
	
	return temp
}

function valida_CPF(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")
		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)))
		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)))
		return false;
	return true;
}


