﻿// #begin-ajax
var ClientID = null;
// #end-ajax
var headers = [];
var liveStockBody;
var liveStockSelected;
var liveStockHeader;
var topStocks = '', isUploaded = true;
var moveStock;
var stockRows = {};
var stockInfos = {};
var detail_qtty = {};
var fixLiveStock;
var scrollTimer;
var row_change;
var ajax_timer;
var selected_symbols;
var page_position;

var 
mk_status,
mk_mi_status,
mk_index,
mk_advance,
mk_nochange,
mk_decline,
mk_vol,
mk_val,
mk_clock,
mk_date;

var isCycle;
var search = '', search_timer;

function InitVariables()
{
    mk_clock = $('#clock');
    mk_date = $('#date');
    mk_status = $('#status');
    mk_mi_status = $('#mi_status');
    mk_index = $('#index');
    mk_advance = $('#advance');
    mk_nochange = $('#nochange');
    mk_decline = $('#decline');
    mk_vol = $('#vol');
    mk_val = $('#val');

    liveStockSelected = $('#liveStock > table > tbody.selected');
    liveStockBody = $('#liveStock > table > tbody.noselect');
    liveStockHeader = $('#liveStock > table > thead');
    fixLiveStock = $('#fixLiveStock > table > thead');
}

function SetUpSymbolBox()
{
   $("input#symbol")
        .focus(function (){ $(this).val('').css('color', '#FFFFFF');})
        .blur(function (){ $(this).val('MãCK1,MãCK2...').css('color', '#88CC88');}).blur();
}

function SetUpStockSelList()
{
    // Update Stock Name
    $("ul.symbols > li > input").each(function (key, value)
    {
        $(value).children('a').attr('title', stockNames[$(value).val()]);
    });
    // Uncheck all options
    $("ul.symbols > li > input").attr('checked', false);
    // When check highlight text
    $("ul.symbols > li > input").change(function ()
        {
            if($(this).attr('checked'))
                $(this).parent().addClass('selected');
            else
                $(this).parent().removeClass('selected');
        }).click(function ()
        {
            $(this).change();
        });
    // When SHOW_ALL switch
    $("input[name='SHOW_ALL']").click(function (){
        $("input[name='SHOW_ALL']").attr('checked', false);
        $(this).attr('checked', true);
        if($("input[name='SHOW_ALL']:checked").val() == 'A')
        {
            $('div#header > div#view_panel > div#select_abc > table > tbody > tr[id!=select_option]').hide();
            $('div#header > div#view_panel > div#select_branch > table > tbody > tr[id!=select_option]').hide();
        }
        else
        {
            abc_filter('ALL');
            $('div#header > div#view_panel > div#select_abc > table > tbody > tr').show();
            $('div#header > div#view_panel > div#select_branch > table > tbody > tr').show();
        }
    });
}

function SetUpStockGrid()
{
    $("#liveStock > table > tbody > tr[id^='row']")
        .live("mouseover", stock_over)
        .live("mouseout", stock_out)
        .live("click", stock_click);
    if(MARKET_NAME == 'UC')
        $("#liveStock > table > tbody > tr[id^='row'] > td")
            .live("mouseover", tip_over)
            .live("mouseout", tip_out);
}

function tip_over()
{
    var this_id = this.id;
    if(this_id == 'BVOL1' || this_id == 'BVOL2' || this_id == 'BVOL3' || 
       this_id == 'SVOL1' || this_id == 'SVOL2' || this_id == 'SVOL3')
    {
        var el = $(this);
        if(el.html() != '')
        {
            var key = el.parent().attr('id').slice(3);
            var temp = detail_qtty[key][this.id].split('-');
            var vol = '', count = 0, tip = '';
            for(var i = 0; i < temp.length; i ++)
            {
                if(vol != temp[i])
                {
                    if(count > 0) tip += count + ' lệnh x KL ' + vol + '<BR/>'
                    count = 1;
                    vol = temp[i];
                }
                else
                {
                    count++;
                }
            }
            if(count > 0) tip += count + ' lệnh x KL ' + vol + '<BR/>'

            el.aqTipOne(tip);
        }
    }
}

function tip_out()
{
    var this_id = this.id;
    if(this_id == 'BVOL1' || this_id == 'BVOL2' || this_id == 'BVOL3' || 
       this_id == 'SVOL1' || this_id == 'SVOL2' || this_id == 'SVOL3')
    {
        $(this).aqTipOne();
    }
}

