var clockID = 0;
var tDate = new Date();
var usingDate = new Date();
var syncTime=new Date();
var strTime;  
function UpdateClock() 
{
    var time=new Date();
    if(clockID)
    {
      clearTimeout(clockID);
      clockID  = 0;
    }
    usingDate.setTime(tDate.getTime()+(time.getTime()-syncTime.getTime()));
    var currentDay=strTime[2];
    var currentMonth=tDate.getMonth()
    var currentHours = usingDate.getHours ( );
    var currentMinutes = usingDate.getMinutes ( );
    var currentSeconds = usingDate.getSeconds ( );
    //
    currentDay = ( currentDay < 10 ? "0" : "" ) + currentDay;
    currentMonth = ( currentMonth < 10 ? "0" : "" ) + currentMonth;
    // Pad the minutes and seconds with leading zeros, if required
    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;  
    // Convert an hours component of "0" to "12"
    currentHours = ( currentHours == 0 ) ? 12 : currentHours;
    document.getElementById('clock').innerHTML = ""                                      
                               + currentHours + ":" 
                               + currentMinutes + ":" 
                               + currentSeconds;   
    clockID = setTimeout("UpdateClock()", 1000);   
    if($get('clock').innerHTML == "8:05:00")
    {
        window.location.reload(true);
    }
         
}
function StartClock()
{
    var a= StockBoard.DataFeeder.GetServerTime(_onGetServerTimeComplete,_onGetServerTimeTimeOut,_onGetServerTimeError);
}
_onGetServerTimeComplete=function(arg)
{   
    var curTime=new Date();
    var serverTime=arg;        
    strTime=serverTime.split('|');
    tDate.setFullYear(strTime[0],strTime[1],strTime[2]);        
    tDate.setHours(strTime[3],strTime[4],strTime[5],strTime[6]); 
    UpdateClock();    
}
 _onGetServerTimeError=function(arg)
{
    setTimeout('StartClock()',500);       
}
 _onGetServerTimeTimeOut=function(arg)
{
     setTimeout('StartClock()',500);   
}
function KillClock()
{
    if(clockID)
    {
        clearTimeout(clockID);
        clockID  = 0;
    }  
}

StartClock();
