var backspace = 8;

function MascararAWB (campo, event){
	if (campo.value.length == 3){
		campo.value = campo.value + '.';
	}else{	
		if (campo.value.length == 10){
			campo.value = campo.value + '-';	
		}	
	}
}

function MascararCODCLIENTE (campo, event){
	if (campo.value.length == 3){
		campo.value = campo.value + '.';
	}	
}

function MascararColeta (campo, event){
	if (campo.value.length == 3){
		campo.value = campo.value + '.';
	}
}

function MascararCPF (campo, event){
	campo.value = RetiraCaracteresInvalidos(campo.value);
	if (((campo.value.length == 3)||(campo.value.length == 7)) && (event.keyCode != backspace)){
		campo.value = campo.value + '.';
	}else{
		if ((campo.value.length == 11) && (event.keyCode != backspace)){
			campo.value = campo.value + '-';
		}
	}
}

function MascararCNPJ (campo, event){
	campo.value = RetiraCaracteresInvalidos(campo.value);
	if ((campo.value.length == 2)||(campo.value.length == 6)){
		if (event.keyCode != backspace) {
			campo.value = campo.value + '.';
		}
	}else{
		if ((campo.value.length == 10) && (event.keyCode != backspace)){
			campo.value = campo.value + '/';
		}else{
			if ((campo.value.length == 15) && (event.keyCode != backspace)){
				campo.value = campo.value + '-';
			}
		}
	}
}

function MascararRG (campo, event){
	if ((campo.value.length == 2)||(campo.value.length == 6)){
		campo.value = campo.value + '.';
	}else{
		if (campo.value.length == 10){
			campo.value = campo.value + '-';
		}
	}
}

function MascararCEP (campo, event){
	campo.value = RetiraCaracteresInvalidos(campo.value)
	if ((campo.value.length == 5) && (event.keyCode != backspace)){
			campo.value = campo.value + '-';
	}

}

function RetiraCaracteresInvalidos(strCampo) {
	var nTamanho = strCampo.length;
	var szCampo = "";
	j = 0;
	for (i = nTamanho-1;i>=0;i--) 
	{
		if (isDigit(strCampo.charAt(i)))
		{
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
		}
	}
    return szCampo;
} 

function isDigit (c){
	return (((c >= "0") && (c <= "9")) || (c == "-") || (c == ".") || (c == "/"))
} 

function MascararData (campo, event){
	if ((campo.value.length == 2) || (campo.value.length == 5)){
		campo.value = campo.value + '/';
	}
}

function MascararHorario (campo, event){
	if (campo.value.length == 2){
		campo.value = campo.value + ':';
	}
}