var DefaultDateFormat = 'MM/DD/YYYY';
var HideWait = 3;
var Y2kPivotPoint = 76;
var FontSize = 11;
var FontFamily = 'Tahoma';
var CellWidth = 18;
var CellHeight = 16;
var ImageURL = 'js/calendImg/calendar.jpg';
var NextURL = 'js/calendImg/calendar_next.gif';
var PrevURL = 'js/calendImg/calendar_prev.gif';
var NextYearURL = 'js/calendImg/calendar_nextYear.gif';
var PrevYearURL = 'js/calendImg/calendar_prevYear.gif';
var CalBGColor = 'white'; var TopRowBGColor = 'buttonface'; var DayBGColor = 'lightgrey'; var ZCounter = 100; var Today = new Date(); var WeekDays = new Array('日', '一', '二', '三', '四', '五', '六'); var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var MonthNames = new Array('1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'); if (document.charset == "big5") { var WeekDays = new Array('ら', '', '', '', '', 'き', 'せ'); var MonthNames = new Array('1る', '2る', '3る', '4る', '5る', '6る', '7る', '8る', '9る', '10る', '11る', '12る') } 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>') } function NumOnly(e) { var a = (e.keyCode) ? e.keyCode : e.which; return ((a == 8) || (a == 9) || (a == 37) || (a == 39) || (a == 46) || ((a > 47) && (a < 58))) } function GetTagPixels(a, b) { var c = (b == 'LEFT') ? a.offsetLeft : a.offsetTop; while ((a.tagName != 'BODY') && (a.tagName != 'HTML')) { a = a.offsetParent; c += (b == 'LEFT') ? a.offsetLeft : a.offsetTop } return c } function BehindCal(a, b, c, d, e, f) { var g = GetTagPixels(a, 'LEFT'); var h = g + a.offsetWidth; var i = f + a.offsetHeight; return (((f < e) && (i > d)) && ((g < c) && (h > b))) } function FixSelectLists(a) { if (navigator.appName == 'Microsoft Internet Explorer') { var b = this.getCalendar(); var c = b.offsetLeft; var d = c + b.offsetWidth; var e = b.offsetTop; var f = e + (CellHeight * 9); var g = 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)) { g = true; i += 3 } if (g) { if (document.forms[j].elements[i].type.substr(0, 6) == 'select') { ListTopY = GetTagPixels(document.forms[j].elements[i], 'TOP'); if (ListTopY < f) { if (BehindCal(document.forms[j].elements[i], c, d, e, f, ListTopY)) { document.forms[j].elements[i].style.visibility = (a) ? 'hidden' : 'visible' } } else break formLoop } } } } } } } function DayCellHover(a, b, c, d) { a.style.backgroundColor = (b) ? DayBGColor : c; if (b) { if ((this.yearValue == Today.getFullYear()) && (this.monthIndex == Today.getMonth()) && (d == Today.getDate())) { self.status = 'Click to select today' } else { var e = d.toString(); switch (e.substr(e.length - 1, 1)) { case '1': e += (d == 11) ? 'th' : 'st'; break; case '2': e += (d == 12) ? 'th' : 'nd'; break; case '3': e += (d == 13) ? 'th' : 'rd'; break; default: e += 'th'; break } self.status = 'Click to select ' + this.monthName + ' ' + e } } else self.status = ''; return true } function PickDisplayDay(a) { this.show(); this.setPicked(this.displayed.yearValue, this.displayed.monthIndex, a) } function BuildCalendarDays() { var a = 5; if (((this.displayed.dayCount == 31) && (this.displayed.firstDay > 4)) || ((this.displayed.dayCount == 30) && (this.displayed.firstDay == 6))) a = 6; else if ((this.displayed.dayCount == 28) && (this.displayed.firstDay == 0)) a = 4; var b = '<table width="' + (CellWidth * 7) + '" cellspacing="0" cellpadding="1" style="cursor:default">'; for (var j = 0; j < a; j++) { b += '<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;' } b += '<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 { b += '<td class="calendarDateInput" style="height:' + CellHeight + '">&nbsp;</td>' } } b += '</tr>' } return b += '</table>' } function GetGoodYear(a) { if (a.length == 4) { return a } else { var b = (a < Y2kPivotPoint) ? 2000 : 1900; return b + parseInt(a, 10) } } function GetDayCount(a, b) { return ((b == 1) && ((a % 400 == 0) || ((a % 4 == 0) && (a % 100 != 0)))) ? 29 : MonthDays[b] } function VirtualButton(a, b) { if (b) { a.style.borderLeft = 'buttonshadow 1px solid'; a.style.borderTop = 'buttonshadow 1px solid'; a.style.borderBottom = 'buttonhighlight 1px solid'; a.style.borderRight = 'buttonhighlight 1px solid' } else { a.style.borderLeft = 'buttonhighlight 1px solid'; a.style.borderTop = 'buttonhighlight 1px solid'; a.style.borderBottom = 'buttonshadow 1px solid'; a.style.borderRight = 'buttonshadow 1px solid' } } function NeighborHover(a, b, c) { if (b) { VirtualButton(a, false); self.status = 'Click to view ' + c.fullName } else { a.style.border = 'buttonface 1px solid'; self.status = '' } return true } function FixDayList(a, b) { var c = a.selectedIndex + 1; if (b != a.length) { var d = a.length; for (var k = Math.min(b, d); k < Math.max(b, d); k++) { (k >= b) ? a.options[b] = null : a.options[k] = new Option(k + 1, k + 1) } c = Math.min(c, b); a.options[c - 1].selected = true } return c } function FixYearInput(a) { var b = new RegExp('\\d{' + a.defaultValue.length + '}'); if (!b.test(a.value)) { a.value = a.defaultValue } } function CalIconHover(a) { var b = (this.isShowing()) ? 'hide' : 'show'; self.status = (a) ? 'Click to ' + b + ' the calendar' : ''; return true } function CalTimerReset() { eval('clearTimeout(' + this.timerID + ')'); eval(this.timerID + '=setTimeout(\'' + this.objName + '.show()\',' + (HideWait * 1000) + ')') } function DoTimer(a) { if (a) { eval('clearTimeout(' + this.timerID + ')') } else { eval(this.timerID + '=null'); this.resetTimer() } } function ShowCalendar() { if (this.isShowing()) { var a = true; this.getCalendar().style.zIndex = --ZCounter; this.getCalendar().style.visibility = 'hidden'; this.fixSelects(false) } else { var a = false; this.fixSelects(true); this.getCalendar().style.zIndex = ++ZCounter; this.getCalendar().style.visibility = 'visible' } this.handleTimer(a); self.status = '' } function dateObject() { this.date = (arguments.length == 1) ? new Date(arguments[0]) : new Date(arguments[0], arguments[1], arguments[2]); this.yearValue = this.date.getFullYear(); this.monthIndex = this.date.getMonth(); this.monthName = MonthNames[this.monthIndex]; this.fullName = this.yearValue + ' ' + this.monthName; this.day = this.date.getDate(); this.dayCount = GetDayCount(this.yearValue, this.monthIndex); var a = new Date(this.yearValue, this.monthIndex, 1); this.firstDay = a.getDay() } function storedMonthObject(a, b, c, d) { dateObject.call(this, b, c, d); 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(); if (a != 'YYYYMMDD') { a.match(/(Y{2,4})$/); if (RegExp.$1.length == 2) this.yearPad = this.yearPad.substr(2) } if (/YYYYMMDD/.test(a)) { this.formatted = this.yearPad + this.monthPad + this.dayPad } else if (/YYYY-MM-DD/.test(a)) { this.formatted = this.yearPad + "-" + this.monthPad + "-" + this.dayPad } else { if (/MM?\/DD?\/Y{2,4}/.test(a)) { var e = this.monthPad + '/' + this.dayPad + '/' } else if (/DD?\/MM?\/Y{2,4}/.test(a)) { var e = this.dayPad + '/' + this.monthPad + '/' } else if (/DD?-((MON)|(MMM))-Y{2,4}/.test(a)) { var e = this.dayPad + '-' + this.monthShort + '-' } else if (/((MON)|(MMM))-DD?-Y{2,4}/.test(a)) { var e = this.monthShort + '-' + this.dayPad + '-' } this.formatted = e + this.yearPad } } function displayMonthObject(a, b, c, d) { dateObject.call(this, b, c, d); this.displayID = a.hiddenFieldName + '_Current_ID'; this.getDisplay = new Function('return document.getElementById(this.displayID)'); this.dayHover = DayCellHover; this.goCurrent = new Function(a.objName + '.getCalendar().style.zIndex=++ZCounter;' + a.objName + '.setDisplayed(Today.getFullYear(),Today.getMonth());'); if (a.formNumber >= 0) { this.getDisplay().innerHTML = this.fullName } } function neighborMonthObject(a, b, c) { dateObject.call(this, c); this.buttonID = a.hiddenFieldName + '_' + b + '_ID'; this.hover = new Function('C', 'O', 'NeighborHover(C,O,this)'); this.getButton = new Function('return document.getElementById(this.buttonID)'); this.go = new Function(a.objName + '.getCalendar().style.zIndex=++ZCounter;' + a.objName + '.setDisplayed(this.yearValue,this.monthIndex);'); if (a.formNumber >= 0) { this.getButton().title = this.monthName } } function neighborYearObject(a, b, c, d) { dateObject.call(this, c, d, 1); this.buttonID = a.hiddenFieldName + '_' + b + '_ID'; this.hover = new Function('C', 'O', 'NeighborHover(C,O,this)'); this.getButton = new Function('return document.getElementById(this.buttonID)'); this.go = new Function(a.objName + '.getCalendar().style.zIndex=++ZCounter;' + a.objName + '.setDisplayed(this.yearValue,this.monthIndex);'); if (a.formNumber >= 0) { this.getButton().title = this.yearValue } } function SetDisplayedMonth(a, b) { this.displayed = new displayMonthObject(this, a, b, 1); 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))); this.previousYear = new neighborYearObject(this, 'PreviousYear', parseInt(a, 10) - 1, b); this.nextYear = new neighborYearObject(this, 'NextYear', parseInt(a, 10) + 1, b); if (this.formNumber >= 0) { this.getDayTable().innerHTML = this.buildCalendar() } } function SetPickedMonth(a, b, c) { this.picked = new storedMonthObject(this.format, a, b, c); this.setHidden(this.picked.formatted); this.setDisplayed(a, b) } function calendarObject(c, d, e) { this.hiddenFieldName = c; this.monthDisplayID = c + '_Current_ID'; this.calendarID = c + '_ID'; this.dayTableID = c + '_DayTable_ID'; this.calendarLinkID = this.calendarID + '_Link'; this.timerID = this.calendarID + '_Timer'; this.objName = c + '_Object'; this.format = d; this.formNumber = -1; this.picked = null; this.displayed = null; this.previous = null; this.next = null; this.setPicked = SetPickedMonth; this.setDisplayed = SetDisplayedMonth; this.fixYear = FixYearInput; this.resetTimer = CalTimerReset; 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.getHiddenField = new Function('return document.forms[this.formNumber].elements[this.hiddenFieldName]'); 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\')'); function getMonthIndex(a) { for (var b = 0; b < MonthNames.length; b++) { if (MonthNames[b].substr(0, 3).toUpperCase() == a.toUpperCase()) { break } } return b } function SetGoodDate(a, b) { a.setPicked(Today.getFullYear(), Today.getMonth(), Today.getDate()); if (b) { alert('WARNING: The supplied date is not in valid \'' + d + '\' format: ' + e + '.\nTherefore, the current system date will be used instead: ' + a.picked.formatted) } } if (e == 'undefined') { SetGoodDate(this, false) } else { if (this.format == 'YYYYMMDD') { (/^\d{8}$/.test(e)) ? this.setPicked(e.substr(0, 4), parseInt(e.substr(4, 2), 10) - 1, e.substr(6, 2)) : SetGoodDate(this, true) } else if (this.format == "YYYY-MM-DD") { if (/^\d{4}-\d{1,2}-\d{1,2}$/.test(e)) { var f = e.split('-'); this.setPicked(f[0], parseInt(f[1], 10) - 1, f[2]) } else { SetGoodDate(this, true) } } else { if (/\//.test(this.format)) { if (/^(\d{1,2})\/(\d{1,2})\/(\d{2,4})$/.test(e)) { if (this.format.substr(0, 1) == 'M') { var g = RegExp.$1; var h = RegExp.$2 } else { var g = RegExp.$2; var h = RegExp.$1 } this.setPicked(GetGoodYear(RegExp.$3), parseInt(g, 10) - 1, h) } else SetGoodDate(this, true) } else if (/-/.test(this.format)) { if (/MON/.test(this.format)) { var i = ''; for (var j = 0; j < MonthNames.length; j++) { if (j > 0) { i += '|' } i += MonthNames[j].substr(0, 3).toUpperCase() } if (this.format.substr(0, 1) == 'D') { var k = new RegExp('^(\\d{1,2})-(' + i + ')-(\\d{2,4})$', 'i'); (k.test(e)) ? this.setPicked(GetGoodYear(RegExp.$3), getMonthIndex(RegExp.$2), RegExp.$1) : SetGoodDate(this, true) } else { var k = new RegExp('^(' + i + ')-(\\d{1,2})-(\\d{2,4})$', 'i'); (k.test(e)) ? this.setPicked(GetGoodYear(RegExp.$3), getMonthIndex(RegExp.$1), RegExp.$2) : SetGoodDate(this, true) } } else { if (/^(\d{2,4})-(\d{1,2})-(\d{1,2})$/.test(e)) { var g = RegExp.$2; var h = RegExp.$3; var l = RegExp.$1; this.setPicked(GetGoodYear(l), parseInt(g, 10) - 1, h) } else { SetGoodDate(this, true) } } } } } } function DateInput(a, b, c) { if (a == undefined) { 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 { if (b == undefined) { b = DefaultDateFormat } else if ((/^YYYYMMDD$/i.test(b)) || (/^YYYY-MM-DD$/i.test(b)) || (/^((MM?)|(DD?))\/((MM?)|(DD?))\/Y{2,4}$/i.test(b)) || (/^((DD?)|((MON)|(MMM)))-((DD?)|((MON)|(MMM)))-Y{2,4}$/i.test(b))) { b = b.toUpperCase() } else { b = DefaultDateFormat; var d = 'WARNING: The supplied date format for the \'' + a + '\' field is not valid: ' + b + '\nTherefore, the default date format will be used instead: ' + DefaultDateFormat; var g = new storedMonthObject(DefaultDateFormat, Today.getFullYear(), Today.getMonth(), Today.getDate()); if (c != undefined) { d += '\n\nThe supplied date cannot be interpreted with the invalid format.\nTherefore, the current system date will be used instead: ' + g.formatted } c = g.formatted; alert(d) } eval(a + '_Object=new calendarObject(\'' + a + '\',\'' + b + '\',\'' + c + '\')'); if (c == undefined) { var h = ' style="visibility:hidden"'; var i = '' } else { var h = ''; var i = eval(a + '_Object.picked.formatted') } with (document) { 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 == 'text') && (forms[f].elements[e].name == a)) { forms[f].elements[e].value = i; forms[f].elements[e].readOnly = true; eval(a + '_Object.formNumber=' + f); break } } } } write(String.fromCharCode(13) + '<a' + h + ' id="' + a + '_ID_Link" href="javascript:' + a + '_Object.show()" onMouseOver="return ' + a + '_Object.iconHover(true)" onMouseOut="return ' + a + '_Object.iconHover(false)"><img src="' + ImageURL + '" align="baseline" title="Calendar" width="16" height="15" border="0"></a>&nbsp;'); writeln('<span id="' + a + '_ID" style="position:absolute;visibility:hidden;width:' + (CellWidth * 7) + 'px;background-color:' + CalBGColor + ';border:1px solid dimgray;" onMouseOver="' + a + '_Object.handleTimer(true)" onMouseOut="' + a + '_Object.handleTimer(false)">'); writeln('<table width="' + (CellWidth * 7) + '" cellspacing="0" cellpadding="1">' + String.fromCharCode(13) + '<tr style="background-color:' + TopRowBGColor + ';">'); writeln('<td id="' + a + '_PreviousYear_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + a + '_Object.previousYear.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + a + '_Object.previousYear.hover(this,true)" onMouseOut="return ' + a + '_Object.previousYear.hover(this,false)" title="' + eval(a + '_Object.previousYear.yearValue') + '"><img src="' + PrevYearURL + '" width="9" height="9"></td>'); writeln('<td id="' + a + '_Previous_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + a + '_Object.previous.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + a + '_Object.previous.hover(this,true)" onMouseOut="return ' + a + '_Object.previous.hover(this,false)" title="' + eval(a + '_Object.previous.monthName') + '"><img src="' + PrevURL + '" width="5" height="9"></td>'); writeln('<td id="' + a + '_Current_ID" style="cursor:pointer" align="center" class="calendarDateInput" style="height:' + CellHeight + '" colspan="3" onClick="' + a + '_Object.displayed.goCurrent()" onMouseOver="self.status=\'Click to view ' + eval(a + '_Object.displayed.fullName') + '\';return true;" onMouseOut="self.status=\'\';return true;" title="Show Current Month">' + eval(a + '_Object.displayed.fullName') + '</td>'); writeln('<td id="' + a + '_Next_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + a + '_Object.next.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + a + '_Object.next.hover(this,true)" onMouseOut="return ' + a + '_Object.next.hover(this,false)" title="' + eval(a + '_Object.next.monthName') + '"><img src="' + NextURL + '" width="5" height="9"></td>'); writeln('<td id="' + a + '_NextYear_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + a + '_Object.nextYear.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + a + '_Object.nextYear.hover(this,true)" onMouseOut="return ' + a + '_Object.nextYear.hover(this,false)" title="' + eval(a + '_Object.next.yearValue') + '"><img src="' + NextYearURL + '" width="9" height="9"></td></tr>' + String.fromCharCode(13) + '<tr>'); for (var w = 0; w < 7; w++) { writeln('<td width="18" 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="' + a + '_DayTable_ID">' + eval(a + '_Object.buildCalendar()') + '</span>' + String.fromCharCode(13) + '</span>') } } }