﻿
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 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 = "all";
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 = true;
var isShowSession1Volume = false;
var isShowSession2Price = false;
var isShowSession2Volume = false;

var isShowGrid = false;

var extraColumnString = "0000100";

var columnCount = 24;

var screenWidth = "100%"; //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 advancesCount = 0;
var noChangeCount = 0;
var declinesCount = 0;

var localizeVN = new LocalizeInfo();
var localizeEN = new LocalizeInfo();
var localizeJP = 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 = 2;
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 rowClassName = "";
var rowSeparatorClassName = "";

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);
    
    //alert(keychar);
    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 (typedString.length >= 2)
//        alert(row.id);
            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.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.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";
            
            localizeJP.ShowSession1Price = "第1節の株価を表示";
            localizeJP.ShowSession1Volume = "第1節の売買高を表示";
            localizeJP.ShowSession2Price = "第2節の株価を表示";
            localizeJP.ShowSession2Volume = "第2節の売買高を表示";
            localizeJP.ShowForeignBuy = "外国人- 買いを表示";
            localizeJP.exchangeName = "ホーチミン証券取引所";
            localizeJP.session = "節";
            localizeJP.sessionValue = "売買代金: ";
            localizeJP.ConnectedCount = "HOSEへの接続件数:";
            localizeJP.Session1Price = "第1節の株価";
            localizeJP.Session1Volume = "第1節の売買高";
            localizeJP.Session2Price = "第2節の株価";
            localizeJP.Session2Volume = "第2節の売買高";
            localizeJP.ForeignBuy = "外国人- 買い";

            
            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";
            
            localizeJP.exchangeName = "ハノイ証券取引所";
            localizeJP.ConnectedCount = "HNXへの接続件数:";
            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";    
            
            localizeJP.exchangeName = "UPCOM市場";
            localizeJP.ConnectedCount = "UPCOMへの接続件数:";
            break;
    }
    
    if (floorType == "HASTC" || floorType == "OTC")
    {
        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";
        
        localizeJP.ShowBuyVolume = "買い注文株数を表示";
        localizeJP.ShowSellVolume = "売り注文株数を表示";
        localizeJP.ShowBuyOrderCount = "買い注文件数を表示";
        localizeJP.ShowSellOrderCount = "売り注文件数を表示";
        localizeJP.ShowForeignBuy = "外国人- 買いを表示";
        localizeJP.ShowForeignSell = "外国人- 売りを表示";
        
        localizeJP.BuyVolume = "買い注文株数";
        localizeJP.SellVolume = "売り注文株数";
        localizeJP.BuyOrderCount = "買い注文件数";
        localizeJP.SellOrderCount = "売り注文件数";
        localizeJP.ForeignBuy = "外国人- 買い";
        localizeJP.ForeignSell = "外国人- 売り";
    }
    
    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 khối lượng:";
    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: 10 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.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.ShowGrid = "Hiển thị lưới";
    
    localizeVN.BoardName = "Chọn bảng hiển thị:";
    
    localizeVN.Hose = "Bảng giá HOSE";
    localizeVN.Hastc = "Bảng giá HNX";
    localizeVN.Otc = "Bảng giá UPCoM";
    localizeVN.PutThrough = "Giao dịch thỏa thuận";
    
    localizeEN.date = "Date:";
    localizeEN.time = "Server time:";
    localizeEN.change = "Change:";
    localizeEN.gainersLosers = "Gainers/Losers:";
    localizeEN.totalMarketVolume = "Total volume:";
    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: 10 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.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.ShowGrid = "Show grid";
    
    localizeEN.BoardName = "Choose board:";
    
    localizeEN.Hose = "HOSE Stock board";
    localizeEN.Hastc = "HNX Stock board";
    localizeEN.Otc = "UPCoM Stock board";
    localizeEN.PutThrough = "Put through";
    
    localizeJP.date = "取引日:";
    localizeJP.time = "サーバータイム:";
    localizeJP.change = "前営業日比:";
    localizeJP.gainersLosers = "値上がり/値下がり銘柄数:";
    localizeJP.totalMarketVolume = "売買高:";
    localizeJP.totalValue = "売買代金:";
    localizeJP.marketStatus = "取引状況:";
    localizeJP.currencyUnit = "10億ドン";
    localizeJP.symbol = "銘柄コード";
    localizeJP.ceiling = "ストップ高";
    localizeJP.floor = "ストップ安";
    localizeJP.basic = "基準株価";
    localizeJP.bid = "買板（気配値）";
    localizeJP.ask = "売板(気配値）";
    localizeJP.open = "寄値";
    localizeJP.high = "高値";
    localizeJP.low = "安値";
    localizeJP.average = "平均値";
    localizeJP.foreignBuy = "外国人「買」";
    localizeJP.totalVolume = "売買高";
    localizeJP.price = "株価";
    localizeJP.volume = "株数";
    localizeJP.matching = "約定";
    localizeJP.selectAll = "すべて選択";
    localizeJP.clearAll = "すべて解除";
    localizeJP.displayAll = "すべて表示";
    localizeJP.selectedSymbolsOnTop = "選択銘柄を表示";
    localizeJP.ScreenWidth = "画面サイズ選択:";
    localizeJP.PriceDescription = "株価単位：1,000ドン";
    if (floorType == "OTC")
        localizeJP.VolumeDescription = "売買高単位：10株";
    else
        localizeJP.VolumeDescription = "売買高単位：10株";
    localizeJP.HitCount = "アクセス数:";
    localizeJP.PutThroughMatching = "相対取引 - 約定";
    localizeJP.PutThroughBuy = "相対取引 - 買い";
    localizeJP.PutThroughSell = "相対取引 - 売り";
    localizeJP.PutThroughPrice = "株価";
    localizeJP.PutThroughValue = "売買代金(100万ドン)";
    localizeJP.PutThroughVolume = "売買高";
    localizeJP.PutThroughSymbol = "銘柄コード";
    localizeJP.PutThroughTime = "タイム";
    localizeJP.PutThroughUnit = "単位：1,000ドン、1株";
    localizeJP.TableType = "株価ボード表示方法選択";
    localizeJP.Normal = "標準";
    localizeJP.ScrollInfinite = "縦自動スクロール";
    localizeJP.Scroll2Directions = "縦横自動スクロール";
    localizeJP.PageReplacement = "自動ページ遷移";
    localizeJP.LineCount = "表示行数設定（自動縦スクロールの場合）";
    localizeJP.ScrollInterval = "スクロール間隔設定（ミリメートル／秒、自動縦スクロールの場合）";
    localizeJP.WaitingTime = "待機時間設定（ミリメートル／秒、縦横自動スクロール及び自動ページ遷移）";
    localizeJP.CurrentRoom = "外国人購入可能株数";
    localizeJP.ShowCurrentRoom = "外国人購入可能株数";
    localizeJP.FontStyle = "フォント";
    localizeJP.FontNormal = "標準フォント";
    localizeJP.FontBoldHalf = "主要項目太字フォント";
    localizeJP.FontBoldAll = "全項目太字フォント";
    localizeJP.ShowVolumeColor = "「株数」列にも「株価」の色を適用";
    localizeJP.ShowGrid = "格子線を表示";
    localizeJP.BoardName = "サーバを選択:";
    localizeJP.Hose = "HOSE株価ボード";
    localizeJP.Hastc = "HNX株価ボード";
    localizeJP.Otc = "UPCOM市場株価ボード";
    localizeJP.PutThrough = "相対取引";
    
    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";
    extraColumnString = "100010";
    
    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 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("displayedSymbolsSelectedString") != null)
