// datedisp.js

var gbDebugMode = "F";

function DispDate(gasDate,gbDebugMode)
{
    // CURRENT DATE
    var gasCurrDate = new Date ();   

    // DOCUMENT DATE
    var gasModDate = new Date (document.lastModified);   

    if (gbDebugMode == "T")
    {
	document.write ('<TABLE Border=3 Width=600 FgColor=White BgColor=Cyan CellPadding=10>');
	document.write ('<TR>');
	document.write ('<TD Width=50%>');
	document.write ("moddate.format('yyyyMMdd-HHmmss')");
	document.write ('</TD>');
	document.write ('<TD Width=50%>');
	document.write (gasModDate.format('yyyyMMdd-HHmmss'));
	document.write ('</TD>');
	document.write ('</TR>');

	document.write ('<TR>');
	document.write ('<TD Width=50%>');
	document.write ("moddate.format('MM/dd/yy')");
	document.write ('</TD>');
	document.write ('<TD Width=50%>');
	document.write (gasModDate.format('MM/dd/yy'));
	document.write ('</TD>');
	document.write ('</TR>');

	document.write ('<TR>');
	document.write ('<TD Width=50%>');
	document.write ("moddate.format('EEEE, MMMM d, yyyy')");
	document.write ('</TD>');
	document.write ('<TD Width=50%>');
	document.write (gasModDate.format('EEEE, MMMM d, yyyy'));
	document.write ('</TD>');
	document.write ('</TR>');

	document.write ('<TR>');
	document.write ('<TD Width=50%>');
	document.write ("currdate.format('dd-MMM-yy HH:mm:ss')");
	document.write ('</TD>');
	document.write ('<TD Width=50%>');
	document.write (gasCurrDate.format('dd-MMM-yy HH:mm:ss'));
	document.write ('</TD>');
	document.write ('</TR>');

	document.write ('<TR>');
	document.write ('<TD Width=50%>');
	document.write ('User Date</TD><TD Width=50%>', gasDate.format('yyyy-MM-dd HH:mm:ss'));
	document.write ('</TD>');
	document.write ('</TR>');
	document.write ('<TR>');
	document.write ('<TD Width=50%>');
	document.write ('Document Date</TD><TD Width=50%>', gasModDate.format('MM/dd/yyyy hh:mm aa'));
	document.write ('</TD>');
	document.write ('</TR>');
	document.write ('<TR>');
	document.write ('<TD Width=50%>');
	document.write ('Current Date</TD><TD Width=50%>', gasCurrDate.format('yyyy-MM-dd HH:mm:ss'));
	document.write ('</TD>');
	document.write ('</TR>');
	document.write ('</TABLE>');
	DispHelp();
    }
}

