﻿// JScript File
    var strStockList;
    function setMarket(strDataMa)
    {        
        var arrDataMa = strDataMa.split('|');
    	document.getElementById('tttt').firstChild.nodeValue = '('+arrDataMa[0]+')';
    	document.getElementById('NgayGD').firstChild.nodeValue = arrDataMa[1];
    	document.getElementById('fMark').firstChild.nodeValue = arrDataMa[2];
    	document.getElementById('fMark').color= arrDataMa[3];
    	document.getElementById('fTang').firstChild.nodeValue = '▲ '+arrDataMa[4];
    	document.getElementById('fDung').firstChild.nodeValue = '■ ' +arrDataMa[5];
    	document.getElementById('fGiam').firstChild.nodeValue = '▼ ' +arrDataMa[6];
    	document.getElementById('KLGT').firstChild.nodeValue = 'Tổng KL GD: '+arrDataMa[7]+' Tổng giá trị GD: '+arrDataMa[8]+' Triệu VNÐ';        	        	
    }
    function UpdateBDT()
    {
        var str = xmlHttpSer.responseText
        //alert(str);
        if(str.replace('@','')!= '')
        {
            var arrLine=new Array();
            var arrItems=new Array();
            arrLine=str.split('@');
            var stockS;
            for(var i=0;i<arrLine.length;i++)
            {
                arrItems = arrLine[i].split('|');
                if(arrItems == '')
                continue;
                stockS = arrItems[0].substring(1,arrItems[0].length);
                var cell=document.getElementById('tr'+stockS);  
                if(cell == null)
                    continue;
                    
                var aw; 
                aw = cell.cells[0] ;
                setStock(aw,arrItems[0].substring(0,1),stockS);              
                for(var j=1;j<arrItems.length;j++)
                {
                    if(arrItems[j]!='')
                    {
                        aw=cell.cells[j+3];
                        setValue(aw,arrItems[j],j);
                    }
                }
            } 
        }
    }
    var g_tu=' ▲';			
    var g_td=' ▼';			
    var g_tn='&nbsp; ■';
    function setStock(o,v,t)
    {
        switch(v)
        {
            case "c":
                o.className = "CK CL";
                o.innerHTML = t + g_tu;
                break;
            case "f":
                o.className = "CK CE";
                o.innerHTML = t + g_td;
                break;
            case "t":
                o.className = "CK C1";
                o.innerHTML = t + g_tu;
                break;
            case "g":
                o.className = "CK C2";
                o.innerHTML = t + g_td;
                break;
            case "s":
                o.className = "CK C0";
                o.innerHTML = t + '<font class=tt>'+ g_tn + '</font>';
                break;
            default:
    	        o.className = "CK C3";
    	        o.innerHTML = t;
        }
        
    }
    var g_cbn = '#1d1d1d';	
