
   	// must set clockFormVar & clockFieldVar equal to FORM & INPUT name we are using on HTML page
   	// set after requiring this file but before calling startTimer (see bottom eg)
	// u can therefore use this file on more than one page 
	// even if the form names are different on each HTML page
	
	// nb but not more than once on each page, as it stands we've only got space to store one set of form names
	 
	// var clockFormVar = ""; 
	var clockFieldVar = "clock"; 
	
	
	
	var clockID = 0; // we use this as a reference to the timeout. Put it outside the
					 // functions below so it remains in global scope and doesn't 
					 // disappear when the functions return
	
	
	// store day (0 to 6) and month (0 to 11) names in array 
	
	var dayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	
	
	/* ************************************************************************ */	
	
	
	
	function startClock() {

 		// Window.setTimeout(code,delay) defer execution of code for delay milliseconds 
		// and keep its timeoutid in clockID 
		
		// nb Window. seems to be the default object because i can leave it out, but if you're looking for 
		// reference material in dreamweaver you will probably have to get to setTimeout() through Window
   
   		clockID = setTimeout("updateClock();", 500); // start the ball rolling in 500 milliseconds
   		
   		return 1;
	}


	
	function updateClock() {
   
   		// nb this is a recursive function, it sets a timer to call itself again after executing
   

  		if (clockID) { // if a timeout exists under clockID clear it and reset
      
  			// Window.clearTimeout(timeoutId) does exactly what it says on the tin
			// pass it the pointer to the timeout
      		
      		clearTimeout(clockID);
      		clockID  = 0;
   		}

		// with no arguments the date constructor creates a date object set to the current (local) time
		// we will be using UTC time anyway so timezone is irrelevant. 

		// UTC time uses seconds since Jan 1st 1970 GMT (unix timestamp)
		// it returns it in milliseconds in javascript but we are not accessing the number directly anyway, will be using Date object UTC methods
		
   		var date = new Date();

   
   		var hours = date.getUTCHours(); // UTC is the same as GMT
   		var minutes = date.getUTCMinutes();
   		var seconds = date.getUTCSeconds();

   		// pad with leading zero if only one digit (can't believe there's no tidier way of doing this but that's javascript and it will do)
   		
   		if (hours < 10) { 
   		
   			hours = "0" + hours; 
   		}
   		
   		if (minutes < 10) { 
   			
   			minutes = "0" + minutes;
   		}
   		
   		if (seconds < 10) {
   			
   			seconds = "0" + seconds;
   		}
   		
   		
   		// build date string
   		
   		var dateStr = dayArray [(date.getUTCDay())] + " " 
   					  + date.getUTCDate() + " " 
   					  + monthArray [(date.getUTCMonth())] + " "  
					  + hours + ":" 
					  + minutes + ":" 
					  + seconds 
					  + " GMT"; 
		
		// that's your date string
	
	/*	
		var dateStr = date.toUTCString();
	*/	
   		// nb eval executes a string as code so you can make the code dependent on form and date variables 
   		// alert(dateStr);
   		eval("document.getElementById('" + clockFieldVar + "').innerHTML = '" + dateStr + "'");
   
   
   		clockID = setTimeout("updateClock();", 1000); // do it all again in a second
   		
   		return 1;
	}		

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


	/* ************************************************************************ */	


/* 

eg 

<HEAD>
  <LINK rel="stylesheet" href="../css.css" type="text/css">
  <SCRIPT language="JavaScript" type="text/Javascript" src="function.clock.js">
<!--
//-->
  </SCRIPT>
</HEAD>

<BODY onload="clockFormVar='theClock';clockFieldVar='theTime';startClock();" onunload="killClock();">
  <FORM name="theClock">
    <INPUT type="text" name="theTime" class="clockField">
  </FORM>
</BODY>

*/
