// made by: Nicolas - http://www.javascript-page.com

var clockID = 0;
var serverTimeId;
var initialDate = null;
var dateOffset = null;

function UpdateClock() {
	if(clockID) {
	  clearTimeout(clockID);
	  clockID  = 0;
	}

	var tDate = new Date();
	if(initialDate != null){
		dateOffset = tDate.getTime() - initialDate.getTime();
		initialDate = null;
	}
	
	if(dateOffset != null){
		tDate.setTime(tDate.getTime() - dateOffset);
	}

	document.getElementById(serverTimeId).innerHTML = 
		"" 
		+ padNumber(tDate.getFullYear())	+ "-" 
		+ padNumber(tDate.getMonth() + 1)	+ "-"
		+ padNumber(tDate.getDate())		+ " " 
		+ padNumber(tDate.getHours())		+ ":" 
		+ padNumber(tDate.getMinutes())		+ ":" 
		+ padNumber(tDate.getSeconds());

	clockID = setTimeout("UpdateClock()", 500);
}

function padNumber(number){
	if(number < 10){
		return "0" + number;
	}
	else {
		return "" + number;
	}
}

function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

