function validarCampo (obj, tipo) {
	switch(tipo){
		case "string" : obj.value = obj.value.replace(/([0-9])/g, "");
						break;
						  
		case "number": obj.value = obj.value.replace(/([ A-Za-z])/g, "");
					   break;
		
		case "date"	:  obj.value = obj.value.replace(/([ A-Za-z,.:?;"\\\-\=\(\)])/g, "");
					   var data  = obj.value;
				        if (data.length == 2){
				            data = data + '/';
				            obj.value = data;
				        }
				        if (data.length == 5){
				            data = data + '/';
				            obj.value = data;
				        }
					   break;
		}
	return true;
}


function validaDvCpf(nuCpf) {
	var numeroDigitado = nuCpf.value;
	var objRegExp = /(\.|\-)/g
	var numeroDigitado = numeroDigitado.replace(objRegExp,"");
	var numeroDigitadoSemDv  = numeroDigitado.substr(0,9);
	var Dv  = new String(numeroDigitado.substr(9,2));
	tam = numeroDigitadoSemDv.length;

    if (numeroDigitado.length != 11) {
		alert("CPF - Número inválido de algarismos!");
		nuCpf.value='';
		//nuCpf.focus();
		return false;
    }

    cpf = numeroDigitado;
    nrepetidos = false;
    if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" ||
        cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" ||
        cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" ||
        cpf == "99999999999"){
      nrepetidos = true;
    }

	var soma = 0;
	for (var i=0; i < tam; i++) {
		soma += parseInt(numeroDigitadoSemDv.charAt(i),10) * (tam+1-i)
	}
	soma = 11 - (soma % 11)
	if (soma == 11 || soma == 10) soma = 0;

	var novo = numeroDigitadoSemDv+soma
	var tam2  = novo.length
	var soma2 = 0;
	for (var i=0; i < tam2; i++) {
		soma2 += parseInt(novo.charAt(i),10) * (tam2+1-i)
	}
	soma2 = 11 - (soma2 % 11)
	if (soma2 == 11 || soma2 == 10) soma2 = 0;

	var DvCalculado = new String(soma)+new String(soma2);
	if (Dv != DvCalculado) {
		alert("CPF INVÁLIDO");
		nuCpf.value='';
		return false;
	}
	if (nrepetidos) {
		alert("Números repetidos não são válidos!");
		nuCpf.value='';
		return false;
    }
	return true;
}