var clock = 0;

function UpdateClock() {
   if(clock) {
      clearTimeout(clock);
      clock = 0;
   }

   	document.getElementById('clock').innerHTML = ReplaceNumbers(GetTime());
	
	if (document.getElementById && document.all){  // Detect IE
		var clkObj = document.getElementById('clock');
		for(var i=0; i<clkObj.childNodes.length; i++){
			
		  var img = clkObj.childNodes[i].firstChild;
		  if(img.tagName == "IMG"){
			  var imgName = img.src.toUpperCase();
			  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			  {
				 var imgID = (img.id) ? "id='" + img.id + "' " : ""
				 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				 var imgStyle = "display:inline-block;" + img.style.cssText 
				 if (img.align == "left") imgStyle = "float:left;" + imgStyle
				 if (img.align == "right") imgStyle = "float:right;" + imgStyle
				 //if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				 var strNewHTML = "<span " + imgID + imgClass + imgTitle
				 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				 img.outerHTML = strNewHTML
				 i = i-1
			  }
		  }
	
		}
	}
	clock = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clock = setTimeout("UpdateClock()", 500);
}

function GetTime(){

   var tDate = new Date();
   
   hour = ''+tDate.getHours();
   minutes = ''+tDate.getMinutes();
   seconds = ''+tDate.getSeconds();
   if(hour.length == 1){ hour = '0'+hour; }
   if(minutes.length == 1){ minutes = '0'+minutes; }
   if(seconds.length == 1){ seconds = '0'+seconds; }

   return hour+' : '+minutes+' : '+seconds;
}

function ReplaceNumbers(string){
   string = string.replace(/0/g,'#0#');
   string = string.replace(/1/g,'#1#');
   string = string.replace(/2/g,'#2#');
   string = string.replace(/3/g,'#3#');
   string = string.replace(/4/g,'#4#');
   string = string.replace(/5/g,'#5#');
   string = string.replace(/6/g,'#6#');
   string = string.replace(/7/g,'#7#');
   string = string.replace(/8/g,'#8#');
   string = string.replace(/9/g,'#9#');
   string = string.replace(/ : /g,'#:#');


   string = string.replace(/#0#/g,'<div style="float:left;"><img src="0.png" width="10" height="13" alt="0"/></div>');
   string = string.replace(/#1#/g,'<div style="float:left;"><img src="1.png" width="10" height="13" alt="1"/></div>');
   string = string.replace(/#2#/g,'<div style="float:left;"><img src="2.png" width="10" height="13" alt="2"/></div>');
   string = string.replace(/#3#/g,'<div style="float:left;"><img src="3.png" width="10" height="13" alt="3"/></div>');
   string = string.replace(/#4#/g,'<div style="float:left;"><img src="4.png" width="10" height="13" alt="4"/></div>');
   string = string.replace(/#5#/g,'<div style="float:left;"><img src="5.png" width="10" height="13" alt="5"/></div>');
   string = string.replace(/#6#/g,'<div style="float:left;"><img src="6.png" width="10" height="13" alt="6"/></div>');
   string = string.replace(/#7#/g,'<div style="float:left;"><img src="7.png" width="10" height="13" alt="7"/></div>');
   string = string.replace(/#8#/g,'<div style="float:left;"><img src="8.png" width="10" height="13" alt="8"/></div>');
   string = string.replace(/#9#/g,'<div style="float:left;"><img src="9.png" width="10" height="13" alt="9"/></div>');
   string = string.replace(/#:#/g,'<div style="float:left;"><img src="colon.png" width="5" height="13" alt=":"/></div>');

	return string;
}

function KillClock() {
   if(clock) {
      clearTimeout(clock);
      clock = 0;
   }
}