//---------------------------------------------------------------------- // PopUp Calendar // (c) 2003 i-TV-T AG, all rights reserved //---------------------------------------------------------------------- function Calendar(form, field, format) { this.name = "cal__" + form + "__" + field; Calendar.calendars[this.name] = this; this.form = form; this.field = field; this.format = format; this.timefmt = arguments.length == 4 ? arguments[3] : ""; this.input = document[form][field]; this.calendar = this.getElement('calendar'); this.calendarMonths = this.getElement('calendar-months'); var date = this.parseDate(this.input.value); this.createPage(date.getFullYear(), date.getMonth()+1, date.getDate()); this.dateIn = date; this.moveElement(this.calendar, this.getLeft(this.input), this.getTop(this.input) + this.getHeight(this.input)); this.showElement(this.calendar); this.calendar.style.display = "block"; this.switchSelects(false); Calendar.setFocus(false); } function Calendar_get(name) { return Calendar.calendars[name]; } //---------------------------------------------------------------------- // basic HTMLElement handling // function Calendar_getElement(name) { if (document.getElementById) { return document.getElementById(name); } else { for (var i = 0; i < document.all.length; i++) if (document.all[i].id == name) return document.all[i]; } } function Calendar_showElement(el) { el.style.visibility = "visible"; } function Calendar_hideElement(el) { el.style.visibility = "hidden"; } function Calendar_moveElement(el, left, top) { var elH = this.getHeight(el); var docH = this.getDocHeight(); if (top + elH > docH) { top = docH - elH; if (top < 0) top = 0; } var elW = this.getWidth(el); var docW = this.getDocWidth(); if (left + elW > docW) { left = docW - elW; if (left < 0) left = 0; } el.style.left = left+"px"; el.style.top = top+"px"; } function Calendar_getDocHeight() { return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight); // if (navigator.appName.indexOf("Microsoft") != -1) { // return document.body.offsetHeight - 2; // } else { // return document.body.scrollHeight; // } } function Calendar_getDocWidth() { return document.body.scrollWidth; } function Calendar_getLeft(e) { return xc(e); /*x = 0; while (e) { x += e.offsetLeft; e = e.offsetParent; } return x;*/ } function Calendar_getTop(e) { return yc(e); // y = 0; //while (e) { // y += e.offsetTop; // e = e.offsetParent; //} //return y; } function Calendar_getHeight(e) { return e.offsetHeight; } function Calendar_getWidth(e) { return e.offsetWidth; } function Calendar_insertHTML(el, html) { el.innerHTML = ""; // IE 5.2 mac bug workaround el.innerHTML = html; } function Calendar_overlaps(a1, l1, a2, l2) { var b1 = a1 + l1; var b2 = a2 + l2; return ((a1 > a2 && a1 < b2) || (b1 > a2 && b1 < b2) || (a2 > a1 && a2 < b1) || (b2 > a1 && b2 < b1)); } function Calendar_switchSelects(on) { var cl = this.getLeft(this.calendar); var ct = this.getTop(this.calendar); var ch = this.getHeight(this.calendar); var cw = this.getWidth(this.calendar); for (var f = 0; f < document.forms.length; f++) { var form = document.forms[f]; for (var e = 0; e < form.elements.length; e++) { var el = form.elements[e]; if (el.type.indexOf('select') >= 0) { var sl = this.getLeft(el); var st = this.getTop(el); var sh = this.getHeight(el); var sw = this.getWidth(el); if (this.overlaps(cl, cw, sl, sw) && this.overlaps(ct, ch, st, sh)) { if (on) { this.showElement(el); } else { this.hideElement(el); } } } } } } //---------------------------------------------------------------------- // date methods // var Calendar_monthDays = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); function Calendar_getMonthDays(year, month) { if (month == 2 && ((year % 400 == 0 || year % 4 == 0 && year % 100 != 0))) return 29; return Calendar_monthDays[month]; } function Calendar_parseDate(s) { var r; var d; if ((r = s.match(/(\d+)\s*\.\s*(\d+)\s*\.\s*(\d+)/)) != null) { d = new Date(parseInt(r[3], 10), parseInt(r[2], 10) - 1, parseInt(r[1], 10), 0, 0, 0, 0); } else if ((r = s.match(/(\d+)\s*\/\s*(\d+)\s*\/\s*(\d+)/)) != null) { d = new Date(parseInt(r[3], 10), parseInt(r[1], 10) - 1, parseInt(r[2], 10), 0, 0, 0, 0); } else if ((r = s.match(/(\d+)\s*-\s*(\d+)\s*-\s*(\d+)/)) != null) { d = new Date(parseInt(r[1], 10), parseInt(r[2], 10) - 1, parseInt(r[3], 10), 0, 0, 0, 0); } else { d = new Date(); } if ((r = s.match(/(\d+)\s*:\s*(\d+)\s+am/i)) != null) { d.setHours(r[1] == '12' ? 0 : parseInt(r[1], 10)); d.setMinutes(parseInt(r[2], 10)); } else if ((r = s.match(/(\d+)\s*:\s*(\d+)\s+pm/i)) != null) { d.setHours(r[1] == '12' ? 12 : parseInt(r[1], 10) + 12); d.setMinutes(parseInt(r[2], 10)); } else if ((r = s.match(/(\d+)\s*:\s*(\d+)/)) != null) { d.setHours(parseInt(r[1], 10)); d.setMinutes(parseInt(r[2], 10)); } return d; } function Calendar_getWeekOfYear(year, month, day) { var date = new Date(year, 0, 1, 0, 0, 0, 0); var yd = date.getDay(); if (yd == 0) yd = 7; yd--; for (i = 1; i < month; i++) { yd += this.getMonthDays(year, i); } yd += day - 1; return Math.floor(yd / 7) + 1; } //---------------------------------------------------------------------- // build calendar stuff // function Calendar_createPage(year, month, monthDay) { var dateInput = this.parseDate(this.input.value); var dateToday = new Date(); var dateFirst = new Date(year, month-1, 1, 0, 0, 0, 0); var weekDay1 = dateFirst.getDay(); if (weekDay1 == 0) weekDay1 = 7; var cw = this.getWeekOfYear(year, month, 1); // surrounding months var lastMonth = month == 1 ? 12 : month - 1; var nextMonth = month == 12 ? 1 : month + 1; var lastYear = month == 1 ? year - 1 : year; var nextYear = month == 12 ? year + 1 : year; var lastDays = this.getMonthDays(lastYear, lastMonth); var thisDays = this.getMonthDays(year, month); var nextDays = this.getMonthDays(nextYear, nextMonth); var scrollMethod = 'Calendar.get(\'' + this.name + '\').scrollPage'; var monthsMethod = 'Calendar.get(\'' + this.name + '\').showMonths'; var handlerBack1 = scrollMethod + '(' + lastYear + ',' + lastMonth + ');'; var handlerBack12 = scrollMethod + '(' + (year-1) + ',' + month + ');'; var handlerFwd1 = scrollMethod + '(' + nextYear + ',' + nextMonth + ');'; var handlerFwd12 = scrollMethod + '(' + (year+1) + ',' + month + ');'; var handlerMonths = monthsMethod + '(' + year + ');'; var header = '' + '' + '' + '
'+ '<<  '+ ' <   ' + Calendar.monthLabels[month] + '  ' + year + '   >   '+ '>>
'; var table = '' + '' + ''; for (i = 0; i < Calendar.dayLabels.length; i++) { table += ''; } table += ""; var daysInLast = weekDay1 - 1; var daysUntilNext = daysInLast + thisDays; var displayedDays = daysUntilNext; while (displayedDays % 7 != 0) displayedDays++; for (i = 0; i < displayedDays; i++) { if (i % 7 == 0) { table += ''; } var style = ""; var d = 0; var selDate = ""; if (i < daysInLast) { d = lastDays - (weekDay1 - 2 - i); style = 'calendar-day-next'; selDate = lastYear + ',' + lastMonth + ',' + d; } else if (i < daysUntilNext) { d = i - daysInLast + 1; if (d == dateInput.getDate() && month == dateInput.getMonth()+1 && year == dateInput.getFullYear()) style = 'calendar-day-selected'; else if (d == dateToday.getDate() && month == dateToday.getMonth()+1 && year == dateToday.getFullYear()) style = 'calendar-day-today'; else style = 'calendar-day-num'; selDate = year + ',' + month + ',' + d; } else { d = i - daysUntilNext + 1; style = 'calendar-day-next'; selDate = nextYear + ',' + nextMonth + ',' + d; } var selectMethod = 'Calendar.get(\'' + this.name + '\').selectDate'; var handler = selectMethod + '(' + selDate + ');'; table += ''; if (i % 7 == 6) table += ''; } table += "
' + header + '
' + Calendar.calendarWeekLabel + '' table += Calendar.dayLabels[i]; table += '
' + (cw++) + ''; table += '' + d + ''; table += '
"; this.insertHTML(this.calendar, table); this.calendarMonthsOpen = this.getElement("calendar-months-open"); } function Calendar_scrollPage(year, month) { this.hideElement(this.calendarMonths); this.createPage(year, month, -1); this.showElement(this.calendar); } function Calendar_selectDate(year, month, day) { if (month < 10) month = '0' + month; if (day < 10) day = '0' + day; var t = ""; var h = this.dateIn.getHours(); var m = this.dateIn.getMinutes(); if (m < 10) m = "0" + m; if (this.timefmt == '12') { var s; if (h < 12) { s = "AM"; if (h == 0) h = 12; } else { s = "PM"; if (h > 12) h -= 12; } t = " " + h + ":" + m + " " + s; } else if (this.timefmt == '24') { if (h < 10) h = "0" + h; t = " " + h + ":" + m; } if (this.format == '.') { this.input.value = day + '.' + month + '.' + year + t; } else if (this.format == '-') { this.input.value = year + '-' + month + '-' + day + t; } else { this.input.value = month + '/' + day + '/' + year + t; } this.hide(); // f.h. 2004/02/25 BEGIN // set focus to calendar input field // this is used to make HTTrace actually work with calendars this.input.focus(); // f.h. 2004/02/25 END } function Calendar_showMonths(year, event) { var choice = ''; var scrollMethod = 'Calendar.get(\'' + this.name + '\').scrollPage'; for (i = 1; i < Calendar.monthLabels.length; i++) { choice += ''; } choice += '
' + Calendar.monthLabels[i] + '
'; this.insertHTML(this.calendarMonths, choice); this.moveElement(this.calendarMonths, this.getLeft(this.calendarMonthsOpen), this.getTop(this.calendarMonthsOpen) + this.getHeight(this.calendarMonthsOpen)); this.showElement(this.calendarMonths); } function Calendar_hide() { this.hideElement(this.calendar); this.hideElement(this.calendarMonths); this.switchSelects(true); } function Calendar_hideAll() { if (window.itvtcalendarkill) { for (var name in Calendar.calendars) Calendar.calendars[name].hide(); } } function Calendar_setFocus(focus) { if (focus) { window.itvtcalendarkill = false; } else { window.itvtcalendarkill = true; if (!window.itvtdocclick) { window.itvtdocclick = Calendar.hideAll.bindAsEventListener(this); Element.observe(document,"mousedown",window.itvtdocclick); } } } //---------------------------------------------------------------------- // initialization // Calendar.calendars = new Object(); Calendar.get = Calendar_get; Calendar.prototype.getElement = Calendar_getElement; Calendar.prototype.showElement = Calendar_showElement; Calendar.prototype.hideElement = Calendar_hideElement; Calendar.prototype.moveElement = Calendar_moveElement; Calendar.prototype.getDocHeight = Calendar_getDocHeight; Calendar.prototype.getDocWidth = Calendar_getDocWidth; Calendar.prototype.getLeft = Calendar_getLeft; Calendar.prototype.getTop = Calendar_getTop; Calendar.prototype.getHeight = Calendar_getHeight; Calendar.prototype.getWidth = Calendar_getWidth; Calendar.prototype.insertHTML = Calendar_insertHTML; Calendar.prototype.switchSelects = Calendar_switchSelects; Calendar.prototype.overlaps = Calendar_overlaps; Calendar.prototype.getMonthDays = Calendar_getMonthDays; Calendar.prototype.parseDate = Calendar_parseDate; Calendar.prototype.getWeekOfYear = Calendar_getWeekOfYear; Calendar.prototype.createPage = Calendar_createPage; Calendar.prototype.scrollPage = Calendar_scrollPage; Calendar.prototype.selectDate = Calendar_selectDate; Calendar.prototype.showMonths = Calendar_showMonths; Calendar.prototype.hide = Calendar_hide; Calendar.hideAll = Calendar_hideAll; Calendar.setFocus = Calendar_setFocus; //---------------------------------------------------------------------- // may be overwritten by localized calendars // Calendar.monthLabels = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); Calendar.dayLabels = new Array("Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"); Calendar.calendarWeekLabel = "CW"; // //---------------------------------------------------------------------- //---------------------------------------------------------------------- // create popups // document.write(''); document.write('');