function FormataIndice(campo,tammax,teclapres,decimal)
{
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	if (tecla == 8 ) { tam = tam - 1 ; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if ( tam <= dec ){ campo.value = vr ; }
			if ( (tam > dec) && (tam <= 7) ){campo.value = vr.substr( 0, tam - dec ) + "," + vr.substr( tam - dec, tam ) ; }
			if ( (tam >= 8) && (tam <= 12) ){campo.value = vr.substr( 0, tam - dec ) + "," + vr.substr( tam - dec, tam ) ; }
		}
}
	
	
function Limpar(valor, validos)
	{ // retira caracteres invalidos da string 
		var result = ""; 
		var aux; 
		for (var i=0; i < valor.length; i++)
			{ 	aux = validos.indexOf(valor.substring(i, i+1)); 
				if (aux>=0) 
					{ 	result += aux; } 
			} 
		return result; 
	} 	