var req;
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function BidingSession(SessionArray)
{
    
    
    
    if (SessionArray[7]=='Y' ||SessionArray[7]=='I'  )
    {
    
        
        var innerHTMLCell;

        innerHTMLCell = "   Đợt " + SessionArray[8] + ":    <span style='color: #000066'>" +"Vn Index: " + "</span>" ;

        //innerHTMLCell = "   Đợt " + SessionArray[8] + ":    <span style='color: #000066'>" +"Vn Index: " + "</span>" ;
        var ChangePercent = RoundNumber( parseFloat( 100*parseFloat( SessionArray[1])/ parseFloat( SessionArray[2])),2) ;
        if (parseFloat( SessionArray[1])>0)
        {
            innerHTMLCell = innerHTMLCell + "<span style='color: #009933'>" +( parseFloat( SessionArray[0])) + "  ▲" + ( parseFloat( SessionArray[1])) + " (" + ChangePercent +  "%)</span>" ;
        }
        else
        {
            if (parseFloat( SessionArray[1])<0)
            {
                innerHTMLCell = innerHTMLCell + "<span style='color: red'>" + (parseFloat(SessionArray[0] ))+  "  ▼" + ( parseFloat( SessionArray[1])) + " (" + ChangePercent +  "%)</span>" ;
            }
            else
            {
                innerHTMLCell = innerHTMLCell + "<span style='color: #ffff00'>" + (parseFloat(SessionArray[0])) +  " " + ( parseFloat( SessionArray[1])) + " (" + ChangePercent +  "%)</span>" ;
            }
        }
        
        
        innerHTMLCell =innerHTMLCell + "  <span style='color: #000066'>" +"KLGD: " + "<span style='color: blue'>" +  (SessionArray[4]) + "</span></span>" ;
        innerHTMLCell = innerHTMLCell + "   " + "<span style='color: #000066'>" +"GTGD: " + "<span style='color: blue'>" +  (SessionArray[5]) + " VNĐ</span></span>" ;
        
        return innerHTMLCell;
        //alert(1);
        
        
    }
    return "";
    
}


function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function displayItems(par1) {
	
	var params = par1;	
	retrieveURL("t_5b6db47c7e807c2953a3b62cd24bf4e7.php", params);
	return true;
}
function retrieveURL(url, pars) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", pars.length);
//req.setRequestHeader("Content-length", "0");
req.send(pars);
} catch (e) {
alert(e);
}
req.send(null);
//req.send(1);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processStateChange;
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", pars.length);
req.send(pars);
//req.send();
}
}
}


function processStateChange() {
if (req.readyState == 4) 
{ // Complete
	if (req.status == 200) 
	{ // OK response
		document.getElementById("thetable").innerHTML = req.responseText;
		document.getElementById("loading1").innerHTML = '';	
	}	
}
else
{

	var load1= "<img src=images/loading1.gif>";				            	
	document.getElementById("loading1").innerHTML = load1;			

}
}

function isDate18(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	
	//var strMonth=dtStr.substring(0,pos1)
	//var strDay=dtStr.substring(pos1+1,pos2)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)	
	
	var strYear=dtStr.substring(pos2+1)

	var currentTime = new Date()
	//var month = currentTime.getMonth() + 1
	//var day = currentTime.getDate()
	var nam = currentTime.getFullYear()
	
	if ((nam - strYear) < 18)
	{
		alert("Chua du 18 tuoi")
		return false		
	}
	return true
}

function timkiem(){
	document.getElementById("Timkiem1").submit();	}

function GetColorStyle(oldData, newData, textValue, type, Textcolor, TextColorDesc, TextColorNo, BgColor )
{
    var innerTextRs="";
    
    switch (type)
    {
        case 1:
            innerTextRs = "<span style='color:" + Textcolor +"'>" + textValue + "</span>";
            break;
        case 2:
        
            if (parseFloat(newData)>parseFloat(oldData))
            {
                innerTextRs = "<span style='color:" + Textcolor +"'>" + textValue + "</span>";
            }
            else
            {
                if (parseFloat(newData)<parseFloat(oldData))
                {
                    innerTextRs = "<span style='color:" + TextColorDesc +"'>" + textValue + "</span>";
                }
                else
                {
                    innerTextRs = "<span style='color:" + TextColorNo +"'>" + textValue + "</span>";
                } 
            }
            break;
        case 3:
            var oldDataVal,newDataVal;
            oldDataVal=(oldData==' '?0:oldData);
            newDataVal=(newData==' '?0:newData);
            //if (parseFloat(oldData)!=parseFloat(newData))
            if (parseFloat(oldDataVal)!=parseFloat(newDataVal))
            {
                
                innerTextRs = "<table cellpadding='0' cellspacing='0' width= 100% height=100%><tr>" + "<td style='color:" + Textcolor + "; FONT-SIZE: 14px; background-color:" + BgColor + ";'>" + textValue + "</td></tr></table>";
               
            }
            else
            {
                innerTextRs = textValue;
                
            }
            break;
    }
    
    return innerTextRs;
}