//    {
//        displayedSymbolsSelectedString = readCookie("displayedSymbolsSelectedString");
//    }
    
    //if (floorType == "HASTC")
        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 (readCookie("isShowGrid") != null)
    {
        isShowGrid = (readCookie("isShowGrid") == "true");
    }
    
    SetTableWidth();
    
    SetTableGridStyle("tableQuote");
    SetTableGridStyle("tableFixedHeader");
    SetTableGridStyle("tableFloatingHeader");
    
    var language = readCookie("lan");
    if (language == null)
        setLanguage("vi-VN");
    else
        setLanguage(language);
        
    if (floorType == "HASTC" || floorType == "OTC")
    {
        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;
    }   
    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 (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
        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:
                case 21:
                    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 22:
                    if (floorType == "HASTC" || floorType == "OTC")
                        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*28 + 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;
    //alert(divScroll.clientHeight);
    
    var theTable = document.getElementById("tableQuote");
    
    //Cuộn vô tận
    if (tableType == 1)
    {
        if (divScroll.scrollTop >= divScroll.scrollHeight - divScroll.clientHeight)
        {
            
            //var a = lineCount + 2;
            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 (divScroll.scrollTop >= divScroll.scrollHeight - divScroll.clientHeight)
//        {
//            divScroll.scrollTop = 0;
//            currentRowIndex = 0;
//        }
    }
    //alert(5);
    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
//            alert(rowIndex);
//            alert(divScroll.scrollTop);
        }
        
        
    }
}
 
 function WaitingScroll()
 {
     //divScroll.scrollTop += scrollDistance;
     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 tableQuote = document.getElementById("tableQuote");
    var tableContainer = document.getElementById("tableContainer");
    var tableFloatingHeader = document.getElementById("tableFloatingHeader");
    var tableFixedHeader = document.getElementById("tableFixedHeader");
    var tableScrollFooter = document.getElementById("tableScrollFooter");
    
    if (screenWidth == "Auto")
    {
        //tableQuote.width = "";
        tableContainer.width = "";
        tableFloatingHeader.width = "";
        tableFixedHeader.width = "";
        tableScrollFooter.width = "";
        
    }
//    else if (screenWidth == "100%")
//    {
//        tableQuote.width = "100%";
//        tableFixedHeader.width = screenWidth;
//        tableContainer.width = "100%";
//        tableFloatingHeader.width = "100%";
//        tableScrollFooter.width = "100%";
//    }
    else
    {
        //tableQuote.width = screenWidth;
        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;
    
    //Lấy danh sách các mã đang được chọn và ghi vào cookie cho board tương ứng
//    GetSelectedSymbolsForChoose();
//    
//    createCookie("displayedSymbolsString" + boardName, displayedSymbolsString, 1000);
//    createCookie("displayedSymbolsSelectedString" + boardName, displayedSymbolsSelectedString, 1000);
    
    //Load cookie của board mới
    LoadBoardCookie();
    
    SetCheckedSymbolsForChoose(false);
    //LoadSymbolsTableForChoose();
    
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    if (displayedSymbolsString == "all")
        chkDisplayAll.checked = true;
    else
        chkDisplayAll.checked = false;
    ToggleDisplayAll();
    //alert(displayedSymbolsString);
 }
 
 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");
//        var tblFloatingHeader = document.getElementById("tableFloatingHeader");	
//        var tblFixedHeader = document.getElementById("tableFixedHeader");	        
//        //var width = 0;

//            //tblFloatingHeader.tHead.rows[0].cells[4].width = width + 'px';
//            for (var i = 0; i < tblQuote.rows[0].cells.length; i++)
//            {
//                tblFixedHeader.tHead.rows[0].cells[i].width = (tblQuote.tHead.rows[0].cells[i].offsetWidth) + 'px';		    		            
//            }
//            for (var i = 0; i < tblQuote.rows[1].cells.length; i++)
//            {
//                //tblFixedHeader.tHead.rows[1].cells[i].width = (tblQuote.rows[0].cells[i].offsetWidth) + 'px';
//            }
//        }                
//        tblFloatingHeader.width = tblQuote.offsetWidth;
//        tblFixedHeader.width = tblQuote.offsetWidth;
    }
       
}  

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 = "";	    		            
            }
            //+/-
            if (tblQuote.rows[2].cells[10].offsetWidth != 0)
                    theTable.tHead.rows[0].cells[5].width = (tblQuote.rows[2].cells[10].offsetWidth) + 'px';	
                else
                    theTable.tHead.rows[0].cells[5].width = "";	 
