var activeCalendar = null; var cal_imgUp = null, cal_imgDown = null, cal_isInitEvents = false; function calendar (rootPath) { initCalendarEvents (); this.setTime = cal_setTime; this.setHour = cal_setHour; //this.popup = cal_popup; this.init = cal_init; this.open = cal_open; this.close = cal_close; this.isOpen = cal_isOpen; this.getShowClock = cal_getShowClock; this.getShowMonth = cal_getShowMonth; this.setShowClock = cal_setShowClock; this.setShowMonth = cal_setShowMonth; this.setFastConfirm = cal_setFastConfirm; this.getFastConfirm = cal_getFastConfirm; this.doShowMonth = cal_showMonth; this.getCloseOnComplete = cal_getCloseOnComplete; this.setCloseOnComplete = cal_setCloseOnComplete; this.parent = null; this.showClock = true; this.showMonth = true; this.onConfirm = null; this.onChanged = null; this.fastConfirm = false; this.rootPath = rootPath; this.closeOnComplete = false; // private this.createMonth = cal_createMonth; this.createClock = cal_createClock; this.setDateTime = cal_setDateTime; this.onblur = cal_onblur; this.afterblur = null; this.afterclose = null; this.open6 = cal_open6; this.getMonthWidth = cal_monthWidth; this.getTotalWidth = cal_totalWidth; this.autoClose = cal_autoClose; } function cal_setDateTime (dt,tm) { var dttm = this.parent.value; if (tm == null) { var pos = dt.indexOf (' '); if (pos > 0) { tm = dt.substr (pos + 1, dt.length); dt = dt.substr (0, pos); } } var adt = "", atm = ""; if (this.getShowClock ()) if (this.getShowMonth ()) { var pos = dttm.indexOf (' '); if (pos >= 0) { adt = dttm.substr (0, pos); atm = dttm.substr (pos + 1, dttm.length); } // if } else atm = dttm; else if (this.getShowMonth ()) adt = dttm; if (typeof (dt) == "string") adt = dt; if (typeof (tm) == "string") atm = tm; if (this.getShowClock ()) if (this.getShowMonth ()) this.parent.value = adt + " " + atm; else this.parent.value = atm; else if (this.getShowMonth ()) this.parent.value = adt; if (this.parent.onblur) this.parent.onblur (); if (this.onConfirm) this.onConfirm (); } function cal_setTime (value) { this.setDateTime (value, null); } function cal_setHour (value) { this.setDateTime (null, value); } function cal_getShowClock () { return this.showClock; } function cal_getShowMonth () { return this.showMonth; } function cal_setShowClock (val) { this.showClock = val; } function cal_setShowMonth (val) { this.showMonth = val; } function cal_setFastConfirm (val) { this.fastConfirm = val; } function cal_getFastConfirm () { return this.fastConfirm; } function cal_setCloseOnComplete (val) {this.closeOnComplete = val;} function cal_getCloseOnComplete () {return this.closeOnComplete;} var daysAMonth = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var monthNames = new Array ('januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december'); var monthsAbbr = new Array ('jan', 'feb', 'maa', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'); var dayAbbr = new Array ('Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'); function getDaysAMonth (dt) { m = dt.getMonth (); if (m != 1 || dt.getFullYear () % 4 != 0) return daysAMonth [m]; else return 29; } function cal_autoClose () { if (activeCalendar.getShowClock ()) if (activeCalendar.getShowMonth ()) { if (activeCalendar.getCloseOnComplete ()) { var dt = activeCalendar.parent.value; var pos = dt.indexOf (' '); if (0 < pos && pos < dt.length - 4) activeCalendar.close (); } // if return; } activeCalendar.close (); } function cal_useTime (newTime) { activeCalendar.setTime (newTime); if (activeCalendar.onChanged) activeCalendar.onChanged (activeCalendar); activeCalendar.autoClose (); } function cal_useHour (newTime) { activeCalendar.setHour (newTime); if (activeCalendar.onChanged) activeCalendar.onChanged (activeCalendar); activeCalendar.autoClose (); } function getDateIndex (day, month, year) { return day + 32 * (month + 16 * year); } function showDayInfo (day, month, year) { tm = ""; if (day < 10) tm = "0"; tm = tm + day + "-"; if (month < 10) tm = tm + "0"; tm = tm + month + '-' + year; return "" + day + ""; } function cal_createMonth (frame,month, year) { var calendarTxt = ""; var thisMonth, nextMonth, prevMonth, toDay; thisMonth = new Date (year, month - 1, 1); if (month <= 11) nextMonth = new Date (year, month, 1); else nextMonth = new Date (year + 1, 0, 1); if (month > 0) prevMonth = new Date (year, month - 2, 1); else prevMonth = new Date (year - 1, 11, 1); if (month == this.current.getMonth () + 1 && year == this.current.getFullYear ()) toDay = this.current.getDate (); else toDay = -1; calendarTxt = calendarTxt + ("
"); calendarTxt = calendarTxt + (""); calendarTxt = calendarTxt + (""); calendarTxt = calendarTxt + (""); calendarTxt = calendarTxt + ("
 < " + monthsAbbr [prevMonth.getMonth()] + " " + prevMonth.getFullYear () + "" + monthNames [thisMonth.getMonth ()] + " " + thisMonth.getFullYear () + "" + monthsAbbr [nextMonth.getMonth ()] + " " + nextMonth.getFullYear () + " > 
\n"); firstday = thisMonth.getDay (); if (firstday == 0) firstday = 6; else --firstday; days = getDaysAMonth (thisMonth); lastday = nextMonth.getDay () - 1; if (lastday < 0) lastday = 6; calendarTxt = calendarTxt + ""; for (day = 0; day <= 6; ++day) calendarTxt = calendarTxt + ''; calendarTxt = calendarTxt + "\n"; calendarTxt = calendarTxt + ""; dayMonth = getDaysAMonth (prevMonth) - firstday + 1; prevMon = prevMonth.getMonth () + 1; prevYear = prevMonth.getFullYear (); for (day = 0; day < firstday; ++day, ++dayMonth) calendarTxt = calendarTxt + (""); dayMonth = 1; for (;day <= 6; ++day, ++dayMonth) if (dayMonth == toDay) calendarTxt = calendarTxt + (""); else calendarTxt = calendarTxt + (""); calendarTxt = calendarTxt + ("\n"); for (;dayMonth <= days;) { calendarTxt = calendarTxt + ("\n"); for (day = 0; day <= 6 && dayMonth <= days; ++dayMonth, ++day) if (dayMonth == toDay) calendarTxt = calendarTxt + (""); else calendarTxt = calendarTxt + (""); prevMon = nextMonth.getMonth () + 1; prevYear = nextMonth.getFullYear (); for (dayMonthL = 1; day <= 6; ++day, ++dayMonthL) calendarTxt = calendarTxt + (""); calendarTxt = calendarTxt + ("\n"); } calendarTxt = calendarTxt + ( "
' + dayAbbr [day] + '
" + showDayInfo (dayMonth, prevMon, prevYear) + "" + showDayInfo (dayMonth, month, year) + "" + showDayInfo (dayMonth, month, year) + "
" + showDayInfo (dayMonth, month, year) + "" + showDayInfo (dayMonth, month, year) + "" + showDayInfo (dayMonthL, prevMon, prevYear) + "
\n"); return calendarTxt; } function cal_doCreateClock (offsx, offsy, radius, firstHour) { result = ""; var i, step = Math.PI / 6, step, posX, posY, hour, angle = 0; hour = firstHour; for (i = 0; i < 12; ++i, ++hour) { posX = offsx + Math.floor (Math.sin(angle)*radius + 0.5); posY = offsy + Math.floor (-Math.cos(angle)*radius + 0.5); result += "
" + hour + "
"; angle += step; } hour = firstHour; angle = step / 2; for (i = 0; i < 12; ++i, ++hour) { posX = offsx + Math.floor (Math.sin(angle)*radius+0.5); posY = offsy + Math.floor (-Math.cos(angle)*radius+0.5); result += "
*
"; angle += step; } return result; } function cal_createClock () { result = ""; if (this.getShowClock ()) { var offsx = 320, offsy = 70, radius = 64; if (this.getShowMonth ()) { } else { offsx = 70; offsy = 70; } result = "
 
\n"; result += cal_doCreateClock (offsx, offsy, 50, 0); result += cal_doCreateClock (offsx, offsy, radius, 12); } return result; } function cal_monthWidth () { return 322; } function cal_totalWidth () { var result = 0; if (this.getShowMonth ()) result = this.getMonthWidth (); if (this.getShowClock ()) result += 210; return result; } function cal_showMonth (frame,month, year) { calendarTxt = ""; if (this.getShowMonth ()) calendarTxt = this.createMonth (frame,month, year) if (this.getShowClock ()) calendarTxt += this.createClock (); return calendarTxt; } function cal_init () { if (0 < IEVersion () && IEVersion () <= 600) return; var frame = GetObjectByRef ("Calendar"); if (frame == null) { var css = document.createElement('link'); css.rel = "stylesheet"; css.type = "text/css"; css.href = escape (this.rootPath + "calendar.css"); //css.href = "data:text/css,'+escape(styles); GetElementsByTagName ("head")[0].appendChild (css); var body = GetElementsByTagName ("body") [0]; frame = document.createElement("div"); frame = body.appendChild (frame); SetAttribute (frame, "id", "Calendar"); SetClassName (frame, "calendarFrame"); frame.style.display = "none"; } } function cal_open6 () { var str_datetime = this.parent.value; activeCalendar = this; if (str_datetime) this.current = str_datetime; else this.current = this.parent.value; width = 0; if (this.getShowMonth ()) width = 340; if (this.getShowClock ()) width += 200; height = 250; if (this.getFastConfirm ()) height = 180; var obj_calwindow = open (this.rootPath + "calendar.htm", "calendar", "titlebar=no, menubar=no, height=" + height + ", width=" + width); obj_calwindow.opener = this; obj_calwindow.focus(); } function cal_open (obj) { this.parent = obj; if (0 < IEVersion () && IEVersion () <= 600) { this.open6 (); return; } this.init (); var frame = GetObjectByRef ("Calendar"); if (frame == null) return; if (frame.style.display == "none") { if (activeCalendar) activeCalendar.close (); activeCalendar = this; width = this.getMonthWidth (); frame.style.width = width + "px"; frame.style.height = "160px"; var refObj = this.parent; var str_datetime = refObj.innerHTML; if (str_datetime == "") str_datetime = refObj.value; if (str_datetime) { var re = /[\/\-\: ]/; var p = str_datetime.split (re); if (p.length > 4) this.current = new Date (p [2], p [1] - 1, p[0], p[3], p[4]); else if (p.length > 2) this.current = new Date (p [2], p [1] - 1, p[0]); else this.current = new Date (); } else this.current = new Date (); if (this.current.getYear ().toString () == "NaN" ) this.current = new Date (); frame.innerHTML = this.doShowMonth (refObj.tagName, this.current.getMonth () + 1, this.current.getFullYear ()); var co = FindObjectPos (refObj); frame.style.display="inline"; frame.style.top = (co[1] + refObj.offsetHeight) + 'px'; var left = co [0]; if (0 < IEVersion () && IEVersion () < 700) left = (co[0] - frame.offsetWidth + refObj.offsetParent.offsetWidth); var iw = window.innerWidth, totalWidth = this.getTotalWidth (); if (left + totalWidth > iw) left = left + refObj.clientWidth - totalWidth; frame.style.left = left + 'px'; if (left < 0) frame.style.left = "0px"; } else this.close (); } function cal_close () { var frame = GetObjectByRef ("Calendar"); if (frame == null) return; frame.style.display = "none"; activeCalendar = null; if (this.afterclose) this.afterclose(this); } function cal_isOpen () { var frame = GetObjectByRef ("Calendar"); if (frame == null) return false; return frame.style.display != "none"; } function showMonth (parentID,month, year) { var frame = GetObjectByRef ("Calendar"); frame.innerHTML = activeCalendar.doShowMonth (parentID, month, year); } function cal_showPressed (o) { if (cal_imgDown) o.src = cal_imgDown.src; } function cal_showRelease (o) { if (cal_imgUp) o.src = cal_imgUp.src; } function cal_onblur (o, param) { if (this.afterblur) this.afterblur (o, param) } function initCalendarEvents () { if (cal_isInitEvents) return; cal_isInitEvents = true; var imgs = GetElementsByTagName ("img"); var i, c = imgs.length; for (i = 0; i < c; ++i) { var img = imgs [i]; if (img.src.indexOf ("cal.gif") >= 0) { if (cal_imgDown == null) { var pos = img.src.indexOf ("cal.gif"); cal_imgUp = new Image (); cal_imgUp.src = img.src; cal_imgDown = new Image (); cal_imgDown.src = img.src.substr (0, pos) + "cald.gif"; } // if SetAttribute (img, "onmouseover", "cal_showPressed (this);"); SetAttribute (img, "onmouseout", "cal_showRelease (this);"); } // if } // for //cal_init (); }