﻿var volume = "";
var price = "";
var gross = "";
var ovolume = "";
var tpower = "";
var sprice = "";

function redirectOrderDepth(id){

    window.location = document.getElementById(id).value;
}

function OrderBookRowClick(type, id)//, value)
{
    var ordinaryRowOddColor = "#ffffff";
    var ordinaryRowColor = "#f6f6f6";
    var ordinaryPanelColor = "#eaeaea";
        
    document.orderBookForm.txtVolume.value = '';
    document.orderBookForm.txtPrice.value = '';
    document.orderBookForm.txtGrossPrice.value = '';
    document.orderBookForm.txtOpenVolume.value = '';
    //document.orderBookForm.txtTradePower.value = '';
    document.orderBookForm.txtStopPrice.value = '';
    
    document.getElementById("main").style.backgroundColor = ordinaryPanelColor;
    
    // disable sell and buy buttons
//    document.getElementById("btnBuy").disabled = "disabled";
//    document.getElementById("btnSell").disabled = "disabled";

    //alert(document.getElementById(type + "_" + id).innerText);
    
    document.getElementById("bo_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bv_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bvi_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("b_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("ao_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("av_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("avi_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("a_1").style.backgroundColor = ordinaryRowOddColor;
    
    document.getElementById("bo_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("bv_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("bvi_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("b_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("ao_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("av_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("avi_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("a_2").style.backgroundColor = ordinaryRowColor;
    
    document.getElementById("bo_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bv_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bvi_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("b_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("ao_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("av_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("avi_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("a_3").style.backgroundColor = ordinaryRowOddColor;
    
    document.getElementById("bo_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("bv_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("bvi_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("b_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("ao_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("av_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("avi_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("a_4").style.backgroundColor = ordinaryRowColor;
    
    document.getElementById("bo_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bv_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bvi_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("b_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("ao_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("av_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("avi_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("a_5").style.backgroundColor = ordinaryRowOddColor;
        
    var value = type == "b" ? document.getElementById("b_" + id).innerText : document.getElementById("a_" + id).innerText; //alert(value);
    
    if (value != '')
    {
        var selectedRowColor = "yellow";
        
        // set text to the price text box
        document.getElementById("txtPrice").value = value;
            
        if (type == "a")
        {
            // enable sell button
            document.getElementById("main").style.backgroundColor = "red";
            
            if (id == 1)
            {
                document.getElementById("ao_1").style.backgroundColor = selectedRowColor;
                document.getElementById("av_1").style.backgroundColor = selectedRowColor;
                document.getElementById("avi_1").style.backgroundColor = selectedRowColor;
                document.getElementById("a_1").style.backgroundColor = selectedRowColor;
            }
            if (id == 2)
            {
                document.getElementById("ao_2").style.backgroundColor = selectedRowColor;
                document.getElementById("av_2").style.backgroundColor = selectedRowColor;
                document.getElementById("avi_2").style.backgroundColor = selectedRowColor;
                document.getElementById("a_2").style.backgroundColor = selectedRowColor;
            }
            if (id == 3)
            {
                document.getElementById("ao_3").style.backgroundColor = selectedRowColor;
                document.getElementById("av_3").style.backgroundColor = selectedRowColor;
                document.getElementById("avi_3").style.backgroundColor = selectedRowColor;
                document.getElementById("a_3").style.backgroundColor = selectedRowColor;
            }
            if (id == 4)
            {
                document.getElementById("ao_4").style.backgroundColor = selectedRowColor;
                document.getElementById("av_4").style.backgroundColor = selectedRowColor;
                document.getElementById("avi_4").style.backgroundColor = selectedRowColor;
                document.getElementById("a_4").style.backgroundColor = selectedRowColor;
            }
            if (id == 5)
            {
                document.getElementById("ao_5").style.backgroundColor = selectedRowColor;
                document.getElementById("av_5").style.backgroundColor = selectedRowColor;
                document.getElementById("avi_5").style.backgroundColor = selectedRowColor;
                document.getElementById("a_5").style.backgroundColor = selectedRowColor;
            }
        }
        else
        {
            // enable buy button
            document.getElementById("main").style.backgroundColor = "blue";
            
            if (id == 1)
            {
                document.getElementById("bo_1").style.backgroundColor = selectedRowColor;
                document.getElementById("bv_1").style.backgroundColor = selectedRowColor;
                document.getElementById("bvi_1").style.backgroundColor = selectedRowColor;
                document.getElementById("b_1").style.backgroundColor = selectedRowColor;
            }
            if (id == 2)
            {
                document.getElementById("bo_2").style.backgroundColor = selectedRowColor;
                document.getElementById("bv_2").style.backgroundColor = selectedRowColor;
                document.getElementById("bvi_2").style.backgroundColor = selectedRowColor;
                document.getElementById("b_2").style.backgroundColor = selectedRowColor;
            }
            if (id == 3)
            {
                document.getElementById("bo_3").style.backgroundColor = selectedRowColor;
                document.getElementById("bv_3").style.backgroundColor = selectedRowColor;
                document.getElementById("bvi_3").style.backgroundColor = selectedRowColor;
                document.getElementById("b_3").style.backgroundColor = selectedRowColor;
            }
            if (id == 4)
            {
                document.getElementById("bo_4").style.backgroundColor = selectedRowColor;
                document.getElementById("bv_4").style.backgroundColor = selectedRowColor;
                document.getElementById("bvi_4").style.backgroundColor = selectedRowColor;
                document.getElementById("b_4").style.backgroundColor = selectedRowColor;
            }
            if (id == 5)
            {
                document.getElementById("bo_5").style.backgroundColor = selectedRowColor;
                document.getElementById("bv_5").style.backgroundColor = selectedRowColor;
                document.getElementById("bvi_5").style.backgroundColor = selectedRowColor;
                document.getElementById("b_5").style.backgroundColor = selectedRowColor;
            }
        }
    }
}

function OrderBookBuyClick()
{
    document.orderBookForm.bs.value = "b";
}

function OrderBookSellClick()
{
    document.orderBookForm.bs.value = "s";
}

function OrderBookAdvancedClick(layer1, layer2)
{
    volume = document.orderBookForm.txtVolume.value;
    price = document.orderBookForm.txtPrice.value;
    gross = document.orderBookForm.txtGrossPrice.value;
    ovolume = document.orderBookForm.txtOpenVolume.value;
    tpower = document.orderBookForm.txtTradePower.value;
    sprice = document.orderBookForm.txtStopPrice.value;
    
    toggleLayer(layer1);
    toggleLayer(layer2);
    
    document.orderBookForm.btnAdvanced.value = document.orderBookForm.btnAdvanced.value == "Advanced" ? "Basic" : "Advanced";
    
    document.orderBookForm.txtVolume.value = volume;
    document.orderBookForm.txtPrice.value = price;
    document.orderBookForm.txtGrossPrice.value = gross;
}

function OrderBookCancelClick(layer1, layer2)
{
    var ordinaryRowOddColor = "#ffffff";
    var ordinaryRowColor = "#f6f6f6";
    var ordinaryPanelColor = "#eaeaea";

    if (document.getElementById(layer1).style.display == "block")
    {
        toggleLayer(layer1);
        toggleLayer(layer2);
    }
    
    document.orderBookForm.btnAdvanced.value = document.orderBookForm.btnAdvanced.value == "Advanced" ? "Basic" : "Advanced";
    
    document.getElementById("bo_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bv_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bvi_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("b_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("ao_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("av_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("avi_1").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("a_1").style.backgroundColor = ordinaryRowOddColor;
   
    document.getElementById("bo_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("bv_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("bvi_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("b_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("ao_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("av_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("avi_2").style.backgroundColor = ordinaryRowColor;
    document.getElementById("a_2").style.backgroundColor = ordinaryRowColor;
    
    document.getElementById("bo_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bv_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bvi_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("b_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("ao_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("av_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("avi_3").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("a_3").style.backgroundColor = ordinaryRowOddColor;
    
    document.getElementById("bo_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("bv_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("bvi_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("b_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("ao_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("av_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("avi_4").style.backgroundColor = ordinaryRowColor;
    document.getElementById("a_4").style.backgroundColor = ordinaryRowColor;

    document.getElementById("bo_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bv_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("bvi_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("b_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("ao_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("av_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("avi_5").style.backgroundColor = ordinaryRowOddColor;
    document.getElementById("a_5").style.backgroundColor = ordinaryRowOddColor;
   
    document.getElementById("main").style.backgroundColor = ordinaryPanelColor;
}

function toggleLayer(whichLayer)
{  
    var elem, vis;  
    //alert(whichLayer);
    if(document.getElementById) 
    {
        // this is the way the standards work
        elem = document.getElementById( whichLayer );
    }
    else if(document.all)
    {
        // this is the way old msie versions work      
        elem = document.all[whichLayer];
    }
    else if(document.layers)
    {
       // this is the way nn4 works    
       elem = document.layers[whichLayer];  
    }
    vis = elem.style;  
    // if the style.display value is blank we try to figure it out here  
    if(vis.display == '' && elem.offsetWidth != undefined&&elem.offsetHeight != undefined)
    {
        vis.display = (elem.offsetWidth!=0 && elem.offsetHeight!=0)?'block':'none';  
    }
    vis.display = (vis.display == '' || vis.display=='block')?'none':'block';
}

function toggleBox(layerId, iState)
{
    if (document.Layers)        // NN4+
    {
        document.Layers[layerId].visibility = iState ? "show" : "hide";
    }
    else if (document.getElementById("layerId"))        // gecko(NN6), IE 5+
    {
        var obj = document.getElementById(layerId);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if (document.all)
    {
        document.all[layerId].style.visibility = iState ? "visible" : "hidden";
    }
}