var bb_count = 0;
var bb_curr_idx = "";
var bb_cache = new Array;
//var bb_debug = false;
var bb_debug = true;
var bb_iframe_script = "store.php";
var bb_iframe_loaded = false;
var bb_target_div = "";



function bb_debug_update (str) {
    if (bb_debug) {
        var divBBDebug = document.getElementById("divBBDebug");        
    }
}



function bb_check_state (  ) {

    if (bb_iframe_loaded == false) {
        return;
    }

    var doc =  window.frames['bbFrame1'].document;
    var new_idx = doc.getElementById('divFrameCount').innerHTML;
	
    if (new_idx != bb_curr_idx) {

        var debug_msg = "IFRAME changed. Was " 
                        + bb_curr_idx 
                        + ", now " 
                        + new_idx;

        //Pull a previous state from the cache (if it exists).
			
        if (bb_cache[new_idx]) {
            var body1 = document.getElementById("body1");
            body1.innerHTML = bb_cache[new_idx];

            debug_msg += " [pulled " 
                         + new_idx 
                         + " from cache]";
        }
        bb_curr_idx = new_idx;

        bb_debug_update (debug_msg);
    }
}

//Called by child IFRAME.

function bb_done_loading () {
    bb_iframe_loaded = true;
}

//Update the hidden IFRAME.

function bb_loadframe (  ) {
    var bbFrame1 = document.getElementById("bbFrame1");
    bb_iframe_loaded = false;
    bbFrame1.src = bb_iframe_script + "?vt=" + bb_count;
	//alert(bbFrame1.src);
	
}

//When requested, save the current state
//in a cache.

function bb_save_state (  ) {
    //Store the new contents in the cache.
    var div_to_cache = document.getElementById(bb_target_div);
    bb_count++;
    bb_cache[bb_count] = div_to_cache.innerHTML;

    //bb_debug_update ("Added " + bb_count + " to cache");		
    //Load the new page into the IFRAME.
    bb_loadframe();

    bb_curr_idx = bb_count;
}

//Load the hidden IFRAME and start an interval timer.

function bb_init (div_name, debug_val) {
	
    bb_target_div = div_name;
    bb_debug = debug_val;

    bb_loadframe (  );
    window.setInterval ('bb_check_state()', 1000);
    bb_save_state (  );	
}


function mouseOverAll(kieu){	
	document.getElementById('truynhapid').style.backgroundImage = "url(images/header_03_04_act.jpg)";
}

function mouseOverOut(kieu){
	document.getElementById('truynhapid').style.backgroundImage = "url(images/header_03_04.jpg)";
}

function mouseOverAll1(kieu){
	kieu.style.color='red';
	kieu.style.textDecoration='underline';
}

function mouseOverOut1(kieu){
	kieu.style.color='#006699';
	kieu.style.textDecoration='none';
}

function mouseOverAllTitle(kieu){
	//kieu.style.color='024E88'; 
	kieu.style.textDecoration='underline';
}

function mouseOverOutTitle(kieu){
	//kieu.style.color='024E88'; 
	kieu.style.textDecoration='none';
}

function mouseOverAllqc(kieu){
	kieu.style.color='FFFFFF'; 
	kieu.style.textDecoration='underline';
}

function mouseOverOutqc(kieu){
	kieu.style.color='FFFFFF'; 
	kieu.style.textDecoration='none';
}

function mouseOverBgr(kieu){
	kieu.style.color='ffffff'; 
	kieu.style.textDecoration='underline';
	kieu.style.backgroundColor='024E88';
}

function mouseOverOutBgr(kieu){
	kieu.style.color='ffffff'; 
	kieu.style.textDecoration='none';
	kieu.style.backgroundColor='318224';
}

function SetDefaultSettings() {

    if (document.getElementById("ChkDefault").checked)
    {
        document.getElementById("BtOK").disabled  = false;
        document.getElementById("txtPageSize").value =20;
        pageSize = 20;
        SetListChkBox(false);
        document.getElementById("ChkAll").checked = false;
        
        ShowNextInterval();
      
    } 

    
}


