var clockID = 0;

clockID = setTimeout("updateClock()", 500);

function updateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
   
   var tDate = new Date();
   getLayer('mainClock').innerHTML = "" + leadingZero(tDate.getDate()) + "." + leadingZero(tDate.getMonth()+1) + "." + takeYear(tDate) + ", " + 
                                     leadingZero(tDate.getHours()) + ":" + leadingZero(tDate.getMinutes()) + ":" + leadingZero(tDate.getSeconds());
   clockID = setTimeout("updateClock()", 1000);
}

function leadingZero(number) {
	if (number < 10) number = "0" + number;
	return number;
}

function takeYear(tDate) {
	x = tDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}
