
// Server Time Clock
var stH;
var stM;
var stS;

var stT=null;
var g_onLoadHandlers = new Array();

function sClock()
{
  if(stT){clearInterval(stT);stT=null;}
  stT=setInterval("work();",1000);
}

function twoDigit(_v)
{
  if(_v<10)_v="0"+_v;
  return _v;
}

function work()
{
  var runTime = new Date();
  var dn = "AM";
  var sstH = stH;
  var sstM = stM;
  var sstS = stS;
  if (sstH >= 12)
  {
    dn = "PM";
    sstH-=12;
  }
  if (!sstH) sstH = 12;
  sstM=twoDigit(sstM);
  sstS=twoDigit(sstS);
  sstH=twoDigit(sstH);
  movingtime = ""+ sstH + ":" + sstM +":"+sstS+" " + dn;
  var o = document.getElementById("clock");
  if(!o)
  	return;
  o.innerHTML='' + movingtime;

  if(++stS>59)
  {
    stS=0;
    if(++stM>59)
    {
      stM=0;
      if(++stH>23)
      {
        stH=0;
      }
    }
  }
}
// end of Server Time Clock

// Registers a function to be called on document load
function registerOnLoadFunction(fn)
{
	g_onLoadHandlers.push(fn);
}


//Sets the loaded flag and launches the registered onload handlers
function onLoadGenericHandler()
{
	document.body._loaded = true;
	
	// Call on load handlers 
	for (var i = 0; i < g_onLoadHandlers.length; i++)
		g_onLoadHandlers[i]();	
}




//Portable attach event to window 
function attachWindowEvent(name, handler)
{
	if (ie)
		window.attachEvent('on'+name, handler);
	else
		window.addEventListener(name, handler, true);	
}

//Attach generic handler to the document
attachWindowEvent('load', onLoadGenericHandler);