// STATIC DEFINITION OF MONTH NAMES
Date.MONTH_NAMES = [
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December" ];

// STATIC DEFINITION OF WEEKDAY NAMES
Date.WEEKDAY_NAMES = [
"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday",
"Saturday" ];

// CLONE THE CURRENT DATE OBJECT AND RETURN A DIFFERENT OBJECT WITH IDENTICAL VALUE
Date.prototype.clone = function () 
{
  return new Date(this.getTime());
}

// CLEAR THE TIME INFORMATION FROM THIS DATE AND RETURN IT
Date.prototype.clearTime = function () 
{
  this.setHours(0); this.setMinutes(0);
  this.setSeconds(0); this.setMilliseconds(0);
  return this;
}

// RETURN THE LAST DAY OF THIS MONTH
Date.prototype.lastDay = function () 
{
  var tempDate = this.clone();
  tempDate.setMonth(tempDate.getMonth()+1);
  tempDate.setDate(0);
  return tempDate.getDate();
}

// RETURN NUMBER OF DAYS SINCE START OF YEAR
Date.prototype.getYearDay = function () 
{
  var today = new Date(this);
  today.setHours(0); today.setMinutes(0); today.setSeconds(0);
  var tempDate = new Date(today);
  // SET START OF YEAR
  tempDate.setDate(1);
  tempDate.setMonth(0);
  return Math.round(
  (today.getTime() - tempDate.getTime())
  / 86400 / 1000) + 1; // Jan/1 is day 1
}

// ADD format() TO DATE
Date.prototype.format = function(formatString) 
{
  var out = new String();
  var token = ""
  for (var i = 0; i < formatString.length; i++) 
  {
    if (formatString.charAt(i) == token.charAt(0)) 
    {
      token = token.concat(formatString.charAt(i));
      continue;
    }
    out = out.concat(this.convertToken(token));
    token = formatString.charAt(i);
  }
  return out + this.convertToken(token);
}

// INTERNAL CALL TO MAP TOKENS TO THE DATE DATA
Date.prototype.convertToken = function (str) 
{
  switch(str.charAt(0)) 
  {
    case 'y': // SET YEAR
      if (str.length > 2)
      return this.getFullYear();
      return this.getFullYear().toString().substring(2);
    case 'd': // SET DATE
      return Date.zeroPad(this.getDate(),str.length);
    case 'D': // SET DAY IN YEAR
      return this.getYearDay();
    case 'a': // SET DAY PART
      return this.getHours() > 11 ? "PM" : "AM";
    case 'H': // SET HOURS (24)
      return Date.zeroPad(this.getHours(),str.length);
    case 'h': // SET HOURS (12)
      return Date.zeroPad(this.get12Hours(),str.length);
    case 'm': // SET MINUTES
      return Date.zeroPad(this.getMinutes(),2);
    case 's': // SET SECONDE
      return Date.zeroPad(this.getSeconds(),2);
    case 'S': // SET MILLISECONDS
      return Date.zeroPad(this.getMilliseconds(),str.length);
    case 'x': // SET EPOCH TIME
      return this.getTime();
    case 'Z': // SET TIME ZONE
      return (this.getTimezoneOffset() / 60) + ":" +
      Date.zeroPad(this.getTimezoneOffset() % 60,2);
    case 'M': // SET MONTH
      if (str.length > 3) return this.getFullMonthName();
      if (str.length > 2) return this.getShortMonthName();
      return Date.zeroPad(this.getMonth()+1,str.length);
    case 'E': // SET DOW
      if (str.length > 3) return this.getDOWName();
      if (str.length > 1) return this.getShortDOWName();
      return this.getDay();
      default:
      return str;
  }
}

// RETREIVE THE MONTH'S NAME IN ENGLISH
Date.prototype.getFullMonthName = function() 
{
  return Date.MONTH_NAMES[this.getMonth()];
}

// RETREIVE THE ABBERVIATED MONTH NAME IN ENGLISH
Date.prototype.getShortMonthName = function() 
{
  return Date.MONTH_NAMES[this.getMonth()].substring(0,3);
}

// RETREIVE THE WEEK DAY NAME IN ENGLISH
Date.prototype.getDOWName = function () 
{
  return Date.WEEKDAY_NAMES[this.getDay()];
}

// RETREIVE THE ABBERVIATED WEEK DAY NAME IN ENGLISH
Date.prototype.getShortDOWName = function () 
{
  return Date.WEEKDAY_NAMES[this.getDay()].substring(0,3);
}

// RETREIVE THE HOUR IN A 12 HOUR CLOCK (WITHOUT THE am/pm SPECIFICATION)
Date.prototype.get12Hours = function () 
{
  return this.getHours() == 0 ? 12 :
  (this.getHours() > 12 ? this.getHours() - 12 : this.getHours());
}

// HELPER FUNCTION TO ADD REQUIRED ZERO CHARACTERS TO FIXED LENGTH FIELDS
Date.zeroPad = function(num, width) 
{
  num = num.toString();
  while (num.length < width)
  num = "0" + num;
  return num;
}


function DispHelp()
{
    document.write('	<blockquote>');
    document.write('	<table border=0 cellspacing=3 cellpadding=0 summary="Chart shows pattern letters, date/time component, presentation, and examples.">');
    document.write('');
    document.write('	 <tr bgcolor="#ccccff">');
    document.write('	     <th align=left>Letter');
    document.write('	     <th align=left>Date or Time Component');
    document.write('	     <th align=left>Presentation');
    document.write('	     <th align=left>Examples');
    document.write('	 <tr>');
    document.write('	     <td><code>G</code>');
    document.write('	     <td>Era designator');
    document.write('	     <td><a href="#text">Text</a>');
    document.write('	     <td><code>AD</code>');
    document.write('');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('	     <td><code>y</code>');
    document.write('	     <td>Year');
    document.write('	     <td><a href="#year">Year</a>');
    document.write('	     <td><code>1996</code>; <code>96</code>');
    document.write('	 <tr>');
    document.write('	     <td><code>M</code>');
    document.write('');
    document.write('	     <td>Month in year');
    document.write('	     <td><a href="#month">Month</a>');
    document.write('	     <td><code>July</code>; <code>Jul</code>; <code>07</code>');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('	     <td><code>w</code>');
    document.write('	     <td>Week in year');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('');
    document.write('	     <td><code>27</code>');
    document.write('	 <tr>');
    document.write('	     <td><code>W</code>');
    document.write('	     <td>Week in month');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>2</code>');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('');
    document.write('	     <td><code>D</code>');
    document.write('	     <td>Day in year');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>189</code>');
    document.write('	 <tr>');
    document.write('	     <td><code>d</code>');
    document.write('	     <td>Day in month');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('');
    document.write('	     <td><code>10</code>');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('	     <td><code>F</code>');
    document.write('	     <td>Day of week in month');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>2</code>');
    document.write('	 <tr>');
    document.write('');
    document.write('	     <td><code>E</code>');
    document.write('	     <td>Day in week');
    document.write('	     <td><a href="#text">Text</a>');
    document.write('	     <td><code>Tuesday</code>; <code>Tue</code>');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('	     <td><code>a</code>');
    document.write('');
    document.write('	     <td>Am/pm marker');
    document.write('	     <td><a href="#text">Text</a>');
    document.write('	     <td><code>PM</code>');
    document.write('	 <tr>');
    document.write('	     <td><code>H</code>');
    document.write('	     <td>Hour in day (0-23)');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>0</code>');
    document.write('');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('	     <td><code>k</code>');
    document.write('	     <td>Hour in day (1-24)');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>24</code>');
    document.write('	 <tr>');
    document.write('	     <td><code>K</code>');
    document.write('');
    document.write('	     <td>Hour in am/pm (0-11)');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>0</code>');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('	     <td><code>h</code>');
    document.write('	     <td>Hour in am/pm (1-12)');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>12</code>');
    document.write('');
    document.write('	 <tr>');
    document.write('	     <td><code>m</code>');
    document.write('	     <td>Minute in hour');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>30</code>');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('	     <td><code>s</code>');
    document.write('');
    document.write('	     <td>Second in minute');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>55</code>');
    document.write('	 <tr>');
    document.write('	     <td><code>S</code>');
    document.write('	     <td>Millisecond');
    document.write('	     <td><a href="#number">Number</a>');
    document.write('	     <td><code>978</code>');
    document.write('');
    document.write('	 <tr bgcolor="#eeeeff">');
    document.write('	     <td><code>z</code>');
    document.write('	     <td>Time zone');
    document.write('	     <td><a href="#timezone">General time zone</a>');
    document.write('	     <td><code>Pacific Standard Time</code>; <code>PST</code>; <code>GMT-08:00</code>');
    document.write('	 <tr>');
    document.write('');
    document.write('	     <td><code>Z</code>');
    document.write('	     <td>Time zone');
    document.write('	     <td><a href="#rfc822timezone">RFC 822 time zone</a>');
    document.write('	     <td><code>-0800</code>');
    document.write('	</table>');
    document.write('    </blockquote>');

}

