
var clockID = 0;

function translateWeekDay(day)
{
    if (day==0)
        return 'Duminica';
    if (day==1)
        return 'Luni';
    if (day==2)
        return 'Marti';
    if (day==3)
        return 'Miercuri';
    if (day==4)
        return 'Joi';
    if (day==5)
        return 'Vineri';
    if (day==6)
        return 'Sambata';
    return 'Lun';
}

function updateClock() 
{
   if (clockID) 
   {
      clearTimeout(clockID);
      clockID  = 0;
    }

   var tDate = new Date();

   document.getElementById('theClock').innerHTML = "" + translateWeekDay(tDate.getDay()) + ", " 
                                   + (tDate.getDate()<10?'0'+tDate.getDate():tDate.getDate()) + " " 
                                   + (tDate.getMonth()+1<10?'0'+(tDate.getMonth()+1):(tDate.getMonth()+1)) + " " 
                                   + tDate.getFullYear() + " " 
                                   + (tDate.getHours()<10?'0'+tDate.getHours():tDate.getHours()) + ":" 
                                   + (tDate.getMinutes()<10?'0'+tDate.getMinutes():tDate.getMinutes()) + ":" 
                                   + (tDate.getSeconds()<10?'0'+tDate.getSeconds():tDate.getSeconds());
   
   clockID = setTimeout("updateClock()", 1000);
}

function startClock() 
{
   clockID = setTimeout("updateClock()", 500);
}

function killClock() 
{
   if (clockID) 
   {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

window.onload = startClock;
window.unnload = killClock;
