function MascaraNumero(campo, decimais, evento)
{
    var tecla = (window.event) ? event.keyCode : evento.which;
    
    if (campo.value.length >= campo.maxLength)
    {
        if ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) || (tecla == 8) || (tecla == 46) || (tecla == 9) || (tecla == 13))
        {
            return true;
        }
        else
        {
            if (window.event) 
                event.returnValue = false;
            else
                evento.returnValue = false;
            
            return false;
        }
    }
    
    if ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105) || (tecla == 8) || (tecla == 46) || (tecla == 9) || (tecla == 13))
    {
        if (tecla == 8 || tecla == 46 || tecla == 9 || tecla == 13)
        {
            return true;
        }
        else
        {
            var tecla2 = tecla;
            if (tecla >= 96 && tecla <= 105)
            {
                tecla2 = tecla - 48;
            }
        
            var Moeda = SoNumero(campo.value + String.fromCharCode(tecla2));
            var MoedaAux = '';
            var campo1 = campo.value + String.fromCharCode(tecla2);
            var ponto = decimais + 3;
            
            var pontoDecimal = ",";
            var pontoMilhar = (decimais > 0) ? "." : "";
            
            for (var i=Moeda.length; i > 0; i--)
            {
                if ((i == Moeda.length - decimais) && (Moeda.length > decimais) && (decimais > 0))
                {
                    MoedaAux = pontoDecimal + MoedaAux;
                    ponto = 3;
                }

                if ((ponto == 0) && (Moeda.length > (decimais + 3)))
                {
                    MoedaAux = pontoMilhar + MoedaAux;
                    ponto = 3;
                }
                
                MoedaAux = Moeda.substr(i-1, 1) + MoedaAux;
                ponto--;
            }
            campo.value = MoedaAux;
            
            if (window.event)
                event.returnValue = false;
            else
                evento.returnValue = false;
        }
    }
    else
    {
        if (window.event) 
            event.returnValue = false;
        else
            evento.returnValue = false;
    }
}
