<!--
function limpaCampo(valor) {
// Retira os simbolos de um campo, retornando apenas os seus digitos
	var numeros = "0123456789";
	var cont = 0;
	while (cont < valor.length)
	  {
	  	if (numeros.indexOf(valor.charAt(cont)) < 0)
				valor = valor.substr(0, cont) + valor.substr(cont + 1);
			else
				cont++;
	  }
	return valor;
}

function FormataCEP(campo,tammax,teclapres,frmName) {
	if (frmName == undefined) frmName = "form";
	nmCampo = eval("document."+frmName+"."+campo);
	if (nmCampo) {
		var tecla = teclapres.keyCode;
		vr = limpaCampo(nmCampo.value);
		tam = vr.length + 1;
		if (tam > 5) {
	 	  vr = vr.substr(0, 5) + '-' + vr.substr(5);
  	}
  	nmCampo.value = vr;
	}
}

function FormataData(campo,tammax,teclapres,frmName) {
	if (frmName == undefined) frmName = "form";
	nmCampo = eval("document."+frmName+"."+campo);
	if (nmCampo) {
		var tecla = teclapres.keyCode;
		vr = limpaCampo(nmCampo.value);
		tam = vr.length + 1;
		if (tam > 2) {
			 vr = vr.substr(0, 2) + '/' + vr.substr(2);
			 if (tam > 4)
			 	  vr = vr.substr(0, 5) + '/' + vr.substr(5);
  	}
  	nmCampo.value = vr;
	}
}

function FormataCpfCgc(campo,tammax,teclapres,frmName) {
	if (frmName == undefined) frmName = "form";
	nmCampo = eval("document."+frmName+"."+campo);
	if (nmCampo) {
		vr = limpaCampo(nmCampo.value);
		if (vr.length <= 11) {
			FormataCpf(campo,tammax,teclapres,frmName)
		} else {
			FormataCgc(campo,tammax,teclapres,frmName)
		}
	}
}

function FormataCpf(campo,tammax,teclapres,frmName) {
	if (frmName == undefined) frmName = "form";
	nmCampo = eval("document."+frmName+"."+campo);
	if (nmCampo) {
		var tecla = teclapres.keyCode;
		vr = limpaCampo(nmCampo.value);
		tam = vr.length + 1;

		if (tam > 3) {
			vr = vr.substr(0, 3) + '.' + vr.substr(3);
			if (tam > 6)
				vr = vr.substr(0, 7) + '.' + vr.substr(7);
				if (tam > 9)
					vr = vr.substr(0, 11) + '-' + vr.substr(11);
		}
  	nmCampo.value = vr;
	}
}

function FormataCgc(campo,tammax,teclapres,frmName) {
	if (frmName == undefined) frmName = "form";
	nmCampo = eval("document."+frmName+"."+campo);
	if (nmCampo) {
		var tecla = teclapres.keyCode;
		vr = limpaCampo(nmCampo.value);
		tam = vr.length + 1;

		if (tam > 2) {
			vr = vr.substr(0, 2) + '.' + vr.substr(2);
			if (tam > 5)
				vr = vr.substr(0, 6) + '.' + vr.substr(6);
				if (tam > 8)
					vr = vr.substr(0, 10) + '/' + vr.substr(10);
					if (tam > 12)
						vr = vr.substr(0, 15) + '-' + vr.substr(15);
		}
  	nmCampo.value = vr;
	}
}
//-->
