var hour, minute, seconds, milliseconds, weekday, day, month, yy, year, startTime, popup, field;

var months = new makeArray('January','February','March',
    'April','May','June','July','August','September',
    'October','November','December');

var weekdays = new makeArray('Sun.','Mon.','Tues.',
    'Wed.','Thurs.','Fri.','Sat.');

date = new Date();
hour = date.getHours();
minute = date.getMinutes();
seconds = date.getSeconds();
milliseconds = date.getMilliseconds();
weekday  = date.getDay() + 1;
day  = date.getDate();
month = date.getMonth() + 1;
yy = date.getYear();
year = (yy < 1000) ? yy + 1900 : yy;
startTime = date.getTime();

function makeArray() {
     for (i = 0; i<makeArray.arguments.length; i++)
          this[i + 1] = makeArray.arguments[i];
}

function showGreeting() {
  var s
  if (hour < 12) s = "Good morning";
  if (hour >= 12 & hour < 17) s = "Good afternoon";
  if (hour >= 17) s = "Good evening";
  document.write(s);
}

function showDay(intDayOfWeek, intMonth, intYear, intEarliest) {
// intEarliest is the earliest day on which the holiday can occur.
// for example, if November 1st is a Thursday, then Thanksgiving
// is on the 22nd (the 4th Thursday), which is the earliest it 
// can occur. It can occur as late as the 28th.
// intDayOFWeek is the numeric day of the week. eg Thanksgiving
// is on a Thursday which is the 5th day of the week.
	for (i = intEarliest; i <= intEarliest + 6; i++) {
		dtDate = new Date(intMonth + '/' + i + '/' + intYear)
		if (dtDate.getDay() + 1 == intDayOfWeek){
			document.write(weekdays[dtDate.getDay() + 1] + ", " + months[intMonth] + " " + i + ", " + intYear); 
		}
	}
}

function showTime(type) {
// showTime available types.....
//		"c" - civilian time eg. 4:30 PM
//		"m" - military time eg. 1400 hours
  var xhour = hour;
  var xminute = minute;
  if (xminute < 10) xminute = "0" + xminute;
  switch (type) {
    case "c":
      var ampm = "AM";
      if (hour >= 12) {
        ampm = "PM";
        if (hour != 12) xhour = hour - 12;
      }
      time = xhour + ":"+ xminute + " " + ampm;
      break;
    case "m":
      if (xhour < 10) xhour = "0" + xhour;
      time = xhour + "" + xminute + " hours ";
      break;
  }
  document.write(time);
}

// showDate available formats.....
//		"mm/dd/yyyy"
//		"dd/mm/yyyy"
//		"dddd, mm dd, yyyy"
//		"dddd, mm dd, yyyy hh:ss"

function showDate (format) {
  switch (format) {
    case "mm/dd/yyyy":      document.write(month + "/" + day + "/" + year);      break;
    case "dd/mm/yyyy":      document.write(day + "/" + month + "/" + year);      break;
    case "dddd, mm dd, yyyy":      document.write(weekdays[weekday] + ", " + months[month] + " " + day + ", " + year);      break;
    case "dddd, mm dd, yyyy hh:ss":      document.write(weekdays[weekday] + ", " + months[month] + " " + day + ", " + year  + " " + time);      break;
    default:      document.write(month + "/" + day + "/" + year);      break;
  }

}