//            if (tblQuote.rows[2].cells[6].offsetWidth != 0)
//                    theTable.tHead.rows[0].cells[6].width = (tblQuote.rows[2].cells[6].offsetWidth) + 'px';	
//                else
//                    theTable.tHead.rows[0].cells[6].width = "";	
            //Giá
            for (var i = 4; i < 10; 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 = "";    
            }
            //Khớp
            for (var i = 11; i < 13; i++)
            {
                //width += tblQuote.rows[0].cells[i].offsetWidth;
                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 = "";    
            }
            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;
    if (floorType == "HOSE")
        tableSessionsRow = document.getElementById("tableSessions").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 spanShowGrid = document.getElementById("spanShowGrid");
    
    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 spanShowCurrentRoom;
    
    if (floorType == "HASTC" || floorType == "OTC")
    {
        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");
    }
    
    
    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 spanHose = document.getElementById("spanHose");
    var spanHastc = document.getElementById("spanHastc");
    var spanOtc = document.getElementById("spanOtc");
    var spanPutThrough = document.getElementById("spanPutThrough");
    
    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;\">";
        
        //spanPutThroughImage.innerHTML = "<img src=\"Images/gdthoathuan.gif\" onclick=\"TogglePutThrough();\" style=\"pointer: hand; cursor: pointer;\">";
        createCookie("lan", "vi-VN", 1000);
    }
    else if (lan == "en-US")
    {
        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;\">";
        
        //spanPutThroughImage.innerHTML = "<img src=\"Images/put_Through.gif\" onclick=\"TogglePutThrough();\" style=\"pointer: hand; cursor: pointer;\">";
        createCookie("lan", "en-US", 1000);
    }
    else
    {
        localizeObject = localizeJP;
        
        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;\">";
        
        //spanPutThroughImage.innerHTML = "<img src=\"Images/gdthoathuan.gif\" onclick=\"TogglePutThrough();\" style=\"pointer: hand; cursor: pointer;\">";
        createCookie("lan", "jp-JP", 1000);
    }
    
    spanOnTop.innerHTML = localizeObject.selectedSymbolsOnTop;
    
    spanHose.innerHTML = localizeObject.Hose;
    spanHastc.innerHTML = localizeObject.Hastc;
    spanOtc.innerHTML = localizeObject.Otc;
    
    if (floorType != "OTC")
        spanPutThrough.innerHTML = localizeObject.PutThrough;
    
    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;
    
    spanCopyright.innerHTML = localizeObject.Copyright;
    spanCopyright1.innerHTML = localizeObject.Copyright;
    spanFooter.innerHTML = localizeObject.Footer;
    
    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;
    }
    
   
    spanSelectAll.innerHTML = localizeObject.selectAll;
    spanClearAll.innerHTML = localizeObject.clearAll;
    spanDisplayAll.innerHTML = localizeObject.displayAll;
    //spanAlphaDevelopment.innerHTML = localizeObject.DevelopedBy;
    //spanTelNo.innerHTML = localizeObject.Tel;
    
    if (floorType == "HASTC" || floorType == "OTC")
    {
        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;
        
    }
    
    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;
    spanShowGrid.innerHTML = localizeObject.ShowGrid;
    
    tdConnectedClientCountTitle.innerHTML = localizeObject.ConnectedCount;
    tdHitCounterTitle.innerHTML = localizeObject.HitCount;
    
    tdScreenWidth.innerHTML = localizeObject.ScreenWidth;
    tdBoardName.innerHTML = localizeObject.BoardName;
    
    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;
            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;
        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;
            
    }
    
    
    spanPutThroughDescription.innerHTML = localizeObject.PutThroughUnit;
    
    SetHeaderText("tableQuote", localizeObject);
    SetHeaderText("tableFixedHeader", localizeObject);
    SetHeaderText("tableFloatingHeader", localizeObject);
    
    //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":
            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[6].innerHTML = localizeObject.matching;
            trGridHeaderTop.cells[7].innerHTML = localizeObject.ask;
            
            trGridHeaderTop.cells[8].innerHTML = localizeObject.open;
            trGridHeaderTop.cells[9].innerHTML = localizeObject.high;
            trGridHeaderTop.cells[10].innerHTML = localizeObject.low;
            trGridHeaderTop.cells[11].innerHTML = localizeObject.average;
            trGridHeaderTop.cells[12].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 = 13;
            
            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[6].innerHTML = localizeObject.matching;
            trGridHeaderTop.cells[7].innerHTML = localizeObject.ask;
            
            trGridHeaderTop.cells[8].innerHTML = localizeObject.open;
            trGridHeaderTop.cells[9].innerHTML = localizeObject.high;
            trGridHeaderTop.cells[10].innerHTML = localizeObject.low;
            //trGridHeaderTop.cells[11].innerHTML = localizeObject.foreignBuy;
            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 (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;
            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 createBoardCookie(name,value,days,board) {
//    name = cookiePrefix + board + 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 readBoardCookie(name,board) {
//    name = cookiePrefix + board + 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;
    
    //if (floorType == "HASTC")
        oldExtraColumnString = extraColumnString;
    
//    var oldDisplayedSymbolsString = displayedSymbolsString;
    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 chkShowGrid = document.getElementById("chkShowGrid");
    
    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 oldShowGrid = isShowGrid;    
    
    isShowVolumeColor = chkShowVolumeColor.checked;
    isShowGrid = chkShowGrid.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")
    {
        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");
        
        //isShowSession1Price = chkShowSession1Price.checked;
        isShowSession1Volume = chkShowSession1Volume.checked;
        isShowSession2Price = chkShowSession2Price.checked;
        isShowSession2Volume = chkShowSession2Volume.checked;
        isShowForeignBuy = chkShowForeignBuy.checked;
        isShowCurrentRoom = chkShowCurrentRoom.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";
    }

    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 tableContainer = document.getElementById("tableContainer");
    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")
    {
        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 (oldExtraColumnString != extraColumnString || needSetScroll == true || oldDisplayedSymbolsString != displayedSymbolsString)
            CreateBasicRows(true);
        else
        {
            if (fontStyle != oldFontStyle)
                SetFontStyle();
            if (oldShowSelectedSymbolsOnTop != showSelectedSymbolsOnTop)
                ToggleOnTop();
                
            if (oldShowVolumeColor != isShowVolumeColor)
                ToggleShowVolumeColor();
                
            if (oldShowGrid != isShowGrid)
                ToggleShowGrid();
        }
    }
    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 (oldShowGrid != isShowGrid)
                ToggleShowGrid();
        }
    }
    
    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("isShowGrid", isShowGrid, 1000);

    //if (floorType == "HASTC")
        createCookie("extraColString", extraColumnString, 1000);
    
    createCookie("tableType", tableType, 1000);
    createCookie("lineCount", lineCount, 1000);
    createCookie("scrollInterval", scrollInterval, 1000);
    createCookie("waitingTime", waitingTime, 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;
        }
        
    }
 }
 
  //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;
        }
        
    }
 }
 
 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;
    }
 }
 
 //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;
    }
 }
 
 function ToggleOption()
 {
    if (isOptionDisplayed == true)
    {
        HideOption();
    }
    else
    {
        ShowOption();
    }
 }
 
 function ShowOption()
 {
    LoadSymbolsTableForChoose();
    
    oldDisplayedSymbolsString = displayedSymbolsString;
    
//    var chkDisplayAll = document.getElementById("chkDisplayAll");
    var chkOnTop = document.getElementById("chkShowSelectedOnTop");
    chkOnTop.checked = showSelectedSymbolsOnTop;
    
    if (floorType == "HASTC" || floorType == "OTC")
    {
        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");
        
        //chkShowSession1Price.checked = isShowSession1Price;
        chkShowSession1Volume.checked = isShowSession1Volume;
        chkShowSession2Price.checked = isShowSession2Price;
        chkShowSession2Volume.checked = isShowSession2Volume;
        chkShowForeignBuy.checked = isShowForeignBuy;
        chkShowCurrentRoom.checked = isShowCurrentRoom;
    }
    
    var chkShowVolumeColor = document.getElementById("chkShowVolumeColor");
    var chkShowGrid = document.getElementById("chkShowGrid");
    
    if (isShowVolumeColor == true)
        chkShowVolumeColor.checked = true;
    else
        chkShowVolumeColor.checked = false;
        
    if (isShowGrid == true)
        chkShowGrid.checked = true;
    else
        chkShowGrid.checked = false;
    
//    if (displayedSymbolsString == "all")
//        chkDisplayAll.checked = true;
//    else
//        chkDisplayAll.checked = false;
//    ToggleDisplayAll();

    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 if (currentLanguage == "en-US")
        spanOption.innerHTML = "<img src=\"Images/hide.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
    else
        spanOption.innerHTML = "<img src=\"Images/an.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 if (currentLanguage == "en-US")
        spanOption.innerHTML = "<img src=\"Images/option.gif\" onclick=\"ToggleOption();\" style=\"pointer: hand; cursor: pointer;\">";
    else
        spanOption.innerHTML = "<img src=\"Images/tuychon.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 ToggleGrid()
 {
    var chkShowGrid = document.getElementById("chkShowGrid");
    chkShowGrid.checked = !chkShowGrid.checked;
 }
 
 function ShowPutThrough()
 {
    var pnlOption = document.getElementById("pnlPutThrough");
    var tabPutThrough = document.getElementById("tabPutThrough");
    var tabPutThroughLeft = document.getElementById("tabPutThroughLeft");
    var tabPutThroughRight = document.getElementById("tabPutThroughRight");
    
    pnlOption.style.display = 'block';
    tabPutThrough.className = "tabActive";
    tabPutThroughLeft.className = "tabActiveLeft";
    tabPutThroughRight.className = "tabActiveRight";
        
    isPutThroughDisplayed = true;
    
    GetPutThroughObject();
    putThroughTimerID = self.setInterval("GetPutThroughObject()", 10*1000);
 }
 
 function HidePutThrough()
 {
    var pnlOption = document.getElementById("pnlPutThrough");
    var tabPutThrough = document.getElementById("tabPutThrough");
    var tabPutThroughLeft = document.getElementById("tabPutThroughLeft");
    var tabPutThroughRight = document.getElementById("tabPutThroughRight");
    
    pnlOption.style.display = 'none';
    tabPutThrough.className = "tabInactive";
    tabPutThroughLeft.className = "tabInactiveLeft";
    tabPutThroughRight.className = "tabInactiveRight";
    
    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 = rowClassName;
        
        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()
 {
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    
    chkDisplayAll.checked = !chkDisplayAll.checked;
    ToggleDisplayAll();
 }
 
 function ToggleDisplayAll()
 {
    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 ToggleShowGrid()
{
    var theTable = document.getElementById("tableQuote"); 
    var row;   
    
    SetTableGridStyle("tableQuote");
    SetTableGridStyle("tableFixedHeader");
    SetTableGridStyle("tableFloatingHeader");
    
    for(var i= 2; i<theTable.rows.length; i++ )
    {
        row = theTable.rows[i];
        
        if (isShowGrid == true)
        {
            if (row.className == "quoteRow")
                row.className = "quoteRowGrid";
            else
                if (row.className == "quoteRowSeparator")
                    row.className = "quoteRowSeparatorGrid";
        }
        else
        {
            if (row.className == "quoteRowGrid")
                row.className = "quoteRow";
            else
                if (row.className == "quoteRowSeparatorGrid")
                    row.className = "quoteRowSeparator";
        }
    }
}

function SetTableGridStyle(tableName)
{
    
    var theTable = document.getElementById(tableName); 
    if (isShowGrid == true)
    {
        theTable.border = "0";
        theTable.cellSpacing = "1";
        theTable.className = "tableQuoteGrid";
        rowClassName = "quoteRowGrid";
        rowSeparatorClassName = "quoteRowSeparatorGrid";
    }
    else
    {
        theTable.border = "1";
        theTable.cellSpacing = "0";
        theTable.className = "tableQuote";
        rowClassName = "quoteRow";
        rowSeparatorClassName = "quoteRowSeparator";
    }
}

 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;
        
    //var chkOnTop = document.getElementById("chkShowSelectedOnTop");
    //Chọn
    if (checkbox.checked == true)
    {        
        var movedPosition = selectedCount + headerRowCount;
        var oldRowIndex = row.rowIndex;
        
        //Chuyển vị trí
        if (showSelectedSymbolsOnTop == true && isFinishBasicRows == false)
        {
            //Xóa màu highlight cũ
            UnHighlight(row);
            
            //Chuyển vị trí
            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 = rowClassName;     
                
                //Đặt thanh phân cách mới    
                row.className = rowSeparatorClassName;
            }
            
            if (Sys.Browser.name == "Microsoft Internet Explorer")
            {
                //theTable.moveRow(row.rowIndex, selectedCount + headerRowCount);
                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 và có cấu hình là hiển thị màu selected
        if ((isShowSelectedColor == true || showSelectedSymbolsOnTop == false) && (currentHighlightSymbol != symbol || (showSelectedSymbolsOnTop == true && oldRowIndex != movedPosition)))
        {
            cellIndex = 0;
            
            row.cells[cellIndex++].style.backgroundColor = backColorSymbolSelected;
            
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            
            
            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;
            
            //ATO
            //row.cells[cellIndex++].style.backgroundColor = backColor2Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            
            if (floorType == "HASTC" || floorType == "OTC")
                row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            
            row.cells[cellIndex++].style.backgroundColor = backColor1Selected;
            //row.cells[24].style.backgroundColor = backColor1Selected;
            
            var lastIndex;
            if (floorType == "HASTC" || floorType == "OTC")
                lastIndex = 24
            else
                lastIndex = 23;
                
            for (var i=lastIndex;i<row.cells.length;i++)
                    row.cells[i].style.backgroundColor = backColor1Selected;
        }
        
        selectedCount++;
        
    }
    //Bỏ chọn
    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 = rowClassName;   
                    
                    //movedPosition = selectedCount + headerRowCount + i;
                    //theTable.moveRow(row.rowIndex, movedPosition);
                    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 = rowSeparatorClassName;
                }
                
            }
        }
        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)
            {
                
                //Lưu vào mảng những mã ko được chọn
                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 = rowClassName;    
                            
                        //Chuyển vị trí
                        movedPosition = selectedCount + headerRowCount + i;
                        //theTable.moveRow(row.rowIndex, movedPosition);
                        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 = rowSeparatorClassName;
                    }
                    
                }
                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]);
        }
                    
        //Đặt lại màu nền gốc nếu chứng khoán bỏ chọn ko phải đang được highlight
        if (currentHighlightSymbol != symbol || (showSelectedSymbolsOnTop == true && movedPosition > -1 && oldRowIndex != movedPosition))
        {
            
//            cellIndex = 0;
//            
//            row.cells[cellIndex++].style.backgroundColor = backColorSymbol;
//            
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//  
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            row.cells[cellIndex++].style.backgroundColor = backColor1Alt;
//            row.cells[cellIndex++].style.backgroundColor = backColor1Alt;
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            
//            
//            row.cells[cellIndex++].style.backgroundColor = backColor2;
//            row.cells[cellIndex++].style.backgroundColor = backColor2;
//            row.cells[cellIndex++].style.backgroundColor = backColor2;
//            
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            row.cells[cellIndex++].style.backgroundColor = backColor1Alt;
//            row.cells[cellIndex++].style.backgroundColor = backColor1Alt;
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            
//            //ATO
//            //row.cells[cellIndex++].style.backgroundColor = backColor2;
//            
//            row.cells[cellIndex++].style.backgroundColor = backColor2;
//            row.cells[cellIndex++].style.backgroundColor = backColor2;
//            
//            if (floorType == "HASTC" || floorType == "OTC")
//                row.cells[cellIndex++].style.backgroundColor = backColor2;
//            
//            row.cells[cellIndex++].style.backgroundColor = backColor1;
//            //row.cells[24].style.backgroundColor = backColor1;
//            
//            var lastIndex;
//            if (floorType == "HASTC" || floorType == "OTC")
//                lastIndex = 23
//            else
//                lastIndex = 22;
//            
//            for (var i=lastIndex;i<row.cells.length;i++)
//                    row.cells[i].style.backgroundColor = backColor1;
        }
        
        selectedCount--;
        
    }
    
    createCookie("selectedSymbolList", selectedSymbolList, 1000);
 }
 
 //Hiển thị màu nền cho row
 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)
