//------------------------------------------------------------------------------------------------------------------------
//	Javascript Graphic Clock
//	version 2.3
//	June 6, 1997
//
// 	Written by: Kendal Van Dyke
//			email: kendal@freenet.tlh.fl.us
//				OR vandyke@cs.fsu.edu
//			web:  http://www.cs.fsu.edu/~vandyke/
//	
//	Revision history:
//		2.3 - June 6, 1997
//		         Fixed a bug that caused massive Javascript errors when the user resized their browser window
//		         Fix also eliminated the need for the findIndexOf function, which has been removed.
//		2.2 - April 30, 1997
//		         Fixed a bug that caused a Javascript error when the hour switched from a double digit hour
//		           to a single digit hour (i.e. 12 AM or PM to 1 AM or PM)	
//		2.11 - April 21, 1997
//		         Changed the URL of the official Javascript Graphic Clock home page
//		2.1 - April 3, 1997
//		         Fixed error in adjusting time to reflect "regular" time....older version would report 12 am as 0 am
//		2.0 - March 31, 1997
//		         Added variables digit_images, separator_images, and ampm_images
//		         Added function makeImageArray to return an array of new images
//		         Added function findIndexOf to find the index of an image in document.images[] based on a
//			string value fed to the function that can be associated with document.images[].name
//		         Added support for preloading all images so that user did not have to constantly be online
//		         Renamed variables number_width to digit_width and colon_width to separator_width
//		         Removed variable base
//		         Images sources are now replaced by referencing an index value in the digit_images,
//			separator_images, and ampm_images arrays
//
//		1.0 - March 27, 1997
//		        This is the first version of this script - there are no revisions!
//
//	This script is released by the author to public domain...but please remember to give credit where credit is due -
//	would you want someone using something you wrote without giving you credit?
//------------------------------------------------------------------------------------------------------------------------

var digit_images;		// The array of digits 0-9
var separator_images;		// The array for blank and colon images
var ampm_images;		// The array of am and pm images

var image_base = "";	// The directory where your digit images are located
var image_type = ".gif";		// The format your digit images are stored as (.gif , .jpg , etc.)
var image_height = 16;		// The height of all of your images
var digit_width =13;		// The width of your digits 0-9 images
var ampm_width = 32;		// The width of your AM and PM images
var separator_width = 4;	// The width of your colon separator image
var clockDelay = 900;		// The delay in milliseconds between clock updates. Because of delays
				//	in changing the image source this should be set to about 800-900
				//	for a one second delay and about 300-400 for a half second delay
var ampm_image_height=16;
var hour1 = "blank";		// The first digit in the hour of the day
var hour2 = "blank";		// The second digit in the hour of the day
var minute1 = "blank";		// The first digit in the minute of the day
var minute2 = "blank";		// The second digit in the minute of the day
var ampm;			// Holds value to tell if it's AM or PM

var now;			// Used in getting the current date
var cur_hour;			// Used in getting the current hour from the date
var cur_minute;			// Used in getting the current minutes from the date


function makeImageArray(length, ImageWidth, ImageHeight){	// Returns an array of Images where
  this.length = length;						//   the index of the 1st array element is 0
  for ( i = 0; i < length; i++ ){
    this[i] = new Image(ImageWidth, ImageHeight);
  }
  return this;
}

