function FormataData(campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

function FormataCPF(pForm,pCampo,pTamMax,pPos1,pPos2,pPosTraco,pTeclaPres){
var wTecla, wVr, wTam;

// alert(pForm[pCampo].value);


if(window.event){
    wTecla = pTeclaPres.keyCode;
}else{
    wTecla = pTeclaPres.which;
}

wVr = pForm[pCampo].value;
wVr = wVr.toString().replace( "-", "" );
wVr = wVr.toString().replace( ".", "" );
wVr = wVr.toString().replace( ".", "" );
wVr = wVr.toString().replace( "/", "" );
wTam = wVr.length ;

if(wTam < pTamMax && wTecla != 8) {
wTam = wVr.length + 1 ;
}

if(wTecla == 8 ) {
wTam = wTam - 1 ;
}

if( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
if( wTam <= 2 ){
pForm[pCampo].value = wVr ;
}
if(wTam > pPosTraco && wTam <= pTamMax) {
wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
}
if( wTam == pTamMax){
wVr = wVr.substr( 0, wTam - pPos1 ) + '.' + wVr.substr(wTam - pPos1, 3) + '.' + wVr.substr(wTam - pPos2, wTam);
}
pForm[pCampo].value = wVr;

}

}


function FormataCampo(Campo,teclapres,mascara){
//pegando o tamanho do texto da caixa de texto com delay de -1 no event
//ou seja o caractere que foi digitado não será contado.
strtext = Campo.value
tamtext = strtext.length
//pegando o tamanho da mascara
tammask = mascara.length
//criando um array para guardar cada caractere da máscara
arrmask = new Array(tammask)
//jogando os caracteres para o vetor
for (var i = 0 ; i < tammask; i++){
arrmask[i] = mascara.slice(i,i+1)
}
//alert (teclapres.keyCode)
//começando o trabalho sujo
if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){
if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){
Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)
}
else{
Detona_Event(Campo,strtext)
}
}
else{//Aqui funcionaria a mascara para números mas eu ainda não implementei
if ((arrmask[tamtext] == "A")) {
charupper = event.valueOf()
//charupper = charupper.toUpperCase()
Detona_Event(Campo,strtext)
masktext = strtext + charupper
Campo.value = masktext
}
}
}
function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){
if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){
separador = arrpos
masktext = strtext + separador
Campo.value = masktext
}
}
function Detona_Event(Campo,strtext){
event.returnValue = false
if (strtext != "") {
Campo.value = strtext
}
}