//        return;
        
    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 = color1;
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1;
    
    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;
    
    //ATO
    //row.cells[cellIndex++].style.backgroundColor = color2;
    
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1;
    row.cells[cellIndex++].style.backgroundColor = color1;
    
    if (floorType == "HASTC" || floorType == "OTC")
        row.cells[cellIndex++].style.backgroundColor = color1;
    
    row.cells[cellIndex++].style.backgroundColor = color1;
    //row.cells[24].style.backgroundColor = color1;
    
    var lastIndex;
    if (floorType == "HASTC" || floorType == "OTC")
        lastIndex = 24
    else
        lastIndex = 23;
    
    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;
    }
    
 }
 
 
 //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;
    }
    
    
 }
 
 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;
    }
 }
 
 function UpdateMarketImmediately()
 {
    if (dataResult.AC != "")
        advancesCount = dataResult.AC;
    if (dataResult.DC != "")
        declinesCount = dataResult.DC;
    if (dataResult.NC != "")
        noChangeCount = dataResult.NC;
    
    UpdateMarketData();
 }
 
 function UpdateMarketData()
 {
    //Thay đổi dữ liệu các chỉ số
    if (dataResult.I != "")
        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>";
    
    var localizeObject;
    if (currentLanguage == "vi-VN")
        localizeObject = localizeVN;
    else if (currentLanguage == "en-US")
        localizeObject = localizeEN;
    else
        localizeObject = localizeJP;
        
    if (floorType == "HOSE")
    {
        var marketIndices = dataResult.SI.split(";");
        
        //Các chỉ số và thay đổi từng phiên
        if (marketIndices[0] != "")
            UpdateSessionInfoImmediately(tdSession1, tdSession1Trading, marketIndices[0], marketIndices[1], marketIndices[2]);
        
        if (marketIndices[4] != "")
            UpdateSessionInfoImmediately(tdSession2, tdSession2Trading, marketIndices[4], marketIndices[5], marketIndices[6]);
      
        if (marketIndices[8] != "")
            UpdateSessionInfoImmediately(tdSession3, tdSession3Trading, marketIndices[8], marketIndices[9], marketIndices[10]);
        
    //    var tdSession1 = document.getElementById("tdSession1");
    //    var tdSession2 = document.getElementById("tdSession2");
    //    
        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;
    }
    
    
    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, tradingCell, index, change, percent)
 {
    if (change.substr(0,1) == "-")
    {
        cell.className = "sessionInfoValueDown";
        tradingCell.className = "sessionInfoValueDown";
        cell.innerHTML = index + "  <img src=\"images/btdown.gif\" /> " + change + " " + " (" + percent + "%)";
    }
    else
        if (change == "0")
        {
            cell.className = "sessionInfoValueUnchange";
            tradingCell.className = "sessionInfoValueUnchange";
            cell.innerHTML = index + "  <img src=\"images/btnochange.jpg\" /> " + change + " " + " (" + percent + "%)";
        }
        else
        {
            cell.className = "sessionInfoValueUp";
            tradingCell.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;
    }
    
    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 = "";
    }
    
    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;
    var spanSymbol = null;
    
    for(var item in updateSegmentDataList)
    {    
        quoteItem = updateSegmentDataList[item];
        valueArray = quoteItem.V.split(";");
        changedRow = document.getElementById("tr" + item);
        spanSymbol = document.getElementById("spanSymbol" + item);   
        
        if (changedRow != null)
        {
            cellIndex = 4;
            if (changedRow.rowIndex%2==0)
            {
                
                
                //Bid
                UpdateCellData(spanSymbol, item, valueArray[0], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[1], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[2], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1Alt, backColor1SelectedAlt, false)
                UpdateCellData(spanSymbol, item, valueArray[3], changedRow.cells[cellIndex++], null, i++, false, backColor1Alt, backColor1SelectedAlt, false)
                UpdateCellData(spanSymbol, item, valueArray[4], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[5], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                
                //Match
                UpdateCellData(spanSymbol, item, valueArray[8], changedRow.cells[cellIndex++], null, i++, true, backColor2, backColor1Selected, true, valueArray[6])
                UpdateCellData(spanSymbol, item, valueArray[6], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor2, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[7], changedRow.cells[cellIndex++], null, i++, false, backColor2, backColor1Selected, false)
                
                if (isShowVolumeColor == true && valueArray[6] != "")
                {
                    updatedCells[i-2].ExtraCellVolume1 = changedRow.cells[0];
                    updatedCells[i-2].ExtraCellVolume2 = changedRow.cells[10];
                    
                }
                //Ask
                UpdateCellData(spanSymbol, item, valueArray[9], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[10], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[11], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1Alt, backColor1SelectedAlt, false)
                UpdateCellData(spanSymbol, item, valueArray[12], changedRow.cells[cellIndex++], null, i++, false, backColor1Alt, backColor1SelectedAlt, false)
                UpdateCellData(spanSymbol, item, valueArray[13], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[14], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                
                if (floorType == "HASTC" || floorType == "OTC")
                {
                    //High, Low, Average
                    UpdateCellData(spanSymbol, item, valueArray[15], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[16], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[17], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    //UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], i++, true, backColor2, backColor2Selected, false)
                    
                    UpdateCellData(spanSymbol, item, valueArray[19], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    //UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[24], i++, false, backColor1, backColor1Selected, false)
                }
                else
                {
                    //ATO
                    //UpdateCellData(spanSymbol, item, valueArray[15], changedRow.cells[cellIndex++], i++, true, backColor2, backColor2Selected, false)
                    
                    //High, Low, Average
                    if (isShowSession1Volume == true)
                        UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex + 3], i++, true, backColor1, backColor1Selected, false)
                    else
                        UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[15], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[16], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    //UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], i++, true, backColor2, backColor2Selected, false)
                    
                    //Total volume
                    UpdateCellData(spanSymbol, item, valueArray[17], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    //UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[24], i++, false, backColor1, backColor1Selected, false)
                }
                
                if (floorType == "HASTC" || floorType == "OTC")
                {
                    if (isShowBuyVolume == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSellVolume == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowBuyOrderCount == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[22], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSellOrderCount == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[24], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowForeignSell == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[25], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[26], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                }
                else if (floorType == "HOSE")
                {
//                    if (isShowSession1Price == true)
//                    {
//                        if (isShowSession1Volume == true)
//                            UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
//                        else
//                            UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
//                    }
                    if (isShowSession1Volume == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[19], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowSession2Price == true)
                    {
                        if (isShowSession2Volume == true)
                            UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1, backColor1Selected, false)
                        else
                            UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[cellIndex++], null, i++, true, backColor1, backColor1Selected, false)
                    }
                    if (isShowSession2Volume == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[22], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1, backColor1Selected, false)
                    }
                    
                }
            }
            else
            {
                //Bid
                UpdateCellData(spanSymbol, item, valueArray[0], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[1], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[2], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1AltR2, backColor1SelectedAlt, false)
                UpdateCellData(spanSymbol, item, valueArray[3], changedRow.cells[cellIndex++], null, i++, false, backColor1AltR2, backColor1SelectedAlt, false)
                UpdateCellData(spanSymbol, item, valueArray[4], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[5], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                
                //Match
                UpdateCellData(spanSymbol, item, valueArray[8], changedRow.cells[cellIndex++], null, i++, true, backColor2R2, backColor2Selected, true, valueArray[6])
                UpdateCellData(spanSymbol, item, valueArray[6], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor2R2, backColor2Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[7], changedRow.cells[cellIndex++], null, i++, false, backColor2R2, backColor2Selected, false)
                
                if (isShowVolumeColor == true && valueArray[6] != "")
                {
                    updatedCells[i-2].ExtraCellVolume1 = changedRow.cells[0];
                    updatedCells[i-2].ExtraCellVolume2 = changedRow.cells[10];
//                    changedRow.cells[0].className = updatedCells[i-3].className + "Code";
//                    changedRow.cells[12].className = updatedCells[i-3].className;
                }
                //Ask
                UpdateCellData(spanSymbol, item, valueArray[9], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[10], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[11], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1AltR2, backColor1SelectedAlt, false)
                UpdateCellData(spanSymbol, item, valueArray[12], changedRow.cells[cellIndex++], null, i++, false, backColor1AltR2, backColor1SelectedAlt, false)
                UpdateCellData(spanSymbol, item, valueArray[13], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                UpdateCellData(spanSymbol, item, valueArray[14], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                
                if (floorType == "HASTC" || floorType == "OTC")
                {
                    //High, Low, Average
                    UpdateCellData(spanSymbol, item, valueArray[15], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[16], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[17], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    //UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], i++, true, backColor2R2, backColor2Selected, false)
                    
                    UpdateCellData(spanSymbol, item, valueArray[19], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    //UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[24], i++, false, backColor1R2, backColor1Selected, false)
                }
                else
                {
                    //ATO
                    //UpdateCellData(spanSymbol, item, valueArray[15], changedRow.cells[cellIndex++], i++, true, backColor2R2, backColor2Selected, false)
                    
                    //High, Low, Average
                    if (isShowSession1Volume == true)
                            UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex + 3], i++, true, backColor1R2, backColor1Selected, false)
                        else
                            UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[15], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    UpdateCellData(spanSymbol, item, valueArray[16], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    //UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], i++, true, backColor2R2, backColor2Selected, false)
                    
                    //Total volume
                    UpdateCellData(spanSymbol, item, valueArray[17], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    //UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[24], i++, false, backColor1R2, backColor1Selected, false)
                
                }
                if (floorType == "HASTC" || floorType == "OTC")
                {
                    if (isShowBuyVolume == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSellVolume == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowBuyOrderCount == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[22], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSellOrderCount == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[23], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[24], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowForeignSell == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[25], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                }
                else if (floorType == "HOSE")
                {
//                    if (isShowSession1Price == true)
//                    {
//                        if (isShowSession1Volume == true)
//                            UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
//                        else
//                            UpdateCellData(spanSymbol, item, valueArray[18], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
//                    }
                    if (isShowSession1Volume == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[19], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSession2Price == true)
                    {
                        if (isShowSession2Volume == true)
                            UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], i++, true, backColor1R2, backColor1Selected, false)
                        else
                            UpdateCellData(spanSymbol, item, valueArray[20], changedRow.cells[cellIndex++], null, i++, true, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowSession2Volume == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[21], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowForeignBuy == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[22], changedRow.cells[cellIndex++], null, i++, false, backColor1R2, backColor1Selected, false)
                    }
                    if (isShowCurrentRoom == true)
                    {
                        UpdateCellData(spanSymbol, item, valueArray[23], 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(spanSymbol, 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)    
                        {
                            cellInfo.data = symbol  + " <img src=\"images/btdown.gif\" />" + " " + data;
                            //spanSymbol.innerHTML = "<img src=\"images/btdown.gif\" />";
                        }    
                            
                    }
                    else
                    //Không đổi
                    if (data == "0")
                    {
                        if (isShowVolumeColor == false)
                            cellInfo.className = "unchangePrice"
                        
                        if (isThreeColors == false)    
                        {
                            cellInfo.data = symbol;//  + " <img src=\"images/btnochange.jpg\" />" + " " + data;
                            //spanSymbol.innerHTML = "<img src=\"images/btnochange.jpg\" />";
                        }
                    }
                    //Tăng giá
                    else
                    {
                        if (isShowVolumeColor == false)
                            cellInfo.className = "upPrice" 
                        
                        if (isThreeColors == false)    
                        {
                            cellInfo.data = symbol  + " <img src=\"images/btup.gif\" />" + " +" + data;
                            //spanSymbol.innerHTML = "<img src=\"images/btup.gif\" />";
                        }
                    }
                    
                    if (isThreeColors == true)
                    {
                        //Giá trần
                        if (currentPrice == basicItemInfo.CeilingPrice)
                        {
                            cellInfo.data = symbol + " " + "CE+" + cellInfo.data;
                        }
                        else 
                        if (currentPrice == basicItemInfo.FloorPrice)
                        {
                            cellInfo.data = symbol + " " + "FL " + cellInfo.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;
                }   
            }
        }
    }
    
//    ResizeHeader();
    
    //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 spanSymbol = null;
    var basicItem;
    var basicValueArray;
    var basicItemInfo;
    

    var i=0;
    var maxIndex;
    var minIndex;
    var cellIndex;
    var item;
    
    if (isFinishUpdatingImmediately == true)
    {
        minIndex = 0;
        maxIndex = 2;
    }
    else
    {
        if (currentUpdatedIndex == 0)
            minIndex = 2;
        else
            minIndex = currentUpdatedIndex;
        maxIndex = currentUpdatedIndex + 30;
        if (maxIndex > currentUpdatedBasicIndex)
            maxIndex = currentUpdatedBasicIndex;
    }
    
    basicItemInfo = new BasicItemInfo();
    
    for(i = minIndex; i<maxIndex; i++)
    //for(var item in updateSegmentDataList)
    {    
//        i++;
//        
//        if (isFinishUpdatingImmediately == true)
//        {
//            currentUpdatedIndex++;
//            if (i >= 3)
//                break;
//        }
//        else
//        {
//            //Bỏ qua những dòng đã cập nhật
//            if (i < currentUpdatedIndex)
//                continue;
//                
//            if (currentUpdatedIndex >= maxIndex)
//                break;
//            
//            //Nếu CK này ko được chọn để hiển thị
//            if (displayedSymbolsString != "all" && displayedSymbolsString.indexOf("'" + item + "'") == -1)
//                continue;
//             
//            currentUpdatedIndex++;
//            
//            if (currentUpdatedIndex <=2)
//                continue;
//        }

        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);
            
            spanSymbol = document.getElementById("spanSymbol" + item);    
                
            basicItem = basicObject.ItemList[item];
            
            if (basicItem != null)// && chkSymbol != null)
            {
                basicValueArray = basicItem.V.split(";");
                
                basicItemInfo.CeilingPrice = basicValueArray[0];
                basicItemInfo.FloorPrice = basicValueArray[1];
                basicItemInfo.ReferencePrice = basicValueArray[2];
                basicItemInfo.Symbol = item;
                
//                if (isThreeColors == true)
//                    basicItemInfo.CurrentPrice = valueArray[6];
                cellIndex = 4;
                if (changedRow.rowIndex%2==0)
                {
                    //Bid
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[0], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[1], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[2], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1Alt, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[3], changedRow.cells[cellIndex++], null, false, backColor1Alt, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[4], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[5], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    
                    //Match
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[8], changedRow.cells[cellIndex++], null, true, backColor2, backColor2Selected, true, valueArray[6])
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[6], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor2, backColor2Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[7], changedRow.cells[cellIndex++], null, false, backColor2, backColor2Selected, false)
                    
                    if (isShowVolumeColor == true && valueArray[6] != "")
                    {
                        changedRow.cells[0].className = changedRow.cells[11].className + "Code";
                        changedRow.cells[10].className = changedRow.cells[11].className;
                    }
                    
                    //Ask
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[9], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[10], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[11], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1Alt, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[12], changedRow.cells[cellIndex++], null, false, backColor1Alt, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[13], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[14], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    
                    if (floorType == "HASTC" || floorType == "OTC")
                    {
                        //High,Low,Average
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[15], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false)
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[16], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false)
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[17], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false)
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false)
                        
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[19], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    }
                    else
                    {
                        //ATO
                        //UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[15], changedRow.cells[cellIndex++], true, backColor2, backColor2Selected, false)
                    
                        //High,Low
                        if (isShowSession1Volume == true)
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex + 3], true, backColor1, backColor1Selected, false) ;
                        else
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false) ;
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[15], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false)
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[16], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false)
                        //UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], true, backColor2, backColor2Selected, false)
                        
                        //Total volume
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[17], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false)
                    }
                    
                    if (floorType == "HASTC" || floorType == "OTC")
                    {
                        if (isShowBuyVolume == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSellVolume == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowBuyOrderCount == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSellOrderCount == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[24], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowForeignSell == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[25], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[26], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                    }
                    else if (floorType == "HOSE")
                    {
//                        if (isShowSession1Price == true)
//                        {
//                            if (isShowSession1Volume == true)
//                                UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false) ;
//                            else
//                                UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false) ;
//                            
//                        }
                        if (isShowSession1Volume == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[19], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSession2Price == true)
                        {
                            if (isShowSession2Volume == true)
                                UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1, backColor1Selected, false) 
                            else
                                UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, true, backColor1, backColor1Selected, false) 
                        }
                        if (isShowSession2Volume == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1, backColor1Selected, false) 
                        }
                    }
                }
                else
                {
                    //Bid
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[0], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[1], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[2], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1AltR2, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[3], changedRow.cells[cellIndex++], null, false, backColor1AltR2, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[4], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[5], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    
                    //Match
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[8], changedRow.cells[cellIndex++], null, true, backColor2R2, backColor2Selected, true, valueArray[6])
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[6], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor2R2, backColor2Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[7], changedRow.cells[cellIndex++], null, false, backColor2R2, backColor2Selected, false)
                    
                    if (isShowVolumeColor == true && valueArray[6] != "")
                    {
                        changedRow.cells[0].className = changedRow.cells[11].className + "Code";
                        changedRow.cells[10].className = changedRow.cells[11].className;
                    }
                        
                    //Ask
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[9], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[10], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[11], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1AltR2, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[12], changedRow.cells[cellIndex++], null, false, backColor1AltR2, backColor1SelectedAlt, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[13], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false)
                    UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[14], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                    
                    if (floorType == "HASTC" || floorType == "OTC")
                    {
                        //High,Low,Average
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[15], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false)
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[16], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false)
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[17], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false)
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false)
                        
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[19], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                        
                    }
                    else
                    {
                        //ATO
                        //UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[15], changedRow.cells[cellIndex++], true, backColor2R2, backColor2Selected, false)
                        
                        //High,Low,Average
                        if (isShowSession1Volume == true)
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex + 3], true, backColor1R2, backColor1Selected, false) 
                        else
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false) 
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[15], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false)
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[16], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false)
                        //UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], true, backColor2R2, backColor2Selected, false)
                        
                        //Total volume
                        UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[17], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false)
                        //UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[24], false, backColor1R2, backColor1Selected, false) 
                    }
                    
                    if (floorType == "HASTC" || floorType == "OTC")
                    {
                        if (isShowBuyVolume == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSellVolume == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowBuyOrderCount == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSellOrderCount == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[24], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowForeignSell == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[25], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[26], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                    }
                    else if (floorType == "HOSE")
                    {
//                        if (isShowSession1Price == true)
//                        {
//                            if (isShowSession1Volume == true)
//                                UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false) 
//                            else
//                                UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[18], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false) 
//                        }
                        if (isShowSession1Volume == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[19], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSession2Price == true)
                        {
                            if (isShowSession2Volume == true)
                                UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], changedRow.cells[cellIndex], true, backColor1R2, backColor1Selected, false) 
                            else
                                UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[20], changedRow.cells[cellIndex++], null, true, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowSession2Volume == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[21], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowForeignBuy == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[22], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                        if (isShowCurrentRoom == true)
                        {
                            UpdateCellDataImmediately(spanSymbol, chkSymbol, basicItemInfo, valueArray[23], changedRow.cells[cellIndex++], null, false, backColor1R2, backColor1Selected, false) 
                        }
                    }
                }
           }
        }
       
    }
    
    currentUpdatedIndex = maxIndex;
    
    var itemCount = orderedSymbolList.length;