function UpdateClock(hr1, hr2, min1, min2, separator){		// Updates the clock

  now = new Date();			// Get the current date
  cur_hour = now.getHours();		// Get the current hour from the date
  cur_minute = now.getMinutes();	// Get the current minutes from the date


  // First determine if it is in the morning or afternoon
  if (cur_hour >= 12){ampm = "pm";}
  else{ampm = "am";}

  // Then adjust the time to reflect "regular" time (i.e. hours 1-12 instead of the military 0-23)
  if (cur_hour >= 13){cur_hour = cur_hour - 12;}
  if (cur_hour == 0){cur_hour = 12;}

  // Before we can break up the hours and minutes into individual digits 
  // we need to convert cur_hour and cur_minute to strings
  cur_hour += "";
  cur_minute += "";

  // Now assign the individual hour digits to variables hour1 and hour2
  if (cur_hour >= 10){
	hour1 = cur_hour.charAt(0);
	hour2 = cur_hour.charAt(1);
  }
  else{
	hour1 = "0";
	hour2 = cur_hour.charAt(0);
  }

  // Now assign the individual minute digits to variables minute1 and minute2
  if (cur_minute >= 10){
	minute1 = cur_minute.charAt(0);
	minute2 = cur_minute.charAt(1);
  }
  else{
	minute1 = "0";
	minute2 = cur_minute.charAt(0);
  }


  // At this point we have all the variables assigned so we need to check and see if the any of the digits in the time has
  // changed. If any of them have, then change the image source to reflect the digit that changed. NOTE: This only works
  // with Netscape 3.0 or above, so check first to see what browser the user has

  if (parseInt(navigator.appVersion.substring(0,1))>=3) {	// Netscape 3.0 or greater
    if (hour1 == "0"){document.clock1.src = image_base + "empty" + image_type;}
      else {document.clock1.src = digit_images[hour1].src;}
    document.clock2.src = digit_images[hour2].src;
    if (separator == "blank"){document.clock3.src = separator_images[0].src;}
      else {document.clock3.src = separator_images[1].src;}
    document.clock4.src = digit_images[minute1].src;
    document.clock5.src = digit_images[minute2].src;
    if (ampm == "am"){document.clock7.src = ampm_images[0].src;}
      else {document.clock7.src = ampm_images[1].src;}
  }

  // The time has been updated for this go around of the function call, so now call the function again recursively so that it
  // can check for the next second. To avoid calling the function a gazillion times we will use setTimeout to pause for the
  // time reflected in clockDelay before this function calls itself again. Doing it this way also allows us to change the
  // separator image to reflect the seconds ticking away.

  if (separator == "blank"){setTimeout("UpdateClock(hour1, hour2, minute1, minute2, 'colon')", clockDelay);}
  else{setTimeout("UpdateClock(hour1, hour2, minute1, minute2, 'blank')", clockDelay);}
} // This bracket ends the UpdateClock function

// This script only works with Netscape 3.0 or above, so first check to see what browser the user has to make sure it's ok
//     to make the calls to write to the document.

if (parseInt(navigator.appVersion.substring(0,1))>=3) {		// Netscape 3.0 or greater

  digit_images = new makeImageArray(10, digit_width, image_height);
  separator_images = new makeImageArray(2, separator_width, image_height);
  ampm_images = new makeImageArray(2, ampm_width, image_height);

  for ( i = 0; i < 10; i++ ){digit_images[i].src = image_base + i + image_type;}
  separator_images[0].src = image_base + "blank" + image_type;
  separator_images[1].src = image_base + "colon" + image_type;
  ampm_images[0].src = image_base + "am" + image_type;
  ampm_images[1].src = image_base + "pm" + image_type;

  //document.write('<A HREF="http://www.cs.fsu.edu/~vandyke/clock/" onMouseOver="window.status=\'Go to the Javascript Graphic Clock home page\'; return true;" onMouseOut="window.status=\'\'; return true;" TARGET="_top">');
  document.write('<IMG NAME="clock1" SRC="' + image_base + 'blank' + image_type + '" WIDTH="' + digit_width + '" HEIGHT="' + image_height + '" class="sinborde">');
  document.write('<IMG NAME="clock2" SRC="' + image_base + 'blank' + image_type + '" WIDTH="' + digit_width + '" HEIGHT="' + image_height + '" class="sinborde">');
  document.write('<IMG NAME="clock3" SRC="' + image_base + 'blank' + image_type + '" WIDTH="' + separator_width + '" HEIGHT="' + image_height + '" class="sinborde">');
  document.write('<IMG NAME="clock4" SRC="' + image_base + 'blank' + image_type + '" WIDTH="' + digit_width + '" HEIGHT="' + image_height + '" class="sinborde">');
  document.write('<IMG NAME="clock5" SRC="' + image_base + 'blank' + image_type + '" WIDTH="' + digit_width + '" HEIGHT="' + image_height + '" class="sinborde">');
  document.write('<IMG NAME="clock6" SRC="' + image_base + 'blank' + image_type + '" WIDTH="' + separator_width + '" HEIGHT="' + image_height + '"  class="sinborde">');
  document.write('<IMG NAME="clock7" SRC="' + image_base + 'blank' + image_type + '" WIDTH="' + ampm_width + '" HEIGHT="' + ampm_image_height + '" class="sinborde">');
  //document.write('</A>');

  // Finally, start the clock running using the UpdateClock function
  UpdateClock("blank", "blank", "blank", "blank", "blank");
} // This bracket ends the Netscape 3.0 or above check

//-->
// Poner esta llamada para mostrar el reloj
//<!-- Fecha del sistema cliente -->
//<BR><SMALL><SUB>[<SCRIPT>todaysDate()</SCRIPT>]</SUB></SMALL><BR>


