calendar = function (mondayfirst, datestr, onselected, onclose) { // member variables this.activediv = null; this.currentdateel = null; this.checkdisabled = null; this.timeout = null; this.onselected = onselected || null; this.onclose = onclose || null; this.dragging = false; this.hidden = false; this.minyear = 1970; this.maxyear = 2050; this.dateformat = calendar._tt["def_date_format"]; this.ttdateformat = calendar._tt["tt_date_format"]; this.ispopup = true; this.weeknumbers = true; this.mondayfirst = mondayfirst; this.datestr = datestr; this.ar_days = null; // html elements this.table = null; this.element = null; this.tbody = null; this.firstdayname = null; // combo boxes this.monthscombo = null; this.yearscombo = null; this.hilitedmonth = null; this.activemonth = null; this.hilitedyear = null; this.activeyear = null; // information this.dateclicked = false; // one-time initializations if (!calendar._dn3) { // table of short day names var ar = new array(); for (var i = 8; i > 0;) { ar[--i] = calendar._dn[i].substr(0, 3); } calendar._dn3 = ar; // table of short month names ar = new array(); for (var i = 12; i > 0;) { ar[--i] = calendar._mn[i].substr(0, 3); } calendar._mn3 = ar; } }; calendar._c = null; calendar.is_ie = ( /msie/i.test(navigator.useragent) && !/opera/i.test(navigator.useragent) ); calendar._dn3 = null; calendar._mn3 = null; calendar.getabsolutepos = function(el) { var r = { x: el.offsetleft, y: el.offsettop }; if (el.offsetparent) { var tmp = calendar.getabsolutepos(el.offsetparent); r.x += tmp.x; r.y += tmp.y; } return r; }; calendar.isrelated = function (el, evt) { var related = evt.relatedtarget; if (!related) { var type = evt.type; if (type == "mouseover") { related = evt.fromelement; } else if (type == "mouseout") { related = evt.toelement; } } while (related) { if (related == el) { return true; } related = related.parentnode; } return false; }; calendar.removeclass = function(el, classname) { if (!(el && el.classname)) { return; } var cls = el.classname.split(" "); var ar = new array(); for (var i = cls.length; i > 0;) { if (cls[--i] != classname) { ar[ar.length] = cls[i]; } } el.classname = ar.join(" "); }; calendar.addclass = function(el, classname) { calendar.removeclass(el, classname); el.classname += " " + classname; }; calendar.getelement = function(ev) { if (calendar.is_ie) { return window.event.srcelement; } else { return ev.currenttarget; } }; calendar.gettargetelement = function(ev) { if (calendar.is_ie) { return window.event.srcelement; } else { return ev.target; } }; calendar.stopevent = function(ev) { if (calendar.is_ie) { window.event.cancelbubble = true; window.event.returnvalue = false; } else { ev.preventdefault(); ev.stoppropagation(); } return false; }; calendar.addevent = function(el, evname, func) { if (el.attachevent) { // ie el.attachevent("on" + evname, func); } else if (el.addeventlistener) { // gecko / w3c el.addeventlistener(evname, func, true); } else { // opera (or old browsers) el["on" + evname] = func; } }; calendar.removeevent = function(el, evname, func) { if (el.detachevent) { // ie el.detachevent("on" + evname, func); } else if (el.removeeventlistener) { // gecko / w3c el.removeeventlistener(evname, func, true); } else { // opera (or old browsers) el["on" + evname] = null; } }; calendar.createelement = function(type, parent) { var el = null; if (document.createelementns) { // use the xhtml namespace; ie won't normally get here unless // _they_ "fix" the dom2 implementation. el = document.createelementns("http://www.w3.org/1999/xhtml", type); } else { el = document.createelement(type); } if (typeof parent != "undefined") { parent.appendchild(el); } return el; }; calendar._add_evs = function(el) { with (calendar) { addevent(el, "mouseover", daymouseover); addevent(el, "mousedown", daymousedown); addevent(el, "mouseout", daymouseout); if (is_ie) { addevent(el, "dblclick", daymousedblclick); el.setattribute("unselectable", true); } } }; calendar.findmonth = function(el) { if (typeof el.month != "undefined") { return el; } else if (typeof el.parentnode.month != "undefined") { return el.parentnode; } return null; }; calendar.findyear = function(el) { if (typeof el.year != "undefined") { return el; } else if (typeof el.parentnode.year != "undefined") { return el.parentnode; } return null; }; calendar.showmonthscombo = function () { var cal = calendar._c; if (!cal) { return false; } var cal = cal; var cd = cal.activediv; var mc = cal.monthscombo; if (cal.hilitedmonth) { calendar.removeclass(cal.hilitedmonth, "hilite"); } if (cal.activemonth) { calendar.removeclass(cal.activemonth, "active"); } var mon = cal.monthscombo.getelementsbytagname("div")[cal.date.getmonth()]; calendar.addclass(mon, "active"); cal.activemonth = mon; mc.style.left = cd.offsetleft + "px"; mc.style.top = (cd.offsettop + cd.offsetheight) + "px"; mc.style.display = "block"; }; calendar.showyearscombo = function (fwd) { var cal = calendar._c; if (!cal) { return false; } var cal = cal; var cd = cal.activediv; var yc = cal.yearscombo; if (cal.hilitedyear) { calendar.removeclass(cal.hilitedyear, "hilite"); } if (cal.activeyear) { calendar.removeclass(cal.activeyear, "active"); } cal.activeyear = null; var y = cal.date.getfullyear() + (fwd ? 1 : -1); var yr = yc.firstchild; var show = false; for (var i = 12; i > 0; --i) { if (y >= cal.minyear && y <= cal.maxyear) { yr.firstchild.data = y; yr.year = y; yr.style.display = "block"; show = true; } else { yr.style.display = "none"; } yr = yr.nextsibling; y += fwd ? 2 : -2; } if (show) { yc.style.left = cd.offsetleft + "px"; yc.style.top = (cd.offsettop + cd.offsetheight) + "px"; yc.style.display = "block"; } }; // event handlers calendar.tablemouseup = function(ev) { var cal = calendar._c; if (!cal) { return false; } if (cal.timeout) { cleartimeout(cal.timeout); } var el = cal.activediv; if (!el) { return false; } var target = calendar.gettargetelement(ev); calendar.removeclass(el, "active"); if (target == el || target.parentnode == el) { calendar.cellclick(el); } var mon = calendar.findmonth(target); var date = null; if (mon) { date = new date(cal.date); if (mon.month != date.getmonth()) { date.setmonth(mon.month); cal.setdate(date); cal.dateclicked = false; cal.callhandler(); } } else { var year = calendar.findyear(target); if (year) { date = new date(cal.date); if (year.year != date.getfullyear()) { date.setfullyear(year.year); cal.setdate(date); cal.dateclicked = false; cal.callhandler(); } } } with (calendar) { removeevent(document, "mouseup", tablemouseup); removeevent(document, "mouseover", tablemouseover); removeevent(document, "mousemove", tablemouseover); cal._hidecombos(); _c = null; return stopevent(ev); } }; calendar.tablemouseover = function (ev) { var cal = calendar._c; if (!cal) { return; } var el = cal.activediv; var target = calendar.gettargetelement(ev); if (target == el || target.parentnode == el) { calendar.addclass(el, "hilite active"); calendar.addclass(el.parentnode, "rowhilite"); } else { calendar.removeclass(el, "active"); calendar.removeclass(el, "hilite"); calendar.removeclass(el.parentnode, "rowhilite"); } var mon = calendar.findmonth(target); if (mon) { if (mon.month != cal.date.getmonth()) { if (cal.hilitedmonth) { calendar.removeclass(cal.hilitedmonth, "hilite"); } calendar.addclass(mon, "hilite"); cal.hilitedmonth = mon; } else if (cal.hilitedmonth) { calendar.removeclass(cal.hilitedmonth, "hilite"); } } else { var year = calendar.findyear(target); if (year) { if (year.year != cal.date.getfullyear()) { if (cal.hilitedyear) { calendar.removeclass(cal.hilitedyear, "hilite"); } calendar.addclass(year, "hilite"); cal.hilitedyear = year; } else if (cal.hilitedyear) { calendar.removeclass(cal.hilitedyear, "hilite"); } } } return calendar.stopevent(ev); }; calendar.tablemousedown = function (ev) { if (calendar.gettargetelement(ev) == calendar.getelement(ev)) { return calendar.stopevent(ev); } }; calendar.caldragit = function (ev) { var cal = calendar._c; if (!(cal && cal.dragging)) { return false; } var posx; var posy; if (calendar.is_ie) { posy = window.event.clienty + document.body.scrolltop; posx = window.event.clientx + document.body.scrollleft; } else { posx = ev.pagex; posy = ev.pagey; } cal.hideshowcovered(); var st = cal.element.style; st.left = (posx - cal.xoffs) + "px"; st.top = (posy - cal.yoffs) + "px"; return calendar.stopevent(ev); }; calendar.caldragend = function (ev) { var cal = calendar._c; if (!cal) { return false; } cal.dragging = false; with (calendar) { removeevent(document, "mousemove", caldragit); removeevent(document, "mouseover", stopevent); removeevent(document, "mouseup", caldragend); tablemouseup(ev); } cal.hideshowcovered(); }; calendar.daymousedown = function(ev) { var el = calendar.getelement(ev); if (el.disabled) { return false; } var cal = el.calendar; cal.activediv = el; calendar._c = cal; if (el.navtype != 300) with (calendar) { addclass(el, "hilite active"); addevent(document, "mouseover", tablemouseover); addevent(document, "mousemove", tablemouseover); addevent(document, "mouseup", tablemouseup); } else if (cal.ispopup) { cal._dragstart(ev); } if (el.navtype == -1 || el.navtype == 1) { cal.timeout = settimeout("calendar.showmonthscombo()", 250); } else if (el.navtype == -2 || el.navtype == 2) { cal.timeout = settimeout((el.navtype > 0) ? "calendar.showyearscombo(true)" : "calendar.showyearscombo(false)", 250); } else { cal.timeout = null; } return calendar.stopevent(ev); }; calendar.daymousedblclick = function(ev) { calendar.cellclick(calendar.getelement(ev)); if (calendar.is_ie) { document.selection.empty(); } }; calendar.daymouseover = function(ev) { var el = calendar.getelement(ev); if (calendar.isrelated(el, ev) || calendar._c || el.disabled) { return false; } if (el.ttip) { if (el.ttip.substr(0, 1) == "_") { var date = null; with (el.calendar.date) { date = new date(getfullyear(), getmonth(), el.caldate); } el.ttip = date.print(el.calendar.ttdateformat) + el.ttip.substr(1); } el.calendar.tooltips.firstchild.data = el.ttip; } if (el.navtype != 300) { calendar.addclass(el, "hilite"); if (el.caldate) { calendar.addclass(el.parentnode, "rowhilite"); } } return calendar.stopevent(ev); }; calendar.daymouseout = function(ev) { with (calendar) { var el = getelement(ev); if (isrelated(el, ev) || _c || el.disabled) { return false; } removeclass(el, "hilite"); if (el.caldate) { removeclass(el.parentnode, "rowhilite"); } el.calendar.tooltips.firstchild.data = _tt["sel_date"]; return stopevent(ev); } }; /** * a generic "click" handler :) handles all types of buttons defined in this * calendar. */ calendar.cellclick = function(el) { var cal = el.calendar; var closing = false; var newdate = false; var date = null; if (typeof el.navtype == "undefined") { calendar.removeclass(cal.currentdateel, "selected"); calendar.addclass(el, "selected"); closing = (cal.currentdateel == el); if (!closing) { cal.currentdateel = el; } cal.date.setdate(el.caldate); date = cal.date; newdate = true; // a date was clicked cal.dateclicked = true; } else { if (el.navtype == 200) { calendar.removeclass(el, "hilite"); cal.callclosehandler(); return; } date = (el.navtype == 0) ? new date() : new date(cal.date); // unless "today" was clicked, we assume no date was clicked so // the selected handler will know not to close the calenar when // in single-click mode. cal.dateclicked = (el.navtype == 0); var year = date.getfullyear(); var mon = date.getmonth(); function setmonth(m) { var day = date.getdate(); var max = date.getmonthdays(m); if (day > max) { date.setdate(max); } date.setmonth(m); }; switch (el.navtype) { case -2: if (year > cal.minyear) { date.setfullyear(year - 1); } break; case -1: if (mon > 0) { setmonth(mon - 1); } else if (year-- > cal.minyear) { date.setfullyear(year); setmonth(11); } break; case 1: if (mon < 11) { setmonth(mon + 1); } else if (year < cal.maxyear) { date.setfullyear(year + 1); setmonth(0); } break; case 2: if (year < cal.maxyear) { date.setfullyear(year + 1); } break; case 100: cal.setmondayfirst(!cal.mondayfirst); return; case 0: // today will bring us here if ((typeof cal.checkdisabled == "function") && cal.checkdisabled(date)) { // remember, "date" was previously set to new // date() if today was clicked; thus, it // contains today date. return false; } break; } if (!date.equalsto(cal.date)) { cal.setdate(date); newdate = true; } } if (newdate) { cal.callhandler(); } if (closing) { calendar.removeclass(el, "hilite"); cal.callclosehandler(); } }; // end: calendar static functions // begin: calendar object functions /** * this function creates the calendar inside the given parent. if _par is * null than it creates a popup calendar inside the body element. if _par is * an element, be it body, then it creates a non-popup calendar (still * hidden). some properties need to be set before calling this function. */ calendar.prototype.create = function (_par) { var parent = null; if (! _par) { // default parent is the document body, in which case we create // a popup calendar. parent = document.getelementsbytagname("body")[0]; this.ispopup = true; } else { parent = _par; this.ispopup = false; } this.date = this.datestr ? new date(this.datestr) : new date(); var table = calendar.createelement("table"); this.table = table; table.cellspacing = 0; table.cellpadding = 0; table.calendar = this; calendar.addevent(table, "mousedown", calendar.tablemousedown); var div = calendar.createelement("div"); this.element = div; div.classname = "calendar"; if (this.ispopup) { div.style.position = "absolute"; div.style.display = "none"; } div.appendchild(table); var thead = calendar.createelement("thead", table); var cell = null; var row = null; var cal = this; var hh = function (text, cs, navtype) { cell = calendar.createelement("td", row); cell.colspan = cs; cell.classname = "button"; calendar._add_evs(cell); cell.calendar = cal; cell.navtype = navtype; if (text.substr(0, 1) != "&") { cell.appendchild(document.createtextnode(text)); } else { // fixme: dirty hack for entities cell.innerhtml = text; } return cell; }; row = calendar.createelement("tr", thead); var title_length = 6; (this.ispopup) && --title_length; (this.weeknumbers) && ++title_length; hh("-", 1, 100).ttip = calendar._tt["toggle"]; this.title = hh("", title_length, 300); this.title.classname = "title"; if (this.ispopup) { this.title.ttip = calendar._tt["drag_to_move"]; this.title.style.cursor = "move"; hh("×", 1, 200).ttip = calendar._tt["close"]; } row = calendar.createelement("tr", thead); row.classname = "headrow"; this._nav_py = hh("«", 1, -2); this._nav_py.ttip = calendar._tt["prev_year"]; this._nav_pm = hh("‹", 1, -1); this._nav_pm.ttip = calendar._tt["prev_month"]; this._nav_now = hh(calendar._tt["today"], this.weeknumbers ? 4 : 3, 0); this._nav_now.ttip = calendar._tt["go_today"]; this._nav_nm = hh("›", 1, 1); this._nav_nm.ttip = calendar._tt["next_month"]; this._nav_ny = hh("»", 1, 2); this._nav_ny.ttip = calendar._tt["next_year"]; // day names row = calendar.createelement("tr", thead); row.classname = "daynames"; if (this.weeknumbers) { cell = calendar.createelement("td", row); cell.classname = "name wn"; cell.appendchild(document.createtextnode(calendar._tt["wk"])); } for (var i = 7; i > 0; --i) { cell = calendar.createelement("td", row); cell.appendchild(document.createtextnode("")); if (!i) { cell.navtype = 100; cell.calendar = this; calendar._add_evs(cell); } } this.firstdayname = (this.weeknumbers) ? row.firstchild.nextsibling : row.firstchild; this._displayweekdays(); var tbody = calendar.createelement("tbody", table); this.tbody = tbody; for (i = 6; i > 0; --i) { row = calendar.createelement("tr", tbody); if (this.weeknumbers) { cell = calendar.createelement("td", row); cell.appendchild(document.createtextnode("")); } for (var j = 7; j > 0; --j) { cell = calendar.createelement("td", row); cell.appendchild(document.createtextnode("")); cell.calendar = this; calendar._add_evs(cell); } } var tfoot = calendar.createelement("tfoot", table); row = calendar.createelement("tr", tfoot); row.classname = "footrow"; cell = hh(calendar._tt["sel_date"], this.weeknumbers ? 8 : 7, 300); cell.classname = "ttip"; if (this.ispopup) { cell.ttip = calendar._tt["drag_to_move"]; cell.style.cursor = "move"; } this.tooltips = cell; div = calendar.createelement("div", this.element); this.monthscombo = div; div.classname = "combo"; for (i = 0; i < calendar._mn.length; ++i) { var mn = calendar.createelement("div"); mn.classname = "label"; mn.month = i; mn.appendchild(document.createtextnode(calendar._mn3[i])); div.appendchild(mn); } div = calendar.createelement("div", this.element); this.yearscombo = div; div.classname = "combo"; for (i = 12; i > 0; --i) { var yr = calendar.createelement("div"); yr.classname = "label"; yr.appendchild(document.createtextnode("")); div.appendchild(yr); } this._init(this.mondayfirst, this.date); parent.appendchild(this.element); }; /** keyboard navigation, only for popup calendars */ calendar._keyevent = function(ev) { if (!window.calendar) { return false; } (calendar.is_ie) && (ev = window.event); var cal = window.calendar; var act = (calendar.is_ie || ev.type == "keypress"); if (ev.ctrlkey) { switch (ev.keycode) { case 37: // key left act && calendar.cellclick(cal._nav_pm); break; case 38: // key up act && calendar.cellclick(cal._nav_py); break; case 39: // key right act && calendar.cellclick(cal._nav_nm); break; case 40: // key down act && calendar.cellclick(cal._nav_ny); break; default: return false; } } else switch (ev.keycode) { case 32: // key space (now) calendar.cellclick(cal._nav_now); break; case 27: // key esc act && cal.hide(); break; case 37: // key left case 38: // key up case 39: // key right case 40: // key down if (act) { var date = cal.date.getdate() - 1; var el = cal.currentdateel; var ne = null; var prev = (ev.keycode == 37) || (ev.keycode == 38); switch (ev.keycode) { case 37: // key left (--date >= 0) && (ne = cal.ar_days[date]); break; case 38: // key up date -= 7; (date >= 0) && (ne = cal.ar_days[date]); break; case 39: // key right (++date < cal.ar_days.length) && (ne = cal.ar_days[date]); break; case 40: // key down date += 7; (date < cal.ar_days.length) && (ne = cal.ar_days[date]); break; } if (!ne) { if (prev) { calendar.cellclick(cal._nav_pm); } else { calendar.cellclick(cal._nav_nm); } date = (prev) ? cal.date.getmonthdays() : 1; el = cal.currentdateel; ne = cal.ar_days[date - 1]; } calendar.removeclass(el, "selected"); calendar.addclass(ne, "selected"); cal.date.setdate(ne.caldate); cal.callhandler(); cal.currentdateel = ne; } break; case 13: // key enter if (act) { cal.callhandler(); cal.hide(); } break; default: return false; } return calendar.stopevent(ev); }; /** * (re)initializes the calendar to the given date and style (if mondayfirst is * true it makes monday the first day of week, otherwise the weeks start on * sunday. */ calendar.prototype._init = function (mondayfirst, date) { var today = new date(); var year = date.getfullyear(); if (year < this.minyear) { year = this.minyear; date.setfullyear(year); } else if (year > this.maxyear) { year = this.maxyear; date.setfullyear(year); } this.mondayfirst = mondayfirst; this.date = new date(date); var month = date.getmonth(); var mday = date.getdate(); var no_days = date.getmonthdays(); date.setdate(1); var wday = date.getday(); var mon = mondayfirst ? 1 : 0; var sat = mondayfirst ? 5 : 6; var sun = mondayfirst ? 6 : 0; if (mondayfirst) { wday = (wday > 0) ? (wday - 1) : 6; } var iday = 1; var row = this.tbody.firstchild; var mn = calendar._mn3[month]; var hastoday = ((today.getfullyear() == year) && (today.getmonth() == month)); var todaydate = today.getdate(); var week_number = date.getweeknumber(); var ar_days = new array(); for (var i = 0; i < 6; ++i) { if (iday > no_days) { row.classname = "emptyrow"; row = row.nextsibling; continue; } var cell = row.firstchild; if (this.weeknumbers) { cell.classname = "day wn"; cell.firstchild.data = week_number; cell = cell.nextsibling; } ++week_number; row.classname = "daysrow"; for (var j = 0; j < 7; ++j) { cell.classname = "day"; if ((!i && j < wday) || iday > no_days) { // cell.classname = "emptycell"; cell.innerhtml = " "; cell.disabled = true; cell = cell.nextsibling; continue; } cell.disabled = false; cell.firstchild.data = iday; if (typeof this.checkdisabled == "function") { date.setdate(iday); if (this.checkdisabled(date)) { cell.classname += " disabled"; cell.disabled = true; } } if (!cell.disabled) { ar_days[ar_days.length] = cell; cell.caldate = iday; cell.ttip = "_"; if (iday == mday) { cell.classname += " selected"; this.currentdateel = cell; } if (hastoday && (iday == todaydate)) { cell.classname += " today"; cell.ttip += calendar._tt["part_today"]; } if (wday == sat || wday == sun) { cell.classname += " weekend"; } } ++iday; ((++wday) ^ 7) || (wday = 0); cell = cell.nextsibling; } row = row.nextsibling; } this.ar_days = ar_days; this.title.firstchild.data = calendar._mn[month] + ", " + year; }; calendar.prototype.setdate = function (date) { if (!date.equalsto(this.date)) { this._init(this.mondayfirst, date); } }; calendar.prototype.refresh = function () { this._init(this.mondayfirst, this.date); }; /** modifies the "mondayfirst" parameter (eu/us style). */ calendar.prototype.setmondayfirst = function (mondayfirst) { this._init(mondayfirst, this.date); this._displayweekdays(); }; calendar.prototype.setdisabledhandler = function (unaryfunction) { this.checkdisabled = unaryfunction; }; calendar.prototype.setrange = function (a, z) { this.minyear = a; this.maxyear = z; }; calendar.prototype.callhandler = function () { if (this.onselected) { this.onselected(this, this.date.print(this.dateformat)); } }; calendar.prototype.callclosehandler = function () { if (this.onclose) { this.onclose(this); } this.hideshowcovered(); }; calendar.prototype.destroy = function () { var el = this.element.parentnode; el.removechild(this.element); calendar._c = null; }; calendar.prototype.reparent = function (new_parent) { var el = this.element; el.parentnode.removechild(el); new_parent.appendchild(el); }; calendar._checkcalendar = function(ev) { if (!window.calendar) { return false; } var el = calendar.is_ie ? calendar.getelement(ev) : calendar.gettargetelement(ev); for (; el != null && el != calendar.element; el = el.parentnode); if (el == null) { // calls closehandler which should hide the calendar. window.calendar.callclosehandler(); return calendar.stopevent(ev); } }; calendar.prototype.show = function () { var rows = this.table.getelementsbytagname("tr"); for (var i = rows.length; i > 0;) { var row = rows[--i]; calendar.removeclass(row, "rowhilite"); var cells = row.getelementsbytagname("td"); for (var j = cells.length; j > 0;) { var cell = cells[--j]; calendar.removeclass(cell, "hilite"); calendar.removeclass(cell, "active"); } } this.element.style.display = "block"; this.hidden = false; if (this.ispopup) { window.calendar = this; calendar.addevent(document, "keydown", calendar._keyevent); calendar.addevent(document, "keypress", calendar._keyevent); calendar.addevent(document, "mousedown", calendar._checkcalendar); } this.hideshowcovered(); }; calendar.prototype.hide = function () { if (this.ispopup) { calendar.removeevent(document, "keydown", calendar._keyevent); calendar.removeevent(document, "keypress", calendar._keyevent); calendar.removeevent(document, "mousedown", calendar._checkcalendar); } this.element.style.display = "none"; this.hidden = true; this.hideshowcovered(); }; calendar.prototype.showat = function (x, y) { var s = this.element.style; s.left = x + "px"; s.top = y + "px"; this.show(); }; calendar.prototype.showatelement = function (el, opts) { var p = calendar.getabsolutepos(el); if (!opts || typeof opts != "string") { this.showat(p.x, p.y + el.offsetheight); return true; } this.show(); var w = this.element.offsetwidth; var h = this.element.offsetheight; this.hide(); var valign = opts.substr(0, 1); var halign = "l"; if (opts.length > 1) { halign = opts.substr(1, 1); } // vertical alignment switch (valign) { case "t": p.y -= h; break; case "b": p.y += el.offsetheight; break; case "c": p.y += (el.offsetheight - h) / 2; break; case "t": p.y += el.offsetheight - h; break; case "b": break; // already there } // horizontal alignment switch (halign) { case "l": p.x -= w; break; case "r": p.x += el.offsetwidth; break; case "c": p.x += (el.offsetwidth - w) / 2; break; case "r": p.x += el.offsetwidth - w; break; case "l": break; // already there } this.showat(p.x, p.y); }; calendar.prototype.setdateformat = function (str) { this.dateformat = str; }; calendar.prototype.setttdateformat = function (str) { this.ttdateformat = str; }; calendar.prototype.parsedate = function (str, fmt) { var y = 0; var m = -1; var d = 0; var a = str.split(/\w+/); if (!fmt) { fmt = this.dateformat; } var b = fmt.split(/\w+/); var i = 0, j = 0; for (i = 0; i < a.length; ++i) { if (b[i] == "d" || b[i] == "dd") { continue; } if (b[i] == "d" || b[i] == "dd") { d = parseint(a[i], 10); } if (b[i] == "m" || b[i] == "mm") { m = parseint(a[i], 10) - 1; } if ((b[i] == "y") || (b[i] == "yy")) { y = parseint(a[i], 10); (y < 100) && (y += (y > 29) ? 1900 : 2000); } if (b[i] == "m" || b[i] == "mm") { for (j = 0; j < 12; ++j) { if (calendar._mn[j].substr(0, a[i].length).tolowercase() == a[i].tolowercase()) { m = j; break; } } } } if (y != 0 && m != -1 && d != 0) { this.setdate(new date(y, m, d)); return; } y = 0; m = -1; d = 0; for (i = 0; i < a.length; ++i) { if (a[i].search(/[a-za-z]+/) != -1) { var t = -1; for (j = 0; j < 12; ++j) { if (calendar._mn[j].substr(0, a[i].length).tolowercase() == a[i].tolowercase()) { t = j; break; } } if (t != -1) { if (m != -1) { d = m+1; } m = t; } } else if (parseint(a[i], 10) <= 12 && m == -1) { m = a[i]-1; } else if (parseint(a[i], 10) > 31 && y == 0) { y = parseint(a[i], 10); (y < 100) && (y += (y > 29) ? 1900 : 2000); } else if (d == 0) { d = a[i]; } } if (y == 0) { var today = new date(); y = today.getfullyear(); } if (m != -1 && d != 0) { this.setdate(new date(y, m, d)); } }; calendar.prototype.hideshowcovered = function () { function getstyleprop(obj, style){ var value = obj.style[style]; if (!value) { if (document.defaultview && typeof (document.defaultview.getcomputedstyle) == "function") { // gecko, w3c value = document.defaultview. getcomputedstyle(obj, "").getpropertyvalue(style); } else if (obj.currentstyle) { // ie value = obj.currentstyle[style]; } else { value = obj.style[style]; } } return value; }; var tags = new array("applet", "iframe", "select"); var el = this.element; var p = calendar.getabsolutepos(el); var ex1 = p.x; var ex2 = el.offsetwidth + ex1; var ey1 = p.y; var ey2 = el.offsetheight + ey1; for (var k = tags.length; k > 0; ) { var ar = document.getelementsbytagname(tags[--k]); var cc = null; for (var i = ar.length; i > 0;) { cc = ar[--i]; p = calendar.getabsolutepos(cc); var cx1 = p.x; var cx2 = cc.offsetwidth + cx1; var cy1 = p.y; var cy2 = cc.offsetheight + cy1; if (this.hidden || (cx1 > ex2) || (cx2 < ex1) || (cy1 > ey2) || (cy2 < ey1)) { if (!cc.__msh_save_visibility) { cc.__msh_save_visibility = getstyleprop(cc, "visibility"); } cc.style.visibility = cc.__msh_save_visibility; } else { if (!cc.__msh_save_visibility) { cc.__msh_save_visibility = getstyleprop(cc, "visibility"); } cc.style.visibility = "hidden"; } } } }; /** internal function; it displays the bar with the names of the weekday. */ calendar.prototype._displayweekdays = function () { var mon = this.mondayfirst ? 0 : 1; var sun = this.mondayfirst ? 6 : 0; var sat = this.mondayfirst ? 5 : 6; var cell = this.firstdayname; for (var i = 0; i < 7; ++i) { cell.classname = "day name"; if (!i) { cell.ttip = this.mondayfirst ? calendar._tt["sun_first"] : calendar._tt["mon_first"]; cell.navtype = 100; cell.calendar = this; calendar._add_evs(cell); } if (i == sun || i == sat) { calendar.addclass(cell, "weekend"); } cell.firstchild.data = calendar._dn3[i + 1 - mon]; cell = cell.nextsibling; } }; /** internal function. hides all combo boxes that might be displayed. */ calendar.prototype._hidecombos = function () { this.monthscombo.style.display = "none"; this.yearscombo.style.display = "none"; }; /** internal function. starts dragging the element. */ calendar.prototype._dragstart = function (ev) { if (this.dragging) { return; } this.dragging = true; var posx; var posy; if (calendar.is_ie) { posy = window.event.clienty + document.body.scrolltop; posx = window.event.clientx + document.body.scrollleft; } else { posy = ev.clienty + window.scrolly; posx = ev.clientx + window.scrollx; } var st = this.element.style; this.xoffs = posx - parseint(st.left); this.yoffs = posy - parseint(st.top); with (calendar) { addevent(document, "mousemove", caldragit); addevent(document, "mouseover", stopevent); addevent(document, "mouseup", caldragend); } }; date._md = new array(31,28,31,30,31,30,31,31,30,31,30,31); /** constants used for time computations */ date.second = 1000 /* milliseconds */; date.minute = 60 * date.second; date.hour = 60 * date.minute; date.day = 24 * date.hour; date.week = 7 * date.day; date.prototype.getmonthdays = function(month) { var year = this.getfullyear(); if (typeof month == "undefined") { month = this.getmonth(); } if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) { return 29; } else { return date._md[month]; } }; date.prototype.getweeknumber = function() { var now = new date(this.getfullyear(), this.getmonth(), this.getdate(), 0, 0, 0); var then = new date(this.getfullyear(), 0, 1, 0, 0, 0); var time = now - then; var day = then.getday(); (day > 3) && (day -= 4) || (day += 3); return math.round(((time / date.day) + day) / 7); }; date.prototype.equalsto = function(date) { return ((this.getfullyear() == date.getfullyear()) && (this.getmonth() == date.getmonth()) && (this.getdate() == date.getdate())); }; date.prototype.print = function (frm) { var str = new string(frm); var m = this.getmonth(); var d = this.getdate(); var y = this.getfullyear(); var wn = this.getweeknumber(); var w = this.getday(); var s = new array(); s["d"] = d; s["dd"] = (d < 10) ? ("0" + d) : d; s["m"] = 1+m; s["mm"] = (m < 9) ? ("0" + (1+m)) : (1+m); s["y"] = y; s["yy"] = new string(y).substr(2, 2); s["w"] = wn; s["ww"] = (wn < 10) ? ("0" + wn) : wn; with (calendar) { s["d"] = _dn3[w]; s["dd"] = _dn[w]; s["m"] = _mn3[m]; s["mm"] = _mn[m]; } var re = /(.*)(\w|^)(d|dd|m|mm|y|yy|mm|m|dd|d|w|ww)(\w|$)(.*)/; while (re.exec(str) != null) { str = regexp.$1 + regexp.$2 + s[regexp.$3] + regexp.$4 + regexp.$5; } return str; }; window.calendar = null;