$(function()
{
    $('span.number, .number span').each(function(i)
    {
        $(this).html(formatLongInt($(this).text()));
    });
});

formatLongInt = function(s)
{
    var i = parseInt(s,10);
    var sResult = "";
    var a, b;
    if (i.toString().length > 4)
    {
        while (i > 0)
        {
            a = Math.floor(i/1000);
            b = (i-a*1000)+"";
            if(a)
            {
                switch(b.length)
                {
                    case 1: b="00"+b; break;
                    case 2: b="0"+b; break;
                    case 3: break;
                    default: b="000"; break;
                }
            }
            //sResult =  "<span>" + b + "</span>" + sResult;
            if (sResult.length)
            {
                sResult =  b + "&nbsp;" + sResult;
            }
            else
            {
                sResult =  b;
            }
            i = a;
        }
    }
    return sResult || s;
}
