var eWorld_CalendarPopup_CurrentCalendar; function CalendarPopup_Calendar(id, textBoxId, labelId, buttonId, imageId, hiddenId, calendarDivId, monthYearDivId, format, monthNames, dayNames, firstDayOfWeek, sundayNumber, saturdayNumber, displayCalendarYearSelection, lowerBoundDate, upperBoundDate, quadrant, padDigits, offsetX, offsetY, showClearDate, clearDateText, nullableText, showGoToToday, goToTodayText, arrowUrl, nextMonthImageUrl, previousMonthImageUrl, nextYearImageUrl, previousYearImageUrl, calendarWidth, visibleDate, monthYearApplyText, monthYearCancelText, javascriptFunction, autoPostBack, allowArbitraryText, monthYearDisabled, nullable) { if (visibleDate == '') { visibleDate = new Date(); } this.Id = id; this.TextBoxId = textBoxId; this.LabelId = labelId; this.ButtonId = buttonId; this.ImageId = imageId; this.HiddenId = hiddenId; this.CalendarDivId = calendarDivId; this.MonthYearDivId = monthYearDivId; this.Format = format; this.MonthNames = monthNames; this.DayNames = dayNames; this.FirstDayOfWeek = firstDayOfWeek; this.SundayNumber = sundayNumber; this.SaturdayNumber = saturdayNumber; this.DisplayCalendarYearSelection = displayCalendarYearSelection; this.LowerBoundDate = new Date(lowerBoundDate); this.UpperBoundDate = new Date(upperBoundDate); this.Quadrant = quadrant; this.PadDigits = padDigits; this.OffsetX = offsetX; this.OffsetY = offsetY; this.ShowClearDate = showClearDate; this.ClearDateText = clearDateText; this.NullableText = nullableText; this.ShowGoToToday = showGoToToday; this.GoToTodayText = goToTodayText; this.MonthYearArrowUrl = arrowUrl; this.NextMonthImageUrl = nextMonthImageUrl; this.PreviousMonthImageUrl = previousMonthImageUrl; this.NextYearImageUrl = nextYearImageUrl; this.PreviousYearImageUrl = previousYearImageUrl; this.CalendarWidth = calendarWidth; this.VisibleDate = new Date(visibleDate); this.MonthYearApplyText = monthYearApplyText; this.MonthYearCancelText = monthYearCancelText; this.JavascriptFunction = javascriptFunction; this.AutoPostBack = autoPostBack; this.AllowArbitraryText = allowArbitraryText; this.MonthYearDisabled = monthYearDisabled; this.Nullable = nullable; this.ActiveMonth = 1; this.ActiveYear = 1; this.SetActiveMonth = function(value) { this.ActiveMonth = value; this.DisplayMonthYear(this.ActiveMonth + '/1/' + this.ActiveYear); } this.SetActiveYear = function(value) { this.ActiveYear = value; this.DisplayMonthYear(this.ActiveMonth + '/1/' + this.ActiveYear); } this.GetStyle = function() { return eWorld_FindItem(eWorld_CalendarPopup_Styles, this.Id); } this.Setup = function() { var div = document.getElementById(this.CalendarDivId); CalendarPopup_MouseOut(); eWorld_AddEvent(div, 'mouseout', CalendarPopup_MouseOut); eWorld_AddEvent(div, 'mouseover', CalendarPopup_MouseOver); } this.Show = function() { eWorld_CalendarPopup_CurrentCalendar = this; var div = document.getElementById(this.CalendarDivId); var divIframe = document.getElementById(this.CalendarDivId + '_iframe'); var tb = document.getElementById(this.TextBoxId); var img = document.getElementById(this.ImageId); var btn = document.getElementById(this.ButtonId); if (div.style.visibility != 'hidden') { this.Hide(); } else { this.DisplayCalendar(this.VisibleDate); this.Setup(); var obj = tb; if (obj == null) obj = img; if (obj == null) obj = btn; var result = eWorld_FindPosition(obj); var x = result.x; var y = result.y; switch (this.Quadrant) { case 1: y += (obj.offsetHeight + 1); break; case 2: x -= (div.offsetWidth - 2); break; case 3: x += (obj.offsetWidth + 1); break; case 4: y -= (div.offsetHeight - 1); } div.style.top = y + this.OffsetY + 'px'; div.style.left = x + this.OffsetX + 'px'; div.style.visibility = 'visible'; if (divIframe != null) { divIframe.width = (document.all) ? div.offsetWidth : div.offsetWidth - 4; divIframe.height = (document.all) ? div.offsetHeight : div.offsetHeight - 4; divIframe.style.top = div.style.top; divIframe.style.left = div.style.left; divIframe.style.visibility = 'visible'; } } } this.GetDate = function() { var date = new Date(); var tb = document.getElementById(this.TextBoxId); var hid = document.getElementById(this.HiddenId); var value = ''; if (tb != null) { value = tb.value; } else { value = hid.value; } if (value != '') { var dateArray = value.replace(/[\.-]/g, '/').split('/'); var format = [[2,1,0],[0,1,2],[1,0,2],[1,2,0]][this.Format % 4]; if (dateArray.length == 3) { date = new Date(eWorld_ReplaceFormat('{0}/{1}/{2}', new Array(dateArray[format[0]], dateArray[format[1]], dateArray[format[2]]))); if (isNaN(date)) date = new Date(); } } return date; } this.FormatDate = function(input) { var date = new Date(input); var month = date.getMonth() + 1; var day = date.getDate(); var year = date.getFullYear(); if (this.PadDigits) { if (month < 10) month = '0' + month; if (day < 10) day = '0' + day; } var separator = '/'; var output = ''; if (this.Format >= 5 && this.Format <= 8) separator = '.'; else if (this.Format >= 9 && this.Format <= 12) separator = '-'; if (this.Format == 1 || this.Format == 5 || this.Format == 9) output = eWorld_ReplaceFormat('{1}{0}{2}{0}{3}', new Array(separator, month, day, year)); else if (this.Format == 2 || this.Format == 6 || this.Format == 10) output = eWorld_ReplaceFormat('{1}{0}{2}{0}{3}', new Array(separator, day, month, year)); else if (this.Format == 3 || this.Format == 7 || this.Format == 11) output = eWorld_ReplaceFormat('{1}{0}{2}{0}{3}', new Array(separator, year, month, day)); else output = eWorld_ReplaceFormat('{1}{0}{2}{0}{3}', new Array(separator, year, day, month)); return output; } this.IsSameDate = function(date1, date2) { var inputDate1 = new Date(date1); var inputDate2 = new Date(date2); return (inputDate1.getMonth() == inputDate2.getMonth() && inputDate1.getDate() == inputDate2.getDate() && inputDate1.getFullYear() == inputDate2.getFullYear()); } this.IsSpecialDay = function(date) { if (typeof eWorld_CalendarPopup_SpecialDays == "undefined" || eWorld_CalendarPopup_SpecialDays == null) return false; for (var i=0; i monthDays[prevMonth - 1]) { prevDay = monthDays[prevMonth - 1]; } var nextMonth = inputMonth + 2; var nextDay = inputDate; var nextYear = inputYear; if (nextMonth > 12) { nextMonth = 1; nextYear++; } if (inputDate > monthDays[nextMonth - 1]) { nextDay = monthDays[nextMonth - 1]; } var startSpaces = inputDate; while (startSpaces > 7) startSpaces -= 7; startSpaces = inputDay - startSpaces + 1; startSpaces = startSpaces - this.FirstDayOfWeek; if (startSpaces < 0) startSpaces += 7; // table output = ' 0) output += eWorld_ReplaceFormat(' width=\"{0}px\"', new Array(this.CalendarWidth)); output += ' style=\"border:black 1px solid;\" border=0 cellspacing=0 cellpadding=2>'; // previous month / year if (!this.DisplayCalendarYearSelection) { if (this.PreviousMonthImageUrl == '') output += eWorld_ReplaceFormat('<', new Array(style.MonthHeader, this.Id, prevMonth, prevDay, prevYear)); else output += eWorld_ReplaceFormat('', new Array(style.MonthHeader, this.Id, prevMonth, prevDay, prevYear, this.PreviousMonthImageUrl)); } else { if (this.PreviousMonthImageUrl == '') output += eWorld_ReplaceFormat('<', new Array(style.MonthHeader, this.Id, prevMonth, prevDay, prevYear)); else output += eWorld_ReplaceFormat('', new Array(style.MonthHeader, this.Id, prevMonth, prevDay, prevYear, this.PreviousMonthImageUrl)); if (this.PreviousYearImageUrl == '') output += eWorld_ReplaceFormat('  <<', new Array(this.Id, inputMonth + 1, inputDate, inputYear - 1)); else output += eWorld_ReplaceFormat('  ', new Array(this.Id, inputMonth + 1, inputDate, inputYear - 1, this.PreviousYearImageUrl)); } // month cell if (!this.MonthYearDisabled) { output += eWorld_ReplaceFormat('{4} {5}', new Array(style.MonthHeader, this.Id, inputMonth + 1, inputYear, this.MonthNames[inputMonth], inputYear)); if (this.MonthYearArrowUrl != '') output += eWorld_ReplaceFormat(' ', new Array(this.MonthYearArrowUrl)); } else { output += eWorld_ReplaceFormat('{1} {2}', new Array(style.MonthHeader.replace(/cursor:pointer;/, ''), this.MonthNames[inputMonth], inputYear)); } output = output + ''; // next month / year if (!this.DisplayCalendarYearSelection) { if (this.NextMonthImageUrl == '') output += eWorld_ReplaceFormat('>', new Array(style.MonthHeader, this.Id, nextMonth, nextDay, nextYear)); else output += eWorld_ReplaceFormat('', new Array(style.MonthHeader, this.Id, nextMonth, nextDay, nextYear, this.NextMonthImageUrl)); } else { if (this.NextYearImageUrl == '') output += eWorld_ReplaceFormat('>>', new Array(style.MonthHeader, this.Id, inputMonth + 1, inputDate, inputYear + 1)); else output += eWorld_ReplaceFormat('', new Array(style.MonthHeader, this.Id, inputMonth + 1, inputDate, inputYear + 1, this.NextYearImageUrl)); if (this.NextMonthImageUrl == '') output += eWorld_ReplaceFormat('  >', new Array(this.Id, nextMonth, nextDay, nextYear)); else output += eWorld_ReplaceFormat('  ', new Array(this.Id, nextMonth, nextDay, nextYear, this.NextMonthImageUrl)); } // day headers output += eWorld_ReplaceFormat('{1}', new Array(style.DayHeader, this.DayNames[0])); output += eWorld_ReplaceFormat('{1}', new Array(style.DayHeader, this.DayNames[1])); output += eWorld_ReplaceFormat('{1}', new Array(style.DayHeader, this.DayNames[2])); output += eWorld_ReplaceFormat('{1}', new Array(style.DayHeader, this.DayNames[3])); output += eWorld_ReplaceFormat('{1}', new Array(style.DayHeader, this.DayNames[4])); output += eWorld_ReplaceFormat('{1}', new Array(style.DayHeader, this.DayNames[5])); output += eWorld_ReplaceFormat('{1}', new Array(style.DayHeader, this.DayNames[6])); // blank starting spaces for (var space=0; space'; if ((lowerAmount > 0 && upperAmount < 0) || (upperAmount > 0 && lowerAmount < 0)) output += eWorld_ReplaceFormat('{1}', new Array(style.DisabledDay.replace(/cursor:pointer;/, ''), spaceDay)); else output += eWorld_ReplaceFormat('{3}', new Array(style.OffMonth, this.Id, spaceMonth, spaceDay, spaceYear)); } // calendar days var count = 1; while (count <= monthDays[inputMonth]) { for (var weekday=startSpaces;weekday<7;weekday++) { var calendarDate = new Date(eWorld_ReplaceFormat('{0}/{1}/{2}', new Array(inputMonth + 1, count, inputYear))); var sameDate = (hid.value.length == 0) ? false : this.IsSameDate(currentDate, calendarDate); var isToday = this.IsSameDate(new Date(), calendarDate); var isSpecialDay = this.IsSpecialDay(calendarDate); var lowerAmount = (this.LowerBoundDate - calendarDate); var upperAmount = (calendarDate - this.UpperBoundDate); var disabled = ((lowerAmount > 0 && upperAmount < 0) || (lowerAmount < 0 && upperAmount > 0) || (this.IsSpecialDayDisabled(calendarDate))); var isWeekend = ((weekday == this.SundayNumber) || (weekday == this.SaturdayNumber)); if (weekday == 0) output = output + ''; if (count <= monthDays[inputMonth]) { // current month if (sameDate) { if (disabled) output += eWorld_ReplaceFormat('{1}', new Array(style.DisabledDay.replace(/cursor:pointer;/, 'cursor:default;'), count)); else { output += eWorld_ReplaceFormat('{3}', new Array(style.SelectedDate, this.Id, inputMonth + 1, count, inputYear)); } } else if (isToday) { if (disabled) output += eWorld_ReplaceFormat('{1}', new Array(style.DisabledDay.replace(/cursor:pointer;/, 'cursor:default;'), count)); else output += eWorld_ReplaceFormat('{3}', new Array(style.TodayDay, this.Id, inputMonth + 1, count, inputYear)); } else if (isSpecialDay) { if (disabled) output += eWorld_ReplaceFormat('{1}', new Array(style.DisabledDay.replace(/cursor:pointer;/, 'cursor:default;'), count)); else output += eWorld_ReplaceFormat('{3}', new Array(style.SpecialDay, this.Id, inputMonth + 1, count, inputYear)); } else if (isWeekend) { if (disabled) output += eWorld_ReplaceFormat('{1}', new Array(style.DisabledDay.replace(/cursor:pointer;/, 'cursor:default;'), count)); else output += eWorld_ReplaceFormat('{3}', new Array(style.Weekend, this.Id, inputMonth + 1, count, inputYear)); } else { if (disabled) output += eWorld_ReplaceFormat('{1}', new Array(style.DisabledDay.replace(/cursor:pointer;/, 'cursor:default;'), count)); else output += eWorld_ReplaceFormat('{3}', new Array(style.Weekday, this.Id, inputMonth + 1, count, inputYear)); } } else { // next month var month, day, year; if (inputMonth == 11) { month = 1; year = inputYear + 1; } else { month = inputMonth + 2; year = inputYear; } day = count - monthDays[inputMonth]; calendarDate = new Date(eWorld_ReplaceFormat('{0}/{1}/{2}', new Array(month, day, year))); lowerAmount = (this.LowerBoundDate - calendarDate); upperAmount = (calendarDate - this.UpperBoundDate); if (disabled) output += eWorld_ReplaceFormat('{1}', new Array(style.DisabledDay.replace(/cursor:pointer;/, 'cursor:default;'), day)); else output += eWorld_ReplaceFormat('{3}', new Array(style.OffMonth, this.Id, month, day, year)); } count++; } output = output + ''; startSpaces = 0; } // go to today if (this.ShowGoToToday) { output += eWorld_ReplaceFormat('{5} {6}', new Array(style.GoToToday, this.Id, todayDate.getMonth() + 1, todayDate.getDate(), todayDate.getFullYear(), this.GoToTodayText, this.FormatDate(todayDate))); } // clear date if (this.ShowClearDate && this.Nullable) { output += eWorld_ReplaceFormat('{2}', new Array(style.ClearDate, this.Id, this.ClearDateText)); } output = output + ''; var div = document.getElementById(this.CalendarDivId); var divIframe = document.getElementById(this.CalendarDivId + '_iframe'); div.innerHTML = output; if (divIframe != null) { divIframe.width = (document.all) ? div.offsetWidth : div.offsetWidth - 4; divIframe.height = (document.all) ? div.offsetHeight : div.offsetHeight - 4; divIframe.style.top = div.style.top; divIframe.style.left = div.style.left; } } this.SelectDate = function(input) { var date = new Date(input); var formattedDate = this.FormatDate(date); if (document.getElementById(this.TextBoxId) != null) { document.getElementById(this.TextBoxId).value = formattedDate; } document.getElementById(this.HiddenId).value = formattedDate; if (document.getElementById(this.LabelId) != null) { document.getElementById(this.LabelId).innerHTML = formattedDate; } this.VisibleDate = date; this.RaiseClientFunctions(); this.Hide(); this.Validate(); } this.Hide = function() { var div = document.getElementById(this.CalendarDivId); var iframe = document.getElementById(this.CalendarDivId + '_iframe'); div.style.visibility = 'hidden'; if (iframe != null) { iframe.style.visibility = 'hidden'; } eWorld_CalendarPopup_CurrentCalendar = null; this.RemoveEvents(); } this.RemoveEvents = function() { var div = document.getElementById(this.CalendarDivId); CalendarPopup_MouseOver(); eWorld_RemoveEvent(div, 'mouseout', CalendarPopup_MouseOut); eWorld_RemoveEvent(div, 'mouseover', CalendarPopup_MouseOver); } this.RaiseClientFunctions = function() { if (this.JavascriptFunction.length > 0) { var value = ''; var tb = document.getElementById(this.TextBoxId); var hid = document.getElementById(this.HiddenId); var value = ''; if (tb != null) { value = tb.value; } else { value = hid.value; } eval(eWorld_ReplaceFormat('{0}("{1}", {2}, "{3}")', new Array(this.JavascriptFunction, value, (value.length == 0), this.Id))); } if (this.AutoPostBack) { __doPostBack(this.Id, ''); } } this.DisplayMonthYear = function(input) { var date = new Date(input); var style = this.GetStyle(); this.ActiveMonth = date.getMonth() + 1; this.ActiveYear = date.getFullYear(); output = eWorld_ReplaceFormat('', new Array(style.MonthYearItem)); output = output + ''; output += eWorld_ReplaceFormat('
'; for (var i=0; i<12; i++) { if (i % 2 == 0) output = output + ''; if (i == date.getMonth()) output += eWorld_ReplaceFormat('', new Array(style.MonthYearSelectedItem, this.Id, i + 1, this.MonthNames[i])); else output += eWorld_ReplaceFormat('', new Array(style.MonthYearItem, this.Id, i + 1, this.MonthNames[i])); if (i % 2 != 0) output = output + ''; } output = output + '
{3}{3}
'; for (var i=(date.getFullYear() - 2); i<(date.getFullYear() + 3); i++) { if (i == date.getFullYear()) output += eWorld_ReplaceFormat('', new Array(style.MonthYearSelectedItem, this.Id, i)); else output += eWorld_ReplaceFormat('', new Array(style.MonthYearItem, this.Id, i)); } output += eWorld_ReplaceFormat('', new Array(style.MonthYearItem, this.Id, date.getFullYear() + 10)); output += '
  {2}  
  {2}  
<<', new Array(style.MonthYearItem, this.Id, date.getFullYear() - 10)); output += eWorld_ReplaceFormat('>>
  {4}    ', new Array(style.MonthYearButton, this.Id, this.ActiveMonth, this.ActiveYear, this.MonthYearApplyText)); output += eWorld_ReplaceFormat('  {2}    
', new Array(style.MonthYearButton, this.Id, this.MonthYearCancelText)); this.RemoveEvents(); var div = document.getElementById(this.MonthYearDivId); var divIframe = document.getElementById(this.MonthYearDivId + '_iframe'); var cal = document.getElementById(this.CalendarDivId); div.innerHTML = output; div.style.left = cal.style.left; div.style.top = cal.style.top; div.style.visibility = 'visible'; if (divIframe != null) { divIframe.width = (document.all) ? div.offsetWidth : div.offsetWidth - 4; divIframe.height = (document.all) ? div.offsetHeight : div.offsetHeight - 4; divIframe.style.top = div.style.top; divIframe.style.left = div.style.left; divIframe.style.visibility = 'visible'; } } this.HideMonthYear = function() { var div = document.getElementById(this.MonthYearDivId); var divIframe = document.getElementById(this.MonthYearDivId + '_iframe'); var calDiv = document.getElementById(this.CalendarDivId); var calDivIframe = document.getElementById(this.CalendarDivId + '_iframe'); div.style.visibility = 'hidden'; if (divIframe != null) { divIframe.style.visibility = 'hidden'; } calDiv.style.visibility = 'visible'; if (calDivIframe != null) { calDivIframe.style.visibility = 'visible'; } eWorld_CalendarPopup_CurrentCalendar = this; this.Setup(); } this.TextChanged = function() { var hid = document.getElementById(this.HiddenId); var tb = document.getElementById(this.TextBoxId); var date = this.GetDate(); if (!this.AllowArbitraryText) { if (tb.value == '' && this.Nullable) { this.Clear(); return; } else { tb.value = this.FormatDate(date); } } this.VisibleDate = date; hid.value = tb.value; this.RaiseClientFunctions(); this.Hide(); this.Validate(); } } function CalendarPopup_Style(id, weekday, weekend, offMonth, selectedDate, monthHeader, dayHeader, clearDate, goToToday, todayDay, specialDay, monthYearItem, monthYearSelectedItem, monthYearButton, disabledDay) { this.Id = id; this.Weekday = weekday; this.Weekend = weekend; this.OffMonth = offMonth; this.SelectedDate = selectedDate; this.MonthHeader = monthHeader; this.DayHeader = dayHeader; this.ClearDate = clearDate; this.GoToToday = goToToday; this.TodayDay = todayDay; this.SpecialDay = specialDay; this.MonthYearItem = monthYearItem; this.MonthYearSelectedItem = monthYearSelectedItem; this.MonthYearButton = monthYearButton; this.DisabledDay = disabledDay; } function CalendarPopup_SpecialDay(id, month, day, year, span, disabled) { this.Id = id; this.Month = month; this.Day = day; this.Year = year; this.Span = span; this.Disabled = disabled; } function CalendarPopup_FindCalendar(id) { return eWorld_FindItem(eWorld_CalendarPopup_Calendars, id); } function CalendarPopup_LostFocus() { if (eWorld_CalendarPopup_CurrentCalendar != null) { eWorld_CalendarPopup_CurrentCalendar.Hide(); } } function CalendarPopup_MouseOut() { eWorld_AddEvent(document, 'mousedown', CalendarPopup_LostFocus); } function CalendarPopup_MouseOver() { eWorld_RemoveEvent(document, 'mousedown', CalendarPopup_LostFocus); }