function SetUpKeyboard()
{
    $(document).keypress(function(event)
    {
        var key = String.fromCharCode(event.which).toLocaleUpperCase();
        if(event.which != 0 && /^[A-Z0-9]+$/.test(key))
        {
            search += key;
            clearTimeout(search_timer);
            search_timer = setTimeout(
                function (){
                    if(moveStock)
                        moveStock.children('td').highlightFade({color: '#666666', speed: 500});
                    search = '';
                }, 500);

            var move = '';
            $.each(stockRows, function (key)
            {
                if(key.indexOf(search) == 0)
                {
                    move = key;
                    return false;
                }
            });
            
            if(stockRows[move] != null)
            {
                moveStock = stockRows[move];
                $(window).scrollTop(moveStock.offset().top - 100);
           } 
        }
    });
}

function OnLoad()
{
    InitVariables();
    SetUpSymbolBox();
    SetUpStockSelList();
    SetUpStockGrid();

    SetUpKeyboard();
    ClientInit();
    HeaderInit();
    ModeClean();
    Static();
    
    $("#ajax").ajaxStart(function(){
        $(this).removeClass('error');
        $(this).addClass('active');
    }).ajaxStop(function(){
        $(this).removeClass('active');
    }).ajaxError(function(){
        $(this).addClass('error');
        setTimeout(AjaxCycle, TIME_WAIT);
    });
    AjaxCycle();
}

function ProcessMessage(result)
{
    var list = result.split("!!");
    var ControlCode = null;
    var htmlStockAdd = '';
    row_change = false;
    data_change = false;

    for(var i = 0; i < list.length; i++)
    {
        var item = list[i].split("|");
        switch(item[0])
        {
            case 'T':
                mk_clock.html(', ' + item[1]);
                break;
            case 'C':
                ControlCode = item[1];
            break;
            case 'A':
                switch(ControlCode)
                {
                    case 'SP':
                        htmlStockAdd += StockAdd(item);
                        row_change = true;
                        data_change = true;
                    break;
                    case 'MK':
                        MarketAdd(item);
                    break;
                    case 'PA':
                        PutadAdd(item);
                    break;
                }
            break;
            case 'U':
                switch(ControlCode)
                {
                    case 'SP':
                        StockUpdate(item);
                        data_change = true;
                    break;
                    case 'MK':
                        MarketUpdate(item);
                    break;
                }
            break;
            case 'R':
                switch(ControlCode)
                {
                    case 'SP':
                        StockRemove(item);
                        row_change = true;
                        data_change = true;
                    break;
                    case 'PA':
                        PutadRemove(item);
                    break;
                }
            break;
        }
    }

    if(row_change)
    {
        liveStockBody.append(htmlStockAdd);
        stockRows = {};
        liveStockBody.children('tr').each(
            function ()
            {
                var key = this.id.slice(3);
                stockRows[key] = $(this);
                if(topStocks.indexOf(key + ',') >= 0)
                    liveStockSelected.append(stockRows[key]);
            }
        );
        setTimeout(AlternateStocks, 5);
    }
    if(data_change)
    {
        setTimeout(UpdateView, 5);
    }
}

function AjaxCycle()
{
    $.post("Live.aspx", "ClientID=" + ClientID + (isUploaded ? '' : ('&top=' + topStocks)),
        function(data, textStatus)
        {
            if(textStatus == "success") ProcessMessage(data);
            setTimeout(AjaxCycle, TIME_WAIT);
        }, "text");
    isUploaded = true;
}

function HandleException(item)
{
}

function ClientInit()
{
    $("input[name='SHOW_ALL'][value='" + ShowAll + "']").click();
    $.each(selected_symbols.split(','), function (key, value){
        $("input[value='"+value+"']").attr('checked', true).change();
    });
}

