﻿var gReposVN=new Array("Kỳ hạn Repos<br/>(ngày)","Đặt mua tốt nhất","Chào bán tốt nhất","GTMG","Lãi suất","Tổng GTMG","Tổng GTMG<br/>Repos lần 2","GD gần nhất","Ngày"," tỷ");
var gReposEN=new Array("Repos Period<br/>(day)","Best Bid","Best Ask","Par Value","Interest<br/>rate","Total Value","Total Value<br/>Second Repos","Last trading","Date"," milliard");

function BondReposMarketCallback(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<6;i++)
                tr.insertCell(i);
        }
        tr.cells[0].innerHTML=a[0];
        tr.cells[1].innerHTML=addCommas(a[4]) + gText[9];
        tr.cells[2].innerHTML=addCommas(a[5]) + gText[9];
        tr.cells[3].innerHTML=MarketState(a[2]);
        tr.cells[4].innerHTML=a[1];
    }
    catch(e)
    {}
}
function CreateReposPriceHeader()
{
    var h="";
    h+="<table class=Grd border=1 cellspacing=0 cellpadding=0>"   
        
    h+="<tr class=RowHeader>";
    //Đặt mua tốt nhất
	h+="<th colspan=2 class=H2>"+gText[1]+"</th>";
    //Kỳ hạn Repos<br/>(năm)
	h+="<td id=th0 rowspan=2 class=H1 height=40px width="+GetWidth("th0")+">"+gText[0]+"</td>";
	//Đặt bán tốt nhất
	h+="<th colspan=2 class=H2>"+gText[2]+"</th>";
	//Tổng GTMG - Repos lan 1
	h+="<th id=th5 rowspan=2 class=H1 width="+GetWidth("th5")+">"+gText[5]+"</th>";
//	//Tổng GTMG - Repos lan 2
//	h+="<th id=th6 rowspan=2 class=H1 width="+GetWidth("th5")+">"+gText[6]+"</th>";
	//GD gần nhất
	h+="<th colspan=3 class=H2>"+gText[7]+"</th>";
    h+="</tr>";

    h+="<tr class=RowHeader>";
	
    //Mua
	h+="<th id=th1 class=H2 width="+GetWidth("th1")+">"+gText[3]+"</th>";
	h+="<th id=th2 class=H2 width="+GetWidth("th2")+">"+gText[4]+"</th>";
	//Ban
	h+="<th id=th3 class=H2 width="+GetWidth("th3")+">"+gText[4]+"</th>";
	h+="<th id=th4 class=H2 width="+GetWidth("th4")+">"+gText[3]+"</th>";
	//GD gan nhat
	h+="<th id=th7 class=H2 width="+GetWidth("th7")+">"+gText[4]+"</th>";
	h+="<th id=th8 class=H2 width="+GetWidth("th8")+">"+gText[3]+"</th>";
	h+="<th id=th9 class=H2 width="+GetWidth("th9")+">"+gText[8]+"</th>";
    
    h+="</tr>";

    h+="</table>";
    
    var header=document.getElementById("ReposPriceHeader");
    if (header)
    {
        header.innerHTML=h;
        header.className=browser;
        var price=document.getElementById("ReposPrice");
        if (price)
        {
            header.style.width = (price.offsetWidth)+"px";
        }
    }
    return;
}
// Create the header of the list of prices
function ReposPriceHeader()
{
    var h="";
    
    h+="<tr class=RowHeader>";
    //Đặt mua tốt nhất
	h+="<th colspan=2 class=H2>"+gText[1]+"</th>";
    //Kỳ hạn Repos<br/>(năm)
	h+="<td id=th0 rowspan=2 class=H1 height=40px>"+gText[0]+"</td>";
	//Đặt bán tốt nhất
	h+="<th colspan=2 class=H2>"+gText[2]+"</th>";
	//Tổng GTMG
	h+="<th id=th5 rowspan=2 class=H1>"+gText[5]+"</th>";
//	//Tổng GTMG
//	h+="<th id=th6 rowspan=2 class=H1>"+gText[6]+"</th>";
	//GD gần nhất
	h+="<th colspan=3 class=H2>"+gText[7]+"</th>";
    h+="</tr>";

    h+="<tr class=RowHeader>";
	
    //Mua
	h+="<th id=th1 class=H2>"+gText[3]+"</th>";
	h+="<th id=th2 class=H2>"+gText[4]+"</th>";
	//Ban
	h+="<th id=th3 class=H2>"+gText[4]+"</th>";
	h+="<th id=th4 class=H2>"+gText[3]+"</th>";
	//GD gan nhat
	h+="<th id=th7 class=H2>"+gText[4]+"</th>";
	h+="<th id=th8 class=H2>"+gText[3]+"</th>";
	h+="<th id=th9 class=H2>"+gText[8]+"</th>";
    
    h+="</tr>";
    return h;    
}
// Create the list of prices
function BondReposCallback(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+=ReposPriceHeader();
                    t+="</table>";
                    var RsltElem=document.getElementById("ReposPrice");
                    RsltElem.innerHTML=t;
               }
            }
            return;
        }
        DrawReposPrice(result, LastValue);
    }    
    catch(e)
    {}
}
function DrawReposPrice(result, LastValue)
{
    var selectedStocks=get_cookie(CookieStockName);
    
    var grid="<table class=Grd border=1 cellspacing=0 cellpadding=0>";
    grid=grid+ReposPriceHeader();
    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("|");
        tr+="<td class=TD1 width=8% style=\""+UP+"\">"+addCommas(a[1])+"</td>";
        tr+="<td class=TD2 width=4% style=\""+UP+"\">"+a[2]+"</td>";
        tr+="<td class=TD4 width=6% style=\""+TC+"\">"+a[0]+"</td>";
        tr+="<td class=TD1 width=4% style=\""+DW+"\">"+a[3]+"</td>";
        tr+="<td class=TD2 width=8% style=\""+DW+"\">"+addCommas(a[4])+"</td>";
        
        tr+="<td class=TD4 width=8% >"+addCommas(a[5])+"</td>";
//        tr+="<td class=TD4 width=4% >"+addCommas(a[6])+"</td>";

        tr+="<td class=TD1 width=4% style=\""+TC+"\">"+a[7]+"</td>";
        tr+="<td class=TD1 width=8% style=\""+TC+"\">"+addCommas(a[8])+"</td>";
        tr+="<td class=TD2 width=6% style=\""+TC+"\">"+a[9]+"</td>";
        
        tr+="</tr>";

        grid2=grid2+tr;
    }
    grid=grid+grid2+"</table>";
        
    var RsltElem=document.getElementById("ReposPrice");
    RsltElem.innerHTML=grid;
    
    CreateReposPriceHeader();
}