var g_cbs = '#444444';	
var g_cbh = '#aaaaaa';	
var g_cbh2 = '#777777'; 
var g_cbhrc = '#555555'; 			
var g_cbhrt = 'rgb(85, 85, 85)'; 	
var g_thbu = 1000;		
var g_thau = 1000;	
 var g_cbn = '#000000';//mau nen
        var g_cbs = '#444444';	
       
    
    function setValue(o,v,t)
    {
       var bg;
       var css;
       if((t>6&&t<10)||(t>15))
        bg=g_cbs;
        else bg = g_cbn;
        o.style.backgroundColor=g_cbh;
        css = o.className;
        o.className = css.substring(0,css.length-1) + v.substring(0,1);
        setTimeout(function()
        {
            o.innerHTML=v.substring(1,v.length);
            //o.innerHTML=v;
            o.style.backgroundColor=g_cbh2;
            setTimeout(function()
                        {o.style.backgroundColor=bg},g_thau)
                        },g_thbu);
    }
        var    total = arrStock.Length;
        function checkKeyCode(o)
        {
            var j;
		    for(j=65; j<=90; j++)
		    {
			    document.getElementById("char" + j).className = "cx1";
		    }
		    o.className = "cd1";
    		
		    var k;
		    for(k=0; k<total; k++)
		    {
			    var chkid = "c_" + k;
			    var spanid = "s_" + k;
			    //if(document.getElementById(chkid).getAttribute("t") == 1)
			    //{
				    document.getElementById(chkid).style.display = '';
				    document.getElementById(spanid).style.display = '';
				    if(document.getElementById(spanid).innerHTML.substring(0,1) == o.innerHTML)
				    {
					    document.getElementById(chkid).style.display = '';
					    document.getElementById(spanid).style.display = '';
				    }
				    else
				    {
					    document.getElementById(chkid).style.display = 'none';									
					    document.getElementById(spanid).style.display = 'none';
				    }
			    /*}
			    else
			    {
				    document.getElementById(chkid).style.display = 'none';									
				    document.getElementById(spanid).style.display = 'none';
			    }	*/		
		    }
        }
        
        function Highlight_On(obj)
        { 
           obj.style.backgroundColor='#484848';
        }
        function Highlight_Off(obj)
        {
           obj.style.backgroundColor = "";
        }		
        
        function Click_Row(r)
        {
            var i=0,m=r.cells.length,ac=false;
            if(r.cells[0].style.backgroundColor==g_cbhrc||r.cells[0].style.backgroundColor==g_cbhrt)
                ac=true;
            else 
                ac=false;
                for(var j=0;j<m;j++)
                {
                    r.cells[j].style.backgroundColor=(ac?g_cbn:g_cbhrc);
                    //r.cells[j].originalBgColor = r.cells[j].style.backgroundColor;
                        //r.cells[j].style.backgroundColor='#484848';
                }
                
                if(ac)
                {   
                    r.cells[1].style.backgroundColor=g_cbs;
                    r.cells[2].style.backgroundColor=g_cbs;
                    r.cells[3].style.backgroundColor=g_cbs;
                    r.cells[10].style.backgroundColor=g_cbs;
                    r.cells[11].style.backgroundColor=g_cbs;
                    r.cells[12].style.backgroundColor=g_cbs;
                    
                    //xet mau background tu cot Tong KL toi cot cuoi cung
                    for(var jj=19;jj<m;jj++)
                    {
                        r.cells[jj].style.backgroundColor=g_cbs;
                    }                    
                }
        }
        
        function CheckAll()
        {
            for(var i=0;i<document.frmSelect.elements.length;i++)
            if(document.frmSelect.elements[i].type=='checkbox')
            {
                if(document.frmSelect.elements[i].style.display=='')
                    {document.frmSelect.elements[i].checked=true;}
                else document.frmSelect.elements[i].checked=false;
            }
        }
        
        function ClearAll()
        {
            for(var i=0;i<document.frmSelect.elements.length;i++)
            {
                if(document.frmSelect.elements[i].type)
                {
                    document.frmSelect.elements[i].checked=false;
                }
             }
        }
        
        function doView()
        {
            SaveSelectList(strStockList);
            window.location.reload();	
	        //showSecuListAll();
        }
        
        function GetExpiryDate(DayCount)
{
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+DayCount*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}
	
function SetCookie(name,value,duration)
{
	CookieString=name+"="+escape(value)+";EXPIRES="+GetExpiryDate(duration);
	document.cookie=CookieString;
}

