var timer;
var timer2;
var timer3;
var timer4;
var timer5;
var value = 30;
var newWin = null;

function x() {}

function showList(id) {
    clearTimeout(timer);
    clearTimeout(timer4);
    clearTimeout(timer5);
    var div_menu;
    var div_menu2;
    var div_menu3;
    if(id == 1) {
        div_menu = document.getElementById("menu2_list");
        div_menu.style.display = "inline";
        hideList(2);
        hideList(3);
    }
    if(id == 2) {
        div_menu2 = document.getElementById("menu2_list2");
        div_menu2.style.display = "inline";
        hideList(1);
        hideList(3);
    }
    if(id == 3) {
        div_menu3 = document.getElementById("menu2_list3");
        div_menu3.style.display = "inline";
        hideList(1);
        hideList(2);
    }
}

function hideList(id) {
    if(id ==1){
    timer = setTimeout("doHide(1);", 100); 
    }
    if(id ==2){
    timer4 = setTimeout("doHide(2);", 100); 
    }
    if(id ==3){
    timer5 = setTimeout("doHide(3);", 100); 
    }
}

function doHide(id) {
    var div_menu;
    var div_menu2;
    var div_menu3;
    if(id == 1){
        div_menu = document.getElementById("menu2_list");
        if (div_menu)
            div_menu.style.display = "none";
    }
    if(id == 2){
        div_menu2 = document.getElementById("menu2_list2");
        if (div_menu2)
            div_menu2.style.display = "none";
    }   
    if(id == 3){
        div_menu3 = document.getElementById("menu2_list3");
        if (div_menu3)
            div_menu3.style.display = "none";
    }
}

function changeBg(obj,id) {
    obj.style.color = "#FFFFFF";
    obj.style.borderColor = "#000000";
    obj.style.fontWeight = "bold";
    obj.style.backgroundColor = "#348781";
    showList(id);
}

function revertBg(obj,id) {
    obj.style.color = "#000000";
    obj.style.borderColor = "#c9d1da";
    obj.style.fontWeight = "normal";
    obj.style.backgroundColor = "#8cb8b0";
    hideList(id);
}

function chgMarket(page, exch) {
    window.location = page + "?exch=" + exch;
}

function chgChart(id, path) {
    while (value > 0) {
        fadeout();
    }

    var chart_type;
    chart_type = path;

    setInterval("fadein()", 100);

    if (document.getElementById('minichart')) {
        document.getElementById('minichart').src = chart_type;

        for (i=1;i<7;i++) {
            if (i == id) {
                document.getElementById("chart"+i).style.backgroundColor = "#B0C1D9";
                document.getElementById("chart"+i).style.fontWeight = "bold";
                document.getElementById("chart"+i).style.color = "#000000";
            }
            else {
                document.getElementById("chart"+i).style.backgroundColor = "#FFFFFF";
                document.getElementById("chart"+i).style.fontWeight = "normal";
                document.getElementById("chart"+i).style.color = "#0000FF";
            }
        }
    }
}

function fadein()
{
    if (value<100)
        value += 2;

    if (window.sidebar) {
        if (document.getElementById("minichart")) {
            document.getElementById("minichart").style.MozOpacity = value / 100;
        }
    }
    else if (window.opera && window.getSelection) {
        if (document.getElementById("minichart")) {
            document.getElementById("minichart").style.opacity = value / 100;
        }
    }
    else if (document.all) {
        if (document.getElementById("minichart")) {
            document.getElementById("minichart").filters[0].opacity = value;
        }
    }
}

function fadeout()
{
    if (value>0)
        value -= 1;

    if (window.sidebar) {
        if (document.getElementById("minichart")) {
            document.getElementById("minichart").style.MozOpacity = value / 100;
        }
    }
    else if (window.opera && window.getSelection) {
        if (document.getElementById("minichart")) {
            document.getElementById("minichart").style.opacity = value / 100;
        }
    }
    else if (document.all) {
        if (document.getElementById("minichart")) {
            document.getElementById("minichart").filters[0].opacity = value;
        }
    }
}