function HeaderInit()
{
    var i = 0, j = 0;

    var col1to4 ='';
    for(j = 0; j < 4; j++)
    {
        col1to4 += '<th rowspan="2" id="' + headers[i] + '">' + (header_lang[headers[i]] ? header_lang[headers[i]] : headers[i]) + '</th>';
        i++;
    }
    
    var colMid = '';
    for(j = 0; j < 15;j++)
    {
        colMid += '<th rowspan="1" id="' + headers[i] + '">' + (header_lang[headers[i]] ? header_lang[headers[i]] : headers[i]) + '</th>';
        i++;
    } 

    var colLast = '';
    for(; i < headers.length;i++)
    {
        colLast += '<th rowspan="2" id="' + headers[i] + '">' + (header_lang[headers[i]] ? header_lang[headers[i]] : headers[i]) + '</th>';
    }

    html = '<tr>' + col1to4 +
        '<th colspan="6" class="BID_SIDE">' + header_lang['BID_SIDE'] + '</th>' +
        '<th colspan="3" class="ORDER_MATCH">' + header_lang['ORDER_MATCH'] + '</th>' +
        '<th colspan="6" class="OFFER_SIDE">' + header_lang['OFFER_SIDE'] + '</th>' +
        colLast + 
        '</tr>' +
        '<tr>' + colMid +
        '</tr>';
    
    $('#chart_bounce > td').attr('colSpan', headers.length);    
    liveStockHeader.html(html);
}

function TopList(result)
{
    topStocks = result[1];
}

function StockInfoAdd(result) {
    stockInfos[result[1]] = result[2];
}

function StockAdd(result)
{
    var symbol = result[1];
    var newStock = '<tr id="row' + symbol + '">';
    var length = ((MARKET_NAME == 'UC') ? result.length - 6 : result.length); 

    for(var j = 2; j < length; j++)
    {
        var css_class = result[j].slice(0, 1);
        newStock += '<td nowrap id="' + headers[j-2] + '"' + (j==2 ? (' title="' + stockNames[symbol] + '"') : '') + ' class="' + (css_class ? css_class : 'w') + '">' + result[j].slice(1) + '</td>';
    }
    
    if(MARKET_NAME == 'UC')
        detail_qtty[symbol] = {
            BVOL3 : result[j++],
            BVOL2 : result[j++],
            BVOL1 : result[j++],
            SVOL1 : result[j++],
            SVOL2 : result[j++],
            SVOL3 : result[j++]};
    newStock += '</tr>';
    return newStock;
}

function StockUpdate(result)
{
    var symbol = result[1];
    if(!stockRows[symbol]) return;
    var els = stockRows[symbol].children('td');
    var length = ((MARKET_NAME == 'UC') ? result.length - 6 : result.length); 

    for(var j = 2; j < length; j++)
    {
        els.eq(j-2).html2(result[j].slice(1), result[j].slice(0,1));
    }

    if(MARKET_NAME == 'UC')
        detail_qtty[symbol] = {
            BVOL3 : result[j++],
            BVOL2 : result[j++],
            BVOL1 : result[j++],
            SVOL1 : result[j++],
            SVOL2 : result[j++],
            SVOL3 : result[j++]};
}

function StockRemove(result)
{
    stockRows[result[1]].remove();
}

function PutadAdd(item)
{
    var html = '<tr id="ad' + item[1] + '">';
    html += '<td id="SYMBOL">' + item[3] + '</td>';
    for(var i = 4; i < item.length; i++)
    {
        html += '<td class="' + item[i].slice(0,1) + '">' + item[i].slice(1) + '</td>';
    }
    html += '</tr>';
    $(html).appendTo('table.putad > tbody#' + item[2]);
}

function PutadRemove(item)
{
    $('#ad' + item[1]).empty();
}

function UpdateClock(result)
{
    mk_clock.html(result[2]);
}

function AlternateStocks()
{
    var i = 0;
    $.each(stockRows, function(key) {
        if(stockRows[key] != null)
        {
            var tr = stockRows[key];
            if (tr.parent().hasClass('noselect')) {
                i++;
                tr.removeClass().addClass((i % 2 == 0) ? 'even' : 'odd');
            }
        }
    });

    liveStockSelected.show();
    if(liveStockSelected.children('tr:visible').length == 0)
    {
        liveStockSelected.hide();
    }        
}

function UpdateView()
{
    liveStockSelected.show();
    if(liveStockSelected.children('tr:visible').length == 0)
    {
        liveStockSelected.hide();
    }
    CalcFixHead();
}

function ToScroll()
{
    ModeClean();
    ScrollInit();
}

