﻿function StockListHoCallback(result, eventArgs)
{
    CreateStockList(result, 'SSI.HOSE');
}
function CreateHoHideColList()
{
    var cols=get_cookie('HO.COLUMN');
    var list="Ẩn các cột:&nbsp;&nbsp;&nbsp;<font color=white>";
    list+=SetHideColumn('P1','Phiên 1',cols,'HO.COLUMN');
    list+=SetHideColumn('P2','Phiên 2',cols,'HO.COLUMN');
    list+=SetHideColumn('NN','Nước ngoài',cols,'HO.COLUMN');
    list+="</font>"
    var divHideColumn=document.getElementById("divHideColumn");
    divHideColumn.innerHTML=list;
}
// Create the header of page (VNIndex, Change, Market state ...)
function HoHeaderCallback_old(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>VN 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[3]+"</td>";
        t+="<td"+style+">"+a[0]+"</td>";
        t+="<td"+style+">"+a[5]+"</td>";
        var d=new Date(),d1=new Date();
        d1.setHours(10,15);
        if (d<d1)
        {
            var advances = get_cookie("ho_advances");
            if (advances==null) advances=0;
            var nochange = get_cookie("ho_nochange");
            if (nochange==null) nochange=0;
            var declines = get_cookie("ho_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>";
        }
        else
        {
            t+="<td style=\"color:#00ff00\">"+a[7]+"</td>";
            t+="<td style=\"color:#ffff00\">"+a[8]+"</td>";
            t+="<td style=\"color:#ff0000\">"+a[9]+"</td>";
        }
        t+="<td>"+addCommas(a[1])+"</td>";
        t+="<td>"+addCommas(a[2])+"</td>";
        t+="<td>"+GetMarketStateHo(a[4])+"</td>";
        t+="<td>"+a[10]+"</td>";
        t+="</tr>";
        t+="<tr><td conspan=6 height=5></td></tr>";
        t+="</table>";

        var RsltElem=document.getElementById("HoHeader");
        RsltElem.innerHTML=t;
        
    }
    catch(e)
    {}
}

//Phunh - 2011-12-14
// Create the header of page (VNIndex, VN30Inex, Change, Market state ...) version 2.0
function HoHeaderCallback(result, eventArgs)
{
    try
    {
        if ((typeof(result)=="undefined") || (result==null) || (result=="") || (result=="undefined"))
            return;
        var a=result.split("|");
        var style = GetIndexColor(a[6]);
        var stype2 = GetIndexColor(a[13]);
        var t="<table cellspacing=0 cellpadding=0>";
        t+="<tr class=Text1>";        
            t+="<td class=Text1>VN Index</td>";
            t+="<td"+style+">"+a[0]+"</td>";
            t+="<td class=Text1>Thay đổi</td>";
            t+="<td"+style+">"+a[5]+"</td>";            
            t+="<td><img src=App_Themes/Default/Images/up.gif /></td>"; 
            t+="<td align =\"left\" style=\"color:#00ff00\">"+a[7]+"</td>";
            t+="<td><img src=App_Themes/Default/Images/equal.gif /></td>";
            t+="<td align =\"left\" style=\"color:#ffff00\">"+a[8]+"</td>";
            t+="<td><img src=App_Themes/Default/Images/down.gif /></td>";        
            t+="<td align =\"left\" style=\"color:#ff0000\">"+a[9]+"</td>";            
            t+="<td>KLGD</td>";        
            t+="<td class=Text2>"+addCommas(a[1])+"</td>";
            t+="<td>GTGD</td>";
            t+="<td class=Text2>"+addCommas(a[2])+"</td>";        
            t+="<td class=Text1>Trạng thái TT</td>";
            t+="<td class=Text1>Thời gian</td>";
            t+="<td class=Text1>Ngày GD</td>";
        t+="</tr>";
        t+="<tr class=Text2>";
            t+="<td class=Text1>VN 30 Index</td>";            
            t+="<td"+stype2+">"+ a[11] +"</td>";
            t+="<td class=Text1>Thay đổi</td>";
            t+="<td"+stype2+">"+ a[12] +"</td>";
            t+="<td><img src=App_Themes/Default/Images/up.gif /></td>";
            t+="<td align =\"left\" style=\"color:#00ff00\">"+ a[16] +"</td>";
            t+="<td><img src=App_Themes/Default/Images/equal.gif /></td>";
            t+="<td align =\"left\" style=\"color:#ffff00\">"+ a[17] +"</td>";
            t+="<td><img src=App_Themes/Default/Images/down.gif /></td>";   
            t+="<td align =\"left\" style=\"color:#ff0000\">"+ a[18] +"</td>";
            t+="<td class=Text1>KLGD</td>";
            t+="<td class=Text2>"+ addCommas(a[14]) +"</td>";
            t+="<td class=Text1>GTGD</td>";
            t+="<td class=Text2>"+ addCommas(a[15]) +"</td>";
            t+="<td>"+GetMarketStateHo(a[4])+"</td>";
            t+="<td>"+a[10]+"</td>";
            t+="<td>"+a[3]+"</td>";
        t+="</tr>";
        t+="<tr><td conspan=6 height=5></td></tr>";
        t+="</table>";
        var RsltElem=document.getElementById("HoHeader");
        RsltElem.innerHTML=t;
    }
    catch(e)
    {}
}

