﻿var requestTimerID = null //Timer lấy dữ liệu từ server
var updatedCells = new Array(); //Danh sách các cell được update
var updatedData = new Array(); //Danh sách dữ liệu được update
var updatedOldBackColor = new Array(); //Danh sách màu nền cũ

var marketTimerID = null; //Timer update chỉ số thị trường
var updateTimerID = null; //Danh sách các timer của mỗi lần update phụ   
var marketUpdateDataTimerID = null;
var updateDataTimerID = null;

var basicRequestTimerID = null //Timer lấy dữ liệu cơ bản từ server
var checkResponseTimerID = null //Timer kiểm tra xem có dữ liệu trả về từ server ko
var setClientInfoTimerID = null; //Timer để gửi dữ liệu clientInfo cho máy chủ
var putThroughTimerID = null;
var scrollTimerID = null;
var waitingTimerID = null;


var dataResult = null; //Dữ liệu trả về từ server
var marketUpdatingData = null;

var basicObject = null;
var stockInfoObject = null;
var isResponded = true;
var isTradingTime = true; //Nếu đang trong giờ giao dịch

var currentVersionId = 0; //Version hiện tại của bảng giá
var currentMarketVersionId = 0;
var currentBasicVersionId = 0; //Version hiện tại của bảng tham chiếu
var isUpdatingBasicData = false; //Đang cập nhật dữ liệu tham chiếu

var currentHoseVersionId = 0;  //Dùng cho bảng mixed
var currentHastcVersionId = 0;  //Dùng cho bảng mixed
var currentOtcVersionId = 0;  //Dùng cho bảng mixed

var currentBasicHoseVersionId = 0;   //Dùng cho bảng mixed
var currentBasicHastcVersionId = 0;   //Dùng cho bảng mixed
var currentBasicOtcVersionId = 0;   //Dùng cho bảng mixed

var selectedCount = 0;
var headerRowCount = 2;



var isSymbolsForDisplayLoaded = false;
var displayedSymbolList = new Array();//Danh sách các mã CK muốn hiển thị
var selectedSymbolList = new Array();//Danh sách các mã CK được chọn
var unselectedSymbolList = new Array();//Danh sách các mã CK ko được chọn
var displayedSymbolsString = "";
var clientId = -1;

var displayedSymbolsSelectedList = new Array();//Danh sách các mã CK muốn hiển thị đang được chọn
var displayedSymbolsSelectedString = "";
var oldDisplayedSymbolsString = "";

var showSelectedSymbolsOnTop = true;
var isOptionDisplayed = false;
var isPutThroughDisplayed = false;


var isShowBuyVolume = false;
var isShowSellVolume = false;
var isShowBuyOrderCount = false;
var isShowSellOrderCount = false;
var isShowForeignBuy = false;
var isShowForeignSell = false;
var isShowCurrentRoom = false;
var isShowSession1Price = false;
var isShowSession1Volume = false;
var isShowSession2Price = false;
var isShowSession2Volume = false;
var isShowAveragePrice = false;

var extraColumnString = "000010000000";

var columnCount = 24;

var screenWidth = "1000"; //Lưu kích thước màn hình

var tdTime;
var tdIndex;
var tdChange;
var tdGainersLosers;
var tdTotalValue;
var tdTotalMarketVolume;
var tdMarketStatus;
var currentHighlightSymbol = null;
var tdSession1;
var tdSession2;
var tdSession3;
var tdSession1Trading;
var tdSession2Trading;
var tdSession3Trading;
var tdConnectedClientCount;
var tablePutThrough = null;
var tablePutThroughBuy = null;
var tablePutThroughSell = null;

var floatingHeader;
var fixedHeader;
var divScroll;

var tdIndex1;
var tdIndex2;
var tdIndex3;
var tdIndex1Trading;
var tdIndex2Trading;
var tdIndex3Trading;

var advancesCount = 0;
var noChangeCount = 0;
var declinesCount = 0;

var localizeVN = new LocalizeInfo();
var localizeEN = new LocalizeInfo();
var currentLanguage = "";

var oldSelectedSymbolList; //Dùng cho hàm CreateBasicRows
var oldUnselectedSymbolList; //Dùng cho hàm CreateBasicRows
var currentUpdatedBasicIndex = 0; //Dòng CK đã được tạo bảng tham chiếu
var currentUpdatedIndex = 0; //Dòng CK đã cập nhật
var orderedSymbolList = new Array();

var isCreatingBasicRows = false; //Kiểm tra có phải đang tạo bảng tham chiếu ko
var isFinishUpdatingImmediately = false; //Có đang cập nhật dữ liệu ngay lập tức ko

var isFloatingHeaderShow = false;
var isReadyToResize = true;
var isScroll = true;
var tableType = 0;
var fontStyle = 1;
var lineCount = 20;
var waitingTime = 10000;
var scrollInterval = 30;
var scrollDistance = 1;
//var replacementInterval = 4000;

var deltaHours = 0;
var deltaMinutes = 0;
var deltaSeconds = 0;

var floorType = "";
var cookiePrefix = "";
var boardName = "Board1";
var currentRowIndex = -1;

var latestTime = new Date();
var typedString = "";
var highlightRow = null;

var quotesHistory = null;
var currentGraphSymbol = "";


function BasicItemInfo()
{
    this.CeilingPrice = "";
    this.FloorPrice = "";
    this.ReferencePrice = "";
    this.CurrentPrice = "";
}

function CellInfo()
{
    this.symbol = "";
    this.checkbox = null;
    this.cell = null;
    this.data = 0;
    this.oldBackColor = backColor1;
    this.oldBackColorSelected = backColor1Selected;
    this.className = "";
}

function LocalizeInfo()
{

}