function ShowChart(SYMBOL)
{
    var stockRow = stockRows[SYMBOL.slice(3)];

    var links = $('#chart_bounce > td > span > a');

    stockRow.before($('#chart_bounce').show());
    $('#chart_title').html(stockNames[SYMBOL.slice(3)]);
    
    links.eq(0).unbind().click(function (){ stock_move(SYMBOL);});
    links.eq(0).html($(stockRow).parent('.noselect').length == 0 ? MOVE_DOWN : MOVE_UP);
    links.eq(1).attr('href', COMPANY_URL + SYMBOL.slice(3));

    $(document).scrollTop(stockRow.offset().top - 450);

    setTimeout(function()
    {
        flashembed("chart", {
                                src : "../Flex/Chart.swf",
                                width: "525px",
                                height: "250px",
                                wmode : "transparent"
                            }, { 
                ClientID : ClientID,
                Symbol: SYMBOL.slice(3),
                StartTime: MARKET_NAME == 'UC' ? 100000 : 83000,
                EndTime: MARKET_NAME == 'UC' ? 150000 : 110000
        });
    }, 5)
}

function HideChart()
{
    $('#chart_bounce').hide();
    $('#chart').empty();
}

function ModeClean()
{
    clearTimeout(scrollTimer);

    $('#scrollStock > table > tbody').appendTo('#liveStock > table');
    $('#scrollStock').dequeue().stop();

    $(window).unbind();
    $('#scrollStock').hide();
    liveStockBody.children('tr').show();
    isCycle = true;
}

function SaveSymbols()
{
    selected_symbols = '';
    $('ul.symbols > li > input:checked').each(function ()
    {
        selected_symbols += $(this).val() + ',';
    });

    $.post("Live.aspx",
        "ClientID=" + ClientID +
        "&ShowAll=" + $("input[name='SHOW_ALL']:checked").val() +
        "&Symbols=" + selected_symbols,
        function(data, textStatus)
        {
            if(textStatus == "success")
            {
                CollapseMenu();
                ProcessMessage(data);
            }
        }, "text");
}

function Static()
{
    $(window).scroll(ShowHeader);
    setTimeout(AlternateStocks, 5);
}

function TwoWayScroll()
{
    ResizeScroll();
    scrollTimer = setTimeout(ScrollToDown, 30 * TIME_PER_PIXEL);
}

function OneWayScroll()
{
    ResizeScroll();
    scrollTimer = setTimeout(ScrollDown, 30 * TIME_PER_PIXEL);
}

function ResizeScroll()
{
    $('#scrollStock').show();

    $('#liveStock > table > tbody').appendTo('#scrollStock > table');
    $('#scrollStock').css('overflow', 'hidden');

    $('#scrollStock').height(
        $(window).height()
        - $('#footer').height()
        - $('#header').height()
        - $('#market').height()
        - $('#liveStock').height()
        + $('div#header > div#view_panel > div:visible').height());

    setTimeout(AlternateStocks, 5);
    ResizeScrollColumns(); 
    $('#scrollStock').scrollTop(0);
}

function ResizeScrollGroupColumns(group, head_group)
{
    var sour = $("table > tbody.noselect > tr:eq(0)").children(group);
    var dest = $('#liveStock > table > thead > tr').children(group);
    var width = 0;
    for(var i = 0; i < sour.length; i++)
    {
        dest.eq(i).width(sour.eq(i).width()+($.browser.msie ? 1 : 0));
        width += sour.eq(i).width()+($.browser.msie ? 1 : 0) + 4;
    }
    
    if(head_group)
        $('#liveStock > table > thead > tr > th' + head_group).width(width - 4);
}

function ResizeScrollColumns()
{
    HideChart();
    var sour = $("#scrollStock > table > tbody.noselect > tr[id^='row']:eq(0)").children('td');
    var dest = $("#liveStock > table > tbody.selected > tr[id^='row']:eq(0)").children('td');

        ResizeScrollGroupColumns('#BPRICE1,#BVOL1,#BPRICE2,#BVOL2,#BPRICE3,#BVOL3');
        ResizeScrollGroupColumns('#PRICE,#VOL,#CHANGE');
        ResizeScrollGroupColumns('#SPRICE1,#SVOL1,#SPRICE2,#SVOL2,#SPRICE3,#SVOL3');
        ResizeScrollGroupColumns('#SYMBOL, #CEILING, #FLOOR, #PRIOR, #TOTAL_VOL, #HIGHEST, #LOWEST,#OPEN_PRICE, #ROOM');
    
    if(dest.length != 0)
    {
        for(var i = 0; i < dest.length; i++)
        {
            dest.eq(i).width(sour.eq(i).width());
        }
    }
}

