/***********************************************
Fool-Proof Date Input Script with DHTML Calendar
by Jason Moon - calendar@moonscript.com
************************************************/
// Customizable variables
var DefaultDateFormat = 'MM/DD/YYYY'; // If no date format is supplied, this will be used instead
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
if(!HideWait) {
var HideWait = 2; // 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 = 'Tahoma';
var CellWidth = 18;
var CellHeight = 16;
var ImageURL = 'images/calendar.jpg';
var NextURL = 'images/next.gif';
var PrevURL = 'images/prev.gif';
var CalBGColor = 'white';
var TopRowBGColor = 'buttonface';
var DayBGColor = 'lightgrey';
}
// Global variables
var ZCounter = 100;
var Today = new Date(1210341363457);
var WeekDays = new Array('S','M','T','W','T','F','S');
var MonthDays = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var MonthNames = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
// Write out the stylesheet definition for the calendar
with (document) {
writeln('');
}
function allowFormSubmit(input, value) {
try {
input.form.doSubmit.value = value;
} catch(err) {
// Do nothing, hidden field called "doSubmit" is probably missing in the form.
}
}
// Only allows certain keys to be used in the date field
function YearDigitsOnly(e) {
if(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 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 = '
';
for (var j=0;j';
for (var i=1;i<=7;i++) {
Day = (j * 7) + (i - tmpFirstDay);
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 += '
' + Day + '
';
}
else HTML += '
';
}
HTML += '';
}
return HTML += '
';
}
// 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, MonthList, NewDays) {
// If there is 13 month it means it´s a blank before the days
// adjust the indexes depending on this
var adjustIndex = (MonthList.length == 12) ? 0 : 1;
var adjustIndex2 = (MonthList.length == 12) ? 1 : 0;
//var adjustIndex = 0;
var DayPick = DayList.selectedIndex + adjustIndex;
//alert("NewDays: " + NewDays);
NewDays = NewDays + adjustIndex;
var dayListLength = DayList.length;
//alert("adjustIndex:" + adjustIndex + "\nNewDays: " + NewDays + "\nDayPick: " + DayPick + "\ndayListLength: " + dayListLength);
if (NewDays != dayListLength) {
var OldSize = dayListLength;
for (var k=Math.min(NewDays,OldSize);k= NewDays) ? DayList.options[NewDays] = null : DayList.options[k] = new Option(k+adjustIndex2, k+adjustIndex2);
}
var selectIndex = Math.min((DayPick - adjustIndex), NewDays - 1);
DayPick = Math.min(DayPick, NewDays) - adjustIndex;
//alert("Select " + selectIndex);
DayList.options[selectIndex].selected = true;
}
return DayPick;
}
// Resets the year to its previous valid value when something invalid is entered
function FixYearInput(YearField, Required) {
var YearRE = new RegExp('\\d{4}');
if (!YearRE.test(YearField.value)) YearField.value = YearField.defaultValue;
if(!Required && YearField.value.length == 0)
this.clearElementValues();
}
// 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.getShadow().style.display = 'none';
this.fixSelects(false);
}
else {
var StopTimer = false;
this.fixSelects(true);
this.getCalendar().style.zIndex = ++ZCounter;
this.getCalendar().style.visibility = 'visible';
if(!document.all) {
var objShadow = this.getShadow();
var objCalendar = this.getCalendar();
objShadow.style.display = 'block';
objShadow.style.top = objCalendar.offsetTop + 2;
objShadow.style.left = objCalendar.offsetLeft + 2;
objShadow.style.width = objCalendar.offsetWidth;
objShadow.style.height = objCalendar.offsetHeight;
}
}
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';
}
// Clear the values of the input elements when the "blank" month,day or year is selected
function ClearElementValues() {
this.getMonthList().selectedIndex = 0;
this.getDayList().selectedIndex = 0;
this.getYearField().value = '';
if(this.getHoursField())
this.getHoursField().value = '';
if(this.getMinutesField())
this.getMinutesField().value = '';
this.getYearField().defaultValue = '';
this.setPicked(Today.getFullYear(), Today.getMonth(), Today.getDate(), '00', '00');
this.setHidden('');
this.setMsHidden('0');
}
// Sets the date, based on the month selected
function CheckMonthChange(MonthList, Required) {
var DayList = this.getDayList();
if (MonthList.options[MonthList.selectedIndex].value == '') {
//DayList.selectedIndex = 0;
this.clearElementValues();
}
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
}
this.fillEmptyValues(Required);
FixDayList(DayList, MonthList, GetDayCount(this.picked.yearValue, MonthList.options[MonthList.selectedIndex].value));
var adjustIndex = !Required ? 0 : 1;
var selectedDay = DayList.selectedIndex + adjustIndex;
this.setPicked(this.picked.yearValue, MonthList.options[MonthList.selectedIndex].value, selectedDay, this.picked.hours, this.picked.minutes);
}
}
// Sets the date, based on the day selected
function CheckDayChange(DayList, Required) {
if (!Required && DayList.selectedIndex == 0) {
//var MonthList = this.getMonthList();
//MonthList.selectedIndex = 0;
this.clearElementValues();
} else {
if (this.isShowing()) this.show();
this.fillEmptyValues(Required);
var MonthList = this.getMonthList();
var adjustIndex = !Required ? 0 : 1;
var selectedMonth = MonthList.selectedIndex - (Required ? 0 : 1);
var selectedDay = DayList.selectedIndex + adjustIndex;
this.setPicked(this.picked.yearValue, selectedMonth, selectedDay, this.picked.hours, this.picked.minutes);
}
}
// Changes the date when a valid year has been entered
function CheckYearInput(YearField, Required) {
if ((YearField.value.length == 4 && !isNaN(YearField.value) && YearField.defaultValue != YearField.value) || (!Required && YearField.value.length == 0)) {
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
}
if(!Required && YearField.value.length == 0) {
//this.setPicked("", 0, 0, "00", "00");
//this.clearElementValues();
YearField.defaultValue = YearField.value;
} else {
var NewYear = GetGoodYear(YearField.value);
var MonthList = this.getMonthList();
var DayList = this.getDayList();
FixDayList(DayList, MonthList, GetDayCount(NewYear, this.picked.monthIndex));
this.fillEmptyValues(Required);
var adjustIndex = !Required ? 0 : 1;
var selectedMonth = MonthList.selectedIndex - (Required ? 0 : 1);
var selectedDay = DayList.selectedIndex + adjustIndex;
this.setPicked(NewYear, selectedMonth, selectedDay, this.picked.hours, this.picked.minutes);
YearField.defaultValue = YearField.value;
}
}
}
// Determines if a number is valid as hours
function GetGoodHours(HourDigits) {
if (HourDigits.length == 2) return YearDigits;
else {
var Millennium = (YearDigits < Y2kPivotPoint) ? 2000 : 1900;
return Millennium + parseInt(YearDigits,10);
}
}
// Changes the date when a valid hour has been entered
function CheckHoursInput(HoursField, Required) {
var minAllowedHours = 1;
var maxAllowedHours = 12;
if(isNaN(HoursField.value) || HoursField.value < minAllowedHours || HoursField.value > maxAllowedHours || (Required && HoursField.value == '')) {
HoursField.value = HoursField.oldValue;
}
if(!Required && HoursField.value.length == 0)
this.clearElementValues();
else {
this.fillEmptyValues(Required);
var NewDay = this.getDayList().selectedIndex + (Required ? 1 : 0);
if(!Required && this.picked.dayIndex == 0)
NewDay = 1;
this.setPicked(this.picked.yearValue, this.picked.monthIndex, NewDay, HoursField.value, this.picked.minutes);
}
HoursField.defaultValue = HoursField.value;
}
// Changes the date when am or pm has been selected
function CheckAmPmInput(Required) {
var NewDay = this.getDayList().selectedIndex + (Required ? 1 : 0);
if(!Required && this.picked.dayIndex == 0)
NewDay = 1;
this.setPicked(this.picked.yearValue, this.picked.monthIndex, NewDay, this.picked.hours, this.picked.minutes);
}
// Changes the date when a valid minute has been entered
function CheckMinutesInput(MinutesField, Required) {
if(isNaN(MinutesField.value) || MinutesField.value < 0 || MinutesField.value > 59 || (Required && MinutesField.value == '')) {
MinutesField.value = MinutesField.oldValue;
}
if(!Required && MinutesField.value.length == 0)
this.clearElementValues();
else {
this.fillEmptyValues(Required);
var NewDay = this.getDayList().selectedIndex + (Required ? 1 : 0);
if(!Required && this.picked.dayIndex == 0)
NewDay = 1;
this.setPicked(this.picked.yearValue, this.picked.monthIndex, NewDay, this.picked.hours, MinutesField.value);
}
MinutesField.defaultValue = MinutesField.value;
}
// Fill empty values when any value has been entered
function FillEmptyValues(Required) {
if(!Required) {
if(this.getYearField().value == '') {
this.getYearField().value = Today.getFullYear();
}
if(this.getMonthList().selectedIndex == 0) {
this.getMonthList().selectedIndex = 1;
this.picked.monthIndex = 0;
}
if(this.getDayList().selectedIndex == 0) {
this.getDayList().selectedIndex = 1;
this.picked.dayIndex = 0;
}
if(this.getHoursField() && this.getHoursField().value == '') {
this.getHoursField().value = '00';
this.getAmPmField().selectedIndex = 0;
this.getHoursField().defaultValue = '00';
this.picked.hours = 0;
}
if(this.getMinutesField() && this.getMinutesField().value == '') {
this.getMinutesField().value = '00';
this.getMinutesField().defaultValue = '00';
this.picked.minutes = 0;
}
}
}
// 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, DateHour, DateMinute, PM) {
(Function.call) ? dateObject.call(this, DateYear, DateMonth, DateDay, DateHour, DateMinute) : dateObject(this, DateYear, DateMonth, DateDay, DateHour, DateMinute);
this.hours = DateHour;
this.minutes = DateMinute;
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 ? 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;
var h = this.hours != "" ? this.hours : "00";
var m = this.minutes != "" ? this.minutes : "00";
if(PM) {
if(h < 12)
h = new Number(h) + 12;
else
h = new Number(h) - 12;
}
this.msFormatted = new Date(this.yearPad, this.monthPad-1, this.dayPad, h, m).getTime();
}
// 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(!document.all) {' + ParentObject.objName + '.getShadow().style.height = ' + ParentObject.objName + '.getCalendar().offsetHeight}');
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, PickedHour, PickedMinute) {
this.picked = new storedMonthObject(this.format, PickedYear, PickedMonth, PickedDay, PickedHour, PickedMinute, this.getAmPmSelection());
this.setHidden(this.picked.formatted);
this.setMsHidden(this.picked.msFormatted);
this.setDisplayed(PickedYear, PickedMonth);
}
// The calendar object
function calendarObject(DateName, DateFormat, DefaultDate, DefaultTime) {
/* Properties */
this.hiddenFieldName = DateName;
this.hiddenMsFieldName = DateName + '_MS';
this.monthListID = DateName + '_Month_ID';
this.dayListID = DateName + '_Day_ID';
this.yearFieldID = DateName + '_Year_ID';
this.hoursFieldID = DateName + '_Hours';
this.amPmFieldID = DateName + '_AmPm';
this.minutesFieldID = DateName + '_Minutes';
this.monthDisplayID = DateName + '_Current_ID';
this.calendarID = DateName + '_ID';
this.shadowID = DateName + '_Shadow_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.fillEmptyValues = FillEmptyValues;
this.setPicked = SetPickedMonth;
this.setDisplayed = SetDisplayedMonth;
this.checkYear = CheckYearInput;
this.checkHours = CheckHoursInput;
this.checkAmPm = CheckAmPmInput;
this.checkMinutes = CheckMinutesInput;
this.fixYear = FixYearInput;
this.changeMonth = CheckMonthChange;
this.changeDay = CheckDayChange;
this.resetTimer = CalTimerReset;
this.hideElements = SetElementStatus;
this.clearElementValues = ClearElementValues;
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');
this.setMsHidden = new Function('D','if (this.formNumber >= 0) this.getMsHiddenField().value=D');
// Returns a reference to these elements
this.getHiddenField = new Function('return document.forms[this.formNumber].elements[this.hiddenFieldName]');
this.getMsHiddenField = new Function('return document.forms[this.formNumber].elements[this.hiddenMsFieldName]');
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.getHoursField = new Function('return document.getElementById(this.hoursFieldID)');
this.getAmPmField = new Function('return document.getElementById(this.amPmFieldID)');
this.getAmPmSelection = new Function('if(document.getElementById(this.amPmFieldID)) return document.getElementById(this.amPmFieldID).selectedIndex == 1; else return false;');
this.getMinutesField = new Function('return document.getElementById(this.minutesFieldID)');
this.getCalendar = new Function('return document.getElementById(this.calendarID)');
this.getShadow = new Function('return document.getElementById(this.shadowID)');
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;MonPosERROR: Missing required parameter in call to \'DateInput\': [name of hidden date field].');
else {
// Aquire time values
if(!Required) {
InitialHours = '';
InitialMinutes = '';
} else if(!DisplayTimeField) {
InitialHours = '00';
InitialMinutes = '00';
}
if(arguments.length < 7 || !DisplayTimeField) {
if(!Required) {
InitialHours = '';
InitialMinutes = '';
} else if(!DisplayTimeField) {
InitialHours = '00';
InitialMinutes = '00';
} else {
InitialHours = Today.getHours();
InitialMinutes = Today.getMinutes();
}
} else if(DefaultTime.indexOf(":") != -1){
InitialHours = DefaultTime.substring(0, DefaultTime.indexOf(":"));
InitialMinutes = DefaultTime.substring(DefaultTime.indexOf(":")+1, DefaultTime.length);
} else {
InitialHours = '00';
InitialMinutes = '00';
}
var PM = false;
// Recalculate the hours if am_pm is used.
if(InitialHours != '') {
if(InitialHours > 12 ) {
InitialHours -= 12;
PM = true;
}
if(InitialHours == 0) {
InitialHours = "12";
PM = true;
}
}
if(InitialHours == '24')
InitialHours = '00'
// Handle DateFormat
if (arguments.length < 5) { // The format wasn't passed in, so use default
DateFormat = DefaultDateFormat;
if (arguments.length < 3) 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 == 6) { // DefaultDate was passed in with an invalid date format
var CurrentDate = new storedMonthObject(DateFormat, Today.getFullYear(), Today.getMonth(), Today.getDate(), InitialHours, InitialMinutes, PM);
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(), InitialHours, InitialMinutes, PM);
// Handle DefaultDate
if (arguments.length < 6) { // 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 + '\',\'' + InitialHours + ':' + InitialMinutes + '\')');
// Determine initial viewable state of day, year, and calendar icon
if ((Required) || (arguments.length >= 6)) {
var InitialStatus = '';
var InitialDate = eval(DateName + '_Object.picked.formatted');
var InitialMsDate = eval(DateName + '_Object.picked.msFormatted');
var InitYearValue = eval(DateName + '_Object.picked.yearPad');
}
else {
//var InitialStatus = ' style="visibility:hidden"';
var InitialStatus = '';
var InitialDate = '';
var InitialMsDate = '0';
eval(DateName + '_Object.setPicked(' + Today.getFullYear() + ',' + Today.getMonth() + ',' + Today.getDate() + ',' + Today.getHours() + ',' + Today.getMinutes() + ')');
var InitYearValue = '';
}
// Create the form elements
with (document) {
writeln('');
writeln('');
// Find this form number
for (var f=0;f