function KeyPress(e)
{
    if (isOptionDisplayed == true || isPutThroughDisplayed == true)
        return;
    if(window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    
    if (keynum == 13)
    {
        typedString = "";
        return;
    }
    var keychar = String.fromCharCode(keynum);
    
    var delayTime = new Date() - latestTime;
    latestTime = new Date();
    if (delayTime <= keypressDelayTime)
        typedString = typedString + keychar;
    else
        typedString = keychar;
    
    var theTable = document.getElementById("tableQuote"); 
    var row;
       
    for (var i=0; i<theTable.rows.length;i++)
    {
        row = theTable.rows[i];
        if (row.id.substring(2).indexOf(typedString) == 0)
        {
            if (highlightRow != null)
            {
                UnHighlight(highlightRow);
                highlightRow = null;   
            }
            
            Highlight(row);
            highlightRow = row;
            var theTable = document.getElementById("tableQuote");
            window.scrollTo(0, row.offsetTop);
            break;
        }
    }
}

function Initialize()
{
    switch (floorType)
    {
        case "HOSE":
            localizeVN.ShowSession1Price = "Hiển thị Giá phiên 1";
            localizeVN.ShowSession1Volume = "Hiển thị Khối lượng phiên 1";
            localizeVN.ShowSession2Price = "Hiển thị Giá phiên 2";
            localizeVN.ShowSession2Volume = "Hiển thị Khối lượng phiên 2";
            localizeVN.ShowForeignBuy = "Hiển thị Nhà đầu tư nước ngoài mua";
            localizeVN.ShowAveragePrice = "Hiển thị Giá trung bình";
            
            localizeVN.exchangeName = "SỞ GIAO DỊCH CHỨNG KHOÁN HỒ CHÍ MINH";
            localizeVN.session = "Đợt";
            localizeVN.sessionValue = "GTGD: ";
            
            localizeVN.ConnectedCount = "Số kết nối HOSE:";
            
            localizeVN.Session1Price = "Giá ph.1";
            localizeVN.Session1Volume = "KL ph.1";
            localizeVN.Session2Price = "Giá ph.2";
            localizeVN.Session2Volume = "KL ph.2";
            localizeVN.ForeignBuy = "NN mua";

            localizeEN.ShowSession1Price = "Show Session 1 Price";
            localizeEN.ShowSession1Volume = "Show Session 1 Volume";
            localizeEN.ShowSession2Price = "Show Session 2 Price";
            localizeEN.ShowSession2Volume = "Show Session 2 Volume";
            localizeEN.ShowForeignBuy = "Show Foreign buy volume";
            localizeEN.ShowAveragePrice = "Show Average price";
            
            localizeEN.exchangeName = "HO CHI MINH STOCK EXCHANGE";
            localizeEN.session = "Ses";
            localizeEN.sessionValue = "Total value: ";
            
            localizeEN.ConnectedCount = "HOSE connection count:";
            
            localizeEN.Session1Price = "Ses.1 Price";
            localizeEN.Session1Volume = "Ses.1 Vol";
            localizeEN.Session2Price = "Ses.2 Price";
            localizeEN.Session2Volume = "Ses.2 Vol";
            localizeEN.ForeignBuy = "Frn buy";

            
            tdSession1 = document.getElementById("tdSession1");
            tdSession2 = document.getElementById("tdSession2");
            tdSession3 = document.getElementById("tdSession3");
            tdSession1Trading = document.getElementById("tdSession1Trading");
            tdSession2Trading = document.getElementById("tdSession2Trading");
            tdSession3Trading = document.getElementById("tdSession3Trading");
            
           
            break;
            
        case "HASTC":
            localizeVN.exchangeName = "SỞ GIAO DỊCH CHỨNG KHOÁN HÀ NỘI";
            
            localizeVN.ConnectedCount = "Số kết nối HNX:";
            
            localizeEN.ConnectedCount = "HNX connection count:";
            localizeEN.exchangeName = "HA NOI STOCK EXCHANGE";
            break;
            
        case "OTC":
            localizeVN.exchangeName = "SÀN GIAO DỊCH CHỨNG KHOÁN UPCOM";
            
            localizeVN.ConnectedCount = "Số kết nối Upcom:";
            
            localizeEN.ConnectedCount = "Upcom connection count:";
            localizeEN.exchangeName = "UPCOM STOCK TRADING CENTER";    
            
            
            break;
        case "MIXED":
            localizeVN.exchangeName = "BẢNG GIÁ TỔNG HỢP";
            
            localizeVN.ConnectedCount = "Số kết nối Mixed:";
            localizeVN.sessionValue = "GTGD: ";
            
            localizeEN.ConnectedCount = "Mixed connection count:";
            localizeEN.exchangeName = "MIXED STOCK QUOTES";
            
            localizeEN.sessionValue = "Total value: ";
            
            tdIndex1 = document.getElementById("tdIndex1");
            tdIndex2 = document.getElementById("tdIndex2");
            tdIndex3 = document.getElementById("tdIndex3");
            tdIndex1Trading = document.getElementById("tdIndex1Trading");
            tdIndex2Trading = document.getElementById("tdIndex2Trading");
            tdIndex3Trading = document.getElementById("tdIndex3Trading");
            
            break;
    }
    
    if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
    {
        if (floorType == "MIXED")
        {
            localizeEN.Session1Price = "Ses.1 Price";
            localizeEN.Session1Volume = "Ses.1 Vol";
            localizeEN.Session2Price = "Ses.2 Price";
            localizeEN.Session2Volume = "Ses.2 Vol";
            
            localizeEN.ShowSession1Price = "Show Session 1 Price";
            localizeEN.ShowSession1Volume = "Show Session 1 Volume";
            localizeEN.ShowSession2Price = "Show Session 2 Price";
            localizeEN.ShowSession2Volume = "Show Session 2 Volume";
            
            localizeVN.ShowSession1Price = "Hiển thị Giá phiên 1";
            localizeVN.ShowSession1Volume = "Hiển thị Khối lượng phiên 1";
            localizeVN.ShowSession2Price = "Hiển thị Giá phiên 2";
            localizeVN.ShowSession2Volume = "Hiển thị Khối lượng phiên 2";
            
            localizeVN.Session1Price = "Giá ph.1";
            localizeVN.Session1Volume = "KL ph.1";
            localizeVN.Session2Price = "Giá ph.2";
            localizeVN.Session2Volume = "KL ph.2";
        
        }
        localizeVN.ShowBuyVolume = "Hiển thị Khối lượng mua";
        localizeVN.ShowSellVolume = "Hiển thị Khối lượng bán";
        localizeVN.ShowBuyOrderCount = "Hiển thị Số lệnh mua";
        localizeVN.ShowSellOrderCount = "Hiển thị Số lệnh bán";
        localizeVN.ShowForeignBuy = "Hiển thị Nhà đầu tư nước ngoài mua";
        localizeVN.ShowForeignSell = "Hiển thị Nhà đầu tư nước ngoài bán";
        
        localizeVN.BuyVolume = "KL mua";
        localizeVN.SellVolume = "KL bán";
        localizeVN.BuyOrderCount = "SL mua";
        localizeVN.SellOrderCount = "SL bán";
        localizeVN.ForeignBuy = "NN mua";
        localizeVN.ForeignSell = "NN bán";
        
        localizeEN.ShowBuyVolume = "Show Buy volume";
        localizeEN.ShowSellVolume = "Show Sell volume";
        localizeEN.ShowBuyOrderCount = "Show Buy order count";
        localizeEN.ShowSellOrderCount = "Show Sell order count";
        localizeEN.ShowForeignBuy = "Show Foreign buy volume";
        localizeEN.ShowForeignSell = "Show Foreign sell volume";
        
        localizeEN.BuyVolume = "Buy vol";
        localizeEN.SellVolume = "Sell vol";
        localizeEN.BuyOrderCount = "Buy count";
        localizeEN.SellOrderCount = "Sell count";
        localizeEN.ForeignBuy = "Frn buy";
        localizeEN.ForeignSell = "Frn sell";
    }
    
    tablePutThroughBuy = document.getElementById("tablePutThroughBuy");
    tablePutThroughSell = document.getElementById("tablePutThroughSell");
    
    localizeVN.date = "Ngày GD:";
    localizeVN.time = "Giờ máy chủ:";
    localizeVN.change = "Thay đổi:";
    localizeVN.gainersLosers = "Số CK tăng/giảm:";
    localizeVN.totalMarketVolume = "Tổng KLượng / KL TThuận:";
    localizeVN.totalValue = "Tổng giá trị:";
    localizeVN.marketStatus = "TTTT:";
    localizeVN.currencyUnit = "tỷ";

    localizeVN.symbol = "CK";
    localizeVN.ceiling = "Trần";
    localizeVN.floor = "Sàn";
    localizeVN.basic = "TC";
    localizeVN.bid = "Dư mua";
    localizeVN.ask = "Dư bán";
    localizeVN.open = "Mở cửa";
    localizeVN.high = "Cao";
    localizeVN.low = "Thấp";
    localizeVN.average = "TB";
    localizeVN.foreignBuy = "NN mua";
    localizeVN.totalVolume = "Tổng KL";
    localizeVN.price = "Giá";
    localizeVN.volume = "KL";
    localizeVN.matching = "Khớp lệnh";
    localizeVN.selectAll = "Chọn tất cả";
    localizeVN.clearAll = "Xóa tất cả";
    localizeVN.displayAll = "Hiển thị tất cả CK";
    localizeVN.selectedSymbolsOnTop = "Hiển thị những mã CK được đánh dấu lên đầu";
    
    localizeVN.ScreenWidth = "Chọn kích thước màn hình:   ";
    
    localizeVN.PriceDescription = "Giá: 1000 đồng";
//    if (floorType == "OTC")
//        localizeVN.VolumeDescription = "Khối lượng: 1 cổ phiếu";
//    else
        localizeVN.VolumeDescription = "Khối lượng: 10 cổ phiếu";
    localizeVN.HitCount = "Số lượt truy cập:";
    
    localizeVN.PutThroughMatching = "Giao dịch thỏa thuận - Khớp lệnh";
    localizeVN.PutThroughBuy = "Giao dịch thỏa thuận - Chào mua";
    localizeVN.PutThroughSell = "Giao dịch thỏa thuận - Chào bán";
    localizeVN.PutThroughPrice = "Giá";
    localizeVN.PutThroughValue = "Giá trị giao dịch (triệu đồng)";
    localizeVN.PutThroughVolume = "Khối lượng";
    localizeVN.PutThroughSymbol = "Chứng khoán";
    localizeVN.PutThroughTime = "Thời gian";
    localizeVN.HistoryTime = "Thời gian";
    localizeVN.HistoryChange = "Thay đổi";
    localizeVN.HistoryChangePercent = "% thay đổi";
    localizeVN.HistoryPrice = "Giá";
    localizeVN.HistoryVolume = "Khối lượng";
    localizeVN.HistoryTotalVolume = "Tổng khối lượng";
    localizeVN.GraphTitle = "Đồ thị giá và lịch sử giá khớp lệnh trong phiên";
    
    localizeVN.PutThroughUnit = "Đơn vị giao dịch thỏa thuận: Giá: 1000 đồng - Khối lượng: 1 cổ phiếu";
    
    localizeVN.TableType = "Kiểu bảng";
    localizeVN.Normal = "Bảng bình thường";
    localizeVN.ScrollInfinite = "Bảng tự động cuộn vô tận";
    localizeVN.Scroll2Directions = "Bảng tự động cuộn 2 chiều";
    localizeVN.PageReplacement = "Bảng lật trang";
    localizeVN.LineCount = "Số dòng hiển thị (Đối với bảng cuộn) ";
    localizeVN.ScrollInterval = "Độ trễ cuộn (mili giây - Đối với bảng cuộn) ";
    localizeVN.WaitingTime = "Thời gian chờ (mili giây - Đối với bảng cuộn 2 chiều và lật trang) ";
    
    localizeVN.CurrentRoom = "Room";
    localizeVN.ShowCurrentRoom = "Hiển thị room nước ngoài còn lại";
    
    localizeVN.FontStyle = "Kiểu chữ";
    localizeVN.FontNormal = "Font chữ bình thường";
    localizeVN.FontBoldHalf = "Font chữ đậm cho các cột chính";
    localizeVN.FontBoldAll = "Font chữ đậm cho tất cả";
    
    localizeVN.ShowVolumeColor = "Hiển thị màu sắc khối lượng theo màu giá CK";
    localizeVN.ShowGraph = "Hiển thị đồ thị giá trong phiên";
    localizeVN.ShowSymbol2 = "Hiển thị mã chứng khoán trong cột khớp lệnh";
    localizeVN.OrderSelectedSymbols = "Hiển thị mã chứng khoán được chọn theo thứ tự ABC";
    
    
    localizeVN.BoardName = "Chọn bảng hiển thị:";
    localizeVN.GraphLinkTitle = "Click để xem đồ thị và lịch sử giá trong phiên";
    localizeVN.GraphIndexLinkTitle = "Click để xem đồ thị và lịch sử chỉ số trong phiên";
   
    localizeEN.date = "Date:";
    localizeEN.time = "Server time:";
    localizeEN.change = "Change:";
    localizeEN.gainersLosers = "Gainers/Losers:";
    localizeEN.totalMarketVolume = "Total vol / PThrough vol:";
    localizeEN.totalValue = "Total value:";
    localizeEN.marketStatus = "Market status:";
    localizeEN.currencyUnit = "bil";
    
    localizeEN.symbol = "Symbol";
    localizeEN.ceiling = "Ceil";
    localizeEN.floor = "Floor";
    localizeEN.basic = "Basic";
    localizeEN.bid = "Bid";
    localizeEN.ask = "Ask";
    localizeEN.open = "Open";
    localizeEN.high = "High";
    localizeEN.low = "Low";
    localizeEN.average = "Avg";
    localizeEN.foreignBuy = "Frn buy";
    localizeEN.totalVolume = "Total vol";
    localizeEN.price = "Prc";
    localizeEN.volume = "Vol";
    localizeEN.matching = "Matching";
    localizeEN.selectAll = "Select all";
    localizeEN.clearAll = "Clear all";
    localizeEN.displayAll = "Display all symbols";
    localizeEN.selectedSymbolsOnTop = "Show below marked symbols on top";
    
    localizeEN.ScreenWidth = "Select screen width:   ";
    
    localizeEN.PriceDescription = "Price unit: 1000 VND";
    
//    if (floorType == "OTC")
//        localizeEN.VolumeDescription = "Volume unit: 1 shares";
//    else
        localizeEN.VolumeDescription = "Volume unit: 10 shares";
    localizeEN.HitCount = "Hit count:";
    
    localizeEN.PutThroughMatching = "Put through - Matching";
    localizeEN.PutThroughBuy = "Put through - Buy advertisement";
    localizeEN.PutThroughSell = "Put through - Sell advertisement";
    localizeEN.PutThroughPrice = "Price";
    localizeEN.PutThroughValue = "Value (mil VND)";
    localizeEN.PutThroughVolume = "Volume";
    localizeEN.PutThroughSymbol = "Symbol";
    localizeEN.PutThroughTime = "Time";
    
    localizeEN.HistoryTime = "Time";
    localizeEN.HistoryChange = "Change";
    localizeEN.HistoryChangePercent = "Change percent";
    localizeEN.HistoryPrice = "Price";
    localizeEN.HistoryVolume = "Volume";
    localizeEN.HistoryTotalVolume = "Total volume";
    localizeEN.GraphTitle = "Matching result graph and history";
    
    localizeEN.PutThroughUnit = "Put through unit: Price unit: 1000 VND - Volume unit: 1 share";
    
    localizeEN.TableType = "Table type:";
    localizeEN.Normal = "Normal";
    localizeEN.ScrollInfinite = "Infinite scroll table";
    localizeEN.Scroll2Directions = "2 directions scroll table";
    localizeEN.PageReplacement = "Page replacement table";
    localizeEN.LineCount = "Line count (for scroll table) ";
    localizeEN.ScrollInterval = "Scroll interval (mili seconds - for scroll table) ";
    localizeEN.WaitingTime = "Waiting time (mili seconds - for 2 directions scroll and page replacement table) ";
    
    localizeEN.CurrentRoom = "Room";
    localizeEN.ShowCurrentRoom = "Show current room";
    
    localizeEN.FontStyle = "Font style:";
    localizeEN.FontNormal = "Normal font";
    localizeEN.FontBoldHalf = "Bold font for main columns";
    localizeEN.FontBoldAll = "Bold font for all board";
    
    localizeEN.ShowVolumeColor = "Display volume color like price color";
    localizeEN.ShowGraph = "Display graph";
    localizeEN.ShowSymbol2 = "Show symbol in matching column";
    localizeEN.OrderSelectedSymbols = "Show selected symbols by alphabet order";
    
    localizeEN.BoardName = "Choose board:";
    localizeEN.GraphLinkTitle = "Click to view matching graph and history";
    localizeEN.GraphIndexLinkTitle = "Click to view Index graph and history";
    
    tdTime = document.getElementById("tdTime");
    tdIndex = document.getElementById("tdIndex");
    tdChange = document.getElementById("tdChange");
    tdGainersLosers = document.getElementById("tdGainersLosers");
    tdTotalValue = document.getElementById("tdTotalValue");
    tdTotalMarketVolume = document.getElementById("tdTotalMarketVolume");
    tdMarketStatus = document.getElementById("tdMarketStatus");
    tablePutThrough = document.getElementById("tablePutThrough");
    divScroll = document.getElementById("divScroll");
    floatingHeader = document.getElementById("floatingHeader");
    

    tdConnectedClientCount = document.getElementById("tdConnectedClientCount");
    
    ConfigLocalize();
}

// This function intializes the global variables and
// assigns default values to the generated proxy.
function LoadHose()
{
    floorType = "HOSE";
    cookiePrefix = "Hose";
    
    AlphaStockBoard.UI.HoseStockQuotes.set_defaultUserContext("Default context");
    AlphaStockBoard.UI.HoseStockQuotes.set_defaultSucceededCallback(GetStockBoardChangedObjectSucceededCallback);
    AlphaStockBoard.UI.HoseStockQuotes.set_defaultFailedCallback(FailedCallback);
    
    Initialize();
    
    LoadCommon();
}

function LoadHastc()
{
    floorType = "HASTC";
    cookiePrefix = "Hastc";
    
    AlphaStockBoard.UI.HastcStockQuotes.set_defaultUserContext("Default context");
    AlphaStockBoard.UI.HastcStockQuotes.set_defaultSucceededCallback(GetStockBoardChangedObjectSucceededCallback);
    AlphaStockBoard.UI.HastcStockQuotes.set_defaultFailedCallback(FailedCallback);
    
    Initialize();
    
    LoadCommon();
}

function LoadOtc()
{
    floorType = "OTC";
    cookiePrefix = "Otc";
    
    AlphaStockBoard.UI.OtcStockQuotes.set_defaultUserContext("Default context");
    AlphaStockBoard.UI.OtcStockQuotes.set_defaultSucceededCallback(GetStockBoardChangedObjectSucceededCallback);
    AlphaStockBoard.UI.OtcStockQuotes.set_defaultFailedCallback(FailedCallback);
    
    Initialize();
    
    LoadCommon();
}

function LoadMixed()
{
    floorType = "MIXED";
    cookiePrefix = "Mixed";
    
    AlphaStockBoard.UI.MixedStockQuotes.set_defaultUserContext("Default context");
    AlphaStockBoard.UI.MixedStockQuotes.set_defaultSucceededCallback(GetStockBoardChangedObjectSucceededCallback);
    AlphaStockBoard.UI.MixedStockQuotes.set_defaultFailedCallback(FailedCallback);
    
    Initialize();
    
    LoadCommon();
    
     var chkDisplayAll = document.getElementById("chkDisplayAll");
    chkDisplayAll.checked = false;
    chkDisplayAll.disabled = true;
}

function LoadCommon() 
{
    GetClientId();
    
    var onTop = readCookie("onTop");
    if (onTop != null)
        if (onTop == "true")
            showSelectedSymbolsOnTop = true;
        else
            showSelectedSymbolsOnTop = false;
    
    if (readCookie("boardName") != null)
        boardName = readCookie("boardName");
        
    LoadBoardCookie();
 
    if (readCookie("selectedSymbolList") != null)
        selectedSymbolList = readCookie("selectedSymbolList").split(",");
  
    if (readCookie("extraColString") != null)
    {
        extraColumnString = readCookie("extraColString");  
    }
    
    if (readCookie("screenWidth") != null)
    {
        screenWidth = readCookie("screenWidth"); 
    }
    
    if (readCookie("tableType") != null)
    {
        tableType = readCookie("tableType");
    }
    
    if (readCookie("fontStyle") != null)
    {
        fontStyle = readCookie("fontStyle");
    }
    
    if (readCookie("lineCount") != null)
    {
        lineCount = parseInt(readCookie("lineCount"));
    }
    
    if (readCookie("scrollInterval") != null)
    {
        scrollInterval = parseInt(readCookie("scrollInterval"));
    }
    
    if (readCookie("waitingTime") != null)
    {
        waitingTime = parseInt(readCookie("waitingTime"));
    }
    
    if (readCookie("isShowVolumeColor") != null)
    {
        isShowVolumeColor = (readCookie("isShowVolumeColor") == "true");
    }
    
    if (readGeneralCookie("isShowGraph") != null)
    {
        isShowGraph = (readGeneralCookie("isShowGraph") == "true");
    }
    
    if (readGeneralCookie("isShowSymbol2") != null)
    {
        isShowSymbol2 = (readGeneralCookie("isShowSymbol2") == "true");
    }
    
    if (readGeneralCookie("isOrderSelectedSymbols") != null)
    {
        isOrderSelectedSymbols = (readGeneralCookie("isOrderSelectedSymbols") == "true");
    }
    
    SetTableWidth();
    
    var language = readCookie("lan");
    if (language == null)
        setLanguage("vi-VN");
    else
        setLanguage(language);
        
    if (floorType == "HASTC" || floorType == "OTC")// || floorType == "MIXED")
    {
        isShowBuyVolume = extraColumnString.charAt(0)=='1'?true:false;
        isShowSellVolume = extraColumnString.charAt(1)=='1'?true:false;
        isShowBuyOrderCount = extraColumnString.charAt(2)=='1'?true:false;
        isShowSellOrderCount = extraColumnString.charAt(3)=='1'?true:false;
        isShowForeignBuy = extraColumnString.charAt(4)=='1'?true:false;
        isShowForeignSell = extraColumnString.charAt(5)=='1'?true:false;
        isShowCurrentRoom = extraColumnString.charAt(6)=='1'?true:false;
    }
    else if (floorType == "HOSE")
    {   
        isShowSession1Price = extraColumnString.charAt(0)=='1'?true:false;
        isShowSession1Volume = extraColumnString.charAt(1)=='1'?true:false;
        isShowSession2Price = extraColumnString.charAt(2)=='1'?true:false;
        isShowSession2Volume = extraColumnString.charAt(3)=='1'?true:false;
        isShowForeignBuy = extraColumnString.charAt(4)=='1'?true:false;
        isShowCurrentRoom = extraColumnString.charAt(5)=='1'?true:false;
        isShowAveragePrice = extraColumnString.charAt(6)=='1'?true:false;
    }   
    else if (floorType == "MIXED")
    {
        isShowSession1Price = extraColumnString.charAt(0)=='1'?true:false;
        isShowSession1Volume = extraColumnString.charAt(1)=='1'?true:false;
        isShowSession2Price = extraColumnString.charAt(2)=='1'?true:false;
        isShowSession2Volume = extraColumnString.charAt(3)=='1'?true:false;
        
        isShowBuyVolume = extraColumnString.charAt(4)=='1'?true:false;
        isShowSellVolume = extraColumnString.charAt(5)=='1'?true:false;
        isShowBuyOrderCount = extraColumnString.charAt(6)=='1'?true:false;
        isShowSellOrderCount = extraColumnString.charAt(7)=='1'?true:false;
        isShowForeignBuy = extraColumnString.charAt(8)=='1'?true:false;
        isShowForeignSell = extraColumnString.charAt(9)=='1'?true:false;
        isShowCurrentRoom = extraColumnString.charAt(10)=='1'?true:false;
        
    }
    isReadyToResize = false;    
    CreateExtraHeaderCells("tableQuote");
    CreateExtraHeaderCells("tableFloatingHeader");
    CreateExtraHeaderCells("tableFixedHeader");
    isReadyToResize = true;
    
    
    SetScroll();
    
    //Đặt thời gian lấy dữ liệu mã CK, tham chiếu, trần, sàn từ server
    basicRequestTimerID = self.setInterval("GetBasicObject()", 1*60*1000) //1 phút
    
    //Kiểm tra dữ liệu có được lấy về từ server ko (kiểm tra đường truyền)
    //Nếu trong thời gian giao dịch thì đặt 15s
    if (isTradingTime == true)
    {
        checkResponseTimerID = self.setInterval("CheckResponse()", 15000)
    }
    //Nếu ngoài thời gian giao dịch thì đặt 15 phút
    else
    {
        checkResponseTimerID = self.setInterval("CheckResponse()", 15*60*1000)
    }
    
    ResizeHeader();
    
    self.setInterval("ResizeHeader()", 1000);
    
    SetTime();
    self.setInterval("SetTime()", 1000);
    
    
    
    //Với IE6 đặt định kỳ cho header vì ko có sự kiện OnScroll
    if (Sys.Browser.name == "Microsoft Internet Explorer" && Sys.Browser.version <= 6)
    {
        floatingHeader.style.position = "absolute";
        self.setInterval("ShowFloatingHeaderIE6()", 300);
    }
    
    //Đặt thời gian gửi dữ liệu ClientInfo cho server
    setClientInfoTimerID = self.setInterval("SetClientInfo()", 2*60*60*1000) //2 tiếng
}

function LoadBoardCookie()
{
    if (floorType == "MIXED")
    {
        if (readCookie("displayedSymbolsString" + boardName) != null)
        {
            displayedSymbolsString = readCookie("displayedSymbolsString" + boardName);
            if (displayedSymbolsString != "all")
                displayedSymbolList = displayedSymbolsString.split(",");
            else
            {
                displayedSymbolsString = "'SSI','STB','HAG','DPM','CTG','VIC','VPD','VCB','PVF','BVS','CTS','SHB','VND','SHN','PVX','VCG','KLS','ACB'";
                displayedSymbolList = displayedSymbolsString.split(",");
            }
        }
        else
        {
            displayedSymbolsString = "'SSI','STB','HAG','DPM','CTG','VIC','VPD','VCB','PVF','BVS','CTS','SHB','VND','SHN','PVX','VCG','KLS','ACB'";
            displayedSymbolList = displayedSymbolsString.split(",");
        }
    }
    else
    {
        if (readCookie("displayedSymbolsString" + boardName) != null)
        {
            displayedSymbolsString = readCookie("displayedSymbolsString" + boardName);
            if (displayedSymbolsString != "all")
                displayedSymbolList = displayedSymbolsString.split(",");
        }
        else
            displayedSymbolsString = "all";
    }    
    
    
    if (readCookie("displayedSymbolsSelectedString" + boardName) != null)
    {
        displayedSymbolsSelectedString = readCookie("displayedSymbolsSelectedString" + boardName);
    }
    else
        if (floorType == "MIXED")
            displayedSymbolsSelectedString = "'SSI','STB','HAG','DPM','CTG','VIC','VPD','VCB','PVF','BVS','CTS','SHB','VND','SHN','PVX','VCG','KLS','ACB'";
        else
            displayedSymbolsSelectedString = "";
}

function SetFontStyle()
{
    var fontStyle1;
    var fontStyle2;
    
    if (fontStyle == 0)
    {
        fontStyle1 = "normal";
        fontStyle2 = "normal";
    }
    else if (fontStyle == 1)
        {
            fontStyle1 = "normal";
            fontStyle2 = "bold";
        }
        else
        {
            fontStyle1 = "bold";
            fontStyle2 = "bold";
        }
    
    var theTable = document.getElementById("tableQuote"); 
    var row;   
    for(var i= 2; i<theTable.rows.length; i++ )
    {
        row = theTable.rows[i];
        for (var j=0; j< row.cells.length; j++)
        {
            switch (j)
            {
                case 0:
                case 1:
                case 2:
                case 3:
                case 10:
                case 11:
                case 12:
                case 19:
                case 20:
                    row.cells[j].style.fontWeight = fontStyle2;
                    break;
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:  
                case 13:
                case 14:
                case 15:
                case 16:
                case 17:
                case 18: 
                    row.cells[j].style.fontWeight = fontStyle1;
                    break;  
                case 21:
                    if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
                        row.cells[j].style.fontWeight = fontStyle2;
                    else
                        row.cells[j].style.fontWeight = fontStyle1;
                    break;
                default:
                    row.cells[j].style.fontWeight = fontStyle1;
            }
        }
    }
}

function SetLinksVisibility()
{
    var tdExchangeLink = document.getElementById("tdExchangeLink");
    var spanFlags = document.getElementById("spanFlags");        
    if (tableType == 0)
    {
        tdExchangeLink.style.visibility = "visible";
        spanFlags.style.visibility = "visible";
    }
    else
    {
        tdExchangeLink.style.visibility = "hidden";
        spanFlags.style.visibility = "hidden";
    }
}

function SetScroll()
{

    var tableFooter = document.getElementById("tableFooter");
    var tableScrollFooter = document.getElementById("tableScrollFooter");
    var tableFixedHeader = document.getElementById("tableFixedHeader");
    var theTable = document.getElementById("tableQuote");
    
    if (scrollTimerID != null)
    {
        self.clearInterval(scrollTimerID);
        scrollTimerID = null;
    }
    if (waitingTimerID != null)
        self.clearTimeout(waitingTimerID);
    
    SetLinksVisibility();
        
    if (tableType == 0)
    {

        tableFixedHeader.style.display = "none";
        theTable.rows[0].style.display = "";
        theTable.rows[1].style.display = "";
        
        divScroll.style.height = "100%";
        tableFooter.style.display = "block";
        tableScrollFooter.style.display = "none";
        divScroll.scrollTop = 0;
    }
    else if (tableType == 1 || tableType == 2 || tableType == 3)
    {
        tableFixedHeader.style.display = "block";
        theTable.rows[0].style.display = "none";
        theTable.rows[1].style.display = "none";
        
        tableFooter.style.display = "none";
        tableScrollFooter.style.display = "block";
        
      
        divScroll.style.height = lineCount*rowHeightScroll + 2 + "px";
        if (isScroll == true)
        {    
            if (scrollTimerID == null)
                //Nếu là lật trang
                if (tableType == 3)
                    scrollTimerID = self.setInterval("Scroll()", waitingTime); 
                else
                    scrollTimerID = self.setInterval("Scroll()", scrollInterval);   
        }
        else
        {
            if (scrollTimerID != null)
            {
                self.clearInterval(scrollTimerID);
                scrollTimerID = null;
            }    
        }
    }
}
 
function Scroll()
{
    if (tableType == 0)
        return;
    else if (tableType == 1)
        scrollDistance = 1;

    
    var theTable = document.getElementById("tableQuote");
    
    //Cuộn vô tận
    if (tableType == 1)
    {
        if (divScroll.scrollTop >= divScroll.scrollHeight - divScroll.clientHeight)
        {
            
            if (theTable.rows.length - 2 <= lineCount)
                return;
            
            var replacedRow = theTable.rows[2];
            var row;
            for (var i=0; i<lineCount; i++)
            {
                row = theTable.rows[theTable.rows.length - 1];
                replacedRow.parentNode.insertBefore(row, replacedRow);
                replacedRow = row;    
            }
            divScroll.scrollTop = 0;
        }
    }
    //Cuộn 2 chiều
    else if (tableType == 2)
    {
        //Về đầu bảng
        if (divScroll.scrollTop <= 0 && scrollDistance == -1)
        {
            scrollDistance = 1;
            self.clearInterval(scrollTimerID);
            scrollTimerID = null;
            waitingTimerID = self.setTimeout("WaitingScroll()", waitingTime); 
            return;
        }
        //Đến cuối bảng
        else if (divScroll.scrollTop >= divScroll.scrollHeight - divScroll.clientHeight && scrollDistance == 1)
        {
            scrollDistance = -1;
            self.clearInterval(scrollTimerID);
            scrollTimerID = null;
            waitingTimerID = self.setTimeout("WaitingScroll()", waitingTime); 
            return;
        }
    }
    //Lật trang
    else 
    {

    }

    if (tableType == 1 || tableType == 2)
        divScroll.scrollTop += scrollDistance;
    else
    {
        if (currentRowIndex == -1)
        {
            currentRowIndex = 0;
            divScroll.scrollTop = 0;
        }
        else
        {
            currentRowIndex = currentRowIndex + lineCount - 1;
            if (currentRowIndex + 2 > theTable.rows.length - 1)
            {
                currentRowIndex = 0;
                divScroll.scrollTop = 0;
            }
            else
                divScroll.scrollTop = theTable.rows[currentRowIndex + 2].offsetTop - 2;//+ 2 vì có 2 dòng headers

        }
        
        
    }
}
 
 function WaitingScroll()
 {

     waitingTimerID = null;
     
     if (scrollTimerID == null)
        scrollTimerID = self.setInterval("Scroll()", scrollInterval);  
 }
 
 function SetTime()
 {
    var currentDate = new Date();
    
    var hours = currentDate.getHours() + deltaHours;
    var minutes = currentDate.getMinutes() + deltaMinutes;
    var seconds = currentDate.getSeconds() + deltaSeconds;
    
    var currentServerDate = new Date();

    currentServerDate.setHours(hours, minutes, seconds, 0);
    
    hours = currentServerDate.getHours();
    minutes = currentServerDate.getMinutes();
    seconds = currentServerDate.getSeconds();
    
    if (hours < 10)
        hours = "0" + hours;
    if (minutes < 10)
        minutes = "0" + minutes;
    if (seconds < 10)
        seconds = "0" + seconds;
    
    tdTime.innerHTML = hours + ":" + minutes + ":" + seconds;

 }
 
 function SetTableWidth()
 {
    var tableContainer = document.getElementById("tableContainer");
    var tableFloatingHeader = document.getElementById("tableFloatingHeader");
    var tableFixedHeader = document.getElementById("tableFixedHeader");
    var tableScrollFooter = document.getElementById("tableScrollFooter");
    
    if (screenWidth == "Auto")
    {
        tableContainer.width = "";
        tableFloatingHeader.width = "";
        tableFixedHeader.width = "";
        tableScrollFooter.width = "";
        
    }
    else
    {
        tableFixedHeader.width = screenWidth;
        tableContainer.width = screenWidth;
        tableFloatingHeader.width = screenWidth;
        tableScrollFooter.width = screenWidth;
    }
 }
 
 function SelectScreen(width)
 {
    var rbtWidth = document.getElementById("rbt" + width);
    rbtWidth.checked = true;
 }
 
 function SelectBoard(board)
 {
    var rbtBoard = document.getElementById("rbt" + board);
    rbtBoard.checked = true;
    LoadBoardSymbols(board);
 }
 
 function LoadBoardSymbols(board)
 {
    boardName = board;

    //Load cookie của board mới
    LoadBoardCookie();
    
    SetCheckedSymbolsForChoose(false);
  
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    if (displayedSymbolsString == "all" && floorType != "MIXED")
        chkDisplayAll.checked = true;
    else
        chkDisplayAll.checked = false;
    ToggleDisplayAll();

 }
 
 function SelectTableType(tableType)
 {
    var rbtTableType = document.getElementById("rbt" + tableType);
    rbtTableType.checked = true;
 }
 
 function SelectFontStyle(fontStyle)
 {
    var rbtFontStyle = document.getElementById("rbt" + fontStyle);
    rbtFontStyle.checked = true;
 }
 
 
 function ResizeHeader()
{
    if (isReadyToResize == true)
    {
        ResizeTableHeader("tableFloatingHeader");
        if (tableType != 0)
            ResizeTableHeader("tableFixedHeader");
    }
       
}  

function ResizeTableHeader(tableId)
{
    var tblQuote = document.getElementById("tableQuote");
    var theTable = document.getElementById(tableId);
    
    if (tableType == 0)
    {
        if (theTable.tHead.rows[0].cells.length < tblQuote.tHead.rows[0].cells.length)
            return;
            
        for (var i = 0; i < tblQuote.tHead.rows[0].cells.length; i++)
        {
            if (tblQuote.tHead.rows[0].cells[i].offsetWidth != 0)
                theTable.tHead.rows[0].cells[i].width = (tblQuote.tHead.rows[0].cells[i].offsetWidth) + 'px';	
            else
                theTable.tHead.rows[0].cells[i].width = "";	    		            
        }
        for (var i = 0; i < tblQuote.tHead.rows[1].cells.length; i++)
        {
            if (tblQuote.tHead.rows[1].cells[i].offsetWidth != 0)
                theTable.tHead.rows[1].cells[i].width = (tblQuote.tHead.rows[1].cells[i].offsetWidth) + 'px';
            else
                theTable.tHead.rows[1].cells[i].width = "";
        }
    }
    else
    {
        if (tblQuote.rows.length > 2)
	    {
	        if (theTable.tHead.rows[0].cells.length - 12 < tblQuote.rows[2].cells.length - 23)
                return;
            
	        theTable.tHead.rows[0].cells[0].width = (tblQuote.rows[2].cells[0].offsetWidth + 2) + 'px';	
	        //Tham chiếu
            for (var i = 1; i < 4; i++)
            {
                if (tblQuote.rows[2].cells[i].offsetWidth != 0)
                    theTable.tHead.rows[0].cells[i].width = (tblQuote.rows[2].cells[i].offsetWidth) + 'px';	
                else
                    theTable.tHead.rows[0].cells[i].width = "";	    		            
            }
            //Giá
            for (var i = 4; i < 12; i++)
            {
                //width += tblQuote.rows[0].cells[i].offsetWidth;
                if (tblQuote.rows[2].cells[i].offsetWidth != 0)
                    theTable.tHead.rows[1].cells[i-4].width = (tblQuote.rows[2].cells[i].offsetWidth) + 'px';
                else
                    theTable.tHead.rows[1].cells[i-4].width = "";    
            }
            theTable.tHead.rows[0].cells[6].width = (tblQuote.rows[2].cells[12].offsetWidth) + 'px';	
            for (var i = 13; i < 19; i++)
            {
                if (tblQuote.rows[2].cells[i].offsetWidth != 0)
                    theTable.tHead.rows[1].cells[i-5].width = (tblQuote.rows[2].cells[i].offsetWidth) + 'px';
                else
                    theTable.tHead.rows[1].cells[i-5].width = "";
            }
            for (var i = 19; i < tblQuote.rows[3].cells.length; i++)
            {
                if (tblQuote.rows[2].cells[i].offsetWidth != 0)
                    theTable.tHead.rows[0].cells[i-11].width = (tblQuote.rows[2].cells[i].offsetWidth) + 'px';
                else
                    theTable.tHead.rows[0].cells[i-11].width = "";		    		            
            }
        }
    }
    if (tblQuote.offsetWidth > 0)
        theTable.width = tblQuote.offsetWidth + 'px';
}
 
 function setLanguage(lan)
 {
    //Không cho thay đổi ngôn ngữ nếu đang cập nhật dữ liệu
    if (isCreatingBasicRows == true || isUpdatingBasicData == true)
        return;
        
    if (lan == currentLanguage)
        return;
        
    currentLanguage = lan;
    
    var tdExchangeName = document.getElementById("tdExchangeName");
    var tdDateTitle = document.getElementById("tdDateTitle");
    var tdTimeTitle = document.getElementById("tdTimeTitle");
    var tdChangeTitle = document.getElementById("tdChangeTitle");
    var tdGainersLosersTitle = document.getElementById("tdGainersLosersTitle");
    var tdTotalValueTitle = document.getElementById("tdTotalValueTitle");
    var tdTotalMarketVolumeTitle = document.getElementById("tdTotalMarketVolumeTitle");
    var tdMarketStatusTitle = document.getElementById("tdMarketStatusTitle");
    
    var tableSessionsRow;
    var tableIndicesRow;
    
    if (floorType == "HOSE")
        tableSessionsRow = document.getElementById("tableSessions").rows[0];
    else
        if (floorType == "MIXED")
            tableIndicesRow = document.getElementById("tableIndices").rows[0];    
     
    
    var spanOnTop = document.getElementById("spanOnTop");
    var spanSelectAll = document.getElementById("spanSelectAll");
    var spanClearAll = document.getElementById("spanClearAll");
    var spanDisplayAll = document.getElementById("spanDisplayAll");
    //var spanAlphaDevelopment = document.getElementById("spanAlphaDevelopment");
    //var spanTelNo = document.getElementById("spanTelNo");
    
    var spanShowVolumeColor = document.getElementById("spanShowVolumeColor");
    var spanShowGraph = document.getElementById("spanShowGraph");
    var spanShowSymbol2 = document.getElementById("spanShowSymbol2");
    var spanOrderSelectedSymbols = document.getElementById("spanOrderSelectedSymbols");
    
    var spanOption = document.getElementById("spanOption");
    var spanHide = document.getElementById("spanHide");
    var spanOK = document.getElementById("spanOK");
    
    var spanShowBuyVolume;
    var spanShowSellVolume;
    var spanShowBuyOrderCount;
    var spanShowSellOrderCount;
    var spanShowForeignBuy;
    var spanShowForeignSell;
    
    var spanShowSession1Price;
    var spanShowSession1Volume;
    var spanShowSession2Price;
    var spanShowSession2Volume;
    var spanShowAveragePrice;
    
    var spanShowCurrentRoom;
    
    if (floorType == "HASTC" || floorType == "OTC")// || floorType == "MIXED")
    {
        spanShowBuyVolume = document.getElementById("spanShowBuyVolume");
        spanShowSellVolume = document.getElementById("spanShowSellVolume");
        spanShowBuyOrderCount = document.getElementById("spanShowBuyOrderCount");
        spanShowSellOrderCount = document.getElementById("spanShowSellOrderCount");
        spanShowForeignSell = document.getElementById("spanShowForeignSell");
    }
    else if (floorType == "HOSE")
    {
        spanShowSession1Price = document.getElementById("spanShowSession1Price");
        spanShowSession1Volume = document.getElementById("spanShowSession1Volume");
        spanShowSession2Price = document.getElementById("spanShowSession2Price");
        spanShowSession2Volume = document.getElementById("spanShowSession2Volume");
        spanShowAveragePrice = document.getElementById("spanShowAveragePrice");
    }
    else if (floorType == "MIXED")
    {
        spanShowSession1Price = document.getElementById("spanShowSession1Price");
        spanShowSession1Volume = document.getElementById("spanShowSession1Volume");
        spanShowSession2Price = document.getElementById("spanShowSession2Price");
        spanShowSession2Volume = document.getElementById("spanShowSession2Volume");
        
        spanShowBuyVolume = document.getElementById("spanShowBuyVolume");
        spanShowSellVolume = document.getElementById("spanShowSellVolume");
        spanShowBuyOrderCount = document.getElementById("spanShowBuyOrderCount");
        spanShowSellOrderCount = document.getElementById("spanShowSellOrderCount");
        spanShowForeignSell = document.getElementById("spanShowForeignSell");
    }
    
    spanShowForeignBuy = document.getElementById("spanShowForeignBuy");
    spanShowCurrentRoom = document.getElementById("spanShowCurrentRoom");
    
    var spanPriceDescription = document.getElementById("spanPriceDescription");
    var spanVolumeDescription = document.getElementById("spanVolumeDescription");
    var spanScrollPriceDescription = document.getElementById("spanScrollPriceDescription");
    var spanScrollVolumeDescription = document.getElementById("spanScrollVolumeDescription");
    
    var tdConnectedClientCountTitle = document.getElementById("tdConnectedClientCountTitle");
    var tdHitCounterTitle = document.getElementById("tdHitCounterTitle");
 
    var tdScreenWidth = document.getElementById("tdScreenWidth");
    var tdBoardName = document.getElementById("tdBoardName");
    
    var spanHidePutThrough = document.getElementById("spanHidePutThrough");
    var spanPutThroughDescription = document.getElementById("spanPutThroughDescription");
    var spanPutThroughImage = document.getElementById("spanPutThroughImage");
    
    var tdTableType = document.getElementById("tdTableType");
    var spanNormal = document.getElementById("spanNormal");
    var spanScrollInfinite = document.getElementById("spanScrollInfinite");
    var spanScroll2Directions = document.getElementById("spanScroll2Directions");
    var spanPageReplacement = document.getElementById("spanPageReplacement");
    var tbLineCount = document.getElementById("tbLineCount");
    var tdScrollInterval = document.getElementById("tdScrollInterval");
    var tdWaitingTime = document.getElementById("tdWaitingTime");
    
    var tdFontStyle = document.getElementById("tdFontStyle");
    var spanFontNormal = document.getElementById("spanFontNormal");
    var spanFontBoldHalf = document.getElementById("spanFontBoldHalf");
    var spanFontBoldAll = document.getElementById("spanFontBoldAll");
    
    var spanCopyright = document.getElementById("spanCopyright");
    var spanCopyright1 = document.getElementById("spanCopyright1");
    var spanFooter = document.getElementById("spanFooter");
    
    var localizeObject;
    
    if (lan == "vi-VN")
    {
        localizeObject = localizeVN;
        
        if (isOptionDisplayed == false)
            spanOption.innerHTML = "<img src=\"Images/tuychon.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
        else
            spanOption.innerHTML = "<img src=\"Images/an.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
        
        spanHide.innerHTML = "<img src=\"Images/an.gif\" onclick=\"HideOption();\" style=\"pointer: hand; cursor: pointer;\">";
        spanHidePutThrough.innerHTML = "<img src=\"Images/an.gif\" onclick=\"HidePutThrough();\" style=\"pointer: hand; cursor: pointer;\">";
        spanOK.innerHTML = "<img src=\"Images/dongy.gif\" onclick=\"OK();\" style=\"pointer: hand; cursor: pointer;\">";
        
        //if (floorType != "OTC")
            spanPutThroughImage.innerHTML = "<img src=\"Images/gdthoathuan.gif\" onclick=\"TogglePutThrough();\" style=\"pointer: hand; cursor: pointer;\">";
        
        createCookie("lan", "vi-VN", 1000);
    }
    else
    {
        localizeObject = localizeEN;
        
        if (isOptionDisplayed == false)
            spanOption.innerHTML = "<img src=\"Images/option.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
        else
            spanOption.innerHTML = "<img src=\"Images/hide.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
            
        spanHide.innerHTML = "<img src=\"Images/hide.gif\" onclick=\"HideOption();\" style=\"pointer: hand; cursor: pointer;\">";
        spanHidePutThrough.innerHTML = "<img src=\"Images/hide.gif\" onclick=\"HidePutThrough();\" style=\"pointer: hand; cursor: pointer;\">";
        spanOK.innerHTML = "<img src=\"Images/ok.gif\" onclick=\"OK();\" style=\"pointer: hand; cursor: pointer;\">";
        
        //if (floorType != "OTC")
            spanPutThroughImage.innerHTML = "<img src=\"Images/put_Through.gif\" onclick=\"TogglePutThrough();\" style=\"pointer: hand; cursor: pointer;\">";
        
        createCookie("lan", "en-US", 1000);
    }
    
    spanOnTop.innerHTML = localizeObject.selectedSymbolsOnTop;
    
    tdExchangeName.innerHTML = localizeObject.exchangeName;
    tdDateTitle.innerHTML = localizeObject.date;
    tdTimeTitle.innerHTML = localizeObject.time;
    tdChangeTitle.innerHTML = localizeObject.change;
    tdGainersLosersTitle.innerHTML = localizeObject.gainersLosers;
    tdTotalValueTitle.innerHTML = localizeObject.totalValue;
    tdTotalMarketVolumeTitle.innerHTML = localizeObject.totalMarketVolume;
    tdMarketStatusTitle.innerHTML = localizeObject.marketStatus;
    
    tdTableType.innerHTML = localizeObject.TableType;
    spanNormal.innerHTML = localizeObject.Normal;
    spanScrollInfinite.innerHTML = localizeObject.ScrollInfinite;
    spanScroll2Directions.innerHTML = localizeObject.Scroll2Directions;
    spanPageReplacement.innerHTML = localizeObject.PageReplacement;
    tbLineCount.innerHTML = localizeObject.LineCount;
    tdScrollInterval.innerHTML = localizeObject.ScrollInterval;
    tdWaitingTime.innerHTML = localizeObject.WaitingTime;
    
    tdFontStyle.innerHTML = localizeObject.FontStyle;
    spanFontNormal.innerHTML = localizeObject.FontNormal;
    spanFontBoldHalf.innerHTML = localizeObject.FontBoldHalf;
    spanFontBoldAll.innerHTML = localizeObject.FontBoldAll;
    
    
    if (floorType == "HOSE")
    {
        tableSessionsRow.cells[1].innerHTML = localizeObject.session + " 1";
        tableSessionsRow.cells[5].innerHTML = localizeObject.session + " 2";
        tableSessionsRow.cells[9].innerHTML = localizeObject.session + " 3";
        
        tableSessionsRow.cells[3].innerHTML = localizeObject.sessionValue;
        tableSessionsRow.cells[7].innerHTML = localizeObject.sessionValue;
        tableSessionsRow.cells[11].innerHTML = localizeObject.sessionValue;
    }
    else if (floorType == "MIXED")
    {
        tableIndicesRow.cells[1].innerHTML = "Hose";
        tableIndicesRow.cells[5].innerHTML = "HNX";
        tableIndicesRow.cells[9].innerHTML = "Upcom";
        
        tableIndicesRow.cells[3].innerHTML = localizeObject.sessionValue;
        tableIndicesRow.cells[7].innerHTML = localizeObject.sessionValue;
        tableIndicesRow.cells[11].innerHTML = localizeObject.sessionValue;
    }
   
    spanSelectAll.innerHTML = localizeObject.selectAll;
    spanClearAll.innerHTML = localizeObject.clearAll;
    spanDisplayAll.innerHTML = localizeObject.displayAll;
    
    if (floorType == "HASTC" || floorType == "OTC")// || floorType == "MIXED")
    {
        spanShowBuyVolume.innerHTML = localizeObject.ShowBuyVolume;
        spanShowSellVolume.innerHTML = localizeObject.ShowSellVolume;
        spanShowBuyOrderCount.innerHTML = localizeObject.ShowBuyOrderCount;
        spanShowSellOrderCount.innerHTML = localizeObject.ShowSellOrderCount;
        
        spanShowForeignSell.innerHTML = localizeObject.ShowForeignSell;
    }
    else if (floorType == "HOSE")
    {
        spanShowSession1Price.innerHTML = localizeObject.ShowSession1Price;
        spanShowSession1Volume.innerHTML = localizeObject.ShowSession1Volume;
        spanShowSession2Price.innerHTML = localizeObject.ShowSession2Price;
        spanShowSession2Volume.innerHTML = localizeObject.ShowSession2Volume; 
        spanShowAveragePrice.innerHTML = localizeObject.ShowAveragePrice; 
    }
    else if (floorType == "MIXED")
    {
        spanShowSession1Price.innerHTML = localizeObject.ShowSession1Price;
        spanShowSession1Volume.innerHTML = localizeObject.ShowSession1Volume;
        spanShowSession2Price.innerHTML = localizeObject.ShowSession2Price;
        spanShowSession2Volume.innerHTML = localizeObject.ShowSession2Volume; 
        
        spanShowBuyVolume.innerHTML = localizeObject.ShowBuyVolume;
        spanShowSellVolume.innerHTML = localizeObject.ShowSellVolume;
        spanShowBuyOrderCount.innerHTML = localizeObject.ShowBuyOrderCount;
        spanShowSellOrderCount.innerHTML = localizeObject.ShowSellOrderCount;
        
        spanShowForeignSell.innerHTML = localizeObject.ShowForeignSell;
    }
    spanShowForeignBuy.innerHTML = localizeObject.ShowForeignBuy;
    spanShowCurrentRoom.innerHTML = localizeObject.ShowCurrentRoom;
    
    spanPriceDescription.innerHTML = localizeObject.PriceDescription;
    spanVolumeDescription.innerHTML = localizeObject.VolumeDescription;
    spanScrollPriceDescription.innerHTML = localizeObject.PriceDescription;
    spanScrollVolumeDescription.innerHTML = localizeObject.VolumeDescription;
    
    spanShowVolumeColor.innerHTML = localizeObject.ShowVolumeColor;
    spanShowGraph.innerHTML = localizeObject.ShowGraph;
    spanShowSymbol2.innerHTML = localizeObject.ShowSymbol2;
    spanOrderSelectedSymbols.innerHTML = localizeObject.OrderSelectedSymbols;
    
     
    tdConnectedClientCountTitle.innerHTML = localizeObject.ConnectedCount;
    tdHitCounterTitle.innerHTML = localizeObject.HitCount;
    
    tdScreenWidth.innerHTML = localizeObject.ScreenWidth;
    tdBoardName.innerHTML = localizeObject.BoardName;
    
    spanCopyright.innerHTML = localizeObject.Copyright;
    spanCopyright1.innerHTML = localizeObject.Copyright;
    spanFooter.innerHTML = localizeObject.Footer;
    
    switch (floorType)
    {
        case "HASTC":
        case "OTC":
            tablePutThrough.rows[0].cells[0].innerHTML = localizeObject.PutThroughMatching;
            tablePutThrough.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThrough.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThrough.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            tablePutThrough.rows[1].cells[3].innerHTML = localizeObject.PutThroughValue;
            tablePutThrough.rows[1].cells[4].innerHTML = localizeObject.PutThroughTime;
            
            tablePutThroughBuy.rows[0].cells[0].innerHTML = localizeObject.PutThroughBuy;
            tablePutThroughBuy.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThroughBuy.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThroughBuy.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            
            tablePutThroughSell.rows[0].cells[0].innerHTML = localizeObject.PutThroughSell;
            tablePutThroughSell.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThroughSell.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThroughSell.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            break;
        case "HOSE":
            tablePutThrough.rows[0].cells[0].innerHTML = localizeObject.PutThroughMatching;
            tablePutThrough.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThrough.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThrough.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            tablePutThrough.rows[1].cells[3].innerHTML = localizeObject.PutThroughValue;
            
            tablePutThroughBuy.rows[0].cells[0].innerHTML = localizeObject.PutThroughBuy;
            tablePutThroughBuy.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThroughBuy.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThroughBuy.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            tablePutThroughBuy.rows[1].cells[3].innerHTML = localizeObject.PutThroughTime;
            
            tablePutThroughSell.rows[0].cells[0].innerHTML = localizeObject.PutThroughSell;
            tablePutThroughSell.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThroughSell.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThroughSell.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            tablePutThroughSell.rows[1].cells[3].innerHTML = localizeObject.PutThroughTime;
            break;
        case "MIXED":
            tablePutThrough.rows[0].cells[0].innerHTML = localizeObject.PutThroughMatching;
            tablePutThrough.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThrough.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThrough.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            tablePutThrough.rows[1].cells[3].innerHTML = localizeObject.PutThroughValue;
            tablePutThrough.rows[1].cells[4].innerHTML = localizeObject.PutThroughTime;
            
            tablePutThroughBuy.rows[0].cells[0].innerHTML = localizeObject.PutThroughBuy;
            tablePutThroughBuy.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThroughBuy.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThroughBuy.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            tablePutThroughBuy.rows[1].cells[3].innerHTML = localizeObject.PutThroughTime;
            
            tablePutThroughSell.rows[0].cells[0].innerHTML = localizeObject.PutThroughSell;
            tablePutThroughSell.rows[1].cells[0].innerHTML = localizeObject.PutThroughSymbol;
            tablePutThroughSell.rows[1].cells[1].innerHTML = localizeObject.PutThroughPrice;
            tablePutThroughSell.rows[1].cells[2].innerHTML = localizeObject.PutThroughVolume;
            tablePutThroughSell.rows[1].cells[3].innerHTML = localizeObject.PutThroughTime;
            break;    
    }
    
    if (isShowGraph == true)
    {
        var tableHistoryHeader = document.getElementById("tableHistoryHeader");
        tableHistoryHeader.rows[0].cells[0].innerHTML = localizeObject.HistoryTime;
        tableHistoryHeader.rows[0].cells[1].innerHTML = localizeObject.HistoryPrice + " (x1000)";
        tableHistoryHeader.rows[0].cells[2].innerHTML = localizeObject.HistoryChange + " (x1000)";
        tableHistoryHeader.rows[0].cells[3].innerHTML = localizeObject.HistoryChangePercent;
        tableHistoryHeader.rows[0].cells[4].innerHTML = localizeObject.HistoryVolume + " (x10)";
        tableHistoryHeader.rows[0].cells[5].innerHTML = localizeObject.HistoryTotalVolume + " (x10)";
    }
    
    spanPutThroughDescription.innerHTML = localizeObject.PutThroughUnit;
    
    SetHeaderText("tableQuote", localizeObject);
    SetHeaderText("tableFixedHeader", localizeObject);
    SetHeaderText("tableFloatingHeader", localizeObject);
    
    if (isShowGraph == true)
    {
        var divGraphTitle = document.getElementById("divGraphTitle");
        divGraphTitle.innerHTML = localizeObject.GraphTitle;
    }
    //CopyFloatingHeader();
    
    //Khi thay đổi language thì phải lấy lại dữ liệu hiển thị
    currentBasicVersionId = 0;
    currentVersionId = 0;
    currentMarketVersionId = 0;
    
    if (requestTimerID != null)
    {
        clearTimeout(requestTimerID);
        requestTimerID = null;
    }
        
    GetBasicObject();
 }
 
 function SetHeaderText(tableId, localizeObject)
 {
    var table = document.getElementById(tableId);
    
    var trGridHeaderTop = table.rows[0];
    var trGridHeader = table.rows[1];
    
    switch (floorType)
    {
        case "HASTC":
        case "OTC":
        case "MIXED":
            trGridHeaderTop.cells[0].innerHTML = localizeObject.symbol;
            trGridHeaderTop.cells[1].innerHTML = localizeObject.ceiling;
            trGridHeaderTop.cells[2].innerHTML = localizeObject.floor;
            trGridHeaderTop.cells[3].innerHTML = localizeObject.basic;
            
            trGridHeaderTop.cells[4].innerHTML = localizeObject.bid;
            trGridHeaderTop.cells[5].innerHTML = localizeObject.matching;
            trGridHeaderTop.cells[7].innerHTML = localizeObject.ask;
            
            trGridHeaderTop.cells[8].innerHTML = localizeObject.high;
            trGridHeaderTop.cells[9].innerHTML = localizeObject.low;
            trGridHeaderTop.cells[10].innerHTML = localizeObject.average;
            trGridHeaderTop.cells[11].innerHTML = localizeObject.totalVolume;

            
            trGridHeader.cells[0].innerHTML = localizeObject.price + " 3";
            trGridHeader.cells[1].innerHTML = localizeObject.volume + " 3";
            trGridHeader.cells[2].innerHTML = localizeObject.price + " 2";
            trGridHeader.cells[3].innerHTML = localizeObject.volume + " 2";
            trGridHeader.cells[4].innerHTML = localizeObject.price + " 1";
            trGridHeader.cells[5].innerHTML = localizeObject.volume + " 1";
            
            trGridHeader.cells[6].innerHTML = localizeObject.price;
            trGridHeader.cells[7].innerHTML = localizeObject.volume;
            
            trGridHeader.cells[8].innerHTML = localizeObject.price + " 1";
            trGridHeader.cells[9].innerHTML = localizeObject.volume + " 1";
            trGridHeader.cells[10].innerHTML = localizeObject.price + " 2";
            trGridHeader.cells[11].innerHTML = localizeObject.volume + " 2";
            trGridHeader.cells[12].innerHTML = localizeObject.price + " 3";
            trGridHeader.cells[13].innerHTML = localizeObject.volume + " 3";
            
            var columnIndex = 12;
            
            if (floorType == "MIXED")
            {
                if (isShowSession1Price == true)
                    trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.Session1Price;
                
                if (isShowSession1Volume == true)
                    trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.Session1Volume;
                    
                if (isShowSession2Price == true)
                    trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.Session2Price;
                
                if (isShowSession2Volume == true)
                    trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.Session2Volume;
            }
                
            if (isShowBuyVolume == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.BuyVolume;
            
            if (isShowSellVolume == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.SellVolume;
                
            if (isShowBuyOrderCount == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.BuyOrderCount;
                
            if (isShowSellOrderCount == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.SellOrderCount;
                
            if (isShowForeignBuy == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.ForeignBuy;
            
            if (isShowForeignSell == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.ForeignSell;
                
            if (isShowCurrentRoom == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.CurrentRoom;    
            break;
        case "HOSE":
            trGridHeaderTop.cells[0].innerHTML = localizeObject.symbol;
            trGridHeaderTop.cells[1].innerHTML = localizeObject.ceiling;
            trGridHeaderTop.cells[2].innerHTML = localizeObject.floor;
            trGridHeaderTop.cells[3].innerHTML = localizeObject.basic;
            
            trGridHeaderTop.cells[4].innerHTML = localizeObject.bid;
            trGridHeaderTop.cells[5].innerHTML = localizeObject.matching;
            trGridHeaderTop.cells[7].innerHTML = localizeObject.ask;
            
            
            trGridHeaderTop.cells[8].innerHTML = localizeObject.high;
            trGridHeaderTop.cells[9].innerHTML = localizeObject.low;
            trGridHeaderTop.cells[10].innerHTML = localizeObject.totalVolume;
            
            trGridHeader.cells[0].innerHTML = localizeObject.price + " 3";
            trGridHeader.cells[1].innerHTML = localizeObject.volume + " 3";
            trGridHeader.cells[2].innerHTML = localizeObject.price + " 2";
            trGridHeader.cells[3].innerHTML = localizeObject.volume + " 2";
            trGridHeader.cells[4].innerHTML = localizeObject.price + " 1";
            trGridHeader.cells[5].innerHTML = localizeObject.volume + " 1";
            
            trGridHeader.cells[6].innerHTML = localizeObject.price;
            trGridHeader.cells[7].innerHTML = localizeObject.volume;
            
            trGridHeader.cells[8].innerHTML = localizeObject.price + " 1";
            trGridHeader.cells[9].innerHTML = localizeObject.volume + " 1";
            trGridHeader.cells[10].innerHTML = localizeObject.price + " 2";
            trGridHeader.cells[11].innerHTML = localizeObject.volume + " 2";
            trGridHeader.cells[12].innerHTML = localizeObject.price + " 3";
            trGridHeader.cells[13].innerHTML = localizeObject.volume + " 3";
            
            var columnIndex = 11;
            
            if (isShowSession1Price == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.Session1Price;
            
            if (isShowSession1Volume == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.Session1Volume;
                
            if (isShowSession2Price == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.Session2Price;
            
            if (isShowSession2Volume == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.Session2Volume;
                
            if (isShowForeignBuy == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.ForeignBuy;
            
            if (isShowCurrentRoom == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.CurrentRoom;
                
            if (isShowAveragePrice == true)
                trGridHeaderTop.cells[columnIndex++].innerHTML = localizeObject.average;
                
            break;
    }
    
    
 }

 
 function createCookie(name,value,days) {
    name = cookiePrefix + name;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    name = cookiePrefix + name;
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createGeneralCookie(name,value,days) {
    //name = name;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readGeneralCookie(name) {
    //name = name;
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

 function OnTopLinkClick()
 {
    var chkOnTop = document.getElementById("chkShowSelectedOnTop");
    
    chkOnTop.checked = !chkOnTop.checked;
   
 }

 
 function OK()
 {
    var oldExtraColumnString;
    
    oldExtraColumnString = extraColumnString;
    
    var oldShowSelectedSymbolsOnTop = showSelectedSymbolsOnTop;
    
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    var chkShowBuyVolume;
    var chkShowSellVolume;
    var chkShowBuyOrderCount;
    var chkShowSellOrderCount;
    var chkShowForeignBuy;
    var chkShowForeignSell;
    var chkShowCurrentRoom;
    
    var chkShowSession1Price;
    var chkShowSession1Volume;
    var chkShowSession2Price;
    var chkShowSession2Volume;
    
    var chkShowVolumeColor = document.getElementById("chkShowVolumeColor");
    var chkShowGraph = document.getElementById("chkShowGraph");
    var chkShowSymbol2 = document.getElementById("chkShowSymbol2");
    var chkOrderSelectedSymbols = document.getElementById("chkOrderSelectedSymbols");
    
    var rbtNormal = document.getElementById("rbtNormal");
    var rbtScrollInfinite = document.getElementById("rbtScrollInfinite");
    var rbtScroll2Directions = document.getElementById("rbtScroll2Directions");
    var txtLineCount = document.getElementById("txtLineCount");
    var txtScrollInterval = document.getElementById("txtScrollInterval");
    var txtWaitingTime = document.getElementById("txtWaitingTime");
    
    var rbtFontNormal = document.getElementById("rbtFontNormal");
    var rbtFontBoldHalf = document.getElementById("rbtFontBoldHalf");
    var rbtFontBoldAll = document.getElementById("rbtFontBoldAll");
    
    
    var oldTableType = tableType;
    var oldFontStyle = fontStyle;
    var needSetScroll = false;
    
    if (rbtNormal.checked == true)
        tableType = 0;
    else
        if (rbtScrollInfinite.checked == true)
            tableType = 1;
        else if (rbtScroll2Directions.checked == true)
            tableType = 2;
        else
            tableType = 3;
    
    if (rbtFontNormal.checked == true)
        fontStyle = 0;
    else if (rbtFontBoldHalf.checked == true)
            fontStyle = 1;
        else
            fontStyle = 2;
            
    var oldShowVolumeColor = isShowVolumeColor;   
    var oldShowGraph = isShowGraph;  
    var oldShowSymbol2 = isShowSymbol2;   
    var oldOrderSelectedSymbols = isOrderSelectedSymbols;
    
    isShowVolumeColor = chkShowVolumeColor.checked;
    isShowGraph = chkShowGraph.checked;
    isShowSymbol2 = chkShowSymbol2.checked;
    isOrderSelectedSymbols = chkOrderSelectedSymbols.checked;
                    
    if (tableType != oldTableType || parseInt(txtLineCount.value) != lineCount || parseInt(txtScrollInterval.value) != scrollInterval || parseInt(txtWaitingTime.value) != waitingTime)
        needSetScroll = true;
            
    lineCount = parseInt(txtLineCount.value);
    scrollInterval = parseInt(txtScrollInterval.value);
    waitingTime = parseInt(txtWaitingTime.value);
        
    if (floorType == "HASTC" || floorType == "OTC")// || floorType == "MIXED")
    {
        chkShowBuyVolume = document.getElementById("chkShowBuyVolume");
        chkShowSellVolume = document.getElementById("chkShowSellVolume");
        chkShowBuyOrderCount = document.getElementById("chkShowBuyOrderCount");
        chkShowSellOrderCount = document.getElementById("chkShowSellOrderCount");
        chkShowForeignBuy = document.getElementById("chkShowForeignBuy");
        chkShowForeignSell = document.getElementById("chkShowForeignSell");
        chkShowCurrentRoom = document.getElementById("chkShowCurrentRoom");
        
        isShowBuyVolume = chkShowBuyVolume.checked;
        isShowSellVolume = chkShowSellVolume.checked;
        isShowBuyOrderCount = chkShowBuyOrderCount.checked;
        isShowSellOrderCount = chkShowSellOrderCount.checked;
        isShowForeignBuy = chkShowForeignBuy.checked;
        isShowForeignSell = chkShowForeignSell.checked;
        isShowCurrentRoom = chkShowCurrentRoom.checked;
        
        extraColumnString = "";
        extraColumnString += isShowBuyVolume?"1":"0";
        extraColumnString += isShowSellVolume?"1":"0";
        extraColumnString += isShowBuyOrderCount?"1":"0";
        extraColumnString += isShowSellOrderCount?"1":"0";
        extraColumnString += isShowForeignBuy?"1":"0";
        extraColumnString += isShowForeignSell?"1":"0";
        extraColumnString += isShowCurrentRoom?"1":"0";
    }
    else if (floorType == "HOSE")
    {
        chkShowSession1Price = document.getElementById("chkShowSession1Price");
        chkShowSession1Volume = document.getElementById("chkShowSession1Volume");
        chkShowSession2Price = document.getElementById("chkShowSession2Price");
        chkShowSession2Volume = document.getElementById("chkShowSession2Volume");
        chkShowForeignBuy = document.getElementById("chkShowForeignBuy");
        chkShowCurrentRoom = document.getElementById("chkShowCurrentRoom");
        chkShowAveragePrice = document.getElementById("chkShowAveragePrice");
        
        isShowSession1Price = chkShowSession1Price.checked;
        isShowSession1Volume = chkShowSession1Volume.checked;
        isShowSession2Price = chkShowSession2Price.checked;
        isShowSession2Volume = chkShowSession2Volume.checked;
        isShowForeignBuy = chkShowForeignBuy.checked;
        isShowCurrentRoom = chkShowCurrentRoom.checked;
        isShowAveragePrice = chkShowAveragePrice.checked;
        
        extraColumnString = "";
        extraColumnString += isShowSession1Price?"1":"0";
        extraColumnString += isShowSession1Volume?"1":"0";
        extraColumnString += isShowSession2Price?"1":"0";
        extraColumnString += isShowSession2Volume?"1":"0";
        extraColumnString += isShowForeignBuy?"1":"0";
        extraColumnString += isShowCurrentRoom?"1":"0";
        extraColumnString += isShowAveragePrice?"1":"0";
    }
    else if (floorType == "MIXED")
    {
        chkShowSession1Price = document.getElementById("chkShowSession1Price");
        chkShowSession1Volume = document.getElementById("chkShowSession1Volume");
        chkShowSession2Price = document.getElementById("chkShowSession2Price");
        chkShowSession2Volume = document.getElementById("chkShowSession2Volume");
        
        chkShowBuyVolume = document.getElementById("chkShowBuyVolume");
        chkShowSellVolume = document.getElementById("chkShowSellVolume");
        chkShowBuyOrderCount = document.getElementById("chkShowBuyOrderCount");
        chkShowSellOrderCount = document.getElementById("chkShowSellOrderCount");
        chkShowForeignBuy = document.getElementById("chkShowForeignBuy");
        chkShowForeignSell = document.getElementById("chkShowForeignSell");
        chkShowCurrentRoom = document.getElementById("chkShowCurrentRoom");
        
        isShowSession1Price = chkShowSession1Price.checked;
        isShowSession1Volume = chkShowSession1Volume.checked;
        isShowSession2Price = chkShowSession2Price.checked;
        isShowSession2Volume = chkShowSession2Volume.checked;
        
        isShowBuyVolume = chkShowBuyVolume.checked;
        isShowSellVolume = chkShowSellVolume.checked;
        isShowBuyOrderCount = chkShowBuyOrderCount.checked;
        isShowSellOrderCount = chkShowSellOrderCount.checked;
        isShowForeignBuy = chkShowForeignBuy.checked;
        isShowForeignSell = chkShowForeignSell.checked;
        isShowCurrentRoom = chkShowCurrentRoom.checked;
        
        extraColumnString = "";
        extraColumnString += isShowSession1Price?"1":"0";
        extraColumnString += isShowSession1Volume?"1":"0";
        extraColumnString += isShowSession2Price?"1":"0";
        extraColumnString += isShowSession2Volume?"1":"0";
        
        extraColumnString += isShowBuyVolume?"1":"0";
        extraColumnString += isShowSellVolume?"1":"0";
        extraColumnString += isShowBuyOrderCount?"1":"0";
        extraColumnString += isShowSellOrderCount?"1":"0";
        extraColumnString += isShowForeignBuy?"1":"0";
        extraColumnString += isShowForeignSell?"1":"0";
        extraColumnString += isShowCurrentRoom?"1":"0";
    }    
    GetSelectedSymbolsForChoose();

    if (chkDisplayAll.checked == true)
        displayedSymbolsString = "all";
    else
    {
        displayedSymbolsString = displayedSymbolsSelectedString;
        if (displayedSymbolsString != "all")
            displayedSymbolList = displayedSymbolsString.split(",");
    }   
    
    var chkOnTop = document.getElementById("chkShowSelectedOnTop");
    showSelectedSymbolsOnTop = chkOnTop.checked;
    
    var screenWidthButtons = document.forms[0].ScreenWidth;
    var radioButton;
    
    for (var i=0; i< screenWidthButtons.length;i++)
    {
        radioButton = screenWidthButtons[i];
        if (radioButton.checked == true)
        {
            screenWidth = radioButton.value;
            break;
        }
    }
    
    SetTableWidth();
    
    if (floorType == "HASTC" || floorType == "HOSE" || floorType == "OTC" || floorType == "MIXED")
    {
        if (oldExtraColumnString != extraColumnString || needSetScroll == true)
        {
            isReadyToResize = false;
            CreateExtraHeaderCells("tableQuote");
            CreateExtraHeaderCells("tableFixedHeader");
            CreateExtraHeaderCells("tableFloatingHeader");
            isReadyToResize = true;
        }
        
        //Nếu thay đổi số CK thì tạo lại bảng tham chiếu
        if (oldOrderSelectedSymbols != isOrderSelectedSymbols || oldShowGraph != isShowGraph || oldShowSymbol2 != isShowSymbol2 || oldExtraColumnString != extraColumnString || needSetScroll == true || oldDisplayedSymbolsString != displayedSymbolsString)
            CreateBasicRows(true);
        else
        {
            if (fontStyle != oldFontStyle)
                SetFontStyle();
            if (oldShowSelectedSymbolsOnTop != showSelectedSymbolsOnTop)
                ToggleOnTop();
                
            if (oldShowVolumeColor != isShowVolumeColor)
                ToggleShowVolumeColor();
        }
    }
    else 
    {
        //Nếu thay đổi số CK thì tạo lại bảng tham chiếu
        if (oldDisplayedSymbolsString != displayedSymbolsString)
            CreateBasicRows(true);
        else
        {
            if (fontStyle != oldFontStyle)
                SetFontStyle();
            if (oldShowSelectedSymbolsOnTop != showSelectedSymbolsOnTop)
                ToggleOnTop();
                
            if (oldShowVolumeColor != isShowVolumeColor)
                ToggleShowVolumeColor();
        }
    }
    
    if (needSetScroll == true)
        SetScroll();
    
    createCookie("onTop", showSelectedSymbolsOnTop, 1000);
    createCookie("boardName", boardName, 1000);
    createCookie("displayedSymbolsString" + boardName, displayedSymbolsString, 1000);
    createCookie("displayedSymbolsSelectedString" + boardName, displayedSymbolsSelectedString, 1000);
    createCookie("screenWidth", screenWidth, 1000);
    
    createCookie("fontStyle", fontStyle, 1000);
    createCookie("isShowVolumeColor", isShowVolumeColor, 1000);

    createCookie("extraColString", extraColumnString, 1000);
    
    createCookie("tableType", tableType, 1000);
    createCookie("lineCount", lineCount, 1000);
    createCookie("scrollInterval", scrollInterval, 1000);
    createCookie("waitingTime", waitingTime, 1000);
    
    createGeneralCookie("isShowGraph", isShowGraph, 1000);
    createGeneralCookie("isShowSymbol2", isShowSymbol2, 1000);
    createGeneralCookie("isOrderSelectedSymbols", isOrderSelectedSymbols, 1000);
    
    HideOption();
 }
 
 function GetSelectedSymbolsForChoose()
 {
    displayedSymbolsSelectedString = "";
    //Tạo danh sách các mã CK được chọn để hiển thị
    
    var theChooseSymbolsTable = document.getElementById("tableChooseSymbols");
    var theRow;
    var checkbox;
    
    for (var i=0; i<theChooseSymbolsTable.rows.length;i++)
    {
        theRow = theChooseSymbolsTable.rows[i];
        for (var j=0; j<theRow.cells.length;j++)
        {
            theCell = theRow.cells[j];
            checkbox = theCell.childNodes[0];
            
            if (checkbox.checked == true)
            {
                if (displayedSymbolsSelectedString == "")
                    displayedSymbolsSelectedString = "'" + checkbox.name + "'";
                else
                    displayedSymbolsSelectedString = displayedSymbolsSelectedString + ",'" + checkbox.name + "'";
                
            }
           
        }
    }
 }
 
 //Gửi thông tin tùy chọn của người dùng cho máy chủ
 function SetClientInfo()
 {
    
    //Nếu chưa có ClientId thì lấy từ server
    if (clientId == -1)
        GetClientId(); //vòng lặp vô tận cho đến khi lấy được clientId từ máy chủ
    else
    {
        switch (floorType)
        {
            case "HASTC":
                AlphaStockBoard.UI.HastcStockQuotes.SetClientInfo(clientId, displayedSymbolsString, extraColumnString, currentLanguage);
                break;
            case "HOSE":
                AlphaStockBoard.UI.HoseStockQuotes.SetClientInfo(clientId, displayedSymbolsString, extraColumnString, currentLanguage);
                break;
            case "OTC":
                AlphaStockBoard.UI.OtcStockQuotes.SetClientInfo(clientId, displayedSymbolsString, extraColumnString, currentLanguage);
                break;
            case "MIXED":
                AlphaStockBoard.UI.MixedStockQuotes.SetClientInfo(clientId, displayedSymbolsString, extraColumnString, currentLanguage);
                break;
        }
        
    }
 }
 
  //Gửi thông tin tùy chọn của người dùng cho máy chủ đồng thời lấy dữ liệu
 function SetClientInfoAndGetData()
 {
    //Xóa bộ định thời cũ
    if (requestTimerID != null)
    {
        clearTimeout(requestTimerID);
        requestTimerID = null;
    }
    
    //Nếu chưa có ClientId thì lấy từ server
    if (clientId == -1)
        GetClientId(); //vòng lặp vô tận cho đến khi lấy được clientId từ máy chủ
    else
    {
        switch (floorType)
        {
            case "HASTC":
                AlphaStockBoard.UI.HastcStockQuotes.SetClientInfoAndGetData(clientId, displayedSymbolsString, extraColumnString, currentLanguage);
                break;
            case "HOSE":
                AlphaStockBoard.UI.HoseStockQuotes.SetClientInfoAndGetData(clientId, displayedSymbolsString, extraColumnString, currentLanguage);
                break;
            case "OTC":
                AlphaStockBoard.UI.OtcStockQuotes.SetClientInfoAndGetData(clientId, displayedSymbolsString, extraColumnString, currentLanguage);
                break;
            case "MIXED":
                AlphaStockBoard.UI.MixedStockQuotes.SetClientInfoAndGetData(clientId, displayedSymbolsString, extraColumnString, currentLanguage);
                break;
        }
        
    }
 }
 
 function GetPutThroughObject()
 {
    switch (floorType)
    {
        case "HASTC":
            AlphaStockBoard.UI.HastcStockQuotes.GetHastcPutThroughObject(currentLanguage);
            break;
        case "HOSE":
            AlphaStockBoard.UI.HoseStockQuotes.GetHosePutThroughObject(currentLanguage);
            break;
        case "OTC":
            AlphaStockBoard.UI.OtcStockQuotes.GetOtcPutThroughObject(currentLanguage);
            break;
        case "MIXED":
            AlphaStockBoard.UI.MixedStockQuotes.GetMixedPutThroughObject(currentLanguage);
            break;
    }
 }
 
  function GetQuotesHistory(symbol)
 {
    switch (floorType)
    {
        case "HASTC":
            AlphaStockBoard.UI.HastcStockQuotes.GetHastcQuotesHistory(symbol, currentLanguage);
            break;
        case "HOSE":
            AlphaStockBoard.UI.HoseStockQuotes.GetHoseQuotesHistory(symbol, currentLanguage);
            break;
        case "OTC":
            AlphaStockBoard.UI.OtcStockQuotes.GetOtcQuotesHistory(symbol, currentLanguage);
            break;
        case "MIXED":
            AlphaStockBoard.UI.MixedStockQuotes.GetMixedQuotesHistory(symbol, currentLanguage);
            break;
    }
 }
 
 //Lấy clientId từ máy chủ
 function GetClientId()
 {
    switch (floorType)
    {
        case "HASTC":
            AlphaStockBoard.UI.HastcStockQuotes.GetClientId();
            break;
        case "HOSE":
            AlphaStockBoard.UI.HoseStockQuotes.GetClientId();
            break;
        case "OTC":
            AlphaStockBoard.UI.OtcStockQuotes.GetClientId();
            break;
        case "MIXED":
            AlphaStockBoard.UI.MixedStockQuotes.GetClientId();
            break;
    }
 }
 
 function ToggleOption()
 {
    if (isOptionDisplayed == true)
    {
        HideOption();
    }
    else
    {
        ShowOption();
    }
 }
 
 function ShowOption()
 {
    LoadSymbolsTableForChoose();
    
    oldDisplayedSymbolsString = displayedSymbolsString;
    
    var chkOnTop = document.getElementById("chkShowSelectedOnTop");
    chkOnTop.checked = showSelectedSymbolsOnTop;
    
    if (floorType == "HASTC" || floorType == "OTC")// || floorType == "MIXED")
    {
        var chkShowBuyVolume = document.getElementById("chkShowBuyVolume");
        var chkShowSellVolume = document.getElementById("chkShowSellVolume");
        var chkShowBuyOrderCount = document.getElementById("chkShowBuyOrderCount");
        var chkShowSellOrderCount = document.getElementById("chkShowSellOrderCount");
        var chkShowForeignBuy = document.getElementById("chkShowForeignBuy");
        var chkShowForeignSell = document.getElementById("chkShowForeignSell");
        var chkShowCurrentRoom = document.getElementById("chkShowCurrentRoom");
        
        
        chkShowBuyVolume.checked = isShowBuyVolume;
        chkShowSellVolume.checked = isShowSellVolume;
        chkShowBuyOrderCount.checked = isShowBuyOrderCount;
        chkShowSellOrderCount.checked = isShowSellOrderCount;
        chkShowForeignBuy.checked = isShowForeignBuy;
        chkShowForeignSell.checked = isShowForeignSell;
        chkShowCurrentRoom.checked = isShowCurrentRoom;
        
    }
    else if (floorType == "HOSE")
    {
        var chkShowSession1Price = document.getElementById("chkShowSession1Price");
        var chkShowSession1Volume = document.getElementById("chkShowSession1Volume");
        var chkShowSession2Price = document.getElementById("chkShowSession2Price");
        var chkShowSession2Volume = document.getElementById("chkShowSession2Volume");
        var chkShowForeignBuy = document.getElementById("chkShowForeignBuy");
        var chkShowCurrentRoom = document.getElementById("chkShowCurrentRoom");
        var chkShowAveragePrice = document.getElementById("chkShowAveragePrice");
        
        chkShowSession1Price.checked = isShowSession1Price;
        chkShowSession1Volume.checked = isShowSession1Volume;
        chkShowSession2Price.checked = isShowSession2Price;
        chkShowSession2Volume.checked = isShowSession2Volume;
        chkShowForeignBuy.checked = isShowForeignBuy;
        chkShowCurrentRoom.checked = isShowCurrentRoom;
        chkShowAveragePrice.checked = isShowAveragePrice;
    }
    else if (floorType == "MIXED")
    {
        var chkShowSession1Price = document.getElementById("chkShowSession1Price");
        var chkShowSession1Volume = document.getElementById("chkShowSession1Volume");
        var chkShowSession2Price = document.getElementById("chkShowSession2Price");
        var chkShowSession2Volume = document.getElementById("chkShowSession2Volume");
        
        var chkShowBuyVolume = document.getElementById("chkShowBuyVolume");
        var chkShowSellVolume = document.getElementById("chkShowSellVolume");
        var chkShowBuyOrderCount = document.getElementById("chkShowBuyOrderCount");
        var chkShowSellOrderCount = document.getElementById("chkShowSellOrderCount");
        var chkShowForeignBuy = document.getElementById("chkShowForeignBuy");
        var chkShowForeignSell = document.getElementById("chkShowForeignSell");
        var chkShowCurrentRoom = document.getElementById("chkShowCurrentRoom");
        
        chkShowSession1Price.checked = isShowSession1Price;
        chkShowSession1Volume.checked = isShowSession1Volume;
        chkShowSession2Price.checked = isShowSession2Price;
        chkShowSession2Volume.checked = isShowSession2Volume;
        
        chkShowBuyVolume.checked = isShowBuyVolume;
        chkShowSellVolume.checked = isShowSellVolume;
        chkShowBuyOrderCount.checked = isShowBuyOrderCount;
        chkShowSellOrderCount.checked = isShowSellOrderCount;
        chkShowForeignBuy.checked = isShowForeignBuy;
        chkShowForeignSell.checked = isShowForeignSell;
        chkShowCurrentRoom.checked = isShowCurrentRoom;
    }
    var chkShowVolumeColor = document.getElementById("chkShowVolumeColor");
    var chkShowGraph = document.getElementById("chkShowGraph");
    var chkShowSymbol2 = document.getElementById("chkShowSymbol2");
    var chkOrderSelectedSymbols = document.getElementById("chkOrderSelectedSymbols");
    
    if (isShowVolumeColor == true)
        chkShowVolumeColor.checked = true;
    else
        chkShowVolumeColor.checked = false;
        
    chkShowGraph.checked = isShowGraph;
    chkShowSymbol2.checked = isShowSymbol2;
    chkOrderSelectedSymbols.checked = isOrderSelectedSymbols;
    
    var pnlOption = document.getElementById("pnlOption");
    pnlOption.style.display = 'block';
        
    isOptionDisplayed = true;
    var spanOption = document.getElementById("spanOption");
    
    if (currentLanguage == "vi-VN")
        spanOption.innerHTML = "<img src=\"Images/an.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
    else
        spanOption.innerHTML = "<img src=\"Images/hide.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
        
    //Chọn button độ rộng màn hình ứng với giá trị hiện tại
    var screenWidthButtons = document.forms[0].ScreenWidth;
    var radioButton;
    
    for (var i=0; i< screenWidthButtons.length;i++)
    {
        radioButton = screenWidthButtons[i];
        if (radioButton.value == screenWidth)
        {
            radioButton.checked = true;
            break;
        }
    }   
    
    var boardNameButtons = document.forms[0].SelectBoard;
    
    for (var i=0; i< boardNameButtons.length;i++)
    {
        radioButton = boardNameButtons[i];
        if (radioButton.value == boardName)
        {
            radioButton.checked = true;
            break;
        }
    } 
    
    var rbtNormal = document.getElementById("rbtNormal");
    var rbtScrollInfinite = document.getElementById("rbtScrollInfinite");
    var rbtScroll2Directions = document.getElementById("rbtScroll2Directions");
    var rbtPageReplacement = document.getElementById("rbtPageReplacement");
    var txtLineCount = document.getElementById("txtLineCount");
    var txtScrollInterval = document.getElementById("txtScrollInterval");
    var txtWaitingTime = document.getElementById("txtWaitingTime");
    
    var rbtFontNormal = document.getElementById("rbtFontNormal");
    var rbtFontBoldHalf = document.getElementById("rbtFontBoldHalf");
    var rbtFontBoldAll = document.getElementById("rbtFontBoldAll");
    
    if (tableType == 0)
        rbtNormal.checked = true;
    else
        if (tableType == 1)
            rbtScrollInfinite.checked = true;
        else if (tableType == 2)
            rbtScroll2Directions.checked = true;
        else
            rbtPageReplacement.checked = true;
            
    if (fontStyle == 0)
        rbtFontNormal.checked = true;
    else
        if (fontStyle == 1)
            rbtFontBoldHalf.checked = true;
        else
            rbtFontBoldAll.checked = true;        
            
    txtLineCount.value = lineCount;
    txtScrollInterval.value = scrollInterval;
    txtWaitingTime.value = waitingTime;
 }
 
 function HideOption()
 {

    var pnlOption = document.getElementById("pnlOption");
    
    pnlOption.style.display = 'none';
        
    isOptionDisplayed = false;
    var spanOption = document.getElementById("spanOption");
    
    if (currentLanguage == "vi-VN")
        spanOption.innerHTML = "<img src=\"Images/tuychon.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
    else
        spanOption.innerHTML = "<img src=\"Images/option.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";

 }
 
 function TogglePutThrough()
 {
    if (isPutThroughDisplayed == true)
        HidePutThrough();
    else
        ShowPutThrough();
 }
 
 function ToggleVolumeColor()
 {
    var chkShowVolumeColor = document.getElementById("chkShowVolumeColor");
    chkShowVolumeColor.checked = !chkShowVolumeColor.checked;
 }
 
 function ToggleShowGraph()
 {
    var chkShowGraph = document.getElementById("chkShowGraph");
    chkShowGraph.checked = !chkShowGraph.checked;
 }
 
 function ToggleShowSymbol2()
 {
    var chkShowSymbol2 = document.getElementById("chkShowSymbol2");
    chkShowSymbol2.checked = !chkShowSymbol2.checked;
 }
 
 function ToggleShowAveragePrice()
 {
    var chkShowAveragePrice = document.getElementById("chkShowAveragePrice");
    chkShowAveragePrice.checked = !chkShowAveragePrice.checked;
 }
 
  function ToggleOrderSelectedSymbols()
 {
    var chkOrderSelectedSymbols = document.getElementById("chkOrderSelectedSymbols");
    chkOrderSelectedSymbols.checked = !chkOrderSelectedSymbols.checked;
 }
 
 function ShowPutThrough()
 {
    var pnlOption = document.getElementById("pnlPutThrough");
    pnlOption.style.display = 'block';
        
    isPutThroughDisplayed = true;
    
    GetPutThroughObject();
    putThroughTimerID = self.setInterval("GetPutThroughObject()", 10*1000);
 }
 
 function HidePutThrough()
 {
    var pnlOption = document.getElementById("pnlPutThrough");
    pnlOption.style.display = 'none';
        
    isPutThroughDisplayed = false;
    
    self.clearInterval(putThroughTimerID);
    putThroughTimerID = null;
 }
 
 function ToggleOnTop()
 {
    if (tableType != 0)
        return;
        
    var chkSymbol;
  
    if (showSelectedSymbolsOnTop == true)
    {
        //Khởi tạo lại các mảng
        selectedSymbolList = new Array();
        unselectedSymbolList = new Array();
        selectedCount = 0;
        
        if (basicObject != null)
        {
            //Thêm dữ liệu mảng dựa vào các mã CK đang được chọn
            for(var itemKey in basicObject.ItemList)
            {
                //Nếu CK này ko được chọn để hiển thị
                if (displayedSymbolsString == "all" || displayedSymbolsString.indexOf("'" + itemKey + "'") != -1)
                    unselectedSymbolList.push(itemKey);
            }
            
                
            for(var itemKey in basicObject.ItemList)
            {
                //Nếu CK này ko được chọn để hiển thị
                if (displayedSymbolsString == "all" || displayedSymbolsString.indexOf("'" + itemKey + "'") != -1)
                {
                    chkSymbol = document.getElementById("chk" + itemKey);
                    if (chkSymbol != null && chkSymbol != "undefined")
                    {
                        if (chkSymbol.checked == true)
                            Toggle(itemKey, false);
                    }
                }
            }
        }
    }
    
    else
    {
        var symbol;
        var theTable = document.getElementById("tableQuote");
        var row;
        var oldTopSelectedCount;
        var replacedRow;
        
        if (isShowSeparator == true && selectedCount > 0)
            theTable.rows[headerRowCount + selectedCount - 1].className = "quoteRow";
            
        for (var j=0; j<selectedSymbolList.length;j++)
        {
            symbol = selectedSymbolList[j];
            oldTopSelectedCount = selectedCount;
            row = document.getElementById("tr" + symbol);
            checkbox = document.getElementById("chk" + symbol);
            
            
            if (checkbox != "undefined")
            {
                for (var i=0; i<unselectedSymbolList.length;i++)
                {
                    //Move từ vị trí top xuống vị trí sắp xếp
                    if (unselectedSymbolList[i] > symbol)
                    {
                        replacedRow = theTable.rows[oldTopSelectedCount + headerRowCount + i];
                        replacedRow.parentNode.insertBefore(row, replacedRow);
                        if (Sys.Browser.name == "Microsoft Internet Explorer")
                        {
                            if (Sys.Browser.version <= 6)
                                checkbox.checked = true;
                            
                        }
                        if (isShowSelectedColor == false)
                            SetRowBackColor(row);

                        oldTopSelectedCount--;
                        break;
                    }
                }            
                
            }
        }
    }
 }
 
 //Phần chọn CK hiển thị 
 function DisplayAllLinkClick()
 {
    if (floorType != "MIXED")
    {
        var chkDisplayAll = document.getElementById("chkDisplayAll");
        
        chkDisplayAll.checked = !chkDisplayAll.checked;
        ToggleDisplayAll();
    }
 }
 
 function ToggleDisplayAll()
 {
    if (floorType == "MIXED")
        return;
        
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    var theChooseSymbolsTable = document.getElementById("tableChooseSymbols");
    var theSelectAllSymbolsTable = document.getElementById("tableSelectSymbols");
    
    theSelectAllSymbolsTable.disabled = chkDisplayAll.checked;
    theChooseSymbolsTable.disabled = chkDisplayAll.checked;
    
    var theChooseSymbolsTable = document.getElementById("tableChooseSymbols");
    var theRow;
    var theCell;
    var checkbox;
    
    if (chkDisplayAll.checked == true)
    {
        for (var i=0; i<theChooseSymbolsTable.rows.length;i++)
        {
            theRow = theChooseSymbolsTable.rows[i];
            for (var j=0; j<theRow.cells.length;j++)
            {
                theCell = theRow.cells[j];
                checkbox = theCell.childNodes[0];
                
                checkbox.disabled = true;
            }
        }
    }
    else
    {
        for (var i=0; i<theChooseSymbolsTable.rows.length;i++)
        {
            theRow = theChooseSymbolsTable.rows[i];
            for (var j=0; j<theRow.cells.length;j++)
            {
                theCell = theRow.cells[j];
                checkbox = theCell.childNodes[0];
                
                checkbox.disabled = false;
            }
        }
    }
 }
 function ToggleShowVolumeColor()
 {
    var theTable = document.getElementById("tableQuote"); 
    var row;   
    for(var i= 2; i<theTable.rows.length; i++ )
    {
        row = theTable.rows[i];
        
        if (isShowVolumeColor == true)
        {
            row.cells[0].className = row.cells[10].className + "Code";
            
            row.cells[5].className = row.cells[4].className;
            row.cells[7].className = row.cells[6].className;
            row.cells[9].className = row.cells[8].className;
            
            row.cells[11].className = row.cells[10].className;
            row.cells[12].className = row.cells[10].className;
            
            row.cells[14].className = row.cells[10].className;
            row.cells[16].className = row.cells[15].className;
            row.cells[18].className = row.cells[17].className;
        }
        else
        {
            row.cells[0].className = "cellCode";
            
            row.cells[5].className = "normalVol";
            row.cells[7].className = "normalVol";
            row.cells[9].className = "normalVol";
            
            row.cells[11].className = "normalVol";
            if (row.cells[10].className == "cellCeiling" || row.cells[10].className == "upPrice")
                row.cells[12].className = "upPrice";
            else if (row.cells[10].className == "downPrice" || row.cells[10].className == "cellFloor")
                    row.cells[12].className = "downPrice";
                 else
                    row.cells[12].className = "unchangePrice"; 
                      
            row.cells[14].className = "normalVol";
            row.cells[16].className = "normalVol";
            row.cells[18].className = "normalVol";
        }
    }
 }
 
 function SelectAll()
 {
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    
    if (chkDisplayAll.checked == true)
        return;
    
    var theChooseSymbolsTable = document.getElementById("tableChooseSymbols");
    var theRow;
    var theCell;
    var checkbox;
    
    for (var i=0; i<theChooseSymbolsTable.rows.length;i++)
    {
        theRow = theChooseSymbolsTable.rows[i];
        for (var j=0; j<theRow.cells.length;j++)
        {
            theCell = theRow.cells[j];
            checkbox = theCell.childNodes[0];
            
            checkbox.checked = true;
            theCell.className = "cellChooseSymbolSelected";
            checkbox.className = "chkChooseSymbolSelected";
        }
    }
 }
 
 function ClearAll()
 {
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    
    if (chkDisplayAll.checked == true)
        return;
        
    var theChooseSymbolsTable = document.getElementById("tableChooseSymbols");
    var theRow;
    var theCell;
    var checkbox;
    
    for (var i=0; i<theChooseSymbolsTable.rows.length;i++)
    {
        theRow = theChooseSymbolsTable.rows[i];
        for (var j=0; j<theRow.cells.length;j++)
        {
            theCell = theRow.cells[j];
            checkbox = theCell.childNodes[0];
            
            checkbox.checked = false;
            theCell.className = "cellChooseSymbol";
            checkbox.className = "chkChooseSymbol";
        }
    }
 }
 
 function ChooseSymbolLinkClick(symbol)
 {
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    
    if (chkDisplayAll.checked == true)
        return;
        
    var checkbox = document.getElementById("chkChoose" + symbol);
    
    checkbox.checked = !checkbox.checked;
    ToggleChooseSymbol(symbol);
 }
 
 function ToggleChooseSymbol(symbol)
 {
    var checkbox = document.getElementById("chkChoose" + symbol);
    var td = document.getElementById("tdChoose" + symbol);
    
    if (checkbox.checked == true)
    {
        td.className = "cellChooseSymbolSelected";
        checkbox.className = "chkChooseSymbolSelected";
    }
    else
    {
        td.className = "cellChooseSymbol";
        checkbox.className = "chkChooseSymbol";
    }
 }
 function ShowColumnLinkClick(columnType)
 {
    var checkbox = document.getElementById("chk" + columnType);
    
    checkbox.checked = !checkbox.checked;
 }
 //Phần chọn CK để highlight
 function Toggle(symbol, isFinishBasicRows)
 {
    if (tableType != 0)
        return;
    var checkbox = document.getElementById("chk" + symbol);
    
    //Nếu đang tạo bảng tham chiếu thì thôi, để tăng tốc độ và chống copy rows ko chính xác
    if (isCreatingBasicRows == true)
    {
        checkbox.checked = false;
        return;
    }
        
    var row = document.getElementById("tr" + symbol);
    var theTable = document.getElementById("tableQuote");
    var cellIndex;
    var replacedRow;

    
    if (checkbox.checked == true)
    {        
        var movedPosition = selectedCount + headerRowCount;
        var oldRowIndex = row.rowIndex;
        
        //Chuyển vị trí
        if (showSelectedSymbolsOnTop == true && isFinishBasicRows == false)
        {
            replacedRow = theTable.rows[selectedCount + headerRowCount];
            replacedRow.parentNode.insertBefore(row, replacedRow);
            
            if (isShowSeparator == true)
            {
                //Ẩn thanh phân cách cũ
                if (selectedCount > 0)
                    theTable.rows[selectedCount + headerRowCount - 1].className = "quoteRow";     
                
                //Đặt thanh phân cách mới    
                row.className = "quoteRowSeparator";
            }
            
            if (Sys.Browser.name == "Microsoft Internet Explorer")
            {
                if (Sys.Browser.version <= 6)
                    checkbox.checked = true;
            }
        }
        
        //Lưu vào mảng những mã được chọn
        selectedSymbolList.push(symbol);
          
        //Xóa khỏi mảng những mã ko được chọn
        for (var i=0; i<unselectedSymbolList.length;i++)
        {
            if (unselectedSymbolList[i] == symbol)
            {
                unselectedSymbolList.splice(i,1);
                break;
            }
        }
        
        //Đặt lại màu cho các row bị thay đổi thứ tự
        if (isFinishBasicRows == false && showSelectedSymbolsOnTop == true)
        {
            var index1;
            if (isShowSelectedColor == true)
                index1 = headerRowCount + selectedCount + 1;
            else
                index1 = headerRowCount;
                
            for (var i = index1; i<= oldRowIndex; i++) 
                //Ko phải là row đang được mouseover
                if (theTable.rows[i].id != "tr" + currentHighlightSymbol)
                    SetRowBackColor(theTable.rows[i]);
        }
        
        //Đặt lại màu nền gốc nếu chứng khoán được chọn ko phải đang được highlight
        if ((isShowSelectedColor == true || showSelectedSymbolsOnTop == false) && (currentHighlightSymbol != symbol || (showSelectedSymbolsOnTop == true && oldRowIndex != movedPosition)))
        {
            cellIndex = 0;
            
            row.cells[cellIndex++].style.backgroundColor = backColorSymbolSelected;
            
            row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1SelectedAlt;
            row.cells[cellIndex++].style.backgroundColor = backColor1SelectedAlt;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            
            row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1SelectedAlt;
            row.cells[cellIndex++].style.backgroundColor = backColor1SelectedAlt;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            
            row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            
            if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
                row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            
            var lastIndex;
            if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
                lastIndex = 23
            else
                lastIndex = 22;
                
            for (var i=lastIndex;i<row.cells.length;i++)
                    row.cells[i].style.backgroundColor = backColor1Selected;
        }
        
        selectedCount++;
        
    }
    else
    {    
        //Xóa khỏi mảng những mã được chọn
        for (var i=0; i<selectedSymbolList.length;i++)
        {
            if (selectedSymbolList[i] == symbol)
            {
                selectedSymbolList.splice(i,1);
                break;
            }
        }
        
        var movedPosition = -1;
        var oldRowIndex = row.rowIndex;
        
        //Nếu symbol là mã cuối cùng
        if (unselectedSymbolList.length > 0 && unselectedSymbolList[unselectedSymbolList.length - 1] < symbol)
        {
            //var i = unselectedSymbolList.length;
            unselectedSymbolList.push(symbol);
                
            //if (Sys.Browser.name == "Microsoft Internet Explorer")
            {
                //Chuyển vị trí
                if (showSelectedSymbolsOnTop == true && isFinishBasicRows == false)
                {
                    //Xóa màu highlight cũ
                    UnHighlight(row);
                    
                    //Ẩn thanh phân cách cũ
                    if (isShowSeparator == true && selectedCount > 0)
                        theTable.rows[selectedCount + headerRowCount - 1].className = "quoteRow";   
                    
                    replacedRow = theTable.rows[theTable.rows.length - 1];
                    replacedRow.parentNode.insertBefore(row);
                    
                    //Đặt thanh phân cách mới  
                    if (isShowSeparator == true && selectedCount - 1 > 0)  
                        theTable.rows[selectedCount + headerRowCount - 2].className = "quoteRowSeparator";
                }
                
            }
        }
        else
        //Lưu vào mảng những mã ko được chọn
        for (var i=0; i<unselectedSymbolList.length;i++)
        {
            if (unselectedSymbolList[i] > symbol)
            {
                unselectedSymbolList.splice(i,0,symbol);
                
                //if (Sys.Browser.name == "Microsoft Internet Explorer")
                {
                    //Chuyển vị trí
                    if (showSelectedSymbolsOnTop == true && isFinishBasicRows == false)
                    {
                        //Xóa màu highlight cũ
                        UnHighlight(row);
                        
                        //Ẩn thanh phân cách cũ
                        if (isShowSeparator == true && selectedCount > 0)
                            theTable.rows[selectedCount + headerRowCount - 1].className = "quoteRow";   
                        
                        movedPosition = selectedCount + headerRowCount + i;
                        
                        replacedRow = theTable.rows[movedPosition];
                        replacedRow.parentNode.insertBefore(row, replacedRow);
                        
                        //Đặt thanh phân cách mới  
                        if (isShowSeparator == true && selectedCount - 1 > 0)  
                            theTable.rows[selectedCount + headerRowCount - 2].className = "quoteRowSeparator";
                    }
                    
                }
                break;
            }
        }
        
        //Đặt lại màu cho các row bị thay đổi thứ tự
        if (showSelectedSymbolsOnTop == true)    
        {
            var index1;
            if (isShowSelectedColor == true)
                index1 = headerRowCount + selectedCount - 1;
            else
                index1 = oldRowIndex;
                for (var i = index1; i<= row.rowIndex; i++) 
                    //Ko phải là row đang được mouseover
                    if (theTable.rows[i].id != "tr" + currentHighlightSymbol)
                        SetRowBackColor(theTable.rows[i]);
        }
       
        selectedCount--;
        
    }
    
    createCookie("selectedSymbolList", selectedSymbolList, 1000);
 }
 
 function SetRowBackColor(row)
 {
    var symbol = row.id.substring(2);
    var isChecked = false;
    
    var checkbox = document.getElementById("chk" + symbol);
    if (checkbox == null)
        return;
    isChecked = checkbox.checked;
    
    var cellIndex = 0;
    var colorSymbol;
    var color1, color1Alt, color2;
    
    if (isChecked == true && (isShowSelectedColor == true || showSelectedSymbolsOnTop == false))
    {
        colorSymbol = backColorSymbolSelected;
        color1 = backColor1Selected;
        color2 = backColor2Selected;
        color1Alt = backColor1SelectedAlt;
    }
    else
    {
        if (row.rowIndex%2 == 0)
        {
            colorSymbol = backColorSymbol;
            color1 = backColor1;
            color2 = backColor2;
            color1Alt = backColor1Alt;
        }
        else
        {
            colorSymbol = backColorSymbolR2;
            color1 = backColor1R2;
            color2 = backColor2R2;
            color1Alt = backColor1AltR2;
        }       
    }
     
    row.cells[cellIndex++].style.backgroundColor = colorSymbol;
    
    row.cells[cellIndex++].style.backgroundColor = color2;
    row.cells[cellIndex++].style.backgroundColor = color2;
    row.cells[cellIndex++].style.backgroundColor = color2;
    
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1Alt;
    row.cells[cellIndex++].style.backgroundColor = color1Alt;
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1;
    
    
    row.cells[cellIndex++].style.backgroundColor = color2;
    row.cells[cellIndex++].style.backgroundColor = color2;
    row.cells[cellIndex++].style.backgroundColor = color2;
    
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1Alt;
    row.cells[cellIndex++].style.backgroundColor = color1Alt;
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1;
    
   
    row.cells[cellIndex++].style.backgroundColor = color2;
    row.cells[cellIndex++].style.backgroundColor = color2;
    
    if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
        row.cells[cellIndex++].style.backgroundColor = color2;
    
    row.cells[cellIndex++].style.backgroundColor = color1;
    
    var lastIndex;
    if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
        lastIndex = 23
    else
        lastIndex = 22;
    
    for (var i=lastIndex;i<row.cells.length;i++)
            row.cells[i].style.backgroundColor = color1;
 }
 
 //Lấy dữ liệu mã CK, tham chiếu, trần, sàn từ server
 function GetBasicObject() 
 {	 
    //Xóa bộ định thời cũ
    if (requestTimerID != null)
    {
        clearTimeout(requestTimerID);
        requestTimerID = null;
    }
    
    switch (floorType)
    {
        case "HASTC":
            AlphaStockBoard.UI.HastcStockQuotes.GetStockBoardBasicObject(clientId, currentBasicVersionId, currentLanguage);
            break;
        case "HOSE":
            AlphaStockBoard.UI.HoseStockQuotes.GetStockBoardBasicObject(clientId, currentBasicVersionId, currentLanguage);
            break;
        case "OTC":
            AlphaStockBoard.UI.OtcStockQuotes.GetStockBoardBasicObject(clientId, currentBasicVersionId, currentLanguage);
            break;
        case "MIXED":
            AlphaStockBoard.UI.MixedStockQuotes.GetStockBoardBasicObject(clientId, currentBasicVersionId, currentBasicHoseVersionId, currentBasicHastcVersionId, currentBasicOtcVersionId, currentLanguage);
            break;
    }
    
 }
 
 
 //Kiểm tra dữ liệu có được lấy về từ server ko (kiểm tra đường truyền)
 function CheckResponse()
 {
    //Nếu ko có dữ liệu nào trả về trong khoảng thời gian đã định thì lấy dữ liệu
    if (isResponded == false)
    {
        //Lấy dữ liệu từ sàn
        if (isTradingTime == true)
            StartRequest();
    }
    else
    {
        isResponded = false;
    }
        
 }

 
 //Lấy dữ liệu từ server
 function StartRequest()
 {
    //Xóa bộ định thời cũ
    if (requestTimerID != null)
    {
        clearTimeout(requestTimerID);
        requestTimerID = null;
    }
    
    switch (floorType)
    {
        case "HASTC":
            AlphaStockBoard.UI.HastcStockQuotes.GetStockBoardChangedObject(clientId, currentVersionId, currentLanguage);
            break;
        case "HOSE":
            AlphaStockBoard.UI.HoseStockQuotes.GetStockBoardChangedObject(clientId, currentVersionId, currentMarketVersionId, currentLanguage);
            break;
        case "OTC":
            AlphaStockBoard.UI.OtcStockQuotes.GetStockBoardChangedObject(clientId, currentVersionId, currentLanguage);
            break;
        case "MIXED":
            AlphaStockBoard.UI.MixedStockQuotes.GetStockBoardChangedObject(clientId, currentVersionId, currentMarketVersionId, currentHoseVersionId, currentHastcVersionId, currentOtcVersionId, currentLanguage);
            break;
    }
    
    
 }
 
 function GetStockInfo()
 {
    //Lấy thông tin chứng khoán, tạm thời lấy tất cả thông tin về
    switch (floorType)
    {
        case "HASTC":
            AlphaStockBoard.UI.HastcStockQuotes.GetStockInfoObject(-1, currentLanguage);
            break;
        case "HOSE":
            AlphaStockBoard.UI.HoseStockQuotes.GetStockInfoObject(-1, currentLanguage);
            break;
        case "OTC":
            AlphaStockBoard.UI.OtcStockQuotes.GetStockInfoObject(-1, currentLanguage);
            break;
        case "MIXED":
            AlphaStockBoard.UI.MixedStockQuotes.GetStockInfoObject(-1, currentLanguage);
            break;
    }
 }
 
 function UpdateMarketImmediately()
 {
    if (dataResult.AC != "")
        advancesCount = dataResult.AC;
    if (dataResult.DC != "")
        declinesCount = dataResult.DC;
    if (dataResult.NC != "")
        noChangeCount = dataResult.NC;
    
    UpdateMarketData();
 }
 
 function UpdateMarketData()
 {
    var localizeObject;
    if (currentLanguage == "vi-VN")
        localizeObject = localizeVN;
    else
        localizeObject = localizeEN;
        
    //Thay đổi dữ liệu các chỉ số
    if (dataResult.I != "")
    {
        if (isShowGraph == true && tableType == 0)
        {
            
            
            var graphLink = "<a class='lnkGraph' id='lnkGraph" + floorType + "' href=\"javascript:OpenGraph('" + floorType + "', '" + floorType + "')\"><img width=\"12\" height=\"12\" title='" + localizeObject.GraphIndexLinkTitle + "' src=\"Images\\Graph.png\"/></a>"
            tdIndex.innerHTML = graphLink + " " + dataResult.I;
        }
        else
            tdIndex.innerHTML = dataResult.I;
    }
    
    tdGainersLosers.innerHTML = "<img src=\"images/btup.gif\" /><span class=\"headerInfoValueUp\">" + advancesCount + "</span>";
    tdGainersLosers.innerHTML += " <img src=\"images/btdown.gif\" /><span class=\"headerInfoValueDown\">" + declinesCount + "</span>";
    tdGainersLosers.innerHTML += " <img src=\"images/btnochange.jpg\" /><span class=\"headerInfoValueUnchange\">" + noChangeCount + "</span>";
        
    if (floorType == "HOSE")
    {
        var marketIndices = dataResult.SI.split(";");
        
        //Các chỉ số và thay đổi từng phiên
        if (marketIndices[0] != "")
            UpdateSessionInfoImmediately(tdSession1, marketIndices[0], marketIndices[1], marketIndices[2]);
        
        if (marketIndices[4] != "")
            UpdateSessionInfoImmediately(tdSession2, marketIndices[4], marketIndices[5], marketIndices[6]);
      
        if (marketIndices[8] != "")
            UpdateSessionInfoImmediately(tdSession3, marketIndices[8], marketIndices[9], marketIndices[10]);
         
        tdSession2.style.width = tdSession1.style.width;
        
        //Giá trị giao dịch từng phiên
        if (marketIndices[3] != "")
            tdSession1Trading.innerHTML = marketIndices[3] + " " + localizeObject.currencyUnit;

        if (marketIndices[7] != "")
            tdSession2Trading.innerHTML = marketIndices[7] + " " + localizeObject.currencyUnit;

        if (marketIndices[11] != "")
            tdSession3Trading.innerHTML = marketIndices[11] + " " + localizeObject.currencyUnit;
    }
    else
    if (floorType == "MIXED")
    {
    
        var marketIndices = dataResult.SI.split(";");
        
        //Các chỉ số và thay đổi từng phiên
        if (marketIndices[0] != "")
            UpdateSessionInfoImmediately(tdIndex1, marketIndices[0], marketIndices[1], marketIndices[2]);
        
        if (marketIndices[4] != "")
            UpdateSessionInfoImmediately(tdIndex2, marketIndices[4], marketIndices[5], marketIndices[6]);
      
        if (marketIndices[8] != "")
            UpdateSessionInfoImmediately(tdIndex3, marketIndices[8], marketIndices[9], marketIndices[10]);
         
        tdIndex2.style.width = tdIndex1.style.width;
        
        //Giá trị giao dịch từng phiên
        if (marketIndices[3] != "")
            tdIndex1Trading.innerHTML = marketIndices[3] + " " + localizeObject.currencyUnit;

        if (marketIndices[7] != "")
            tdIndex2Trading.innerHTML = marketIndices[7] + " " + localizeObject.currencyUnit;

        if (marketIndices[11] != "")
            tdIndex3Trading.innerHTML = marketIndices[11] + " " + localizeObject.currencyUnit;
    }
    if (dataResult.TVal != "")
        tdTotalValue.innerHTML = dataResult.TVal + " " + localizeObject.currencyUnit;
    
    if (dataResult.TVol != "")    
        tdTotalMarketVolume.innerHTML = dataResult.TVol;
        
    if (dataResult.MS != "")
        tdMarketStatus.innerHTML = dataResult.MS;
    
    if (dataResult.IC != "")
    {
        if (dataResult.IC.substr(0,1) == "-")
        {
            tdIndex.className = "headerInfoValueDown";
            tdChange.className = "headerInfoValueDown";
            tdChange.innerHTML = dataResult.IC + " <img src=\"images/btdown.gif\" />" + " (" + dataResult.ICP + "%)";
        }
        else
            if (dataResult.IC == "0")
            {
                tdIndex.className = "headerInfoValueUnchange";
                tdChange.className = "headerInfoValueUnchange";
                tdChange.innerHTML = dataResult.IC + " <img src=\"images/btnochange.jpg\" />" + " (" + dataResult.ICP + "%)";
            }
            else
            {
                tdIndex.className = "headerInfoValueUp";
                tdChange.className = "headerInfoValueUp";
                tdChange.innerHTML = dataResult.IC + " <img src=\"images/btup.gif\" />" + " (" + dataResult.ICP + "%)";
            }
     }
 }
 
 function UpdateSessionInfoImmediately(cell, index, change, percent)
 {
    if (change.substr(0,1) == "-")
    {
        cell.className = "sessionInfoValueDown";
        cell.innerHTML = index + "  <img src=\"images/btdown.gif\" /> " + change + " " + " (" + percent + "%)";
    }
    else
        if (change == "0")
        {
            cell.className = "sessionInfoValueUnchange";
            cell.innerHTML = index + "  <img src=\"images/btnochange.jpg\" /> " + change + " " + " (" + percent + "%)";
        }
        else
        {
            cell.className = "sessionInfoValueUp";
            cell.innerHTML = index + "  <img src=\"images/btup.gif\" /> " + change + " " + " (" + percent + "%)";
        }
 }
 
 function UpdateMarket()
 {
    //Xóa đồng hồ đặt xóa màu nền trước đó, chủ động xóa luôn
    if (marketTimerID != null)
    {
        self.clearTimeout(marketTimerID);
        marketTimerID = null;
        ClearMarketBgColor();
    }
    
    
    //Thay đổi màu nền các chỉ số
    if (dataResult.I != "")
        tdIndex.style.backgroundColor = updatingBackColor;      
    
    if (dataResult.AC != "" || dataResult.DC != "" || dataResult.NC != "")
    {
        tdGainersLosers.style.backgroundColor = updatingBackColor;  
        if (dataResult.AC != "")    
            advancesCount = dataResult.AC;
        if (dataResult.DC != "")
            declinesCount = dataResult.DC;
        if (dataResult.NC != "")
            noChangeCount = dataResult.NC;     
    }   
    
    if (floorType == "HOSE")
    {
        var marketIndices = dataResult.SI.split(";");
        if (marketIndices[0] != "")
            tdSession1.style.backgroundColor = updatingBackColor;
        
        if (marketIndices[4] != "")
            tdSession2.style.backgroundColor = updatingBackColor;
            
        if (marketIndices[8] != "")
            tdSession3.style.backgroundColor = updatingBackColor;
        
        if (marketIndices[3] != "")
            tdSession1Trading.style.backgroundColor = updatingBackColor;
            
        if (marketIndices[7] != "")
            tdSession2Trading.style.backgroundColor = updatingBackColor;
            
        if (marketIndices[11] != "")
            tdSession3Trading.style.backgroundColor = updatingBackColor;
    }
    else if (floorType == "MIXED")
    {
        var marketIndices = dataResult.SI.split(";");
        if (marketIndices[0] != "")
            tdIndex1.style.backgroundColor = updatingBackColor;
        
        if (marketIndices[4] != "")
            tdIndex2.style.backgroundColor = updatingBackColor;
            
        if (marketIndices[8] != "")
            tdIndex3.style.backgroundColor = updatingBackColor;
        
        if (marketIndices[3] != "")
            tdIndex1Trading.style.backgroundColor = updatingBackColor;
            
        if (marketIndices[7] != "")
            tdIndex2Trading.style.backgroundColor = updatingBackColor;
            
        if (marketIndices[11] != "")
            tdIndex3Trading.style.backgroundColor = updatingBackColor;
    }
    
    if (dataResult.TVal != "")
        tdTotalValue.style.backgroundColor = updatingBackColor;
    
    if (dataResult.TVol != "")  
        tdTotalMarketVolume.style.backgroundColor = updatingBackColor;  
    
    if (dataResult.IC != "")
        tdChange.style.backgroundColor = updatingBackColor;
        
    if (dataResult.MS != "")
        tdMarketStatus.style.backgroundColor = updatingBackColor;
    
    //Chờ 1 lúc trước khi thay đổi dữ liệu
    marketUpdateDataTimerID = self.setTimeout("DisplayMarketUpdateData()", 500)
 }
 
 function DisplayMarketUpdateData()
 {    
    
    UpdateMarketData();
    
    //Lưu dữ liệu cũ để biết các cell cần xóa màu nền
    marketUpdatingData = dataResult;
    
    //Chờ 1 lúc trước khi xóa màu nền
    marketTimerID = self.setTimeout("ClearMarketBgColor()", 5000)
 }
 
 function ClearMarketBgColor()
 {
    if (marketUpdatingData == null)
        return;
        
    //Thay đổi lại màu nền các chỉ số như cũ
    if (marketUpdatingData.I != "")
        tdIndex.style.backgroundColor = "";     
    
    if (marketUpdatingData.AC != "" || marketUpdatingData.DC != "" || marketUpdatingData.NC != "")
        tdGainersLosers.style.backgroundColor = "";       
        
    if (marketUpdatingData.TVal != "")
        tdTotalValue.style.backgroundColor = "";
    
    if (marketUpdatingData.TVol != "")  
        tdTotalMarketVolume.style.backgroundColor = "";
    
    if (marketUpdatingData.IC != "")
        tdChange.style.backgroundColor = "";
        
    if (marketUpdatingData.MS != "")
        tdMarketStatus.style.backgroundColor = "";
        
    if (floorType == "HOSE")
    {
        var marketIndices = marketUpdatingData.SI.split(";");
        if (marketIndices[0] != "")
            tdSession1.style.backgroundColor = "";
        
        if (marketIndices[4] != "")
            tdSession2.style.backgroundColor = "";
            
        if (marketIndices[8] != "")
            tdSession3.style.backgroundColor = "";
        
        if (marketIndices[3] != "")
            tdSession1Trading.style.backgroundColor = "";
            
        if (marketIndices[7] != "")
            tdSession2Trading.style.backgroundColor = "";
            
        if (marketIndices[11] != "")
            tdSession3Trading.style.backgroundColor = "";
    }
    else if (floorType == "MIXED")
    {
        var marketIndices = marketUpdatingData.SI.split(";");
        if (marketIndices[0] != "")
            tdIndex1.style.backgroundColor = "";
        
        if (marketIndices[4] != "")
            tdIndex2.style.backgroundColor = "";
            
        if (marketIndices[8] != "")
            tdIndex3.style.backgroundColor = "";
        
        if (marketIndices[3] != "")
            tdIndex1Trading.style.backgroundColor = "";
            
        if (marketIndices[7] != "")
            tdIndex2Trading.style.backgroundColor = "";
            
        if (marketIndices[11] != "")
            tdIndex3Trading.style.backgroundColor = "";
    }
    marketUpdatingData = null;    
    marketTimerID = null;
 }
 
 
 //Cập nhật bảng giá
 function StartUpdate()
 {
    if (dataResult == null || basicObject == null)
        return;
        
    if (isUpdatingBasicData == true || isCreatingBasicRows == true)
    {
        var updateLaterTimer = self.setTimeout("UpdateImmediately()", 50)
        return;
    }
    
    //Xóa đồng hồ đặt xóa màu nền trước đó, chủ động xóa luôn
    if (updateTimerID != null)
    {
        self.clearTimeout(updateTimerID);
        updateTimerID = null;
        ClearBgColor();
    }
    
        
    var updateSegmentDataList;
    //Thay đổi dữ liệu và màu nền
    
    updateSegmentDataList = dataResult.ItemList;
    
    updatedCells = new Array();
    var quoteItem;
    var i = 0;
    var valueArray;
    var cellIndex;
    
    for(var item in updateSegmentDataList)
    {    
        quoteItem = updateSegmentDataList[item];
        valueArray = quoteItem.V.split(";");
        changedRow = document.getElementById("tr" + item);
        if (changedRow != null)
        {
            cellIndex = 4;
            if (changedRow.rowIndex%2==0)
            {
                //Bid
                UpdateCellData(item, valueArray[0], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                UpdateCellData(item, valueArray[1], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                UpdateCellData(item, valueArray[2], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1Alt, backColor1SelectedAlt, false)
                UpdateCellData(item, valueArray[3], changedRow.cells[cellIndex++], null, i++, false, backColor1Alt, backColor1SelectedAlt, false)
                UpdateCellData(item, valueArray[4], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                UpdateCellData(item, valueArray[5], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                
                //Match
                UpdateCellData(item, valueArray[6], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor2, backColor2Selected, false)
                UpdateCellData(item, valueArray[7], changedRow.cells[cellIndex++], null, i++, false, backColor2, backColor2Selected, false)
                UpdateCellData(item, valueArray[8], changedRow.cells[cellIndex++], null, i++, true, backColor2, backColor2Selected, true, valueArray[6])
                
                if (isShowVolumeColor == true && valueArray[6] != "")
                {
                    updatedCells[i-3].ExtraCellVolume1 = changedRow.cells[0];
                    updatedCells[i-3].ExtraCellVolume2 = changedRow.cells[12];
                }
                    
                //Ask
                UpdateCellData(item, valueArray[9], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                UpdateCellData(item, valueArray[10], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                UpdateCellData(item, valueArray[11], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1Alt, backColor1SelectedAlt, false)
                UpdateCellData(item, valueArray[12], changedRow.cells[cellIndex++], null, i++, false, backColor1Alt, backColor1SelectedAlt, false)
                UpdateCellData(item, valueArray[13], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                UpdateCellData(item, valueArray[14], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                
                if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED" )
                {
                    //High, Low, Average
                    UpdateCellData(item, valueArray[16], changedRow.cells[cellIndex++], null, i++, true, backColor2, backColor2Selected, false)
                    UpdateCellData(item, valueArray[17], changedRow.cells[cellIndex++], null, i++, true, backColor2, backColor2Selected, false)
                    UpdateCellData(item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor2, backColor2Selected, false)
                    
                    UpdateCellData(item, valueArray[19], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                }
                else
                {
                    //High, Low, Average
                    UpdateCellData(item, valueArray[15], changedRow.cells[cellIndex++], null, i++, true, backColor2, backColor2Selected, false)
                    UpdateCellData(item, valueArray[16], changedRow.cells[cellIndex++], null, i++, true, backColor2, backColor2Selected, false)
                    
                    //Total volume
                    UpdateCellData(item, valueArray[17], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                }
                
                if (floorType == "HASTC" || floorType == "OTC")
                {
                    if (isShowBuyVolume == true)
                    {
                        UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSellVolume == true)
                    {
                        UpdateCellData(item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowBuyOrderCount == true)
                    {
                        UpdateCellData(item, valueArray[22], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSellOrderCount == true)
                    {
                        UpdateCellData(item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(item, valueArray[24], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowForeignSell == true)
                    {
                        UpdateCellData(item, valueArray[25], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(item, valueArray[26], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                }
                else if (floorType == "HOSE")
                {
                    if (isShowSession1Price == true)
                    {
                        if (isShowSession1Volume == true)
                            UpdateCellData(item, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                        else
                            UpdateCellData(item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    }
                    if (isShowSession1Volume == true)
                    {
                        UpdateCellData(item, valueArray[19], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSession2Price == true)
                    {
                        if (isShowSession2Volume == true)
                            UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                        else
                            UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    }
                    if (isShowSession2Volume == true)
                    {
                        UpdateCellData(item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(item, valueArray[22], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowAveragePrice == true)
                    {
                        UpdateCellData(item, valueArray[24], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    }
                }
                else
                if (floorType == "MIXED")
                {
                     if (isShowSession1Price == true)
                    {
                        if (isShowSession1Volume == true)
                            UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                        else
                            UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    }
                    if (isShowSession1Volume == true)
                    {
                        UpdateCellData(item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSession2Price == true)
                    {
                        if (isShowSession2Volume == true)
                            UpdateCellData(item, valueArray[22], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                        else
                            UpdateCellData(item, valueArray[22], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    }
                    if (isShowSession2Volume == true)
                    {
                        UpdateCellData(item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    
                    if (isShowBuyVolume == true)
                    {
                        UpdateCellData(item, valueArray[24], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSellVolume == true)
                    {
                        UpdateCellData(item, valueArray[25], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowBuyOrderCount == true)
                    {
                        UpdateCellData(item, valueArray[26], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSellOrderCount == true)
                    {
                        UpdateCellData(item, valueArray[27], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(item, valueArray[28], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowForeignSell == true)
                    {
                        UpdateCellData(item, valueArray[29], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(item, valueArray[30], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                }
            }
            else
            {
                //Bid
                UpdateCellData(item, valueArray[0], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                UpdateCellData(item, valueArray[1], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                UpdateCellData(item, valueArray[2], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1AltR2, backColor1SelectedAlt, false)
                UpdateCellData(item, valueArray[3], changedRow.cells[cellIndex++], null, i++, false, backColor1AltR2, backColor1SelectedAlt, false)
                UpdateCellData(item, valueArray[4], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                UpdateCellData(item, valueArray[5], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                
                //Match
                UpdateCellData(item, valueArray[6], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor2R2, backColor2Selected, false)
                UpdateCellData(item, valueArray[7], changedRow.cells[cellIndex++], null, i++, false, backColor2R2, backColor2Selected, false)
                UpdateCellData(item, valueArray[8], changedRow.cells[cellIndex++], null, i++, true, backColor2R2, backColor2Selected, true, valueArray[6])
                
                if (isShowVolumeColor == true && valueArray[6] != "")
                {
                    updatedCells[i-3].ExtraCellVolume1 = changedRow.cells[0];
                    updatedCells[i-3].ExtraCellVolume2 = changedRow.cells[12];
                }
               
                //Ask
                UpdateCellData(item, valueArray[9], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                UpdateCellData(item, valueArray[10], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                UpdateCellData(item, valueArray[11], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1AltR2, backColor1SelectedAlt, false)
                UpdateCellData(item, valueArray[12], changedRow.cells[cellIndex++], null, i++, false, backColor1AltR2, backColor1SelectedAlt, false)
                UpdateCellData(item, valueArray[13], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                UpdateCellData(item, valueArray[14], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                
                if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
                {
                    //High, Low, Average
                    UpdateCellData(item, valueArray[16], changedRow.cells[cellIndex++], null, i++, true, backColor2R2, backColor2Selected, false)
                    UpdateCellData(item, valueArray[17], changedRow.cells[cellIndex++], null, i++, true, backColor2R2, backColor2Selected, false)
                    UpdateCellData(item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor2R2, backColor2Selected, false)
                    
                    UpdateCellData(item, valueArray[19], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                }
                else
                {
                    
                    //High, Low, Average
                    UpdateCellData(item, valueArray[15], changedRow.cells[cellIndex++], null, i++, true, backColor2R2, backColor2Selected, false)
                    UpdateCellData(item, valueArray[16], changedRow.cells[cellIndex++], null, i++, true, backColor2R2, backColor2Selected, false)
                    
                    //Total volume
                    UpdateCellData(item, valueArray[17], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    
                }
                if (floorType == "HASTC" || floorType == "OTC")
                {
                    if (isShowBuyVolume == true)
                    {
                        UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSellVolume == true)
                    {
                        UpdateCellData(item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowBuyOrderCount == true)
                    {
                        UpdateCellData(item, valueArray[22], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSellOrderCount == true)
                    {
                        UpdateCellData(item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(item, valueArray[24], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowForeignSell == true)
                    {
                        UpdateCellData(item, valueArray[25], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(item, valueArray[26], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                }
                else if (floorType == "HOSE")
                {
                    if (isShowSession1Price == true)
                    {
                        if (isShowSession1Volume == true)
                            UpdateCellData(item, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                        else
                            UpdateCellData(item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSession1Volume == true)
                    {
                        UpdateCellData(item, valueArray[19], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSession2Price == true)
                    {
                        if (isShowSession2Volume == true)
                            UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                        else
                            UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSession2Volume == true)
                    {
                        UpdateCellData(item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(item, valueArray[22], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowAveragePrice == true)
                    {
                        UpdateCellData(item, valueArray[24], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    }
                }
                else if (floorType == "MIXED")
                {
                    if (isShowSession1Price == true)
                    {
                        if (isShowSession1Volume == true)
                            UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                        else
                            UpdateCellData(item, valueArray[20], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSession1Volume == true)
                    {
                        UpdateCellData(item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSession2Price == true)
                    {
                        if (isShowSession2Volume == true)
                            UpdateCellData(item, valueArray[22], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                        else
                            UpdateCellData(item, valueArray[22], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSession2Volume == true)
                    {
                        UpdateCellData(item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowBuyVolume == true)
                    {
                        UpdateCellData(item, valueArray[24], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSellVolume == true)
                    {
                        UpdateCellData(item, valueArray[25], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowBuyOrderCount == true)
                    {
                        UpdateCellData(item, valueArray[26], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSellOrderCount == true)
                    {
                        UpdateCellData(item, valueArray[27], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(item, valueArray[28], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowForeignSell == true)
                    {
                        UpdateCellData(item, valueArray[29], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(item, valueArray[30], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                }
            }
           
        }
       
    }
 
    //Đặt thời gian xóa màu nền và cập nhật dữ liệu
    updateDataTimerID = self.setTimeout("DisplayUpdateData()", 500)
 }
 
 function UpdateCellData(symbol, data, cell, volumeCell, i, isPrice, backColor, backColorSelected, isPriceChange, currentPrice)
 {
    if (isUpdatingBasicData == true)
        return;
        
    if (data != "") 
    {
        
        var cellInfo = new CellInfo()
        cellInfo.cell = cell
        
        
        if (tableType == 0)
        {
            var chkSymbol = document.getElementById("chk" + symbol);
            cellInfo.checkbox = chkSymbol;
        }
        else
            cellInfo.checkbox = null;
            
        cellInfo.oldBackColor = backColor
        cellInfo.oldBackColorSelected = backColorSelected
        
        cellInfo.data = data
        cellInfo.symbol = symbol
        cellInfo.ExtraCellVolume1 = null;
        cellInfo.ExtraCellVolume2 = null;
        
        updatedCells[i] = cellInfo
        
        if (isPrice == true)
        {
            var basicItem = basicObject.ItemList[symbol];
            var basicValueArray = basicItem.V.split(";");
            
            var basicItemInfo = new BasicItemInfo();
            basicItemInfo.CeilingPrice = basicValueArray[0];
            basicItemInfo.FloorPrice = basicValueArray[1];
            basicItemInfo.ReferencePrice = basicValueArray[2];
            
            if (basicItem != null)
            {
                if (isPriceChange == false)
                {
                    if (data == " ")
                    {
                        cell.className = "normalPrice";
                        if (isShowVolumeColor == true && volumeCell != null)
                            volumeCell.className = "normalPriceCode";
                    }
                    else 
                    //Tăng trần
                    if (data == basicItemInfo.CeilingPrice)
                    {
                        cellInfo.className = "cellCeiling";
                        if (isShowVolumeColor == true && volumeCell != null)
                            volumeCell.className = "cellCeiling";
                    }
                    else
                    //Giảm sàn
                    if (data == basicItemInfo.FloorPrice)
                    {
                        cellInfo.className = "cellFloor";
                        if (isShowVolumeColor == true && volumeCell != null)
                            volumeCell.className = "cellFloor";
                    }
                    else
                    //ATO hoặc ATC
                    if (data == "ATO" || data == "ATC")
                    {    
                        cellInfo.className = "ATOATC";
                        if (isShowVolumeColor == true && volumeCell != null)
                            volumeCell.className = "ATOATC";
                    }else
                    //Tăng giá
                    if (data.length > basicItemInfo.ReferencePrice.length || (data.length == basicItemInfo.ReferencePrice.length && data > basicItemInfo.ReferencePrice))
                    {
                        cellInfo.className = "upPrice";
                        if (isShowVolumeColor == true && volumeCell != null)
                            volumeCell.className = "upPrice";
                    }
                    else
                    //Giảm giá
                    if (data != "0" && (data.length < basicItemInfo.ReferencePrice.length || (data.length == basicItemInfo.ReferencePrice.length && data < basicItemInfo.ReferencePrice)))
                    {
                        cellInfo.className = "downPrice";
                        if (isShowVolumeColor == true && volumeCell != null)
                            volumeCell.className = "downPrice";
                    }
                    //Giá ko đổi
                    else
                    {
                        cellInfo.className = "unchangePrice";
                        if (isShowVolumeColor == true && volumeCell != null)
                            volumeCell.className = "unchangePrice";
                    }
                    
                }
                else
                {
                    //Giảm giá
                    if (data.length > 0 && data.substr(0,1) == "-")
                    {
                        if (isShowVolumeColor == false)
                            cellInfo.className = "downPrice";
                        
                        if (isThreeColors == false)  
                            if (isShowSymbol2 == true) 
                                cellInfo.data = symbol  + " <img src=\"images/btdown.gif\" /> " + data;
                            else
                                cellInfo.data = data  + " <img src=\"images/btdown.gif\" />";

                    }
                    else
                    //Không đổi
                    if (data == "0")
                    {
                        if (isShowVolumeColor == false)
                            cellInfo.className = "unchangePrice"
                        
                        if (isThreeColors == false)    
                            if (isShowSymbol2 == true) 
                            cellInfo.data = symbol;//  + " <img src=\"images/btnochange.jpg\" /> " + data;
                        else
                            cellInfo.data =data + " <img src=\"images/btnochange.jpg\" />";   
                    }
                    //Tăng giá
                    else
                    {
                        if (isShowVolumeColor == false)
                            cellInfo.className = "upPrice" 
                        
                        if (isThreeColors == false)    
                            if (isShowSymbol2 == true) 
                                cellInfo.data = symbol  + " <img src=\"images/btup.gif\" /> +" + data;
                            else
                                cellInfo.data = data  + " <img src=\"images/btup.gif\" />";
                    }
                    
                    if (isThreeColors == true)
                    {
                        if (isShowSymbol2 == true) 
                        {
                            //Giá trần
                            if (currentPrice == basicItemInfo.CeilingPrice)
                            {
                                cellInfo.data = symbol + " " + "CE+" + data;
                            }
                            else 
                            if (currentPrice == basicItemInfo.FloorPrice)
                            {
                                cellInfo.data = symbol + " " + "FL " + data;
                            }
                            else
                                //Giảm giá
                                if (data.length > 0 && data.substr(0,1) == "-")
                                {
                                    cellInfo.data = symbol + " " + data;
                                }
                                else
                                //Không đổi
                                if (data == "0")
                                    cellInfo.data = symbol;
                                else
                                    cellInfo.data = symbol + " +" + data;
                            
                        }
                        else
                        {
                            //Giá trần
                            if (currentPrice == basicItemInfo.CeilingPrice)
                            {
                                cellInfo.data = "CE+" + data;
                            }
                            else 
                            if (currentPrice == basicItemInfo.FloorPrice)
                            {
                                cellInfo.data = "FL " + data;
                            }

                        }
                    }
                    
                }
            }
            
        }
        else
        {
            
        }
        cell.style.backgroundColor = updatingBackColor;
    }
 }
 
 //Kết thúc cập nhật các ô dữ liệu
 function DisplayUpdateData()
 {
    //Nếu đang cập nhật bảng tham chiếu thì cập nhật giá sau 300ms
    if (isUpdatingBasicData == true)
    {
        var updateLaterTimer = self.setTimeout("DisplayUpdateData()", 300)
        return;
    }
        
    var cellInfo
    
    for (var i=0;i<updatedCells.length;i++)
    {
        if (updatedCells[i] != null)
        {
            cellInfo = updatedCells[i]
            cellInfo.cell.innerHTML = cellInfo.data
            
            //Ko có className trong trường hợp là volume
            if (cellInfo.className != "")
            {
                cellInfo.cell.className = cellInfo.className;
                if (cellInfo.ExtraCellVolume1 != null)
                {
                    cellInfo.ExtraCellVolume1.className = cellInfo.className + "Code";//alert(cellInfo.className + "Code");
                    cellInfo.ExtraCellVolume2.className = cellInfo.className;
                }   
            }
        }
    }
    
    //Request tiếp theo
    if (isTradingTime == true && requestTimerID == null)
         requestTimerID = self.setTimeout("StartRequest()", 1500);
    
    clearTimeout(updateTimerID)
    updateTimerID = self.setTimeout("ClearBgColor()", 5000)
 }
 
 //Xóa màu nền
 function ClearBgColor()
 {
    if (isUpdatingBasicData == true)
        return;
        
    var cellInfo
    //Xóa màu nền
    for (var i=0;i<updatedCells.length;i++)
    {
        if (updatedCells[i] != null)
        {
            cellInfo = updatedCells[i]
            
            if (cellInfo.symbol != currentHighlightSymbol)
            {
                if (tableType == 0)
                    if (cellInfo.checkbox != null && cellInfo.checkbox.checked == true && (isShowSelectedColor == true || showSelectedSymbolsOnTop == false))
                        cellInfo.cell.style.backgroundColor=cellInfo.oldBackColorSelected;
                    else
                        cellInfo.cell.style.backgroundColor=cellInfo.oldBackColor;
                else
                    cellInfo.cell.style.backgroundColor=cellInfo.oldBackColor;
            }
            //Nếu đang được highlight
            else
            {
                cellInfo.cell.style.backgroundColor = mouseOverBackColor;
            }
        }
    }
    
    self.clearTimeout(updateTimerID);
    updateTimerID = null;
 }
 
 //Update bảng giá ngay lập tức, ko đặt timer và độ trễ cho cập nhật
 function UpdateImmediately()
 {
    if (dataResult == null)
        return;
    //Nếu đang cập nhật bảng tham chiếu thì cập nhật giá sau 50ms
    if (basicObject == null || isUpdatingBasicData == true || (currentUpdatedIndex >= currentUpdatedBasicIndex))
    {
        var updateLaterTimer = self.setTimeout("UpdateImmediately()", 50)
        return;
    }
        
    var updateSegmentDataList;
    //Thay đổi dữ liệu và màu nền
    updateSegmentDataList = dataResult.ItemList;
    
    var quoteItem;
    var valueArray;
    var i = 0;
    var chkSymbol = null;
    var basicItem;
    var basicValueArray;
    var basicItemInfo;
    

    var i=0;
    var maxIndex;
    var minIndex;
    var cellIndex;
    var item;
    
        
    if (isFinishUpdatingImmediately == true)
    {
        if (isFixSymbolsWhenScroll == true && tableType != 0)
        {
            minIndex = 0;
            maxIndex = oldSelectedSymbolList.length + 2;
        }
        else
        {
            minIndex = 0;
            maxIndex = 2;
        }
    }
    else
    {
        if (currentUpdatedIndex == 0)
            if (isFixSymbolsWhenScroll == true && tableType != 0)
                minIndex = oldSelectedSymbolList.length + 2;
            else
                minIndex = 2;
        else
            minIndex = currentUpdatedIndex;
        maxIndex = currentUpdatedIndex + 30;
        if (maxIndex > currentUpdatedBasicIndex)
            maxIndex = currentUpdatedBasicIndex;
    }
    
    for(i = minIndex; i<maxIndex; i++)
    {    
       
        item = orderedSymbolList[i];
        
        quoteItem = updateSegmentDataList[item];
        if (quoteItem == null)
            continue;
        valueArray = quoteItem.V.split(";");
        changedRow = document.getElementById("tr" + item);
        if (changedRow != null)
        {
            if (tableType == 0)
                chkSymbol = document.getElementById("chk" + item);
                
            basicItem = basicObject.ItemList[item];
            
            if (basicItem != null)// && chkSymbol != null)
            {
                basicValueArray = basicItem.V.split(";");
                
                basicItemInfo = new BasicItemInfo();
                basicItemInfo.CeilingPrice = basicValueArray[0];
                basicItemInfo.FloorPrice = basicValueArray[1];
                basicItemInfo.ReferencePrice = basicValueArray[2];
                basicItemInfo.Symbol = item;
                
                cellIndex = 4;
                if (changedRow.rowIndex%2==0)
                {
                    //Bid
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[0], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[1], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[2], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1Alt, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[3], changedRow.cells[cellIndex++], null, false, backColor1Alt, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[4], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[5], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    
                    //Match
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[6], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor2, backColor2Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[7], changedRow.cells[cellIndex++], null, false, backColor2, backColor2Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[8], changedRow.cells[cellIndex++], null, true, backColor2, backColor2Selected, true, valueArray[6])
                    
                    if (isShowVolumeColor == true && valueArray[6] != "")
                    {
                        changedRow.cells[0].className = changedRow.cells[10].className + "Code";
                        changedRow.cells[12].className = changedRow.cells[10].className;
                    }
                    
                    //Ask
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[9], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[10], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[11], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1Alt, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[12], changedRow.cells[cellIndex++], null, false, backColor1Alt, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[13], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[14], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    
                    if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
                    {
                        //High,Low,Average
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[16], changedRow.cells[cellIndex++], null, true, backColor2, backColor2Selected, false)
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[17], changedRow.cells[cellIndex++], null, true, backColor2, backColor2Selected, false)
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor2, backColor2Selected, false)
                        
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[19], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    }
                    else
                    {
                        //High,Low
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[15], changedRow.cells[cellIndex++], null, true, backColor2, backColor2Selected, false)
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[16], changedRow.cells[cellIndex++], null, true, backColor2, backColor2Selected, false)
                        
                        //Total volume
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[17], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    }
                    
                    if (floorType == "HASTC" || floorType == "OTC")
                    {
                        if (isShowBuyVolume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSellVolume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowBuyOrderCount == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSellOrderCount == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[24], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowForeignSell == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[25], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[26], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                    }
                    else if (floorType == "HOSE")
                    {
                        if (isShowSession1Price == true)
                        {
                            if (isShowSession1Volume == true)
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false) ;
                            else
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false) ;
                            
                        }
                        if (isShowSession1Volume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[19], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSession2Price == true)
                        {
                            if (isShowSession2Volume == true)
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false) 
                            else
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSession2Volume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowAveragePrice == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[24], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false) 
                        }
                    }
                    else
                    if (floorType == "MIXED")
                    {
                        if (isShowSession1Price == true)
                        {
                            if (isShowSession1Volume == true)
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false) ;
                            else
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false) ;
                            
                        }
                        if (isShowSession1Volume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSession2Price == true)
                        {
                            if (isShowSession2Volume == true)
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false) 
                            else
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSession2Volume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowBuyVolume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[24], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSellVolume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[25], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowBuyOrderCount == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[26], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSellOrderCount == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[27], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[28], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowForeignSell == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[29], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[30], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                    }
                }
                else
                {
                    //Bid
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[0], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[1], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[2], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1AltR2, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[3], changedRow.cells[cellIndex++], null, false, backColor1AltR2, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[4], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[5], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    
                    //Match
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[6], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor2R2, backColor2Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[7], changedRow.cells[cellIndex++], null, false, backColor2R2, backColor2Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[8], changedRow.cells[cellIndex++], null, true, backColor2R2, backColor2Selected, true, valueArray[6])
                    
                    if (isShowVolumeColor == true && valueArray[6] != "")
                    {
                        changedRow.cells[0].className = changedRow.cells[10].className + "Code";
                        changedRow.cells[12].className = changedRow.cells[10].className;
                    }
                        
                    //Ask
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[9], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[10], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[11], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1AltR2, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[12], changedRow.cells[cellIndex++], null, false, backColor1AltR2, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[13], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[14], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    
                    if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
                    {
                        //High,Low,Average
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[16], changedRow.cells[cellIndex++], null, true, backColor2R2, backColor2Selected, false)
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[17], changedRow.cells[cellIndex++], null, true, backColor2R2, backColor2Selected, false)
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor2R2, backColor2Selected, false)
                        
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[19], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                        
                    }
                    else
                    {
                        //High,Low,Average
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[15], changedRow.cells[cellIndex++], null, true, backColor2R2, backColor2Selected, false)
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[16], changedRow.cells[cellIndex++], null, true, backColor2R2, backColor2Selected, false)
                        
                        //Total volume
                        UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[17], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    }
                    
                    if (floorType == "HASTC" || floorType == "OTC")
                    {
                        if (isShowBuyVolume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSellVolume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowBuyOrderCount == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSellOrderCount == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[24], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowForeignSell == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[25], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[26], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                    }
                    else if (floorType == "HOSE")
                    {
                        if (isShowSession1Price == true)
                        {
                            if (isShowSession1Volume == true)
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false) 
                            else
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSession1Volume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[19], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSession2Price == true)
                        {
                            if (isShowSession2Volume == true)
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false) 
                            else
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSession2Volume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowAveragePrice == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[24], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false) 
                        }
                    }
                    else if (floorType == "MIXED")
                    {
                        if (isShowSession1Price == true)
                        {
                            if (isShowSession1Volume == true)
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false) 
                            else
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSession1Volume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSession2Price == true)
                        {
                            if (isShowSession2Volume == true)
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false) 
                            else
                                UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSession2Volume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowBuyVolume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[24], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSellVolume == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[25], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowBuyOrderCount == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[26], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSellOrderCount == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[27], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[28], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowForeignSell == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[29], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(chkSymbol, basicItemInfo, valueArray[30], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                    }
                }
           }
        }
       
    }
    
    currentUpdatedIndex = maxIndex;
    
    var itemCount = orderedSymbolList.length;
        
    if (isFinishUpdatingImmediately == false)
    {
        if (currentUpdatedIndex < itemCount)
            var contUpdateRowsTimer = self.setTimeout("UpdateImmediately()", 100);
        else
        {
            isFinishUpdatingImmediately = true;
            currentUpdatedIndex = 0;
            var contUpdateRowsTimer = self.setTimeout("UpdateImmediately()", 100);
        }
    }
    else
        if (isTradingTime == true && requestTimerID == null)
                requestTimerID = self.setTimeout("StartRequest()", 1000)
 }
 
 //Cập nhật ô dữ liệu bảng giá ngay lập tức
 function UpdateCellDataImmediately(chkSymbol, basicItemInfo, data, cell, volumeCell, isPrice, backColor, backColorSelected, isPriceChange, currentPrice)
 {
    
    if (isUpdatingBasicData == true)
        return;
        
    if (data != "") 
    {
        cell.innerHTML = data
        
        if (tableType == 0)
            if (chkSymbol.checked == true && (isShowSelectedColor == true || showSelectedSymbolsOnTop == false))
                cell.style.backgroundColor = backColorSelected;
            else
                cell.style.backgroundColor = backColor; 
        else
            cell.style.backgroundColor = backColor; 
            
        if (isPrice == true)
        {
            
            if (isPriceChange == false)
            {
                if (data == " ")
                {
                    cell.className = "normalPrice";
                    if (isShowVolumeColor == true && volumeCell != null)
                        volumeCell.className = "normalPriceCode";
                }
                else    
                //Tăng trần
                if (data == basicItemInfo.CeilingPrice)
                {
                    cell.className = "cellCeiling";
                    if (isShowVolumeColor == true && volumeCell != null)
                        volumeCell.className = "cellCeiling";
                }
                else
                //Giảm sàn
                if (data == basicItemInfo.FloorPrice)
                {
                    cell.className = "cellFloor";
                    if (isShowVolumeColor == true && volumeCell != null)
                        volumeCell.className = "cellFloor";
                }
                else
                //ATO hoặc ATC
                if (data == "ATO" || data == "ATC")
                {
                    cell.className = "ATOATC";
                    if (isShowVolumeColor == true && volumeCell != null)
                        volumeCell.className = "ATOATC";
                }
                else
                //Tăng giá
                if (data.length > basicItemInfo.ReferencePrice.length || (data.length == basicItemInfo.ReferencePrice.length && data > basicItemInfo.ReferencePrice))
                {
                    cell.className = "upPrice";
                    if (isShowVolumeColor == true && volumeCell != null)
                        volumeCell.className = "upPrice";
                }
                else
                //Giảm giá
                if (data != "0" && (data.length < basicItemInfo.ReferencePrice.length || (data.length == basicItemInfo.ReferencePrice.length && data < basicItemInfo.ReferencePrice)))
                {
                    cell.className = "downPrice";
                    if (isShowVolumeColor == true && volumeCell != null)
                        volumeCell.className = "downPrice";
                }
                //Giá ko đổi
                else
                {
                    cell.className = "unchangePrice";
                    if (isShowVolumeColor == true && volumeCell != null)
                        volumeCell.className = "unchangePrice"; 
                }
                
            }
            else
            {   
                //Giảm giá
                if (data.length > 0 && data.substr(0,1) == "-")
                {
                    if (isShowVolumeColor == false)
                        cell.className = "downPrice"
                    
                    if (isThreeColors == false)   
                        if (isShowSymbol2 == true) 
                            cell.innerHTML = basicItemInfo.Symbol  + " <img src=\"images/btdown.gif\" /> " + data;
                        else
                            cell.innerHTML = data  + " <img src=\"images/btdown.gif\" />";
                }
                else
                //Không đổi
                if (data == "0")
                {
                    if (isShowVolumeColor == false)
                         cell.className = "unchangePrice"
                    
                    if (isThreeColors == false)    
                        if (isShowSymbol2 == true) 
                            cell.innerHTML = basicItemInfo.Symbol;//  + " <img src=\"images/btnochange.jpg\" /> " + data;
                        else
                            cell.innerHTML =data + " <img src=\"images/btnochange.jpg\" />";    
                }
                //Tăng giá
                else
                {
                    if (isShowVolumeColor == false)
                        cell.className = "upPrice" 
                    
                    if (isThreeColors == false)    
                        if (isShowSymbol2 == true) 
                            cell.innerHTML = basicItemInfo.Symbol  + " <img src=\"images/btup.gif\" /> +" + data;
                        else
                            cell.innerHTML = data  + " <img src=\"images/btup.gif\" />";
                }
                
                if (isThreeColors == true)
                {
                    
                    
                    if (isShowSymbol2 == true) 
                    {
                        //Giá trần
                        if (currentPrice == basicItemInfo.CeilingPrice)
                        {
                            cell.innerHTML = basicItemInfo.Symbol + " " + "CE+" + data;
                        }
                        else 
                        if (currentPrice == basicItemInfo.FloorPrice)
                        {
                            cell.innerHTML = basicItemInfo.Symbol + " " + "FL " + data;
                        }
                        else
                            //Giảm giá
                            if (data.length > 0 && data.substr(0,1) == "-")
                            {
                                cell.innerHTML = basicItemInfo.Symbol + " " + data;
                            }
                            else
                            //Không đổi
                            if (data == "0")
                                cell.innerHTML = basicItemInfo.Symbol;
                            else
                                cell.innerHTML = basicItemInfo.Symbol + " +" + data;
                        
                    }
                    else
                    {
                        //Giá trần
                        if (currentPrice == basicItemInfo.CeilingPrice)
                        {
                            cell.innerHTML = "CE+" + data;
                        }
                        else 
                        if (currentPrice == basicItemInfo.FloorPrice)
                        {
                            cell.innerHTML = "FL " + data;
                        }

                        }
                }

            }
        }
    }
 }
 
 //Khi di chuột lên 1 dòng CK
 function OnMouseOverQuote()
 {
    //Nếu đang tạo bảng tham chiếu thì thôi, để tăng tốc độ và chống copy rows ko chính xác
    if (isCreatingBasicRows == true)
        return;
    if (new Date() - latestTime <= 500)
        return;

    if (highlightRow != null)
        UnHighlight(highlightRow);
    Highlight(this);
    highlightRow = this;
    
 }
 
 function Highlight(row)
 {
    
    var cell;
    currentHighlightSymbol = row.id.substring(2);
    
    for (var i=0; i<row.cells.length;i++)
    {
        cell = row.cells[i];
        cell.style.backgroundColor = mouseOverBackColor;
    }
 }
 
 function UnHighlight(row)
 {
    currentHighlightSymbol = "";
    
    var symbol = row.id.substring(2);
    var isChecked = false;
    
    if (tableType == 0)
    {
        var checkbox = document.getElementById("chk" + symbol);
        if (checkbox == null)
            return;
        isChecked = checkbox.checked;
    }
    
    var cell;
    
    for (var i=0; i<row.cells.length;i++)
    {
        cell = row.cells[i];
        switch (i)
        {
            case 0:
                if ((isShowSelectedColor == true || showSelectedSymbolsOnTop == false) && isChecked == true)
                    cell.style.backgroundColor = backColorSymbolSelected;
                else
                    if (row.rowIndex%2 == 0)
                            cell.style.backgroundColor = backColorSymbol;
                        else
                            cell.style.backgroundColor = backColorSymbolR2;
                break;
            case 4:
            case 5:
            case 8:
            case 9:
            case 13:
            case 14:
            case 17:
            case 18:
            case 22:
            case 23:
            case 24:
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            //case 24:
                if ((isShowSelectedColor == true || showSelectedSymbolsOnTop == false) && isChecked == true)
                    cell.style.backgroundColor = backColor1Selected;
                else
                    if (row.rowIndex%2 == 0)
                            cell.style.backgroundColor = backColor1;
                        else
                            cell.style.backgroundColor = backColor1R2;
                break;
            case 1:
            case 2:
            case 3:
            case 10:
            
            case 11:
            case 12:
            
            case 19:
            case 20:
                if ((isShowSelectedColor == true || showSelectedSymbolsOnTop == false) && isChecked == true)
                    cell.style.backgroundColor = backColor2Selected;
                else
                    if (row.rowIndex%2 == 0)
                        cell.style.backgroundColor = backColor2;
                    else
                        cell.style.backgroundColor = backColor2R2;
                break;            
            case 21:
            //case 22:
                if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
                {
                    if ((isShowSelectedColor == true || showSelectedSymbolsOnTop == false) && isChecked == true)
                        cell.style.backgroundColor = backColor2Selected;
                    else
                        if (row.rowIndex%2 == 0)
                            cell.style.backgroundColor = backColor2;
                        else
                            cell.style.backgroundColor = backColor2R2;
                }
                else
                {
                    if ((isShowSelectedColor == true || showSelectedSymbolsOnTop == false) && isChecked == true)
                        cell.style.backgroundColor = backColor1Selected;
                    else
                        if (row.rowIndex%2 == 0)
                                cell.style.backgroundColor = backColor1;
                            else
                                cell.style.backgroundColor = backColor1R2;
                }
                break;
            default:
                if ((isShowSelectedColor == true || showSelectedSymbolsOnTop == false) && isChecked == true)
                    cell.style.backgroundColor = backColor1SelectedAlt;
                else
                    if (row.rowIndex%2 == 0)
                        cell.style.backgroundColor = backColor1Alt;
                    else
                        cell.style.backgroundColor = backColor1AltR2;
                break;
        }
    }
 }
 
  //Khi di chuột ra khỏi 1 dòng CK
 function OnMouseOutQuote()
 {
    //Nếu đang tạo bảng tham chiếu thì thôi, để tăng tốc độ và chống copy rows ko chính xác
    if (isCreatingBasicRows == true)
        return;
        
    UnHighlight(this);

 }
 
 function LoadSymbolsTableForChoose()
 {
    if (isSymbolsForDisplayLoaded == true)
        return;
        
    SetCheckedSymbolsForChoose(true);
    
    isSymbolsForDisplayLoaded = true;
 }
 
 function SetCheckedSymbolsForChoose(insertNewRows)
 {
    var theChooseSymbolsTable = document.getElementById("tableChooseSymbols");
    
    //Xóa các rows hiện tại trên bảng
    if (insertNewRows == true)
        for(var i= theChooseSymbolsTable.rows.length-1; i>=0; i-- )
        {
            theChooseSymbolsTable.deleteRow(i);
        }
    if (basicObject != null && basicObject.ItemList != null && basicObject.ItemCount > 0)
    {             
        var index = 0;
        var chooseSymbolNewRow;
        var chooseSymbolNewCell;
        
        //Tạo rows mới
        for(var itemKey in basicObject.ItemList)
        {
            if (insertNewRows == true)
            {
                //Tạo dòng mới cho bảng chọn CK
                if (index%15 == 0)
                {
                    chooseSymbolNewRow = theChooseSymbolsTable.insertRow(-1);
                }
                
                //Thêm CK vào bảng chọn CK để hiển thị
                chooseSymbolNewCell = chooseSymbolNewRow.insertCell(-1);
                chooseSymbolNewCell.id = "tdChoose" + itemKey;
            }
            else
                chooseSymbolNewCell = document.getElementById("tdChoose" + itemKey);
            
            if (chooseSymbolNewCell != null && chooseSymbolNewCell != "undefined")
            {
                //Nếu trước đó mã CK này được chọn
                if (displayedSymbolsSelectedString.indexOf("'" + itemKey + "'") != -1)
                {
                    chooseSymbolNewCell.className = "cellChooseSymbolSelected";
                    chooseSymbolNewCell.innerHTML = "<input type=\"checkbox\" class=\"chkChooseSymbolSelected\" checked=\"true\" id=\"chkChoose" + itemKey + "\" name=\"" + itemKey + "\" onClick=\"ToggleChooseSymbol('" + itemKey + "');\"/><a href=\"javascript:ChooseSymbolLinkClick('" + itemKey + "')\">" + itemKey + "</a>";
                }
                else
                {
                    chooseSymbolNewCell.className = "cellChooseSymbol";
                    chooseSymbolNewCell.innerHTML = "<input type=\"checkbox\" class=\"chkChooseSymbol\" id=\"chkChoose" + itemKey + "\" name=\"" + itemKey + "\" onClick=\"ToggleChooseSymbol('" + itemKey + "');\"/><a href=\"javascript:ChooseSymbolLinkClick('" + itemKey + "')\">" + itemKey + "</a>";
                }
            }
            index++;
        }
    }
    
    if (floorType != "MIXED")
    {
        var chkDisplayAll = document.getElementById("chkDisplayAll");
        if (displayedSymbolsString == "all")
            chkDisplayAll.checked = true;
        else
            chkDisplayAll.checked = false;
        ToggleDisplayAll();
    }
 }
 
 function CreateExtraHeaderCells(tableId)
 {
    
    var theTable = document.getElementById(tableId);
    var theHeaderRow = theTable.rows[0];
    var isNone = false;
    
    if (theHeaderRow.style.display == "none")
    {
        isNone = true;
        theHeaderRow.style.display = "block";
    }
    var lastIndex;
    if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
        lastIndex = 11;
    else
        lastIndex = 10;
            
    for(var i=theHeaderRow.cells.length-1;i>=lastIndex + 1; i--)
    {
        theHeaderRow.deleteCell(i);
    }
    
    var headerCell;
     if (currentLanguage == "vi-VN")
    {
        localizeObject = localizeVN;
    }
    else
    {
        localizeObject = localizeEN;
    }
    
    if (floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED")
        columnCount = 24;
    else
        columnCount = 23;
    
    
    //Thêm các cột phụ
    if (isShowSession1Price == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.Session1Price;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;
 
        columnCount++;
    }
    
    if (isShowSession1Volume == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.Session1Volume;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isShowSession2Price == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.Session2Price;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isShowSession2Volume == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.Session2Volume;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    if (isShowBuyVolume == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.BuyVolume;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isShowSellVolume == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.SellVolume;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isShowBuyOrderCount == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.BuyOrderCount;
        headerCell.className = "tableHeader7";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isShowSellOrderCount == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.SellOrderCount;
        headerCell.className = "tableHeader7";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    
    
    if (isShowForeignBuy == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.ForeignBuy;
        headerCell.className = "tableHeader8";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isShowForeignSell == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.ForeignSell;
        headerCell.className = "tableHeader8";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isShowCurrentRoom == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.CurrentRoom;
        headerCell.className = "tableHeader8";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isShowAveragePrice == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.average;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;

        columnCount++;
    }
    
    if (isNone == true)
        theHeaderRow.style.display = "none";

 }
 
 function CreateBasicRows(setClientInfo)
 {
    isFinishUpdatingImmediately = false;
    
    //Lấy lại dữ liệu mới nhất sau khi nạp bảng tham chiếu
    currentVersionId = 0;
    
    if (floorType == "HOSE")
        currentMarketVersionId = 0;
        
    //Lấy dữ liệu
    if (setClientInfo == true)
        SetClientInfoAndGetData();
    else
        StartRequest();
        
    var tableQuote = document.getElementById("tableQuote");
    var tableFixedHeader = document.getElementById("tableFixedHeader");
    var theTable;
    
    var tdDate = document.getElementById("tdDate");
    var graphLink = "";
    
    if (basicObject == null || basicObject.ItemList == null)
        return;
    
    isCreatingBasicRows = true;
    isUpdatingBasicData = true;
    
    tdDate.innerHTML = basicObject.Date;            

    
    for(var i= tableQuote.rows.length-1; i>=0; i-- )
    {
        if (i >= headerRowCount)
            tableQuote.deleteRow(i);
    }
    
    //Nếu là fix CK được chọn
    if (isFixSymbolsWhenScroll == true)
    {
        for(var i= tableFixedHeader.rows.length-1; i>=0; i-- )
        {
            if (i >= headerRowCount)
                tableFixedHeader.deleteRow(i);
        }
    }

    var basicItem;
    var valueArray;
    var newRow;
    var newCell;
    
    var fontStyle1;
    var fontStyle2;
    
    if (fontStyle == 0)
    {
        fontStyle1 = "normal";
        fontStyle2 = "normal";
    }
    else if (fontStyle == 1)
        {
            fontStyle1 = "normal";
            fontStyle2 = "bold";
        }
        else
        {
            fontStyle1 = "bold";
            fontStyle2 = "bold";
        }
    
    //Lưu lại mảng những CK được chọn
    oldSelectedSymbolList = selectedSymbolList;
    oldUnselectedSymbolList = unselectedSymbolList;
    
    //Khởi tạo lại từ đầu
    selectedSymbolList = new Array();
    unselectedSymbolList = new Array();
    selectedCount = 0;
    var i = 0;
    currentUpdatedBasicIndex = 0;
    
    var tempSelectedSymbolString = oldSelectedSymbolList.join();
    orderedSymbolList = new Array();
    
    var itemKey;
    
    //Nếu là hiển thị các mã được chọn theo thứ tự ABC
    if (isOrderSelectedSymbols == true)
    {
        for(var itemKey in basicObject.ItemList)
        {
            if (tempSelectedSymbolString.indexOf(itemKey) >= 0 && (displayedSymbolsString == "all" || displayedSymbolsString.indexOf("'" + itemKey + "'") >= 0))
                orderedSymbolList.push(itemKey);
        }
    }
    else
    {
        for(var i = 0;i<= oldSelectedSymbolList.length-1;i++)
        {
            itemKey = oldSelectedSymbolList[i];
            if (basicObject.ItemList[itemKey] != null && (displayedSymbolsString == "all" || displayedSymbolsString.indexOf("'" + itemKey + "'") >= 0))
                orderedSymbolList.push(itemKey);
        }
    }
    
    var selectedSymbolsCount = orderedSymbolList.length;

    for(var itemKey in basicObject.ItemList)
    {
        if (tempSelectedSymbolString.indexOf(itemKey) == -1 && (displayedSymbolsString == "all" || displayedSymbolsString.indexOf("'" + itemKey + "'") >= 0))
            orderedSymbolList.push(itemKey);
    }
    
    
    var maxBasicIndex;
    
    //Nếu là fix khi cuộn thì tạo các row selected trên bảng header tĩnh
    if (isFixSymbolsWhenScroll == true && tableType != 0)
    {
        maxBasicIndex = selectedSymbolsCount;
        theTable = tableFixedHeader;
    }
    else
    {
        maxBasicIndex = 30;
        if (orderedSymbolList.length < 30)
            maxBasicIndex = orderedSymbolList.length;
        theTable = tableQuote;
    }
    
    var localizeObject;
    
    if (currentLanguage == "vi-VN")
        localizeObject = localizeVN;
    else
        localizeObject = localizeEN;
        
    //Tạo rows mới
    for (currentUpdatedBasicIndex=0; currentUpdatedBasicIndex< maxBasicIndex; currentUpdatedBasicIndex++)
    {
        itemKey = orderedSymbolList[currentUpdatedBasicIndex];
        //Thêm dòng và ô vào bảng thông tin CK
        unselectedSymbolList.push(itemKey);
        
        basicItem = basicObject.ItemList[itemKey];
        valueArray = basicItem.V.split(";");
        
        if (isShowGraph == true)
            graphLink = "<a class='lnkGraph' id='lnkGraph" + itemKey + "' href=\"javascript:OpenGraph('" + itemKey + "', '" + floorType + "')\"><img width=\"12\" height=\"12\" title='" + localizeObject.GraphLinkTitle + "' src=\"Images\\Graph.png\"/></a>"
        
        //Row đầu tiên thì tự tạo
        if (currentUpdatedBasicIndex == 0)
        {
            if (isFixSymbolsWhenScroll == true && tableType != 0)
                newRow = InsertFirstRow(theTable, itemKey, graphLink, fontStyle1, fontStyle2, valueArray, false, false);
            else
                newRow = InsertFirstRow(theTable, itemKey, graphLink, fontStyle1, fontStyle2, valueArray, true, true);
        }
        //Các row tiếp theo thì copy để tăng tốc độ
        else
        {
            newRow = InsertNextRow(theTable, itemKey, graphLink, fontStyle1, fontStyle2, valueArray, currentUpdatedBasicIndex, false);
        }        
    }
    
    //Nếu là fix các mã được chọn thì tạo 2 dòng đầu tiên cho bảng cuộn
    if (isFixSymbolsWhenScroll == true && tableType != 0)
    {
        maxBasicIndex = currentUpdatedBasicIndex + 2;
        if (orderedSymbolList.length < maxBasicIndex)
            maxBasicIndex = orderedSymbolList.length;
            
        theTable = tableQuote;
        var rowIndex = 0;
        
        for (;currentUpdatedBasicIndex< maxBasicIndex; currentUpdatedBasicIndex++)
        {
            itemKey = orderedSymbolList[currentUpdatedBasicIndex];
            //Thêm dòng và ô vào bảng thông tin CK
            unselectedSymbolList.push(itemKey);
            
            basicItem = basicObject.ItemList[itemKey];
            valueArray = basicItem.V.split(";");
            
            if (isShowGraph == true)
                graphLink = "<a class='lnkGraph' id='lnkGraph" + itemKey + "' href=\"javascript:OpenGraph('" + itemKey + "', '" + floorType + "')\"><img width=\"12\" height=\"12\" title='" + localizeObject.GraphLinkTitle + "' src=\"Images\\Graph.png\"/></a>"
            
            //Row đầu tiên thì tự tạo
            if (rowIndex == 0)
            {
                if (isFixSymbolsWhenScroll == true && tableType != 0)
                    newRow = InsertFirstRow(theTable, itemKey, graphLink, fontStyle1, fontStyle2, valueArray, true, true);
                else
                    newRow = InsertFirstRow(theTable, itemKey, graphLink, fontStyle1, fontStyle2, valueArray, false, false);
            }
            //Các row tiếp theo thì copy để tăng tốc độ
            else
            {
                newRow = InsertNextRow(theTable, itemKey, graphLink, fontStyle1, fontStyle2, valueArray, rowIndex, true);
            }   
            
            rowIndex++;
        }
    }
    
    isUpdatingBasicData = false;
    
    var itemCount;
    if (displayedSymbolsString == "all")
        itemCount = basicObject.ItemCount;
    else
        itemCount = displayedSymbolList.length;
        
    //Nếu chưa cập nhật hết thì đặt đồng hồ để tiếp tục cập nhật sau 100ms
    if (currentUpdatedBasicIndex <  itemCount)
        var contCreateBasicRowsTimer = self.setTimeout("CreateBasicRowsCont()", 10);
    else
        FinishCreateBasicRows();
 }
 
  function CreateBasicRowsCont()
 {
    isUpdatingBasicData = true;
    var theTable = document.getElementById("tableQuote");
    var basicItem;
    var valueArray;
    var newRow;
    var newCell;
    

    var maxBasicIndex = currentUpdatedBasicIndex + 30;
    if (orderedSymbolList.length < maxBasicIndex)
        maxBasicIndex = orderedSymbolList.length;
    
    var itemKey;
    
    var localizeObject;
    
    if (currentLanguage == "vi-VN")
        localizeObject = localizeVN;
    else
        localizeObject = localizeEN;
            
    //Tạo rows mới
    for (;currentUpdatedBasicIndex< maxBasicIndex; currentUpdatedBasicIndex++)
    {

        itemKey = orderedSymbolList[currentUpdatedBasicIndex];
            
        if (currentUpdatedBasicIndex%2 == 0)
            newRow = theTable.rows[2].cloneNode(true);
        else
            newRow = theTable.rows[3].cloneNode(true);
        
        
        newRow.id="tr" + itemKey;
        theTable.rows[2].parentNode.appendChild(newRow);

        var graphLink = "";
        
        if (isShowGraph == true)
            graphLink = "<a class='lnkGraph' id='lnkGraph" + itemKey + "' href=\"javascript:OpenGraph('" + itemKey + "', '" + floorType + "')\"><img width=\"12\" height=\"12\" title='" + localizeObject.GraphLinkTitle + "' src=\"Images\\Graph.png\"/></a>"
        
        
        if (tableType == 0)
            if (stockUrl == "")
                newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/>" + graphLink + itemKey;                
            else
                newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/>" + graphLink + "<a id='lnk" + itemKey + "' href='" + stockUrl + itemKey + stockUrl2 + "'>" + itemKey + "</a>";
           
        else
            if (stockUrl == "")
                newRow.cells[0].innerHTML = itemKey;
            else
                newRow.cells[0].innerHTML = "<a href='" + stockUrl + itemKey+ stockUrl2 + "'>" + itemKey + "</a>";
            
                
        //Thêm dòng và ô vào bảng thông tin CK
        unselectedSymbolList.push(itemKey);
        
        basicItem = basicObject.ItemList[itemKey];
        valueArray = basicItem.V.split(";");
        
        newRow.cells[1].innerHTML = valueArray[0];
        newRow.cells[2].innerHTML = valueArray[1];
        newRow.cells[3].innerHTML = valueArray[2];  
        
        newRow.onmouseover = OnMouseOverQuote;
        newRow.onmouseout = OnMouseOutQuote;
                  
    }
    
    isUpdatingBasicData = false;
    
    var itemCount;
    if (displayedSymbolsString == "all")
        itemCount = basicObject.ItemCount;
    else
        itemCount = displayedSymbolList.length;
    
    //Nếu chưa cập nhật hết thì đặt đồng hồ để tiếp tục cập nhật sau 100ms
    if (currentUpdatedBasicIndex <  itemCount)
        var contCreateBasicRowsTimer = self.setTimeout("CreateBasicRowsCont()", 1)
    else
        FinishCreateBasicRows();
 }
 
 function FinishCreateBasicRows()
 {
    isUpdatingBasicData = true;
    isCreatingBasicRows = false; //Để cho phép Toggle symbol
    
    if (tableType == 0)
    {
        //Check vào những mã CK được chọn trước đó
        var selectedSymbol;
        
        for (var i=0; i<oldSelectedSymbolList.length;i++)
        {
            selectedSymbol = oldSelectedSymbolList[i];
            var chkSymbol = document.getElementById("chk" + selectedSymbol);
            
            if (chkSymbol != null && chkSymbol != "undefined")
            {
                chkSymbol.checked = true;
                Toggle(selectedSymbol, true);
            }
        }
        
        if (showSelectedSymbolsOnTop == true && isShowSeparator == true && selectedCount > 0)
        {
            var theTable = document.getElementById("tableQuote");
            theTable.rows[selectedCount + headerRowCount - 1].className = "quoteRowSeparator";
        }

    }
    else
    {
        unselectedSymbolList = oldUnselectedSymbolList;
        selectedSymbolList = oldSelectedSymbolList;
    }


    isUpdatingBasicData = false;
    
    if (isPutThroughDisplayed == true)
        GetPutThroughObject();
        
    if (isShowTooltip == true && tableType == 0)    
    {
        var stockInfoTimerID = self.setTimeout("UpdateStockInfoTooltip()", 2000);
    }
 }
 
 function InsertNewCell(newRow, className, width, style, isSetCellWidth, value)
 {
    var newCell = newRow.insertCell(-1);
    newCell.className = className;
    if (isSetCellWidth == true)
        newCell.style.width = width;
    newCell.style.fontWeight = style;
    if (value != null)
        newCell.innerHTML = value;
    return newCell;
 }
 
 function InsertFirstRow(theTable, itemKey, graphLink, fontStyle1, fontStyle2, valueArray, isSetCellWidth, isSetCellWidth2)
 {
    var newRow = theTable.insertRow(-1);
    newRow.style.height = rowHeight;
    newRow.id="tr" + itemKey;
    newRow.onmouseover = OnMouseOverQuote;
    newRow.onmouseout = OnMouseOutQuote;
    
    var newCell = newRow.insertCell(-1);
    newCell.className = "cellCode";
    
    if (tableType == 0)
    {
        if (stockUrl == "")
            newCell.innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/>" + graphLink + itemKey;                
        else
            newCell.innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/>" + graphLink + "<a id='lnk" + itemKey + "' href='" + stockUrl + itemKey+ stockUrl2 + "'>" + itemKey + "</a>";
    }
    else
    {
        newCell.style.fontSize = "12pt";
        newCell.style.paddingLeft = "4px";
        
        if (stockUrl == "")
            newCell.innerHTML = itemKey;
        else
            newCell.innerHTML = "<a href='" + stockUrl + itemKey + stockUrl2 + "'>" + itemKey + "</a>";
    }
    
    if (isSetCellWidth == true)
        newCell.style.width = "5%";
        
    newCell.style.fontWeight = fontStyle2;
    newCell.style.wordWrap = "normal";
    
    InsertNewCell(newRow, "cellCeiling", "3%", fontStyle2, isSetCellWidth, valueArray[0]);
    InsertNewCell(newRow, "cellFloor", "3%", fontStyle2, isSetCellWidth, valueArray[1]);
    InsertNewCell(newRow, "cellRef", "3%", fontStyle2, isSetCellWidth, valueArray[2]);

    newRow.cells[0].style.backgroundColor = backColorSymbol;
    newRow.cells[1].style.backgroundColor = backColor2;
    newRow.cells[2].style.backgroundColor = backColor2;
    newRow.cells[3].style.backgroundColor = backColor2; 
    
    InsertNewCell(newRow, "normalPrice", "3%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalVol", "3.5%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalPrice", "3%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalVol", "3.5%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalPrice", "3%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalVol", "3.5%", fontStyle1, isSetCellWidth);
    
    InsertNewCell(newRow, "normalMatchingPrice", "3.5%", fontStyle2, isSetCellWidth);
    InsertNewCell(newRow, "normalMatchingVol", "3.5%", fontStyle2, isSetCellWidth);
    newCell = InsertNewCell(newRow, "normalChange", "4.5%", fontStyle2, isSetCellWidth);
    newCell.style.wordWrap = "normal";
    
    if (isShowSymbol2 == true)
    {
        newCell.style.textAlign = "left";
        newCell.style.paddingLeft = "3px";
    }
    
    InsertNewCell(newRow, "normalPrice", "3%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalVol", "3.5%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalPrice", "3%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalVol", "3.5%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalPrice", "3%", fontStyle1, isSetCellWidth);
    InsertNewCell(newRow, "normalVol", "3.5%", fontStyle1, isSetCellWidth);
                
    InsertNewCell(newRow, "normalHighLowPrice", "3.8%", fontStyle2, isSetCellWidth);
    InsertNewCell(newRow, "normalHighLowPrice", "3.8%", fontStyle2, isSetCellWidth);
    
 
    switch (floorType)
    {
        case "HASTC":
        case "OTC":
        case "MIXED":
            InsertNewCell(newRow, "normalHighLowPrice", "3.8%", fontStyle2, isSetCellWidth);
            InsertNewCell(newRow, "normalVol", "3.8%", fontStyle1, isSetCellWidth);
            
            if (floorType == "MIXED")
            {
                 if (isShowSession1Price == true)
                    InsertNewCell(newRow, "normalPrice", "3.8%", fontStyle1, isSetCellWidth2);                 
                
                if (isShowSession1Volume == true)
                    InsertNewCell(newRow, "normalVol", "3.8%", fontStyle1, isSetCellWidth2);
                
                if (isShowSession2Price == true)
                    InsertNewCell(newRow, "normalPrice", "3.5%", fontStyle1, isSetCellWidth2);                 
                
                if (isShowSession2Volume == true)
                    InsertNewCell(newRow, "normalVol", "3.5%", fontStyle1, isSetCellWidth2);
            }
            
            if (isShowBuyVolume == true)
                InsertNewCell(newRow, "extraBuyVol", "3.8%", fontStyle1, isSetCellWidth2);
            
            if (isShowSellVolume == true)
                InsertNewCell(newRow, "extraSellVol", "3.8%", fontStyle1, isSetCellWidth2);
            
            if (isShowBuyOrderCount == true)
                InsertNewCell(newRow, "extraBuyVol", "3.5%", fontStyle1, isSetCellWidth2);
            
            if (isShowSellOrderCount == true)
                InsertNewCell(newRow, "extraSellVol", "3.5%", fontStyle1, isSetCellWidth2);
            
            if (isShowForeignBuy == true)
                InsertNewCell(newRow, "extraBuyVol", "3.8%", fontStyle1, isSetCellWidth2);
            
            if (isShowForeignSell == true)
                InsertNewCell(newRow, "extraSellVol", "3.8%", fontStyle1, isSetCellWidth2);
            
            if (isShowCurrentRoom == true)
                InsertNewCell(newRow, "extraSellVol", "3.8%", fontStyle1, isSetCellWidth2);
                
            break;
        case "HOSE":
            InsertNewCell(newRow, "normalVol", "3.8%", fontStyle1, isSetCellWidth);
                            
            if (isShowSession1Price == true)
                InsertNewCell(newRow, "normalPrice", "3.8%", fontStyle1, isSetCellWidth2);                 
            
            if (isShowSession1Volume == true)
                InsertNewCell(newRow, "normalVol", "3.8%", fontStyle1, isSetCellWidth2);
            
            if (isShowSession2Price == true)
                InsertNewCell(newRow, "normalPrice", "3.5%", fontStyle1, isSetCellWidth2);                 
            
            if (isShowSession2Volume == true)
                InsertNewCell(newRow, "normalVol", "3.5%", fontStyle1, isSetCellWidth2);
                
            if (isShowForeignBuy == true)
                InsertNewCell(newRow, "extraBuyVol", "3.5%", fontStyle1, isSetCellWidth2);
           
            if (isShowCurrentRoom == true)
                InsertNewCell(newRow, "extraSellVol", "3.8%", fontStyle1, isSetCellWidth2);
           
            if (isShowAveragePrice == true)
                InsertNewCell(newRow, "normalPrice", "3.5%", fontStyle1, isSetCellWidth2);
                
            break;                    
    }
    return newRow;
 }
 
 
 function InsertNextRow(theTable, itemKey, graphLink, fontStyle1, fontStyle2, valueArray, rowIndex, isSetCellWidth)
 {
    var newRow;
    if (rowIndex == 1)
    {        
        newRow = theTable.rows[2].cloneNode(true);
        theTable.rows[2].parentNode.appendChild(newRow);
        
        newRow.cells[0].style.backgroundColor = backColorSymbolR2;
        newRow.cells[1].style.backgroundColor = backColor2R2;
        newRow.cells[2].style.backgroundColor = backColor2R2;
        newRow.cells[3].style.backgroundColor = backColor2R2;
    }
    else
        if (rowIndex%2 == 0)
        {
            newRow = theTable.rows[2].cloneNode(true);
            theTable.rows[2].parentNode.appendChild(newRow);
        }
        else
        {
            newRow = theTable.rows[3].cloneNode(true);
            theTable.rows[3].parentNode.appendChild(newRow);
        }
    
    newRow.id="tr" + itemKey;
    
    if (tableType == 0)
        if (stockUrl == "")
            newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/>" + graphLink + itemKey;                
        else
            newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/>" + graphLink + "<a id='lnk" + itemKey + "' href='" + stockUrl + itemKey + stockUrl2 + "'>" + itemKey + "</a>";
        
    else
        if (stockUrl == "")
            newRow.cells[0].innerHTML = itemKey;
        else
            newRow.cells[0].innerHTML = "<a href='" + stockUrl + itemKey+ stockUrl2 + "'>" + itemKey + "</a>";
        
        
    newRow.cells[1].innerHTML = valueArray[0];
    newRow.cells[2].innerHTML = valueArray[1];
    newRow.cells[3].innerHTML = valueArray[2];  
    
    newRow.onmouseover = OnMouseOverQuote;
    newRow.onmouseout = OnMouseOutQuote;
 }
 
 
function GetStockBoardChangedObjectSucceededCallback(result, userContext, methodName)
{ 
    switch(methodName)
    {
        case ("GetStockBoardBasicObject"):
        {
        
            if (result != null)
            {
                isTradingTime = result.IsTradingTime;
                
                //Thoát nếu versionId=0, nghĩa là ko có dữ liệu version cần cập nhật
                if (result.VId == 0)
                    break;
                
                //Nếu dữ liệu cũ hơn dữ liệu hiện tại thì ko cập nhật
                if (result.VId < currentBasicVersionId)
                    break;
                    
                //Lưu lại versionId
                currentBasicVersionId = result.VId;
                
                var serverTime = result.Time.split(":");
                var currentClientTime = new Date();
                
                deltaHours = serverTime[0] - currentClientTime.getHours();
                deltaMinutes = serverTime[1] - currentClientTime.getMinutes();
                deltaSeconds = serverTime[2] - currentClientTime.getSeconds();
                
                tdConnectedClientCount.innerHTML = result.Connected;
                
                //Nếu có dữ liệu thì nạp lại bảng tham chiếu
                if (result.ItemList != null && result.ItemCount > 0)
                {
                    //Để lần sau load lại danh sách CK cho chọn để hiển thị
                    isSymbolsForDisplayLoaded = false;
                    
                    //Nếu đang hiển thị danh sách CK để hiển thị thì phải load lại
                    if (isOptionDisplayed == true)
                        LoadSymbolsTableForChoose();
                    
                    //Lưu lại dữ liệu
                    basicObject = result;
                    
                    //Lấy thông tin chứng khoán
                    if (isShowTooltip == true)
                        GetStockInfo();
                    
                    //Tạo lại danh sách bảng tham chiếu
                    CreateBasicRows(false);
                  
                }    
                
            }
            break;
        }
        case ("SetClientInfoAndGetData"):
        case ("GetStockBoardChangedObject"):
        {
            //Đã có dữ liệu trả về từ server
            isResponded = true; 
            
            if (result == null)
            {
                if (isTradingTime == true && requestTimerID == null)
                    requestTimerID = self.setTimeout("StartRequest()", 2000)
                break;
            }
            
            //Nếu trả về -1 nghĩa là versionId của client đã cũ, cần load lại bảng giá tham chiếu
            if (result.VId == -1)
            {
                GetBasicObject();
                if (isTradingTime == true && requestTimerID == null)
                    requestTimerID = self.setTimeout("StartRequest()", 2000)
                break;
            }
            
            //Nếu dữ liệu này cũ hơn dữ liệu hiện tại thì ko cập nhật
            if (result.VId < currentVersionId)
                break;
            if (floorType == "HOSE")
                if (result.MVId < currentMarketVersionId)
                    break;
            
             
            dataResult = result.Data;
            
            if (dataResult != null)
            {              
                //Lần đầu tiên load nên cập nhật ngay lập tức
                if (currentVersionId == 0)
                {
                    currentVersionId = result.VId;
                    
                    if (floorType == "HOSE")
                        currentMarketVersionId = result.MVId;
                        
                    if (floorType == "MIXED")
                    {
                        currentMarketVersionId = result.MVId;
                        currentHoseVersionId = result.HoseVId;
                        currentHastcVersionId = result.HastcVId;
                        currentOtcVersionId = result.OtcVId;
                    }
                    
                    UpdateMarketImmediately();
                    
                    currentUpdatedIndex = 0;
                    UpdateImmediately();

                }
                else
                {
                    currentVersionId = result.VId;
                    
                    if (floorType == "HOSE")
                        currentMarketVersionId = result.MVId;
                    
                    if (floorType == "MIXED")
                    {
                        currentMarketVersionId = result.MVId;
                        currentHoseVersionId = result.HoseVId;
                        currentHastcVersionId = result.HastcVId;
                        currentOtcVersionId = result.OtcVId;
                    }
                    
                    UpdateMarket();
                    
                    StartUpdate();

                }
            }
            else
            {            
                currentVersionId = result.VId;
                
                if (floorType == "HOSE")
                    currentMarketVersionId = result.MVId;
                    
                if (floorType == "MIXED")
                {
                    currentMarketVersionId = result.MVId;
                    currentHoseVersionId = result.HoseVId;
                    currentHastcVersionId = result.HastcVId;
                    currentOtcVersionId = result.OtcVId;
                }
                
                if (isTradingTime == true && requestTimerID == null)
                    requestTimerID = self.setTimeout("StartRequest()", 2000)
            }
            
            break;
        }
        case ("GetHosePutThroughObject"):
        case ("GetHastcPutThroughObject"):
        case ("GetOtcPutThroughObject"):
        case ("GetMixedPutThroughObject"):
        {
            DeletePutThroughTable(tablePutThrough);
            
            DeletePutThroughTable(tablePutThroughBuy);
            DeletePutThroughTable(tablePutThroughSell);
            
            if (result == null)
                return;
            if (result.ML != null)
                UpdatePutThroughTable(tablePutThrough, result.ML, true);
            
            if (result.BL != null)
                UpdatePutThroughTable(tablePutThroughBuy, result.BL, false);
            if (result.SL != null)
                UpdatePutThroughTable(tablePutThroughSell, result.SL, false);
            
            
            break;
        }
        case ("GetClientId"):
        {
            if (result > 0)
            {
                clientId = result;
                SetClientInfo();
            }
            break;
        }
        case ("GetStockInfoObject"):
        {
            if (result == null)
                return;
            stockInfoObject = result;  
            
            break;
        }
        case ("GetHastcQuotesHistory"):
        case ("GetHoseQuotesHistory"):
        case ("GetOtcQuotesHistory"):
        case ("GetMixedQuotesHistory"):
        {
             if (result == null)
                return;
             quotesHistory = result;  
             CreateQuotesHistory(false);
             
             break;
        }
    }
         
}

function UpdateStockInfoTooltip()
{

    if (stockInfoObject == null || stockInfoObject.ItemList == null)
        return;
    var theTable = document.getElementById("tableQuote");
    var symbol;
    var stockInfo;
    var link;
    for(var i=0; i<theTable.rows.length;i++)
    {
        symbol = theTable.rows[i].id.substring(2);
        stockInfo = stockInfoObject.ItemList[symbol];
        if (stockInfo != null)
        {
            link = document.getElementById("lnk" + symbol);
            if (link != null)
                link.title = stockInfo;
        }
    }
}

function ClearCurrentData()
{
    var img = document.getElementById("img");
    img.innerHTML = "";
    var theTable = document.getElementById("tableHistory");
    
    for(var i= theTable.rows.length-1; i>=0; i-- )
    {
        theTable.deleteRow(i);
    }
}

function CreateQuotesHistory(isShowAll)
{
    var item;
    var newRow;
    var newCell;
    var newCellChange;
    var newCellPercent;
    var valueArr;
    var basicItem;
    var basicValueArray;
    var basicItemInfo;
    var theTable = document.getElementById("tableHistory");
    var showAllHistory = document.getElementById("showAllHistory");
    
    var localizeObject;
    
    if (currentLanguage == "vi-VN")
        localizeObject = localizeVN;
    else
        localizeObject = localizeEN;
            
    if (currentGraphSymbol == "HOSE" || currentGraphSymbol == "HASTC" || currentGraphSymbol == "OTC" || currentGraphSymbol == "MIXED")
    {
        var tableHistoryHeader = document.getElementById("tableHistoryHeader");
        tableHistoryHeader.rows[0].cells[0].innerHTML = localizeObject.HistoryTime;
        tableHistoryHeader.rows[0].cells[1].innerHTML = "Index";
        tableHistoryHeader.rows[0].cells[2].innerHTML = localizeObject.HistoryChange;
        tableHistoryHeader.rows[0].cells[3].innerHTML = localizeObject.HistoryChangePercent;
        tableHistoryHeader.rows[0].cells[4].innerHTML = localizeObject.HistoryVolume;
        tableHistoryHeader.rows[0].cells[5].innerHTML = localizeObject.HistoryTotalVolume;
    }
    else
    {
        var tableHistoryHeader = document.getElementById("tableHistoryHeader");
        tableHistoryHeader.rows[0].cells[0].innerHTML = localizeObject.HistoryTime;
        tableHistoryHeader.rows[0].cells[1].innerHTML = localizeObject.HistoryPrice + " (x1000)";
        tableHistoryHeader.rows[0].cells[2].innerHTML = localizeObject.HistoryChange + " (x1000)";
        tableHistoryHeader.rows[0].cells[3].innerHTML = localizeObject.HistoryChangePercent;
        tableHistoryHeader.rows[0].cells[4].innerHTML = localizeObject.HistoryVolume + " (x10)";
        tableHistoryHeader.rows[0].cells[5].innerHTML = localizeObject.HistoryTotalVolume + " (x10)";
    }
    
    var rowCount = maxHistoryRowCount;
    
    if (isShowAll == false)
    {    
        if (quotesHistory.length < rowCount)
        {
            showAllHistory.disabled = true;
            rowCount = quotesHistory.length;
        }
        else
            showAllHistory.disabled = false;
    }
    else
    {
        showAllHistory.disabled = true;
        rowCount = quotesHistory.length;
    }
    
    for(var i=0; i< rowCount; i++)
    {
        item = quotesHistory[i];
        valueArr = item.split(";");
        
        newRow = theTable.insertRow(-1);
        newRow.style.height = rowHeightHistory;

        InsertNewHistoryCell(newRow, "normalTimeHistory", "20%", true, valueArr[5]);
        newCell = InsertNewHistoryCell(newRow, "normalPriceHistory", "18%", true, valueArr[0]);
        newCell.style.textAlign = "center";
        newCellChange = InsertNewHistoryCell(newRow, "normalPriceHistory", "12%", true, valueArr[1]);
        newCellPercent = InsertNewHistoryCell(newRow, "normalPriceHistory", "10%", true, valueArr[2]);

        
        if (currentGraphSymbol == "HOSE" || currentGraphSymbol == "HASTC" || currentGraphSymbol == "OTC" || currentGraphSymbol == "MIXED")
        {
            if (valueArr[1] == "0")
            {
                newCell.className = "unchangePriceHistory" 
                newCellChange.className = "unchangePriceHistory"
                newCellPercent.className = "unchangePriceHistory"
                newCellChange.innerHTML += " <img src=\"images/quotes_ref.gif\" />"
            }
            else
            if (valueArr[1].substr(0,1) == "-")
            {
                newCell.className = "downPriceHistory"
                newCellChange.className = "downPriceHistory"
                newCellPercent.className = "downPriceHistory"
                newCellChange.innerHTML += " <img src=\"images/quotes_down.gif\" />"
                    
            }
            else
            {
                newCell.className = "upPriceHistory"
                newCellChange.className = "upPriceHistory"
                newCellPercent.className = "upPriceHistory"
                newCellChange.innerHTML += " <img src=\"images/quotes_up.gif\" />"
            }
                
        }
        else
        {
            
            basicItem = null;
            if (basicObject != null)
                basicItem = basicObject.ItemList[currentGraphSymbol];

            if (basicItem != null)
            {
                basicValueArray = basicItem.V.split(";");
                
                basicItemInfo = new BasicItemInfo();
                basicItemInfo.CeilingPrice = basicValueArray[0];
                basicItemInfo.FloorPrice = basicValueArray[1];
                basicItemInfo.ReferencePrice = basicValueArray[2];
                
                if (valueArr[0] == basicItemInfo.CeilingPrice)
                {
                    newCell.className = "cellCeilingHistory"
                    newCellChange.className = "upPriceHistory"
                    newCellPercent.className = "upPriceHistory"
                    newCellChange.innerHTML += " <img src=\"images/btup.gif\" />"
                }
                else
                if (valueArr[0] == basicItemInfo.FloorPrice)
                {
                    newCell.className = "cellFloorHistory"
                    newCellChange.className = "downPriceHistory"
                    newCellPercent.className = "downPriceHistory"
                    newCellChange.innerHTML += " <img src=\"images/btdown.gif\" />"
                }
                else
                if (valueArr[0].length > basicItemInfo.ReferencePrice.length || valueArr[0] > basicItemInfo.ReferencePrice)
                {
                    newCell.className = "upPriceHistory"
                    newCellChange.className = "upPriceHistory"
                    newCellPercent.className = "upPriceHistory"
                    newCellChange.innerHTML += " <img src=\"images/btup.gif\" />"
                }
                else
                if (valueArr[0] != "0" && (valueArr[0].length < basicItemInfo.ReferencePrice.length || valueArr[0] < basicItemInfo.ReferencePrice))
                {
                    newCell.className = "downPriceHistory"
                    newCellChange.className = "downPriceHistory"
                    newCellPercent.className = "downPriceHistory"
                    newCellChange.innerHTML += " <img src=\"images/btdown.gif\" />"
                }
                else
                {
                    newCell.className = "unchangePriceHistory" 
                    newCellChange.className = "unchangePriceHistory"
                    newCellPercent.className = "unchangePriceHistory"
                    newCellChange.innerHTML += " <img src=\"images/btnochange.jpg\" />"
                }
                if (isThreeColors == true)
                {
                    //Giá trần
                    if (valueArr[0] == basicItemInfo.CeilingPrice)
                    {
                        newCellChange.innerHTML = "CE+" + newCellChange.innerHTML;
                    }
                    else 
                    if (valueArr[0] == basicItemInfo.FloorPrice)
                    {
                        newCellChange.innerHTML = "FL " + newCellChange.innerHTML;
                    }
                }
            }
            else
            {
                newCell.className = "normalPriceHistory";
            }
        }
        
        InsertNewHistoryCell(newRow, "normalVolHistory", "15%", true, valueArr[3]);
        InsertNewHistoryCell(newRow, "normalVolHistory", "20%", true, valueArr[4]);
        InsertNewHistoryCell(newRow, "normalVolHistory", "5%", true);

    }
}

 function InsertNewHistoryCell(newRow, className, width, isSetCellWidth, value)
 {
    var newCell = newRow.insertCell(-1);
    newCell.className = className;
    if (isSetCellWidth == true)
        newCell.style.width = width;
    
    if (value != null)
        newCell.innerHTML = value;
    return newCell;
 }

function ShowAllHistory()
{
    var theTable = document.getElementById("tableHistory");
    
    for(var i= theTable.rows.length-1; i>=0; i-- )
    {
        theTable.deleteRow(i);
    }
    CreateQuotesHistory(true);
}

function DeletePutThroughTable(theTable)
{
    for(var i= theTable.rows.length-1; i>=0; i-- )
    {
        if (i >= 2)
            theTable.deleteRow(i);
    }
}

function UpdatePutThroughTable(theTable, dataList, isMatching)
{
    
    var item;
    var newRow;
    var newCell;
    var valueArr;
    var basicItem;
    var basicValueArray;
    var basicItemInfo;
    
    for(var i=0; i< dataList.length; i++)
    {
        item = dataList[i];
        valueArr = item.split(";");
        
        newRow = theTable.insertRow(-1);
        newRow.style.height = rowHeightPutThrough;
        
        InsertNewPutThroughCell(newRow, "cellCode", valueArr[0]);
        newCell = InsertNewPutThroughCell(newRow, "normalPrice", valueArr[1]);
        
        basicItem = null;
        if (basicObject != null)
            basicItem = basicObject.ItemList[valueArr[0]];

        if (basicItem != null)
        {
            basicValueArray = basicItem.V.split(";");
            
            basicItemInfo = new BasicItemInfo();
            basicItemInfo.CeilingPrice = basicValueArray[0];
            basicItemInfo.FloorPrice = basicValueArray[1];
            basicItemInfo.ReferencePrice = basicValueArray[2];
            
            if (valueArr[1] == basicItemInfo.CeilingPrice)
            {
                newCell.className = "cellCeiling"
            }
            else
            if (valueArr[1] == basicItemInfo.FloorPrice)
            {
                newCell.className = "cellFloor"
            }
            else
            if (valueArr[1].length > basicItemInfo.ReferencePrice.length || valueArr[1] > basicItemInfo.ReferencePrice)
            {
                newCell.className = "upPrice"
            }
            else
            if (valueArr[1] != "0" && (valueArr[1].length < basicItemInfo.ReferencePrice.length || valueArr[1] < basicItemInfo.ReferencePrice))
            {
                newCell.className = "downPrice"
            }
            else
            {
                newCell.className = "unchangePrice" 
            }
        }
        else
        {
            newCell.className = "normalPrice";
        }

        InsertNewPutThroughCell(newRow, "normalVol", valueArr[2]);
        
        if ((floorType == "HASTC" || floorType == "OTC" || floorType == "MIXED") && isMatching == true)
        {
            InsertNewPutThroughCell(newRow, "normalValue", valueArr[3]);
            InsertNewPutThroughCell(newRow, "normalTime", valueArr[4]);
        }
        else if (floorType == "HOSE" || floorType == "MIXED")
        {
            if (isMatching == true)
                InsertNewPutThroughCell(newRow, "normalValue", valueArr[3]);
            else
                InsertNewPutThroughCell(newRow, "normalTime", valueArr[3]);
        }

    }
}

function InsertNewPutThroughCell(newRow, className, value)
{
    var newCell = newRow.insertCell(-1);
    newCell.innerHTML = value;
    newCell.className = className;
    return newCell;
}

function OnScroll()
{
    var currentY = GetPageTop();
    var topY = 120;
    
    if (isOptionDisplayed == true)
    {
        var pnlOption = document.getElementById("pnlOption");
        topY += pnlOption.offsetHeight;
    }    
    
    if (isPutThroughDisplayed == true)
    {
        var pnlPutThrough = document.getElementById("pnlPutThrough");
        topY += pnlPutThrough.offsetHeight;
    }
    
    if (/*isOptionDisplayed == false && isPutThroughDisplayed == false && */currentY >= topY && tableType == 0)
    {
        if (isFloatingHeaderShow == false)
        {
            floatingHeader.style.display = 'block';
            isFloatingHeaderShow = true;
        }
       
    }
    else
    {
        if (isFloatingHeaderShow == true)
        {
            floatingHeader.style.display = 'none';
            isFloatingHeaderShow = false;
        }
    }
}

function ShowFloatingHeaderIE6()
{
    var currentY = GetPageTop();
    var topY = 120;
    
    if (isOptionDisplayed == true)
    {
        var pnlOption = document.getElementById("pnlOption");
        topY += pnlOption.offsetHeight;
    }    
    
    if (isPutThroughDisplayed == true)
    {
        var pnlPutThrough = document.getElementById("pnlPutThrough");
        topY += pnlPutThrough.offsetHeight;
    }
    
    if (/*isOptionDisplayed == false && isPutThroughDisplayed == false && */currentY >= topY)
    {
        floatingHeader.style.top = currentY;
        if (isFloatingHeaderShow == false)
        {
            floatingHeader.style.display = 'block';
            isFloatingHeaderShow = true;
        }
       
    }
    else
    {
        if (isFloatingHeaderShow == true)
        {
            floatingHeader.style.display = 'none';
            isFloatingHeaderShow = false;
        }
    }
}

function GetPageTop()
{
    if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	else if (document.body)
		return document.body.scrollTop;
	else if (window.pageYOffset)
	    return window.pageYOffset;
	else
	    return 0;
}


// Callback function invoked when the call to 
// the Web service methods fails.
function FailedCallback(error, userContext, methodName) 
{

}

function DisplayMessage(message)
{
 
}
    

    
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();