function ScrollDown()
{
    var height_scroll = $('#scrollStock > table').height() - $('#scrollStock').height();

    if(height_scroll > 0)
    {
        $('#scrollStock').animate({'scrollTop': "+=" + height_scroll}, height_scroll * TIME_PER_PIXEL, 'linear',
            function ()
            {
                MoveBlock();
                ScrollDown();
            });
    }
}

function MoveBlock()
{
    var children = liveStockBody.children('tr');
    var scrollStock = $('#scrollStock');
    var scrollTable = $('#scrollStock > table');
    var max_position = scrollStock.position().top;
    var i = 0;
    while( i < children.length)
    {
        if(children.eq(i).position().top + children.eq(i).height() > max_position)
            break;
        i++;
    }

    var moveto = children.eq(i);
    var distance = max_position - children.eq(i).position().top;

    children.slice(0, i).appendTo(liveStockBody);
    scrollStock.scrollTop(moveto.position().top - scrollTable.position().top + distance);
}

function ScrollToDown()
{
    var height_scroll = $('#scrollStock > table').height() - $('#scrollStock').height();

    $('#scrollStock').scrollTop(0);
    $('#scrollStock').animate({'scrollTop': height_scroll}, height_scroll * TIME_PER_PIXEL, 'linear',
        function ()
        {
            $('#scrollStock').dequeue().stop();
            scrollTimer = setTimeout(ScrollToUp, 30 * TIME_PER_PIXEL);
        });
}

function ScrollToUp()
{
    var height_scroll = $('#scrollStock > table').height() - $('#scrollStock').height();    
    $('#scrollStock').scrollTop(height_scroll);
    $('#scrollStock').animate({'scrollTop': 0}, height_scroll * TIME_PER_PIXEL, 'linear',
        function ()
        {
            $('#scrollStock').dequeue().stop();
            scrollTimer = setTimeout(ScrollToDown, 30 * TIME_PER_PIXEL);
        });
}

//function PageScroll()
//{
//    ResizeScroll();
//    scrollTimer = setTimeout(ScrollPageDown, 30 * TIME_PER_PIXEL);
//}

//function ScrollPageDown()
//{
//    var children = liveStockBody.children('tr');
//    var max_position = $('#scrollStock').position().top + $('#scrollStock').height();

//    var i = 0;
//    while( i < children.length)
//    {
//        if(children.eq(i).position().top + children.eq(i).height() > max_position)
//            break;
//        i++;
//    }
//    
//    if(i == children.length)
//        $('#scrollStock').animate({'scrollTop': 0}, 500, 'linear',
//            function ()
//            {
//                $('#scrollStock').dequeue().stop();
//                scrollTimer = setTimeout(ScrollPageDown, TIME_PER_PAGE);
//            });
//    else
//        $('#scrollStock').animate({'scrollTop': "+=" + (children.eq(i).position().top - $('#scrollStock').position().top)}, 500, 'linear',
//            function ()
//            {
//                $('#scrollStock').dequeue().stop();
//                scrollTimer = setTimeout(ScrollPageDown, TIME_PER_PAGE);
//            });
//}

function PageScroll()
{
    //ResizeScroll();
    page_position = 0;
    ScrollPageDown();
}

function ScrollPageDown()
{
    var scroll_stock = liveStockBody.children('tr');
    var length = scroll_stock.hide().length;
    var from = page_position;
    var to = (page_position + PAGE_SIZE) % length;
    
    if(to > from)
    {
        scroll_stock.slice(from, to).show();
        page_position = (page_position + PAGE_SIZE) % length;
    }
    else
    {
        scroll_stock.slice(from, length - 1).show();
        page_position = 0;
    }

    scrollTimer = setTimeout(ScrollPageDown, TIME_PER_PAGE);
}

function stock_over(event)
{
    $(this).children().css('backgroundColor','#FFFF55');
}

function stock_out(event)
{
    $(this).children().css('backgroundColor', '');
}

function stock_click(event)
{
    if(event.altKey)
    {
        mi_remove_stock($(this).attr('id'));
        return;
    }

    if(!event.ctrlKey)
    {
        stock_move($(this).attr('id'));
        return;
    }

    ShowChart($(this).attr('id'));
    return;
}