//    if (displayedSymbolsString == "all")
//        itemCount = basicObject.ItemCount;
//    else
//        itemCount = displayedSymbolList.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(spanSymbol, chkSymbol, basicItemInfo, data, cell, volumeCell, isPrice, backColor, backColorSelected, isPriceChange, currentPrice)
 {
    if (isUpdatingBasicData == true)
        return;
        
    if (data != "") 
    {
        //var chkSymbol = document.getElementById("chk" + symbol);
        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"; 
                }
                //cellInfo.data = "CE+" + data;
        
            }
            else
            {   
                //Giảm giá
                if (data.length > 0 && data.substr(0,1) == "-")
                {
                    if (isShowVolumeColor == false)
                        cell.className = "downPrice"
                    
                    if (isThreeColors == false)  
                    {  
                        cell.innerHTML = basicItemInfo.Symbol + " <img src=\"images/btdown.gif\" />" + " " + data;
                        //spanSymbol.innerHTML = "<img src=\"images/btdown.gif\" />";
                    }
                }
                else
                //Không đổi
                if (data == "0")
                {
                    if (isShowVolumeColor == false)
                         cell.className = "unchangePrice"
                    
                    if (isThreeColors == false)  
                    {  
                        cell.innerHTML = basicItemInfo.Symbol;// + " <img src=\"images/btnochange.jpg\" />" + " " + data;
                        //spanSymbol.innerHTML = "<img src=\"images/btnochange.jpg\" />";
                    }
                }
                //Tăng giá
                else
                {
                    if (isShowVolumeColor == false)
                        cell.className = "upPrice" 
                    
                    if (isThreeColors == false)   
                    { 
                        cell.innerHTML = basicItemInfo.Symbol + " <img src=\"images/btup.gif\" />" + " +" + data;
                        //spanSymbol.innerHTML = "<img src=\"images/btup.gif\" />";
                    }
                }
                
                if (isThreeColors == 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
                        cell.innerHTML = basicItemInfo.Symbol + " " + cell.innerHTML;
                }
//                else
//                    alert(currentPrice)
            }
            
            
        }
    }
 }
 
 //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)