function GetCookie(CookieName) 
{
    var CookieString;var index1;var index2;
    var arrCookie = document.cookie.split(';');
    for(i=0;i<arrCookie.length;i++)
    {
	    CookieString = arrCookie[i];
	    //alert(CookieString);
	    index1=CookieString.indexOf(CookieName+ '=');
	    if (index1==-1 || CookieName=="") 
	        continue; 
	    index2=CookieString.indexOf(';',index1);
	    //index2=CookieString.length;
	    if (index2==-1) index2=CookieString.length; 	
	    //alert(CookieString.substring(index1+CookieName.length,index2));
	   return unescape(CookieString.substring(index1+CookieName.length + 1,index2));
	    
	}
	
	return "";
}
        
        function BuildSelectList()
        {
	        var strSelectList="";
	        for (var i=0; i < document.frmSelect.elements.length; i++)
		        if (document.frmSelect.elements[i].type == 'checkbox')
			        if (document.frmSelect.elements[i].checked /*&& document.frmSelect.elements[i].style.display==''*/)
				        strSelectList +=  document.frmSelect.elements[i].value + ",";
        				
	        //strSelectList=strSelectList.substring(0,strSelectList.length-1);
	        return strSelectList;
        }
        function SaveSelectList(CookieName)
        {
	        g_cl=BuildSelectList();	
	        SetCookie(CookieName, g_cl, 2);
        }

        function LoadSelectList(CookieName)
        {
	        var str=GetCookie(CookieName);
	        for (var i=0; i < document.frmSelect.elements.length; i++)
		        if (document.frmSelect.elements[i].type == 'checkbox')
			        if (str.indexOf(document.frmSelect.elements[i].value+",")>=0)
				        document.frmSelect.elements[i].checked = true;
        }
        
        function doHidd()
        {
            document.getElementById("StockList").style.display='none';
        }
        
        function renderStock()
        {
            var i;
            var str="";
            for(i=65; i<= 90; i++)
            {
	              str += "<span onmouseover=\"this.className='cx2'\" onmouseout=\"this.className='cx1'\" style='cursor: pointer;' id='char" + i + "' class='cx1' onClick='checkKeyCode(this);'>" + String.fromCharCode(i);
		            str += "</span>";
		            str += "<font class='cx1'>&nbsp;|&nbsp;</font>";
		       
            } 
            
            str +=  "<span onmouseover=\"this.className='cx2'\" onmouseout=\"this.className='cx1'\" style='cursor: pointer;' id='viewCCQ' class='cx1' onClick='doChange(this);'>CCQ</span>";
            str += "</span>";
            str += "<font class='cx1'>&nbsp;|&nbsp;</font>";
            str +=  "<span onmouseover=\"this.className='cx2'\" onmouseout=\"this.className='cx1'\" style='cursor: pointer;' id='viewAll' class='cx1' onClick='doChange(this);'>Xem tất</span>";
            
            if (document.getElementById||document.all)
		                    obj.innerHTML=str
	                    else if (document.layers){
		                    obj.document.write(str)
		                    obj.document.close()
		                    }
		                    
		                    
            var thecontent = "";
            var index =0;
            for(i=0; i < arrStock.length; i++)
            {
                 thecontent += '<input value='+ arrStock[i][0] +' name='+arrStock[i][0]+' style=\"\"id=c_'+i
                                +' type=checkbox t=1><span id=s_'+i
                                +' class=ckx1 t=1>'+ arrStock[i][0]+'</span>';
                  /*  
                 index = i+1;
                if(index%20==0)
                {
                    thecontent += '<br />';
                }*/
            }
            thecontent += '<input value=ALL'+strStockList+' name=ALL'+strStockList+' style=\"\"id=c_ALL'+strStockList+' type=checkbox onclick=AllClick(this.checked)><span id=s_ALL'
                                +' class=ckx1 t=1>Tất Cả</span>';
            if (document.getElementById||document.all)
		                menuobj.innerHTML=thecontent
	                else if (document.layers){
		                menuobj.document.write(thecontent)
		                menuobj.document.close()
		                }
           
		        
        }
        
        function AllClick(v)
        {
            if(v)CheckAll();
            else ClearAll();
        }
        
        function ClickInfoStock(v)
        {         
            for(var iy=0; iy < arrStock.length; iy++)
            {
                if(arrStock[iy][0] == v) 
                {   
                     window.open('http://finance.vinabull.com/WebPages/Tongquan.aspx?code='+arrStock[iy][2]); 
                }
            }
        }
	