function stock_move(itemValue)
{
    var move_to;
    var item = $('#' + itemValue);
    var symbol = itemValue.slice(3) + ',';
    if(item.parent('.noselect').length == 1)
    {
        topStocks += symbol;
        isUploaded = false;
        move_to = liveStockSelected;
    }
    else
    {
        topStocks = topStocks.replace(symbol, '');
        isUploaded = false;
        move_to = liveStockBody;
    }

    var noselect = move_to.children('tr');

    for(var i = 0; i < noselect.length; i++)
    {
        if(noselect.eq(i).attr('id') > itemValue)
        {
            break;
        }
    }

    if(i == 0)
        item.prependTo(move_to);
    else if(i == noselect.length)
        item.appendTo(move_to);
    else
        item.insertBefore(noselect.eq(i));

    item.children().css('backgroundColor','');

    HideChart();
    
    setTimeout(AlternateStocks, 5);
}

function abc_filter(start, selected)
{
    $('#abc-filter > li.selected').removeClass();
    $(selected).parent().addClass('selected');

    if(start == 'ALL') $("ul.symbols > li").show();
    else if(start == 'CCQ')
    {
        $("ul.symbols > li").hide();
        $("ul.symbols > li[stype='U']").show();
    }
    else
    {
        $("ul.symbols > li").hide();
        $("ul.symbols > li:has(a[innerHTML^='" + start + "'])").show();
    }
}

function invert_symbol(link)
{
    var input = $(link).parent().children('input');
    input.attr('checked', !input.attr('checked')).change();
}

function branch_filter(branch, selected)
{
    $('#branch-filter > li.selected').removeClass();
    $(selected).parent().addClass('selected');

    if(branch == 'ALL')
        $("ul.symbols > li").show();
    else
    {
        $("ul.symbols > li").hide();
        $(branchSymbols[branch]).show();
    }
}

function ShowHeader()
{
    if($(window).scrollTop() > liveStockHeader.offset().top)
        $('#fixLiveStock').show();
    else
        $('#fixLiveStock').hide();
}

function CalcFixHead()
{
    fixLiveStock.html(liveStockHeader.html());

    $('#fixLiveStock > table').width($('#liveStock > table').width() + ($.browser.msie ? 4 : 0));
    
    var sour = liveStockHeader.find('tr > th');
    var dest = fixLiveStock.find('tr > th');
    
    for(var i = 0; i < sour.length ; i++)
    {
        dest.eq(i).width(sour.eq(i).width()+1);
    }
}

function ScreenMode(mode)
{
    $('div#body').css('width', mode);
    CalcFixHead();
    ResizeScrollColumns(); 
}

function CollapseMenu()
{
    $('div#header > table > tbody > tr > td.selected').removeClass();
    $('div#header > div#view_panel > div').hide();
}

function MoveSymbols(source, dest)
{
    $('div#header > div#view_panel div#' + source + ' > table > tbody > tr#symbol_list').prependTo('div#header > div#view_panel div#' + dest + ' > table > tbody');
    $('div#header > div#view_panel div#' + source + ' > table > tbody > tr#select_option').prependTo('div#header > div#view_panel div#' + dest + ' > table > tbody');    
}

function ShowMenu(item, menu)
{
    CollapseMenu();

    if(menu == 'select_abc')
        MoveSymbols('select_branch', menu);

    if(menu == 'select_branch')
        MoveSymbols('select_abc', menu);

    $(item).parent().addClass('selected');    
    $('div#header > div#view_panel > div#' + menu).show();
}

function SwitchPutAd(item)
{
    if($('div#putad:visible').length == 0)
    {
        $('div#putad').show();
        $(item).html("[-] Giao dịch thỏa thuận");
    }
    else
    {
        $('div#putad').hide();
        $(item).html("[+] Giao dịch thỏa thuận");
    }
}

function hideMarketChart() {
    $('#marketChartBounce').hide();
    $('#marketChart').empty();
}

function showMarketChart(market) {
    $('#marketChartBounce').show();
    setTimeout(function() {
    flashembed("marketChart", {
            src: "../Flex/IndexVol.swf",
            width: "525px",
            height: "250px",
            wmode: "transparent"
        }, {
            ClientID: ClientID,
            Market: market,
            StartTime: MARKET_NAME == 'UC' ? 100000 : 83000,
            EndTime: MARKET_NAME == 'UC' ? 150000 : 110000
        });
    }, 5)
}

$(document).ready(OnLoad);