//        alert("null");
//        else
//    alert(highlightRow.id);
    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 row = document.getElementById("tr" + symbol);
    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 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 8:
            case 9:
            case 13:
            case 14:
            case 17:
            case 18:
            
            case 19:
            case 20:
            
            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 10:
            
            case 11:
            case 12:
            
            
                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")
//                {
//                    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);
    //highlightRow = null;
    //alert("out");
 }
 
 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++;
        }
    }
    
    var chkDisplayAll = document.getElementById("chkDisplayAll");
    if (displayedSymbolsString == "all")
        chkDisplayAll.checked = true;
    else
        chkDisplayAll.checked = false;
    ToggleDisplayAll();
 }
 
 function CreateExtraHeaderCells(tableId)
 {
    //isReadyToResize = false;
    
    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")
        lastIndex = 12;
    else
        lastIndex = 11;
            
    for(var i=theHeaderRow.cells.length-1;i>=lastIndex + 1; i--)
    {
        theHeaderRow.deleteCell(i);
    }
    
    var headerCell;
     if (currentLanguage == "vi-VN")
    {
        localizeObject = localizeVN;
    }
    else if (currentLanguage == "en-US")
    {
        localizeObject = localizeEN;
    }
    else
    {
        localizeObject = localizeJP;
    }
    
    if (floorType == "HASTC" || floorType == "OTC")
        columnCount = 25;
    else
        columnCount = 24;
    
    
    //Thêm các cột phụ
    if (isShowBuyVolume == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.BuyVolume;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;
        
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "4%";
        //headerCell.id = "tdBuyVolume";
        columnCount++;
    }
    
    if (isShowSellVolume == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.SellVolume;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "4%";
        //headerCell.id = "tdSellVolume";
        columnCount++;
    }
    
    if (isShowBuyOrderCount == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.BuyOrderCount;
        headerCell.className = "tableHeader7";
        headerCell.rowSpan = 2;
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "3%";
        //headerCell.id = "tdBuyOrderCount";
        columnCount++;
    }
    
    if (isShowSellOrderCount == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.SellOrderCount;
        headerCell.className = "tableHeader7";
        headerCell.rowSpan = 2;
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "3%";
        //headerCell.id = "tdSellOrderCount";
        columnCount++;
    }
    
//    if (isShowSession1Price == true)
//    {
//        headerCell = theHeaderRow.insertCell(-1);
//        headerCell.innerHTML = localizeObject.Session1Price;
//        headerCell.className = "tableHeader6";
//        headerCell.rowSpan = 2;
//        
//        //if (tableId != "tableFixedHeader")
//        //    headerCell.width = "4%";
//        //headerCell.id = "tdBuyVolume";
//        columnCount++;
//    }
    
    if (isShowSession1Volume == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.Session1Volume;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;
        
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "4%";
        //headerCell.id = "tdBuyVolume";
        columnCount++;
    }
    
    if (isShowSession2Price == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.Session2Price;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;
        
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "4%";
        //headerCell.id = "tdBuyVolume";
        columnCount++;
    }
    
    if (isShowSession2Volume == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.Session2Volume;
        headerCell.className = "tableHeader6";
        headerCell.rowSpan = 2;
        
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "4%";
        //headerCell.id = "tdBuyVolume";
        columnCount++;
    }
    
    if (isShowForeignBuy == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.ForeignBuy;
        headerCell.className = "tableHeader8";
        headerCell.rowSpan = 2;
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "4%";
        //headerCell.id = "tdForeignBuy";
        columnCount++;
    }
    
    if (isShowForeignSell == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.ForeignSell;
        headerCell.className = "tableHeader8";
        headerCell.rowSpan = 2;
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "4%";
        //headerCell.id = "tdForeignSell";
        columnCount++;
    }
    
    if (isShowCurrentRoom == true)
    {
        headerCell = theHeaderRow.insertCell(-1);
        headerCell.innerHTML = localizeObject.CurrentRoom;
        headerCell.className = "tableHeader8";
        headerCell.rowSpan = 2;
        //if (tableId != "tableFixedHeader")
        //    headerCell.width = "4%";
        //headerCell.id = "tdForeignSell";
        columnCount++;
    }
    
    if (isNone == true)
        theHeaderRow.style.display = "none";
    //isReadyToResize = true;
 }
 
 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();
        
