function txtBoxFormat(objForm, strField, sMask, evtKeyPress){
	var i, nCount, sValue, sCampo, fldLen, mskLen,bolMask, sCod, nTecla;
	
	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	}
	else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	}
	
	//alert(document.getElementById(strField));
	sCampo = document.getElementById(strField);
	
	sValue = sCampo.value;
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	
	while (i <= mskLen){
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
		
		if (bolMask){
			sCod += sMask.charAt(i);
			mskLen++;
		}
		else{
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		
		i++;
	}
	
	sCampo.value = sCod;
	if (nTecla != 8) { // backspace
		if (sMask.charAt(i-1) == "9"){ // apenas números...
			return ((nTecla > 47) && (nTecla < 58));
		} // números de 0 a 9
		else { // qualquer caracter...          
			return true;        
		}
	}
	else{
		return true;
	}
}

function ValidaCPF(CPF) {
	var i;
	var numCPF='';
	
	for(i=0;i<CPF.length;i++) {
		if(!isNaN(CPF.substring(i,i+1))) {
			numCPF+=CPF.substring(i,i+1);
		}
	}
	
	CPF = numCPF
	
	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;
}


function TESTACPF(campo){ 
	var strCampo = document.getElementById(campo);
	
	if(strCampo.value != ''){
		if(ValidaCPF(strCampo.value) == true){ 
			//alert("CNPJ válido!"); 
		} 
		else{ 
			alert("CPF inválido!"); 
			strCampo.value = "";
			strCampo.focus();
		}
		return; 
	}
} 
