var exchangeRates = new Component("exchangeRates");
app.registerComponent(exchangeRates);

exchangeRates.on( "load", function(){
    trackAction("ForeignExchangeRates - View");
    var self = this,
    bykey = app.selectBpKey;
    if(!bykey){ 
        return;
    }
    var url = "exchangeRates/" + bykey + "?asOfDate=" + app.selectDateValue;
    var displayDivId = "foreignExchangeTableZone";   
    return self.render("template/exchange_rates.html", displayDivId, url).done(function(template, data){
        $("#foreignExchangeTable tr:odd").addClass("fextableRowOdd");
        $("#foreignExchangeTable tr:even").addClass("fextableRowEven");
        if(data.data.result.hasMetalCcy){
            $("#noteExchangeRates").attr("msgId","notes_exchangeRates2");
            lang.renderMessage("notes_exchangeRates2", "noteExchangeRates");
        }else{
            $("#noteExchangeRates").attr("msgId","notes_exchangeRates1");
            lang.renderMessage("notes_exchangeRates1", "noteExchangeRates");
        }
        
    });

        
});

exchangeRates.redoDatarow = function (data){
    if(data.data === false){
        return;
    }
    var items = data.result.items;
    var dataRows = [],row = [];
    
    for(var i = 0; i < items.length; i++){
        row.push(items[i]);
        if(i % 2 == 1 && row.length == 2){
            dataRows.push(row);
            row = [];
        }
    }
    return dataRows;
};