//    if (setClientInfo == true)
//        self.setTimeout("SetClientInfoAndGetData()", 5000);
//    else
//        self.setTimeout("StartRequest()", 5000);
   
    
    var theTable = document.getElementById("tableQuote");
    var tdDate = document.getElementById("tdDate");
    
    if (basicObject == null || basicObject.ItemList == null)
        return;
    
    isCreatingBasicRows = true;
    isUpdatingBasicData = true;
    
    tdDate.innerHTML = basicObject.Date;            
    
//    if (tableType == 0)
//        headerRowCount = 2;
//    else
//        headerRowCount = 0;
    
    for(var i= theTable.rows.length-1; i>=0; i-- )
    {
        if (i >= headerRowCount)
            theTable.deleteRow(i);
    }
//alert(headerRowCount);
    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;
    
    //Tạo danh sách mã CK theo thứ tự các mã được chọn được đưa lên trên
    var tempSelectedSymbolString = oldSelectedSymbolList.join();
    orderedSymbolList = new Array();
    
    if (showSelectedSymbolsOnTop == true)
    {
        var itemKey;
        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);
        }
//        for(var itemKey in basicObject.ItemList)
//        {
//            if (tempSelectedSymbolString.indexOf(itemKey) >= 0 && (displayedSymbolsString == "all" || displayedSymbolsString.indexOf("'" + itemKey + "'") >= 0))
//                orderedSymbolList.push(itemKey);
//        }
        for(var itemKey in basicObject.ItemList)
        {
            if (tempSelectedSymbolString.indexOf(itemKey) == -1 && (displayedSymbolsString == "all" || displayedSymbolsString.indexOf("'" + itemKey + "'") >= 0))
                orderedSymbolList.push(itemKey);
        }
    }
    else
    {
        for(var itemKey in basicObject.ItemList)
        {
            if (displayedSymbolsString == "all" || displayedSymbolsString.indexOf("'" + itemKey + "'") >= 0)
                orderedSymbolList.push(itemKey);
        }
    }
    //alert(tempSelectedSymbolString.indexOf("ALP"));
    var maxBasicIndex = 30;
    if (orderedSymbolList.length < 30)
        maxBasicIndex = orderedSymbolList.length;
    
    //Tạo rows mới
    //for(var itemKey in basicObject.ItemList)
    for (currentUpdatedBasicIndex=0; currentUpdatedBasicIndex< maxBasicIndex; currentUpdatedBasicIndex++)
    {
        //i++;
        
        //Nếu CK này ko được chọn để hiển thị
//        if (displayedSymbolsString != "all" && displayedSymbolsString.indexOf("'" + itemKey + "'") == -1)
//            continue;
            
//        if (currentUpdatedBasicIndex >= 30)
//            break;
//        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(";");
        
        //Row đầu tiên thì tự tạo
        if (currentUpdatedBasicIndex == 0)
        {
            newRow = theTable.insertRow(-1);
            newRow.style.height = "27px";
            newRow.id="tr" + itemKey;
            newRow.className=rowClassName;
            newRow.onmouseover = OnMouseOverQuote;
            newRow.onmouseout = OnMouseOutQuote;
            
            
            newCell = newRow.insertCell(-1);
            newCell.className = "cellCode";
            
            if (tableType == 0)
            {
                if (stockUrl == "")
                    newCell.innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/><span id=\"spanSymbol" + itemKey + "\"></span> " + itemKey;                
                else
                    newCell.innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/><span id=\"spanSymbol" + itemKey + "\"></span> " + "<a id='lnk" + itemKey + "' href='javascript:OpenWindow(\"" + itemKey + "\")'>" + itemKey + "</a>";
            }
            else
            {
                //newCell.style.fontSize = "9pt";
                newCell.style.paddingLeft = "4px";
                
                if (stockUrl == "")
                    newCell.innerHTML = "<span id=\"spanSymbol" + itemKey + "\"></span> " + itemKey;
                else
                    newCell.innerHTML = "<span id=\"spanSymbol" + itemKey + "\"></span> <a href='javascript:OpenWindow(\"" + itemKey + "\")'>" + itemKey + "</a>";
            }
            
            newCell.style.width = "4.5%";
            newCell.style.fontWeight = fontStyle2;
            newCell.style.wordWrap = "normal";
            
            newCell = newRow.insertCell(-1);
            newCell.className = "cellCeiling";
            newCell.innerHTML = valueArray[0];
            newCell.style.width = "3%";
            newCell.style.fontWeight = fontStyle2;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "cellFloor";
            newCell.innerHTML = valueArray[1];
            newCell.style.width = "3%";
            newCell.style.fontWeight = fontStyle2;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "cellRef";
            newCell.innerHTML = valueArray[2];
            newCell.style.width = "3%";
            newCell.style.fontWeight = fontStyle2;

            newRow.cells[0].style.backgroundColor = backColorSymbol;
            newRow.cells[1].style.backgroundColor = backColor1;
            newRow.cells[2].style.backgroundColor = backColor1;
            newRow.cells[3].style.backgroundColor = backColor1; 
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalPrice";
            newCell.style.width = "3.0%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalVol";
            newCell.style.width = "3.5%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalPrice";
            newCell.style.width = "3.0%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalVol";
            newCell.style.width = "3.5%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalPrice";
            newCell.style.width = "3.0%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalVol";
            newCell.style.width = "3.5%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            //newCell.colSpan = 2;
            newCell.className = "normalChange";
            newCell.style.width = "6.5%";
            newCell.style.fontWeight = fontStyle2;
            newCell.style.wordWrap = "normal";
            newCell.style.textAlign = "left";
            newCell.style.paddingLeft = "8px";
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalMatchingPrice";
            newCell.style.width = "3.5%";
            newCell.style.fontWeight = fontStyle2;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalMatchingVol";
            newCell.style.width = "3.5%";
            newCell.style.fontWeight = fontStyle2;
            
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalPrice";
            newCell.style.width = "3.0%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalVol";
            newCell.style.width = "3.5%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalPrice";
            newCell.style.width = "3.0%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalVol";
            newCell.style.width = "3.5%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalPrice";
            newCell.style.width = "3.0%";
            newCell.style.fontWeight = fontStyle1;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalVol";
            newCell.style.width = "3.5%";
            newCell.style.fontWeight = fontStyle1;
                        
            newCell = newRow.insertCell(-1);
            newCell.className = "normalHighLowPrice";
            newCell.style.width = "3.8%";
            newCell.style.fontWeight = fontStyle2;
            
            newCell = newRow.insertCell(-1);
            newCell.className = "normalHighLowPrice";
            newCell.style.width = "3.8%";
            newCell.style.fontWeight = fontStyle2;
                        
            newCell = newRow.insertCell(-1);
            newCell.className = "normalHighLowPrice";
            newCell.style.width = "3.8%";
            newCell.style.fontWeight = fontStyle2;
            
//            newCell = newRow.insertCell(-1);
//            newCell.className = "normalHighLowPrice";
//            newCell.style.width = "3.8%";
            
//            newCell = newRow.insertCell(-1);
//            newCell.className = "normalHighLowPrice";
            
//            newCell = newRow.insertCell(-1);
//            newCell.className = "normalVol";
            
            switch (floorType)
            {
                case "HASTC":
                case "OTC":
                    newCell = newRow.insertCell(-1);
                    newCell.className = "normalHighLowPrice";
                    newCell.style.width = "3.8%";
                    newCell.style.fontWeight = fontStyle2;
            
                    newCell = newRow.insertCell(-1);
                    newCell.className = "normalVol";
                    newCell.style.width = "3.8%";
                    newCell.style.fontWeight = fontStyle1;
                    
                    if (isShowBuyVolume == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraBuyVol";
                        newCell.style.width = "3.8%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowSellVolume == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraSellVol";
                        newCell.style.width = "3.8%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowBuyOrderCount == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraBuyVol";
                        newCell.style.width = "3.5%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowSellOrderCount == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraSellVol";
                        newCell.style.width = "3.5%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowForeignBuy == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraBuyVol";
                        newCell.style.width = "3.8%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowForeignSell == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraSellVol";
                        newCell.style.width = "3.8%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowCurrentRoom == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraSellVol";
                        newCell.style.width = "3.8%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    break;
                case "HOSE":
//                    newCell = newRow.insertCell(-1);
//                    newCell.className = "extraBuyVol";
//                    newCell.style.width = "4%";
                        
                    newCell = newRow.insertCell(-1);
                    newCell.className = "normalVol";
                    newCell.style.width = "3.8%";
                    newCell.style.fontWeight = fontStyle1;
                    
//                    if (isShowSession1Price == true)
//                    {
//                        newCell = newRow.insertCell(-1);
//                        newCell.className = "normalPrice";
//                        newCell.style.width = "3.8%";
//                        newCell.style.fontWeight = fontStyle1;
//                    }
                    
                    if (isShowSession1Volume == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "normalVol";
                        newCell.style.width = "3.8%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowSession2Price == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "normalPrice";
                        newCell.style.width = "3.5%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowSession2Volume == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "normalVol";
                        newCell.style.width = "3.5%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowForeignBuy == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraBuyVol";
                        newCell.style.width = "3.8%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    
                    if (isShowCurrentRoom == true)
                    {
                        newCell = newRow.insertCell(-1);
                        newCell.className = "extraSellVol";
                        newCell.style.width = "3.8%";
                        newCell.style.fontWeight = fontStyle1;
                    }
                    break;
                    
            }
            
//            var colIndex = 0;
//            var tableFixedHeader = document.getElementById("tableFixedHeader");
//            //alert(newRow.cells.length);
//            for (colIndex = 0; colIndex < newRow.cells.length; colIndex++)
//            {
//                newRow.cells[0].style.width = tableFixedHeader.tHead.rows[1].cells[0].style.width;
//            }
            
        }
        //Các row tiếp theo thì copy để tăng tốc độ
        else
        {
            if (currentUpdatedBasicIndex == 1)
            {        
                newRow = theTable.rows[2].cloneNode(true);
                theTable.rows[2].parentNode.appendChild(newRow);
                
                newRow.cells[0].style.backgroundColor = backColorSymbolR2;
                newRow.cells[1].style.backgroundColor = backColor1R2;
                newRow.cells[2].style.backgroundColor = backColor1R2;
                newRow.cells[3].style.backgroundColor = backColor1R2;
            }
            else
                if (currentUpdatedBasicIndex%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);\"/><span id=\"spanSymbol" + itemKey + "\"></span> " + itemKey;                
                else
                    newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/><span id=\"spanSymbol" + itemKey + "\"></span> " + "<a id='lnk" + itemKey + "' href='javascript:OpenWindow(\"" + itemKey + "\")'>" + itemKey + "</a>";
                //newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "');\"/>" + "<a href='http://www.shs.com.vn'>" + itemKey + "</a>";
            else
                if (stockUrl == "")
                    newRow.cells[0].innerHTML = "<span id=\"spanSymbol" + itemKey + "\"></span> " + itemKey;
                else
                    newRow.cells[0].innerHTML = "<span id=\"spanSymbol" + itemKey + "\"></span> <a href='javascript:OpenWindow(\"" + itemKey + "\")'>" + itemKey + "</a>";
                //newRow.cells[0].innerHTML = "<a href='http://www.shs.com.vn'>" + 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;
            
        }        
    }
    
    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 i = 0;
    
    var itemKey;
    //Tạo rows mới
    //for(var itemKey in basicObject.ItemList)
    for (;currentUpdatedBasicIndex< maxBasicIndex; currentUpdatedBasicIndex++)
    {

        //Nếu CK này ko được chọn để hiển thị
//        if (displayedSymbolsString != "all" && displayedSymbolsString.indexOf("'" + itemKey + "'") == -1)
//            continue;
//            
//        i++;
//        //Bỏ qua những dòng đã cập nhật
//        if (i <= currentUpdatedBasicIndex)
//            continue;
//            
//        if (currentUpdatedBasicIndex >= maxBasicIndex)
//            break;
//         
//        currentUpdatedBasicIndex++;
        itemKey = orderedSymbolList[currentUpdatedBasicIndex];
            
        if (currentUpdatedBasicIndex%2 == 0)
            newRow = theTable.rows[2].cloneNode(true);
        else
            newRow = theTable.rows[3].cloneNode(true);
        //newRow = theTable.rows[2].cloneNode(true);
        
        newRow.id="tr" + itemKey;
        theTable.rows[2].parentNode.appendChild(newRow);
        
        if (tableType == 0)
            if (stockUrl == "")
                newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/><span id=\"spanSymbol" + itemKey + "\"></span> " + itemKey;                
            else
                newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "', false);\"/><span id=\"spanSymbol" + itemKey + "\"></span> " + "<a id='lnk" + itemKey + "' href='javascript:OpenWindow(\"" + itemKey + "\")'>" + itemKey + "</a>";
            //newRow.cells[0].innerHTML = "<input type=\"checkbox\" id=\"chk" + itemKey + "\" onClick=\"Toggle('" + itemKey + "');\"/>" + "<a href='http://www.shs.com.vn'>" + itemKey + "</a>";
        else
            if (stockUrl == "")
                newRow.cells[0].innerHTML = "<span id=\"spanSymbol" + itemKey + "\"></span> " + itemKey;
            else
                newRow.cells[0].innerHTML = "<span id=\"spanSymbol" + itemKey + "\"></span> <a href='javascript:OpenWindow(\"" + itemKey + "\")'>" + itemKey + "</a>";
            //newRow.cells[0].innerHTML = "<a href='http://www.shs.com.vn'>" + 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;
                //if (isShowSelectedColor == true || showSelectedSymbolsOnTop == false)
                    Toggle(selectedSymbol, true);
            }
        }
        if (showSelectedSymbolsOnTop == true && isShowSeparator == true && selectedCount > 0)
        {
            var theTable = document.getElementById("tableQuote");
            theTable.rows[selectedCount + headerRowCount - 1].className = rowSeparatorClassName;
        }
        //if (isShowSelectedColor == true || showSelectedSymbolsOnTop == false)
//        {
//            unselectedSymbolList = oldUnselectedSymbolList;
//            selectedSymbolList = oldSelectedSymbolList;
//        }
    }
    else
    {
        unselectedSymbolList = oldUnselectedSymbolList;
        selectedSymbolList = oldSelectedSymbolList;
    }

    //ResizeHeader();
    isUpdatingBasicData = false;
    
    if (isPutThroughDisplayed == true)
        GetPutThroughObject();
        
    if (isShowTooltip == true && tableType == 0)    
    {
        var stockInfoTimerID = self.setTimeout("UpdateStockInfoTooltip()", 2000);
    }
 }
 
 function OpenWindow(symbol)
 {
    var options = "";
    options += "resizable=yes,scrollbars=yes,status=yes,";
    options += "menubar=no,toolbar=no,location=yes,directories=no";
    var newWin = window.open(stockUrl + symbol, 'newWin', options);
    newWin.focus();

 }
 
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);
                    
                    
                    //self.setTimeout("GetStockInfo()", 2000);
                }    
                
            }
            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;
                    
                    UpdateMarketImmediately();
                    
                    currentUpdatedIndex = 0;
                    UpdateImmediately();
                    //StartUpdate();
                    
                    //Chuyển sang gọi trong UpdateImmediately để tránh xung đột
