﻿var gBondVN=new Array("KH còn lại<br/>(năm)","Đặt mua tốt nhất","Mã TP","Chào bán tốt nhất","KL","Giá","Lãi suất","Tổng KLTH","Cao<br/>nhất","Thấp<br/>nhất","Cuối<br/>cùng"," tỷ");
var gBondEN=new Array("Time to maturity<br/>(year)","Best Bid","Code","Best Ask","Volume","Clean price","Yield","Total Volume","High","Low","Last"," milliard");

function BondOutRightMarketCallback(result, eventArgs)
{
    try
    {
        if ((typeof(result)=="undefined") || (result==null) || (result=="") || (result=="undefined"))
            return;
        var a=result.split("|");
        var i=0;
        var tr=document.getElementById("trHeader");
        if (tr.cells.length==0)
        {
            for (i=0;i<5;i++)
                tr.insertCell(i);
        }
        tr.cells[0].innerHTML=a[0];
//        tr.cells[1].innerHTML=addCommas(a[4]);
        tr.cells[1].innerHTML=addCommas(a[5]) + gText[11];
//        tr.cells[3].innerHTML=addCommas(a[7]);
        tr.cells[2].innerHTML=addCommas(a[8]) + gText[11];
        tr.cells[3].innerHTML=MarketState(a[2]);
        tr.cells[4].innerHTML=a[1];
    }
    catch(e)
    {}
}
function CreateOutRightPriceHeader()
{
    var h="";
    h+="<table class=Grd border=1 cellspacing=0 cellpadding=0>"   
       
    h+="<tr class=RowHeader>";
    //Kỳ hạn<br/>(năm)
	//h+="<td rowspan=2 class=H1 height=40px width="+GetWidth("th0")+">"+gText[0]+"</td>";
	//KH còn lại<br/>(ngày)
	h+="<th rowspan=2 class=H2 height=40px width="+GetWidth("th1")+">"+gText[0]+"</th>";
    //Đặt mua tốt nhất
	h+="<th colspan=3 class=H1>"+gText[1]+"</th>";
	//Mã TP
	h+="<th rowspan=2 class=H2 width="+GetWidth("th5")+">"+gText[2]+"</th>";
	//Đặt bán tốt nhất
	h+="<th colspan=3 class=H1>"+gText[3]+"</th>";
	// Lai suat
	h+="<th colspan=3 class=H2>"+gText[6]+"</th>";	
	//Tổng KLTH
	h+="<th rowspan=2 class=H1 width="+GetWidth("th12")+">"+gText[7]+"</th>";
    h+="</tr>";

    h+="<tr class=RowHeader>";
    //Mua
	h+="<th class=H2 width="+GetWidth("th2")+">"+gText[4]+"</th>";
	h+="<th class=H1 width="+GetWidth("th3")+">"+gText[5]+"</th>";
	h+="<th class=H1 width="+GetWidth("th4")+">"+gText[6]+"</th>";
	//Ban
	h+="<th class=H1 width="+GetWidth("th6")+">"+gText[6]+"</th>";
	h+="<th class=H1 width="+GetWidth("th7")+">"+gText[5]+"</th>";
	h+="<th class=H1 width="+GetWidth("th8")+">"+gText[4]+"</th>";
	//Lai suat
	h+="<th class=H1 width="+GetWidth("th9")+">"+gText[8]+"</th>";
	h+="<th class=H1 width="+GetWidth("th10")+">"+gText[9]+"</th>";
	h+="<th class=H1 width="+GetWidth("th11")+">"+gText[10]+"</th>";

    h+="</tr>";

    h+="</table>";
    
    var header=document.getElementById("OutRightPriceHeader");
    if (header)
    {
        header.innerHTML=h;
        header.className=browser;
        var price=document.getElementById("OutRightPrice");
        if (price)
        {
            header.style.width = (price.offsetWidth)+"px";
        }
    }
    return;
}
// Create the header of the list of prices
function OutRightPriceHeader()
{
    var h="";
    
    h+="<tr class=RowHeader>";
    //Kỳ hạn<br/>(năm)
	//h+="<td id=th0 rowspan=2 class=H2 height=40px>"+gText[0]+"</td>";
	//KH còn lại<br/>(năm)
	h+="<th id=th1 rowspan=2 class=H2 height=40px>"+gText[0]+"</th>";
    //Đặt mua tốt nhất
	h+="<th colspan=3 class=H1>"+gText[1]+"</th>";
	//Mã TP
	h+="<th id=th5 rowspan=2 class=H2>"+gText[2]+"</th>";
	//Đặt bán tốt nhất
	h+="<th colspan=3 class=H1>"+gText[3]+"</th>";
	// Lai suat
	h+="<th colspan=3 class=H2>"+gText[6]+"</th>";	
	//Tổng KLTH
	h+="<th id=th12 rowspan=2 class=H1>"+gText[7]+"</th>";
    h+="</tr>";

    h+="<tr class=RowHeader>";
    //Mua
	h+="<th id=th2 class=H1>"+gText[4]+"</th>";
	h+="<th id=th3 class=H1>"+gText[5]+"</th>";
	h+="<th id=th4 class=H1>"+gText[6]+"</th>";
	//Ban
	h+="<th id=th6 class=H1>"+gText[6]+"</th>";
	h+="<th id=th7 class=H1>"+gText[5]+"</th>";
	h+="<th id=th8 class=H1>"+gText[4]+"</th>";
	//Lai suat
	h+="<th id=th9 class=H2>"+gText[8]+"</th>";
	h+="<th id=th10 class=H2>"+gText[9]+"</th>";
	h+="<th id=th11 class=H2>"+gText[10]+"</th>";

    h+="</tr>";
    return h;    
}
// Create the list of prices
function BondOutRightCallback(result,eventArgs)
{
    try
    {
        var LastValue=CheckChangeData(result);
        if (LastValue=="")
        {
            var divLastValue = document.getElementById("LastValue");
            if ((typeof(divLastValue) != "undefined") && (divLastValue != null) && (divLastValue != "undefined"))
            {
                LastValue = divLastValue.innerText;
                if (LastValue=="")
                {
                    var t="<table class=Grd border=1 cellspacing=0 cellpadding=0>";
                    t+=OutRightPriceHeader();
                    t+="</table>";
                    var RsltElem=document.getElementById("OutRightPrice");
                    RsltElem.innerHTML=t;
               }
            }
            return;
        }
        DrawOutRightPrice(result, LastValue);
    }    
    catch(e)
    {}
}
function DrawOutRightPrice(result, LastValue)
{
    var selectedStocks=get_cookie(CookieStockName);
    
    var grid="<table class=Grd border=1 cellspacing=0 cellpadding=0>";
    grid=grid+OutRightPriceHeader();
    var grid1="";
    var grid2="";
    var line="";
    var rows=result.split("#");
    var old=LastValue.split("#");
    if (rows.length != old.length)
        old=rows;
    
    //alert(result);
    for (var i=0; i<rows.length; i++)
    {
        var v="";
        var tr="<tr height=18px onmouseover=mover(this) onmouseout=mout(this)>";
        var a=rows[i].split("|");
        var b=old[i].split("|");
//        // Ky han
//        tr+="<td class=TD1 width=4% style=\""+TC+"\">"+a[0]+"</td>";
        // Ky han
        tr+="<td class=TD2 width=6% style=\""+TC+"\">"+a[0]+"</td>";
        // KL mua
        tr+="<td class=TD3 width=8% >"+addCommas(a[1])+"</td>";
        // Gia mua
        tr+="<td class=TD3 width=6% style=\""+UP+"\">"+addCommas(a[2])+"</td>";
        // Lai suat mua
        tr+="<td class=TD4 width=5% style=\""+UP+"\">"+a[3]+"</td>";
        
        // Ma Trai phieu
        tr+="<td class=MaTP width=8% >"+a[4]+"</td>";

        // Lai suat
        tr+="<td class=TD3 width=5% style=\""+DW+"\">"+a[5]+"</td>";
        // Gia mua
        tr+="<td class=TD3 width=6% style=\""+DW+"\">"+addCommas(a[6])+"</td>";
        // KL mua
        tr+="<td class=TD4 width=8% >"+addCommas(a[7])+"</td>";
        
        // Cao nhat
        tr+="<td class=TD1 width=4% style=\""+TC+"\">"+a[8]+"</td>";
        // Thap nhat
        tr+="<td class=TD1 width=4% style=\""+TC+"\">"+a[9]+"</td>";
        // Cuoi cung
        tr+="<td class=TD2 width=4% style=\""+TC+"\">"+a[10]+"</td>";

        // Tong KL
        tr+="<td class=TD4 width=8% >"+addCommas(a[11])+"</td>";
        
        tr+="</tr>";

        grid2=grid2+tr;
    }
    grid=grid+grid2+"</table>";
        
    var RsltElem=document.getElementById("OutRightPrice");
    RsltElem.innerHTML=grid;
    
    CreateOutRightPriceHeader();
}