// returns XMLHttp Object in an IE/Mozilla/Safari-friendly method
// with code modified from http://jibbering.com/2002/4/httprequest.html
function getXMLHttpObject() {
  var XMLobj = null;
  try {
    XMLobj = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      XMLobj = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      XMLobj = null;
    }
  }
  if (!XMLobj && typeof XMLHttpRequest != 'undefined') {
    XMLobj = new XMLHttpRequest();
  }
  return XMLobj;  
}

function showHideMenu(id) {
    if (document.getElementById("sub_mnu_" + id)) {
        var obj = document.getElementById("sub_mnu_" + id);
        if (obj.style.display == "block") {
            obj.style.display = "none";
        }
        else if (obj.style.display == "none") {
            obj.style.display = "block";
        }
    }
}

function _bgRed(obj) {
    obj.style.backgroundColor = "#c9d1da";
    obj.style.color = "#000000";
}

function _bgWhite(obj) {
    obj.style.backgroundColor = "#6aa0da";
    obj.style.color = "#ffffff";
}

function openTellUs(page) {
    window.open('tellus.php?pg='+page, 'tellus', 'height=600,width=600,status=no,menubar=no,location=no,resizable=no,scrollbars=no,fullscreen=no');
}

function chkValue(obj) {
    var chk = document.getElementById("news");
    var chk_1 = document.getElementById("news_1");
    var chk_2 = document.getElementById("news_2");
    var chk_3 = document.getElementById("news_3");

    if (obj.id == chk.id) {
        if (chk.checked) {
            chk_1.checked = true;
            chk_2.checked = true;
            chk_3.checked = true;
        }
        else {
            chk_1.checked = false;
            chk_2.checked = false;
            chk_3.checked = false;
        }
    }
    else {
        if ((chk_1.checked == false) && (chk_2.checked == false) && (chk_3.checked == false)) {
            chk.checked = false;
        }
        else
            chk.checked = true;
    }
}

function showPost() {
    clearTimeout(timer2);
    var div_post;

    div_post = document.getElementById("divPost");
    div_post.style.display = "block";
}

function hidePost() {
    timer2 = setTimeout("doHide2();", 100);
}

function doHide2() {
    var div_post;

    div_post = document.getElementById("divPost");
    div_post.style.display = "none";
}

function changeBg1(obj) {
    obj.style.color = "#DC1212";
    obj.style.borderColor = "#3F89C3";
    obj.style.fontWeight = "bold";
    showPost();
}

function revertBg1(obj) {
    obj.style.color = "#3F89C3";
    obj.style.borderColor = "#DC1212";
    obj.style.fontWeight = "normal";
    hidePost();
}

function showRealTime() {
    clearTimeout(timer3);
    var obj = document.getElementById("rtDiv");
    obj.style.display = "block";
}

function hideRealTime() {
    timer3 = setTimeout("hideRT();", 1000);
}

function hideRT() {
    var obj = document.getElementById("rtDiv");
    obj.style.display = "none";
}

function loadPage(pg, symbol) {
	// 1 - Trade Summary, 2 - Time & Sale, 3 - Historical Prices, 4 - KLSE Announcement, 5 - Fundamentals, 6 - Business Summary
	symbol = symbol.substring(0, symbol.length - 3);
	if (pg == 1)
		window.location = "list.php?ss=" + symbol;
	else if (pg == 2) 
		window.location = "tsales.php?ss=" + symbol;
	else if (pg == 3) 
		window.location = "'hquotes.php?ss=" + symbol;
	else if (pg == 4)
		window.location = "news.php?ss=" + symbol;
	else if (pg == 5)
		window.location = "fundamental.php?ss=" + symbol;
	else if (pg == 6) 
		window.location = "bsumm.php?ss=" + symbol;
 }
 
 function popShow() {
    var strURL = "stksearch.php"; 
    var strType = "console";
    var strHeight = 320;
    var strWidth = 650;
    
    if (newWin != null && !newWin.closed) 
        newWin.close(); 
        
    var strOptions=""; 
    if (strType=="console") 
        strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth; 
        
    if (strType=="fixed") 
        strOptions="status,height="+strHeight+",width="+strWidth; 
        
    if (strType=="elastic") 
        strOptions="toolbar,menubar,scrollbars,"+"resizable,location,height="+strHeight+",width="+strWidth; 
    
    newWin = window.open(strURL, 'newWin', strOptions); 
    newWin.focus(); 
 }