var id0=0;
var serverTime=0;
var stObj=new Array();
var timeInt=1000;

function stockResponse(ajaxResponse){
    var update=new Array();
    var updateDiv=new Array();
    if(ajaxResponse.indexOf('<br>' != -1)) {
        update = ajaxResponse.split('<br>');
        serverTime=parseInt(update[0]);
        for (i=1;i<update.length;i++){
              updateDiv=update[i].split(',');
              if (updateDiv.length>1){
                stObj[updateDiv[0]]=updateDiv[2];
                var myObj=getObj(updateDiv[0]);
                if (updateDiv[1].indexOf('down')!=-1)
                  myObj.style.backgroundColor="#ff0000";
                else
                  myObj.style.backgroundColor="#00ff00";
              }
        }
    }
}

function xmlhttpPost(strURL, strSubmit, strResultFunc) {
//http://www.onlamp.com/pub/a/onlamp/2005/05/19/xmlhttprequest.html
        var xmlHttpReq = false;
        
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
                xmlHttpReq = new XMLHttpRequest();
                xmlHttpReq.overrideMimeType('text/xml');
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }     xmlHttpReq.open('POST', strURL, true);
        xmlHttpReq.setRequestHeader('Content-Type', 
		     'application/x-www-form-urlencoded');
        xmlHttpReq.onreadystatechange = function() {
                if (xmlHttpReq.readyState == 4) {
                        eval(strResultFunc + '(xmlHttpReq.responseText);');
                }
        }
        xmlHttpReq.send(strSubmit);
}

function getObj(id){
var objID= (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null; 
return objID
}

function showID(layerID){
        //document.Show.stockSymbol.value = layerID
        overlib(stObj[layerID],TIMEOUT,2000,WRAP,FGCOLOR,'#FFFFFF');
	return true
}

function onLoad() {
      runTime();
      setTimeout("runTime()",300);
      doData("true");
}

function runTime() {
//dbgObj=getObj("dbg");
//dbgObj.style.visibility="visible";
  now = new Date();
  xmlhttpPost("./getStockPrice.jsp","","stockResponse");
  hour = serverTime+2;
  if (hour>24)
   hour=hour-24;
  pos1=25*(24-hour)-300;
  barObj=getObj("bar");
  bar2Obj=getObj("bar2");
//dbgObj=getObj("dbg");
  if (pos1<0){
     bar2Obj.style.visibility="visible";
     bar2Left=parseInt(600+pos1);
     barTemp=bar2Left+"px";
     bar2Obj.style.left=barTemp;
  }
  else{
     bar2Obj.style.visibility="hidden";
     barTemp="300px";
     barObj.style.width=barTemp;
  } 
//dbgObj.innerHTML=pos1;
//dbgObj.style.visibility="visible";
  barObj.style.left=pos1+"px";
  if (timeInt<32000){
    doData('false');
    timeInt=timeInt*2;
    doData('true');
  }
//dbgObj.style.visibility="hidden";
//dbgObj.innerHTML=timeInt;
}

function endInterval(id){
    clearInterval(id);
}

function doData(run){
  // var timeInt=set Globally, see top
  if (run=='true'){
    clearInterval(id0);
    id0=setInterval("runTime()",timeInt);
  }
  else{
    clearInterval(id0);
  }
}