//                    if (isTradingTime == true && requestTimerID == null)
//                        requestTimerID = self.setTimeout("StartRequest()", 3000)
                }
                else
                {
                    currentVersionId = result.VId;
                    
                    if (floorType == "HOSE")
                        currentMarketVersionId = result.MVId;
                    
                    UpdateMarket();
                    
                    StartUpdate();
                    
//                    if (isTradingTime == true && requestTimerID == null)
//                        requestTimerID = self.setTimeout("StartRequest()", 2000);
                    //updateTimerID = self.setTimeout("StartUpdate()", 1)
                    
                }
            }
            else
            {            
                currentVersionId = result.VId;
                
                if (floorType == "HOSE")
                    currentMarketVersionId = result.MVId;
                
                if (isTradingTime == true && requestTimerID == null)
                    requestTimerID = self.setTimeout("StartRequest()", 2000)
            }
            
            break;
        }
        case ("GetHosePutThroughObject"):
        case ("GetHastcPutThroughObject"):
        {
            DeletePutThroughTable(tablePutThrough);
            
            //if (floorType == "HOSE")
            {
                DeletePutThroughTable(tablePutThroughBuy);
                DeletePutThroughTable(tablePutThroughSell);
            }
            if (result == null)
                return;
            if (result.ML != null)
                UpdatePutThroughTable(tablePutThrough, result.ML, true);
            
            //if (floorType == "HOSE")
            {
                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;
        }
    }
         
}

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 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 itemKey in dataList)
    {
        item = dataList[itemKey];
        valueArr = item.split(";");
        
        newRow = theTable.insertRow(-1);
        newRow.style.height = "19px";
        
        newCell = newRow.insertCell(-1);
        newCell.className = "cellCode";
        newCell.innerHTML = valueArr[0];
        
        newCell = newRow.insertCell(-1);
        newCell.innerHTML = valueArr[1];
        newCell.className = "normalPrice";
        
        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";
        }
        newCell = newRow.insertCell(-1);
        newCell.className = "normalVol";
        newCell.innerHTML = valueArr[2];
        
        if ((floorType == "HASTC" || floorType == "OTC") && isMatching == true)
        {
            newCell = newRow.insertCell(-1);
            newCell.innerHTML = valueArr[3];
            newCell.className = "normalValue";
            
            newCell = newRow.insertCell(-1);
            newCell.innerHTML = valueArr[4];
            newCell.className = "normalTime";
        }
        else if (floorType == "HOSE")
        {
            newCell = newRow.insertCell(-1);
            newCell.innerHTML = valueArr[3];
            if (isMatching == true)
                newCell.className = "normalValue";
            else
                newCell.className = "normalTime";
        }
            
//        if (floorType == "HASTC" && theTable == tablePutThrough)
//        {
//            newCell = newRow.insertCell(-1);
//            newCell.className = "normalTime";
//            newCell.innerHTML = valueArr[4];
//        }

    }
}

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();


