﻿/************* settings prices **************/
//Builds the string of option ids and send 
//them to the server's GetOptionPrices service
function getOptionPrices() {
    var i = 0;
    var o;
    var strRequest = "";
    try {
        if (!isVarDefined("totalOptions")) return;
        for (i = 1; i <= totalOptions; i++) {
            if (isVarDefined("dataAssetTradeBlock" + i)) {
                o = eval("dataAssetTradeBlock" + i);
                strRequest += o.OptionID + ";";
            }
        }
        qs.GetOptionPrices(strRequest, onGetOptionPrices);
    }
    catch (e) {
        debugger;
    }
    setTimeout("getOptionPrices()", 3000);
}

//GetOptionPrices service returns here on sucesses
//It then Changes the prices of the options objects 
function onGetOptionPrices(result) {
    var prices = eval(result);
    
    var currentBlock;
    try 
    {
        if (typeof (totalOptions) == 'undefined') return;
    
        for (i = 1; i <= totalOptions; i++) {
            currentBlock = "AssetTradeBlock" + i;
            o = eval("data" + currentBlock); //data obj
            if (typeof (o) == 'undefined') return;
            for (j = 0; j < prices.length; j++) 
            {
                if (prices[j] != null && prices[j].OptionID == o.OptionID) 
                {
                    if (prices[j].Price > 0) 
                    {
                        o.Price = prices[j].Price;
                        o.OrigPrice = prices[j].OrigPrice;
                        setTimeout('setPriceDisplay("' + currentBlock + '")', 100);                
                    }
                }
            }

        }
    }
    catch (e) {
        debugger;
    }
}

function setPriceDisplay(controlID) {
    try {
        o = eval("data" + controlID);
        var elm = document.getElementById("Price" + controlID);
        if (o.Price != undefined) {
            elm.innerHTML = o.Price;

            //Check if the quote belongs to the currently active tradeed asset
            if (typeof (m_activeTradeBlock) != 'undefined' && controlID == m_activeTradeBlock) {
                var elmTradeOrderBlockPrice = document.getElementById("TradeBlockPrice");
                if (m_activeTradeBlock != null) {
                    elmTradeOrderBlockPrice.innerHTML = o.Price;
                }

            }
            //pushChartData('demoChart1', generateQuotesChartXML(o.OrigPrice), true);
        }

        //Flot Refresh
        if ((typeof (isFlot) != "undefined") && (isFlot == "true")) {
            RefreshFlot(controlID);
        }

    }
    catch (e) {
        debugger;
        ShowMsgbox(e.description);
    }
}


/************* settings prices **************/
/********* Dealing with expiration **********/
