﻿function StockListHaCallback(result, eventArgs)
{
    CreateStockList(result, 'SSI.HASTC');
}
// Create the header of page (VNIndex, Change, Market state ...)
function HaHeaderCallback(result, eventArgs)
{
    try
    {
        if ((typeof(result)=="undefined") || (result==null) || (result=="") || (result=="undefined"))
            return;
        var a=result.split("|");
        var t="<table cellspacing=0 cellpadding=0>";
        t+="<tr class=Text1>";
        t+="<td class=Text1>Ngày GD</td>";
        t+="<td class=Text1>HNX Index</td>";
        t+="<td class=Text1>Thay đổi</td>";
        t+="<td><img src=App_Themes/Default/Images/up.gif /></td>";
        t+="<td><img src=App_Themes/Default/Images/equal.gif /></td>";
        t+="<td><img src=App_Themes/Default/Images/down.gif /></td>";
        t+="<td>KLGD</td>";
        t+="<td>GTGD</td>";
        t+="<td class=Text1>Trạng thái TT</td>";
        t+="<td class=Text1>Thời gian</td>";
        t+="</tr>";
        
        var style=GetIndexColor(a[6]);
        t+="<tr class=Text2>";
        t+="<td>"+a[2]+"</td>";
        t+="<td"+style+">"+a[5]+"</td>";
        t+="<td"+style+">"+a[6]+" ("+a[7]+" %)"+"</td>";
        
        var advances = get_cookie("ha_advances");
        if (advances==null) advances=0;
        var nochange = get_cookie("ha_nochange");
        if (nochange==null) nochange=0;
        var declines = get_cookie("ha_declines");
        if (declines==null) declines=0;
        t+="<td style=\"color:#00ff00\">"+advances+"</td>";
        t+="<td style=\"color:#ffff00\">"+nochange+"</td>";
        t+="<td style=\"color:#ff0000\">"+declines+"</td>";
        
        t+="<td>"+addCommas(a[3])+"</td>";
        t+="<td>"+addCommas(a[4])+"</td>";
        t+="<td>"+GetMarketStateHa(a[8])+"</td>";
        t+="<td>"+a[9]+"</td>";
        t+="</tr>";
        t+="<tr><td conspan=6 height=5></td></tr>";
        t+="</table>";

        var RsltElem=document.getElementById("HaHeader");
        RsltElem.innerHTML=t;
    }
    catch(e)
    {}
}
function CreateHaPriceHeader()
{
    var h="";
    h+="<table class=Grd border=1 cellspacing=0 cellpadding=0>"

    h+="<tr class=RowHeader>";

	h+="<td colspan=2 rowspan=2 class=H1 height=41px>Mã CK</td>";

	h+="<th colspan=4 class=H2>Giá</th>";

	h+="<th rowspan=2 class=H2 width="+GetWidth("th6")+">Tổng<br />KLTH</th>";

	h+="<th colspan=6 class=H1>Đặt mua</th>";
	h+="<th colspan=3 class=H2>Giao dịch</th>";
	h+="<th colspan=6 class=H1>Chào bán</th>";
	
	h+="<th colspan=2 class=H2>Nước ngoài</th>";
    h+="</tr>";
    
    h+="<tr class=RowHeader>";

	h+="<th class=H2 width="+GetWidth("th2")+">TC</th>";
	h+="<th class=H2 width="+GetWidth("th3")+">Trần</th>";
	h+="<th class=H2 width="+GetWidth("th4")+">Sàn</th>";
	h+="<th class=H2 width="+GetWidth("th5")+">TB</th>";
	
	h+="<th class=H1 width="+GetWidth("th7")+">KL3</th>";
	h+="<th class=H1 width="+GetWidth("th8")+">Giá<br/>3</th>";
	h+="<th class=H1 width="+GetWidth("th9")+">KL2</th>";
	h+="<th class=H1 width="+GetWidth("th10")+">Giá<br/>2</th>";
	h+="<th class=H1 width="+GetWidth("th11")+">KL1</th>";
	h+="<th class=H1 width="+GetWidth("th12")+">Giá<br/>1</th>";

	h+="<th class=H2 width="+GetWidth("th13")+">Giá<br/>TH</th>";
	h+="<th class=H2 width="+GetWidth("th14")+">+/-<br/>Giá</th>";
	h+="<th class=H2 width="+GetWidth("th15")+">KLTH</th>";

	h+="<th class=H1 width="+GetWidth("th16")+">Giá<br/>1</th>";
	h+="<th class=H1 width="+GetWidth("th17")+">KL1</th>";
	h+="<th class=H1 width="+GetWidth("th18")+">Giá<br/>2</th>";
	h+="<th class=H1 width="+GetWidth("th19")+">KL2</th>";
	h+="<th class=H1 width="+GetWidth("th20")+">Giá<br/>3</th>";
	h+="<th class=H1 width="+GetWidth("th21")+">KL3</th>";
	
	h+="<th class=H2 width="+GetWidth("th22")+">Mua</th>";
	h+="<th class=H2 width="+GetWidth("th23")+">Bán</th>";

    h+="</tr>";
    h+="<tr height=1><td width="+GetWidth("th1")+"></td><td width="+GetWidth("thImg")+"></td><td colspan=22></td></tr>";
    
    h+="</table>";
    
    var HaHeader=document.getElementById("HaHeaderPrice");
    if (HaHeader)
    {
        HaHeader.innerHTML=h;
        HaHeader.className=browser;
        var HaPrice=document.getElementById("HaPrice");
        if (HaPrice)
        {
            HaHeader.style.width = (HaPrice.offsetWidth)+"px";
        }
    }
    return;
}
// Create the header of the list of prices
function HaPriceHeader()
{
    var h="";

    h+="<tr class=RowHeader>";
	h+="<td colspan=2 rowspan=2 class=H1 height=40px>Mã CK</td>";
	h+="<th colspan=4 class=H2>Giá</th>";
	h+="<th id=th6 rowspan=2 class=H2>Tổng<br/>KLTH</th>";

	h+="<th colspan=6 class=H1>Đặt mua</th>";
	h+="<th colspan=3 class=H2>Giao dịch</th>";
	h+="<th colspan=6 class=H1>Chào bán</th>";
	
	h+="<th colspan=2 class=H2>Nước ngoài</th>";
    h+="</tr>";
    
    h+="<tr class=RowHeader>";
	h+="<th id=th2 class=H2>TC</th>";
	h+="<th id=th3 class=H2>Trần</th>";
	h+="<th id=th4 class=H2>Sàn</th>";
	h+="<th id=th5 class=H2>TB</th>";
	
	h+="<th id=th7 class=H1>KL3</th>";
	h+="<th id=th8 class=H1>Giá<br/>3</th>";
	h+="<th id=th9 class=H1>KL2</th>";
	h+="<th id=th10 class=H1>Giá<br/>2</th>";
	h+="<th id=th11 class=H1>KL1</th>";
	h+="<th id=th12 class=H1>Giá<br/>1</th>";

	h+="<th id=th13 class=H2>Giá<br/>TH</th>";
	h+="<th id=th14 class=H2>+/-<br/>Giá</th>";
	h+="<th id=th15 class=H2>KLTH</th>";

	h+="<th id=th16 class=H1>Giá<br/>1</th>";
	h+="<th id=th17 class=H1>KL1</th>";
	h+="<th id=th18 class=H1>Giá<br/>2</th>";
	h+="<th id=th19 class=H1>KL2</th>";
	h+="<th id=th20 class=H1>Giá<br/>3</th>";
	h+="<th id=th21 class=H1>KL3</th>";
	
	h+="<th id=th22 class=H2>Mua</th>";
	h+="<th id=th23 class=H2>Bán</th>";

    h+="</tr>";
    h+="<tr height=0><td id=th1></td><td id=thImg></td><td colspan=22></td></tr>";
    return h;    
}
// Create the list of prices
function HaPriceCallback(result,eventArgs)
{
    try
    {
        var LastValue=CheckChangeData(result);
        if (LastValue=="")
            return;
        DrawHaPrice(result, LastValue);
    }    
    catch(e)
    {}
}
function DrawHaPrice(result, LastValue)
{
    var selectedStocks=get_cookie("SSI.HASTC");
    
    var grid="<table class=Grd border=1 cellspacing=0 cellpadding=0>";
    grid=grid+HaPriceHeader();
    var grid1="";
    var grid2="";
    var line="";
    var rows=result.split("#");
    var old=LastValue.split("#");
    if (rows.length != old.length)
        old=rows;
    gAdvances=0;
    gDeclines=0;
    gNochange=0;
    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("|");
        // Stock symbol
        tr+="<td class=MaCK width=3% title="+GetTitle(a[0])+">"+a[0]+"</td>";
        //Image
        tr+="<td class=Img width=1%>"+Image(a[11],a[1])+"</td>";  
        // Gia TC
        tr+="<td class=TD1 width=4% style=\""+TC+"\">"+FormatNum(a[1])+"</td>";
        // Gia Tran
        tr+="<td class=TD1 width=4% style=\""+CE+"\">"+FormatNum(a[2])+"</td>";
        // Gia San
        tr+="<td class=TD1 width=4% style=\""+FL+"\">"+FormatNum(a[3])+"</td>";
        // Gia Trung binh
        tr+=P("TD2","4%",a[21],a[1],a[2],a[3],a[21]);
        // Tong KLTH
        tr+=KLHA("TD4","5%",a[4],b[4]);
        
        //KL mua 3
        tr+=KLHA("TD1","5%",a[5],b[5]);
        //Gia mua 3
        tr+=P("TD1","4%",a[6],a[1],a[2],a[3],b[6]);
        //KL mua 2
        tr+=KLHA("TD1","5%",a[7],b[7]);
        //Gia mua 2
        tr+=P("TD1","4%",a[8],a[1],a[2],a[3],b[8]);
        //KL mua 1
        tr+=KLHA("TD1","5%",a[9],b[9]);
        //Gia mua 1
        tr+=P("TD2","4%",a[10],a[1],a[2],a[3],b[10]);
        
        //Gia tam khop
        tr+=P("TD3","4%",a[11],a[1],a[2],a[3],b[11]);
        //Chenh lech
        tr+=DiffP("TD3","3%",a[11],a[1],a[2],a[3],b[11]);
        //KL tam khop
        tr+=KLHA("TD4","5%",a[12],b[12]);
        //Gia ban 1
        tr+=P("TD1","4%",a[13],a[1],a[2],a[3],b[13]);
        //KL ban 1
        tr+=KLHA("TD1","5%",a[14],b[14]);
        //Gia ban 2
        tr+=P("TD1","4%",a[15],a[1],a[2],a[3],b[15]);
        //KL ban 2
        tr+=KLHA("TD1","5%",a[16],b[16]);
        //Gia ban 3
        tr+=P("TD1","4%",a[17],a[1],a[2],a[3],b[17]);
        //KL ban 3
        tr+=KLHA("TD2","5%",a[18],b[18]);

        //Nuoc ngoai Mua - Ban
        tr+=KLHA("TD3","4%",a[19],b[19]);
        tr+=KLHA("TD4","4%",a[20],b[20]);
        
        tr+="</tr>";
        var isselected=0;
        if (selectedStocks!=null && selectedStocks!="undefined")
            if (selectedStocks.indexOf(a[0]) != -1)
                isselected=1;
        if (isselected==1)
            grid1=grid1+tr;
        else
            grid2=grid2+tr;
    }
    if (grid1 != "")
        line="<tr><td colspan=24 bgcolor=white height=1></td></tr>";
    grid=grid+grid1+line+grid2+"</table>";
    
    write_cookie("ha_advances", gAdvances, 1);
    write_cookie("ha_declines", gDeclines, 1);
    write_cookie("ha_nochange", gNochange, 1);
    
    var RsltElem=document.getElementById("HaPrice");
    RsltElem.innerHTML=grid;
    
    CreateHaPriceHeader();
}

