﻿var smallStatsRowTemplate =
    '<tr class="{0} statsRow" onclick="ViewInstrument({6})">'
    + '<td>{1}</td><td class="{4}">{2}</td><td class="{5}">{3}</td>'
    + '</tr>';
function ViewInstrument(id) {
    document.location = String.format("ViewSymbol.aspx?id={0}", id);
}
function ToFixed(price) {
    if (price == null)
        return "-";
    else
        return price.toFixed(4);
}
function ToDeal(price, amount) {
    if (price != null && amount != null)
        return String.format("{0} / {1}", price.toFixed(4), amount);
    else
        return "-";
}
function ShowSmallTradingStats(target) {
    IndxContentSite.TradingStats.GetSmallTradingStats(function(res) {
        $(target + " tr:gt(0)").remove();
        var s = "";
        for (var i in res) {
            var class1 = "", class2 = "";
            if (res[i].LastDealPrice > res[i].AveragePrice) class1 = "priceup_arrow";
            if (res[i].LastDealPrice < res[i].AveragePrice) class1 = "pricedown_arrow";
            if (res[i].AveragePrice > res[i].OpeningPrice) class2 = "priceup_arrow";
            if (res[i].AveragePrice < res[i].OpeningPrice) class2 = "pricedown_arrow";

            s += String.format(smallStatsRowTemplate,
                i % 2 == 0 ? "even" : "odd",
                res[i].SymbolName, ToFixed(res[i].LastDealPrice), ToFixed(res[i].AveragePrice),
                class1, class2, res[i].SymbolID);
        }
        $(target).append(s);
    }, Fail);
}