function CreateHoPriceHeader()
{
    var P1=true;
    var P2=true;
    var NN=true;
    var cols=get_cookie('HO.COLUMN');
    if (cols!=null && cols!="undefined")
    {
        if (cols.indexOf('P1') != -1)
        {
            P1=false;
        }
        if (cols.indexOf('P2') != -1)
        {
            P2=false;
        }
        if (cols.indexOf('NN') != -1)
        {
            NN=false;
        }
    }
    var h="";
    h+="<table class=Grd border=1 cellspacing=0 cellpadding=0>"
    h+="<tr class=RowHeader>";

	h+="<td rowspan=2 colspan=2 class=H1 height=40px>Mã CK</td>";

	h+="<td colspan=3 class=H2>Giá</td>";
    if (P1)
	    h+="<td colspan=2 class=H2>Phiên 1</td>";
	if (P2)
	    h+="<td colspan=2 class=H2>Phiên 2</td>";

	h+="<td colspan=6 class=H1>Đặt mua</td>";
	h+="<td colspan=3 class=H2>Giao dịch</td>";
	h+="<td colspan=6 class=H1>Chào bán</td>";
	if (NN)
	    h+="<td colspan=2 class=H2>Nước ngoài</td>";
	
    h+="</tr>";
    h+="<tr class=RowHeader>";

	h+="<td class=H2 width="+GetWidth("th2")+">TC</td>";
	h+="<td class=H2 width="+GetWidth("th3")+">Trần</td>";
	h+="<td class=H2 width="+GetWidth("th4")+">Sàn</td>";
	
	if (P1)
	{
	    h+="<td class=H2 width="+GetWidth("th5")+">Giá</td>";
	    h+="<td class=H2 width="+GetWidth("th6")+">KL</td>";
	}
	if (P2)
	{
	    h+="<td class=H2 width="+GetWidth("th7")+">Giá</td>";
	    h+="<td class=H2 width="+GetWidth("th8")+">KL</td>";
	}
	
	h+="<td class=H1 width="+GetWidth("th9")+">KL3</td>";
	h+="<td class=H1 width="+GetWidth("th10")+">Giá<br/>3</td>";
	h+="<td class=H1 width="+GetWidth("th11")+">KL2</td>";
	h+="<td class=H1 width="+GetWidth("th12")+">Giá<br/>2</td>";
	h+="<td class=H1 width="+GetWidth("th13")+">KL1</td>";
	h+="<td class=H1 width="+GetWidth("th14")+">Giá<br/>1</td>";

	h+="<td class=H2 width="+GetWidth("th15")+">Giá<br/>TH</td>";
	h+="<td class=H2 width="+GetWidth("th16")+">+/-<br/>Giá</td>";
	h+="<td class=H2 width="+GetWidth("th17")+">Tổng<br/>KLTH</td>";

	h+="<td class=H1 width="+GetWidth("th18")+">Giá<br/>1</td>";
	h+="<td class=H1 width="+GetWidth("th19")+">KL1</td>";
	h+="<td class=H1 width="+GetWidth("th20")+">Giá<br/>2</td>";
	h+="<td class=H1 width="+GetWidth("th21")+">KL2</td>";
	h+="<td class=H1 width="+GetWidth("th22")+">Giá<br/>3</td>";
	h+="<td class=H1 width="+GetWidth("th23")+">KL3</td>";
	if (NN)
	{
	    h+="<td class=H2 width="+GetWidth("th24")+">Mua</td>";
	    h+="<td class=H2 width="+GetWidth("th25")+">Room</td>";
	}
    h+="</tr>";
    h+="<tr height=0><td width="+GetWidth("th1")+"></td><td width="+GetWidth("thImg")+"></td><td colspan=24></td></tr>";
    
    var HoHeader=document.getElementById("HoHeaderPrice");
    if (HoHeader)
    {
        HoHeader.innerHTML=h;
        HoHeader.className=browser;
        var HoPrice=document.getElementById("HoPrice");
        if (HoPrice)
        {
            HoHeader.style.width = (HoPrice.offsetWidth)+"px";
        }
    }
    return;
}
// Create the header of the list of prices
function HoPriceHeader(P1,P2,NN)
{
    var h="<tr class=RowHeader>";

	h+="<td rowspan=2 colspan=2 class=H1 height=40px>Mã CK</td>";

	h+="<td colspan=3 class=H2>Giá</td>";
    if (P1)
	    h+="<td colspan=2 class=H2>Phiên 1</td>";
	if (P2)
	    h+="<td colspan=2 class=H2>Phiên 2</td>";

	h+="<td colspan=6 class=H1>Đặt mua</td>";
	h+="<td colspan=3 class=H2>Giao dịch</td>";
	h+="<td colspan=6 class=H1>Chào bán</td>";
	if (NN)
	    h+="<td colspan=2 class=H2>Nước ngoài</td>";
	
    h+="</tr>";
    h+="<tr class=RowHeader>";

	h+="<td id=th2 class=H2>TC</td>";
	h+="<td id=th3 class=H2>Trần</td>";
	h+="<td id=th4 class=H2>Sàn</td>";
	
	if (P1)
	{
	    h+="<td id=th5 class=H2>Giá</td>";
	    h+="<td id=th6 class=H2>KL</td>";
	}
	if (P2)
	{
	    h+="<td id=th7 class=H2>Giá</td>";
	    h+="<td id=th8 class=H2>KL</td>";
	}
	
	h+="<td id=th9 class=H1>KL3</td>";
	h+="<td id=th10 class=H1>Giá<br/>3</td>";
	h+="<td id=th11 class=H1>KL2</td>";
	h+="<td id=th12 class=H1>Giá<br/>2</td>";
	h+="<td id=th13 class=H1>KL1</td>";
	h+="<td id=th14 class=H1>Giá<br/>1</td>";

	h+="<td id=th15 class=H2>Giá<br/>TH</td>";
	h+="<td id=th16 class=H2>+/-<br/>Giá</td>";
	h+="<td id=th17 class=H2>Tổng<br/>KLTH</td>";

	h+="<td id=th18 class=H1>Giá<br/>1</td>";
	h+="<td id=th19 class=H1>KL1</td>";
	h+="<td id=th20 class=H1>Giá<br/>2</td>";
	h+="<td id=th21 class=H1>KL2</td>";
	h+="<td id=th22 class=H1>Giá<br/>3</td>";
	h+="<td id=th23 class=H1>KL3</td>";
	if (NN)
	{
	    h+="<td id=th24 class=H2>Mua</td>";
	    h+="<td id=th25 class=H2>Room</td>";
	}
    h+="</tr>";
    h+="<tr height=0><td id=th1></td><td id=thImg></td><td colspan=24></td></tr>";
    
    return h;
    
}
// Create the list of prices
function HoPriceCallback(result, eventArgs)
{
    try
    {
        var LastValue=CheckChangeData(result);
        if (LastValue=="")
            return;
        DrawHoPrice(result, LastValue);
    }    
    catch(e)
    {}
}
function DrawHoPrice(result, LastValue)
{
    var P1=true;
    var P2=true;
    var NN=true;
    var colnumber=26;
    var cols=get_cookie('HO.COLUMN');
    if (cols!=null && cols!="undefined")
    {
        if (cols.indexOf('P1') != -1)
        {
            P1=false;
            colnumber -= 2;
        }
        if (cols.indexOf('P2') != -1)
        {
            P2=false;
            colnumber -= 2;
        }
        if (cols.indexOf('NN') != -1)
        {
            NN=false;
            colnumber -= 2;
        }
    }
    var selectedStocks=get_cookie("SSI.HOSE");
    var grid="<table class=Grd border=1 cellspacing=0 cellpadding=0>";
    grid=grid+HoPriceHeader(P1,P2,NN);
    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
        v=a[0];
        if (v.length>3)
        {
            v=v.substr(0,3)+"<br/>"+v.substr(3,3);
        }
        tr+="<td class=MaCK width=3% title="+GetTitle(a[0])+">"+v+"</td>";
        //Image
        tr+="<td class=Img width=1%>"+Image(a[8],a[3])+"</td>";  
        // Gia TC
        tr+="<td class=TD1 width=4% style=\""+TC+"\">"+FormatNum(a[3])+"</td>";
        // Gia Tran
        tr+="<td class=TD1 width=4% style=\""+CE+"\">"+FormatNum(a[1])+"</td>";
        // Gia San
        tr+="<td class=TD2 width=4% style=\""+FL+"\">"+FormatNum(a[2])+"</td>";
        // Gia khop phien 1
        if (P1)
        {
            tr+=P("TD3","4%",a[4],a[3],a[1],a[2],a[4]);
            tr+=KL("TD4","5%",a[5],a[5]);
        }
        // Gia khop phien 2
        if (P2)
        {
            tr+=P("TD3","4%",a[6],a[3],a[1],a[2],a[6]);
            tr+=KL("TD4","5%",a[7],a[7]);
        }
        //KL mua 3
        tr+=KL("TD1","5%",a[15],b[15]);
        //Gia mua 3
        tr+=P("TD1","4%",a[14],a[3],a[1],a[2],b[14]);
        //KL mua 2
        tr+=KL("TD1","5%",a[13],b[13]);
        //Gia mua 2
        tr+=P("TD1","4%",a[12],a[3],a[1],a[2],b[12]);
        //KL mua 1
        tr+=KL("TD1","5%",a[11],b[11]);
        //Gia mua 1
        tr+=PAT("TD2","4%",a[10],a[3],a[1],a[2],a[8],b[10]);
        
        //Gia tam khop
        tr+=P("TD3","4%",a[8],a[3],a[1],a[2],b[8]);
        //Chenh lech
        tr+=DiffP("TD3","3%",a[8],a[3],a[1],a[2],b[8]);
        //KL tam khop
        tr+=KL("TD4","5%",a[9],b[9]);
        
        //Gia ban 1
        tr+=PAT("TD1","4%",a[16],a[3],a[1],a[2],a[8],b[16]);
        //KL ban 1
        tr+=KL("TD1","5%",a[17],b[17]);
        //Gia ban 2
        tr+=P("TD1","4%",a[18],a[3],a[1],a[2],b[18]);
        //KL ban 2
        tr+=KL("TD1","5%",a[19],b[19]);
        tr+=P("TD1","4%",a[20],a[3],a[1],a[2],b[20]);
        tr+=KL("TD2","5%",a[21],b[21]);
        
        //Nuoc ngoai Mua - Room
        if (NN)
        {
            tr+=KL("TD3","5%",a[22],b[22]);
            tr+=KL("TD4","5%",a[23],b[23]);
        }

        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="+colnumber+" bgcolor=white height=1></td></tr>";
    grid=grid+grid1+line+grid2+"</table>";

    write_cookie("ho_advances", gAdvances, 1);
    write_cookie("ho_declines", gDeclines, 1);
    write_cookie("ho_nochange", gNochange, 1);

    var RsltElem=document.getElementById("HoPrice");
    RsltElem.innerHTML=grid;
    CreateHoPriceHeader();
}

