PageSourceSearch

https://cientia.unizar.es/cientia-unizar-jsf/js/calendar/popcalendar.js

js unizar.es collected 2026-09-24 08:29:41 UTC 59,146 bytes, 1,675 lines download raw bytes

1//    based on code written by Tan Ling Wee on 2 Dec 2001
2//    last updated 20 June 2003
3//    email :    [email protected]
4//
5// Modified to be completely object-oriented, CSS based and using proper DOM-access functions
6// @author Martin Marinschek
7// @author Sylvain Vieujot
8
9
10org_apache_myfaces_CalendarInitData = function()
11{
12    // x position (-1 if to appear below control)
13    this.fixedX = -1;
14
15    // y position (-1 if to appear below control)
16    this.fixedY = -1;
17
18    // 0 - sunday ; 1 - monday (aka firstDayOfWeek)
19    this.startAt = 1;
20
21    // 0 - don't show; 1 - show
22    this.showWeekNumber = 1;
23
24    // 0 - don't show; 1 - show
25    this.showToday = 1;
26
27    // directory for images ... e.g. this.imgDir="/img/"
28    this.imgDir = "images/";
29
30    this.themePrefix = "jscalendar-DB";
31
32    this.gotoString = "Go To Current Month";
33    this.todayString = "Today is";
34    this.todayDateFormat = null;
35    this.weekString = "Wk";
36    this.scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically.";
37    this.scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically."
38    this.selectMonthMessage = "Click to select a month."
39    this.selectYearMessage = "Click to select a year."
40    this.selectDateMessage = "Select [date] as date." // do not replace [date], it will be replaced by date.
41
42    this.popupLeft=false;
43
44    this.monthName = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
44November", "December");
45    this.dayName = this.startAt == 0 ? new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat") : new Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");
46
47    this.selectMode = "day";
48}
49
50org_apache_myfaces_DateParts = function(sec, min, hour, date, month, year)
51{
52    this.sec = sec;
53    this.min = min;
54    this.hour = hour;
55    this.date = date;
56    this.month = month;
57    this.year = year;
58}
59
60org_apache_myfaces_HolidayRec = function(d, m, y, desc)
61{
62    this.d = d;
63    this.m = m;
64    this.y = y;
65    this.desc = desc;
66}
67
68org_apache_myfaces_PopupCalendar = function()
69{
70    this.idPrefix = "org_apache_myfaces_PopupCalendar";
71
72    this.selectedDate = new org_apache_myfaces_DateParts(0, 0, 0, 0, 0, 0);
73    this.saveSelectedDate = new org_apache_myfaces_DateParts(0, 0, 0, 0, 0, 0);
74
75    this.monthConstructed = false;
76    this.yearConstructed = false;
77    this.intervalID1;
78    this.intervalID2;
79    this.timeoutID1;
80    this.timeoutID2;
81    this.ctlToPlaceValue;
82    this.ctlNow;
83    this.containerCtl;
84    this.dateFormat="MM/dd/yyyy";
85    this.nStartingYear;
86    this.bPageLoaded = false;
87
88    // Detect whether the browser is Microsoft Internet Explorer.
89    // Testing for the presence of document.all is not sufficient, as Opera provides that.
90    // However hopefully nothing but IE implements ActiveX..
91    this.ie = window.ActiveXObject ? true : false;
92
93    this.dom = document.getElementById;
94    this.ns4 = document.layers;
95    this.dateFormatSymbols = new org_apache_myfaces_dateformat_DateFormatSymbols();
96    this.initData = new org_apache_myfaces_CalendarInitData();
97    this.today = new Date();
98    this.dateNow = this.today.getDate();
99    this.monthNow = this.today.getMonth();
100    this.yearNow = this.today.getYear();
101
102    // list of images to be preloaded from the server
103    this.imgSrc = new Array("drop1.gif", "drop2.gif", "left1.gif", "left2.gif", "right1.gif", "right2.gif");
104    this.img = new Array();
105
106    //elements which need to change their dynamical
107    //representation over time
108    this.calendarDiv;
109    this.selectMonthDiv;
110    this.selectYearDiv;
111    this.todaySpan = null;
112    this.captionSpan = null;
113    this.contentSpan = null;
114    this.acceptMonthSpan = null;
115    this.closeCalendarSpan = null;
116    this.monthSpan = null;
117    this.yearSpan = null
118    this.changeMonthImg = null;
119    this.changeYearImg = null;
120
121    this.holidaysCounter = 0;
122    this.holidays = new Array();
123
124    this.bClickOnCalendar = false;
125    this.bCalendarHidden = true;
126
127    this.myFacesCtlType = "x:inputCalendar";
128    this.inputDateClientId;
129}
130
131org_apache_myfaces_PopupCalendar.prototype._MSECS_PER_DAY = 24*60*60*1000;
132
133/**
134popups always have to be
135at the dom level nowhere else
136*/
137org_apache_myfaces_PopupCalendar.prototype._fixPopupDomOrder = function(overDiv) {
138    if(document.body != overDiv.parentNode) {
139        overDiv.parentNode.removeChild(overDiv);
140        document.body.appendChild(overDiv);
141    }
142};
143
144// IE bug workaround: hide background controls under the specified div.
145org_apache_myfaces_PopupCalendar.prototype._showPopupPostProcess = function(overDiv)
146{
147
148
149    if (this.ie)
150    {
151        // The iframe created here is a hack to work around an IE bug. In IE,
152        // "windowed controls" (esp selectboxes) do not respect the z-index
153        // setting of "non-windowed controls", meaning they will be drawn on
154        // top of components that they should theoretically be underneath.
155        // However a selectbox will NOT be drawn on top of an iframe, so the
156        // workaround is to create an iframe with no content, then in function
157        // _recalculateElement position the iframe under the "popup" div to
158        // "mask out" the unwanted elements.
159        var iframe = document.getElementById(overDiv.id + "_IFRAME");
160
161        if (iframe == null)
162        {
163            // the source attribute is to avoid a IE error message about non secure content on https connections
164            iframe = document.createElement(
165            "<iframe"
166            + " src='javascript:false;'"
167            + " id='" + overDiv.id + "_IFRAME'"
168            + " style='visibility:hidden; position: absolute; top:0px;left:0px;'"
169            + "/>");
170            //we can append it lazily since we are late here anyway and everything is rendered
171            document.body.appendChild(iframe);
172        }
173
174        // now put the iframe at the appropriate location, and make it visible.
175        this._recalculateElement(overDiv);
176    }
177}
178
179// IE bug workaround: hide background controls under the specified div; see _showPopupPostProcess.
180// This should be called whenever a popup div is moved.
181org_apache_myfaces_PopupCalendar.prototype._recalculateElement = function(overDiv)
182{
183    if (this.ie)
184    {
185        var iframe = document.getElementById(overDiv.id + "_IFRAME");
186
187        if (iframe)
188        {
189            // ok, there is a "masking iframe" associated with this div, so make its
190            // size and position match the div exactly, and set its z-index to 
190just
191            // below the div. This hack blocks IE selectboxes from being drawn on top
192            // of the div.
193            var popup = overDiv;
194
195            popup.style.zIndex = 98;
196
197            iframe.style.zIndex = popup.style.zIndex - 1;
198            iframe.style.width = popup.offsetWidth;
199            iframe.style.height = popup.offsetHeight;
200            iframe.style.top = popup.style.top;
201            iframe.style.left = popup.style.left;
202            iframe.style.display = "block";
203            iframe.style.visibility = "visible";
204            /*we have to set an explicit visible otherwise it wont work*/
205        }
206    }
207}
208
209// IE bug workaround: unhide background controls that are beneath the specified div; see _showPopupPostProcess.
210// Note that although this is called _showeElement, it is called when the popup is being *hidden*,
211// in order to *show* the underlying controls again.
212// we also reallign the floating div
213org_apache_myfaces_PopupCalendar.prototype._hidePopupPostProcess = function(overDiv)
214{
215
216
217    if (this.ie)
218    {
219        var iframe = document.getElementById(overDiv.id + "_IFRAME");
220        if (iframe) iframe.style.display = "none";
221    }
222}
223
224org_apache_myfaces_PopupCalendar.prototype.addHoliday = function(d, m, y, desc)
225{
226    this.holidays[this.holidaysCounter++] = new org_apache_myfaces_HolidayRec (d, m, y, desc);
227}
228
229org_apache_myfaces_PopupCalendar.prototype._swapImage = function(srcImg, destImg)
230{
231
232    if (srcImg)
233        srcImg.setAttribute("src", this.initData.imgDir + destImg);
234}
235
236org_apache_myfaces_PopupCalendar.prototype._keypresshandler = function()
237{
238    // This method is intended for use on IE browsers only; they are the only
239    // browsers that define window.event and window.event.keyCode.
240    // Q: Why is this done only for IE?
241    if (window["event"] && window.event["keyCode"] && (window.event.keyCode == 27))
242    {
243        this._hideCalendar();
244    }
245}
246
247org_apache_myfaces_PopupCalendar.prototype._clickhandler = function()
248{
249    if (!this.bClickOnCalendar)
250    {
251        this._hideCalendar();
252    }
253
254    this.bClickOnCalendar = false;
255}
256
257org_apache_myfaces_PopupCalendar.prototype._isDaySelectable = function()
258{
259return (this.initData.selectMode == "day");
260}
261
262org_apache_myfaces_PopupCalendar.prototype._isWeekSelectable = function()
263{
264return (this.initData.selectMode == "week");
265}
266
267org_apache_myfaces_PopupCalendar.prototype._isMonthSelectable = function()
268{
269return (this.initData.selectMode == "month");
270}
271
272org_apache_myfaces_PopupCalendar.prototype.init = function(containerCtl)
273{
274    if (this.dom)
275    {
276
277        if (!this.calendarDiv)
278        {
279            for (var i = 0; i < this.imgSrc.length; i++)
280            {
281                // force preload of all images, so that when DOM nodes have their src set to
282                // the name of this image, it has already been loaded from the server.
283                this.img[i] = new Image;
284                this.img[i].src = this.initData.imgDir + this.imgSrc[i];
285            }
286
287            this.containerCtl = containerCtl;
288
289            this.calendarDiv = document.createElement("div");
290            this.calendarDiv.id = containerCtl.id + "_calendarDiv";
291            this.calendarDiv.className = this.initData.themePrefix + "-div-style";
292
293            Event.observe(this.calendarDiv, "click", function()
294            {
295                this.bClickOnCalendar = true;
296            }.bind(this), false);
297
298            this.containerCtl.appendChild(this.calendarDiv);
299
300            var mainTable = document.createElement("table");
301            mainTable.className = this.initData.themePrefix + "-table-" + ((this.initData.showWeekNumber == 1)?"show":"hide") + "-week-style";
302
303            this.calendarDiv.appendChild(mainTable);
304
305            //This is necessary for IE. If you don't create a tbody element, the table will never show up!
306            var mainBody = document.createElement("tbody");
307            mainTable.appendChild(mainBody);
308
309            var mainRow = document.createElement("tr");
310            mainRow.className = this.initData.themePrefix + "-title-background-style";
311
312            mainBody.appendChild(mainRow);
313
314            var mainCell = document.createElement("td");
315
316            mainRow.appendChild(mainCell);
317
318            var contentTable = document.createElement("table");
319            contentTable.className = this.initData.themePrefix + "-content-table-" + ((this.initData.showWeekNumber == 1)?"show":"hide") + "-week-style";
320
321            var contentBody = document.createElement("tbody");
322            contentTable.appendChild(contentBody);
323
324            mainCell.appendChild(contentTable);
325
326            var headerRow = document.createElement("tr");
327            contentBody.appendChild(headerRow);
328
329            var captionCell = document.createElement("td");
330            captionCell.className = this.initData.themePrefix + "-title-style";
331            headerRow.appendChild(captionCell);
332
333            this.captionSpan = document.createElement("span");
334            captionCell.appendChild(this.captionSpan);
335
336            if (this._isMonthSelectable())
337            {
338                var acceptMonthCell = document.createElement("td");
339                acceptMonthCell.className = this.initData.themePrefix + "-cell-style";
340                headerRow.appendChild(acceptMonthCell);
341
342                var acceptMonthLink = document.createElement("a");
343                acceptMonthLink.setAttribute("href", "#");
344                Event.observe(acceptMonthLink, "click", function(event)
345                {
346                    this.selectedDate.date = 1; // force first of the selected month
347                    this._closeCalendar();
348                    Event.stop(event);
349                }.bindAsEventListener(this), false);
350
351                acceptMonthCell.appendChild(acceptMonthLink);
352                this.acceptMonthSpan = document.createElement("span");
353                this.acceptMonthSpan.appendChild(document.createTextNode("Y"));
354
355                acceptMonthLink.appendChild(this.acceptMonthSpan);
356            }
357
358            var closeButtonCell = document.createElement("td");
359            closeButtonCell.className = this.initData.themePrefix + "-close-style";
360            headerRow.appendChild(closeButtonCell);
361
362            var closeCalendarLink = document.createElement("a");
363            closeCalendarLink.setAttribute("href", "#");
364            Event.observe(closeCalendarLink, "click", function(event)
365            {
366                this._hideCalendar();
367                Event.stop(event);
368            }.bindAsEventListener(this), false);
369
370            closeButtonCell.appendChild(closeCalendarLink);
371
372            this.closeCalendarSpan = document.createElement("span");
373
374            closeCalendarLink.appendChild(this.closeCalendarSpan);
375
376            var contentRow = document.createElement("tr");
377            mainBody.appendChild(contentRow);
378
379            var contentCell = document.createElement("td");
380            contentCell.className = this.initData.themePrefix + "-body-style";
381            contentRow.appendChild(contentCell);
382
383            this.contentSpan = document.createElement("span");
384            contentCell.appendChild(this.contentSpan);
385
386            if (this.initData.showToday == 1)
387            {
388                var todayRow = document.createElement("tr");
389                todayRow.className = this.initData.themePrefix + "-today-style";
390                mainBody.appendChild(todayRow);
391
392                var todayCell = document.createElement("td");
393                todayCell.className = this.initData.themePrefix + "-today-lbl-style";
394                todayRow.appendChild(todayCell);
395
396                this.todaySpan = document.createElement("span");
397                todayCell.appendChild(this.todaySpan);
398            }
399
400            this.selectMonthDiv = document.createElement("div");
401            this.selectMonthDiv.id = this.containerCtl.id + "_selectMonthDiv";
402            this.selectMonthDiv.className = this.initData.themePrefix + "-div-style";
403
404            this.containerCtl.appendChild(this.selectMonthDiv);
405
406            this.selectYearDiv = document.createElement("div");
407            this.selectYearDiv.id = this.containerCtl.id + "_selectYearDiv";
408            this.selectYearDiv.className = this.initData.themePrefix + "-div-style";
409
410            this.containerCtl.appendChild(this.selectYearDiv);
411
412            // Catch global keypresses and clicks, so that entering data into any field
413            // outside the calendar, or clicking anywhere outside the calendar, will
414            // close it.
415            //
416            // This is ugly, as it's quite a load on the client to check this for every
417            // keystroke/click. It would be nice to find an alternative...maybe register
418            // these listeners only when a calendar is open?
419            Event.observe(document, "keypress", this._keypresshandler.bind(this), false);
420            Event.observe(document, "click", this._clickhandler.bind(this), false);
421        }
422    }
423
424
425    if (!this.ns4)
426    {
427        if (!this.ie)
428            this.yearNow += 1900;
429
430        this._hideCalendar();
431
432        this.monthConstructed = false;
433        this.yearConstructed = false;
434
435        if (this.initData.showToday == 1)
436        {
437            // TODO this.dateFormatSymbols is probably never set at this point.
438            this.todayDateFormatter = new org_apache_myfaces_dateformat_SimpleDateFormatter(
439                this.initData.todayDateFormat? this.initData.todayDateFormat:this.dateFormat,
440                this.dateFormatSymbols,
441                this.initData.startAt);
442
443            this.todaySpan.appendChild(document.createTextNode(this.initData.todayString + " "))
444
445            var todayLink = document.createElement("a");
446            todayLink.className = this.initData.themePrefix + "-today-style";
447            todayLink.setAttribute("title", this.initData.gotoString);
448            todayLink.setAttribute("href", "#")
449            todayLink.appendChild(document.createTextNode(this._todayIsDate(
449)));
450            Event.observe(todayLink, "click", function(event)
451            {
452                this.selectedDate.month = this.monthNow;
453                this.selectedDate.year = this.yearNow;
454                this._constructCalendar();
455                Event.stop(event);
456            }.bindAsEventListener(this), false);
457            Event.observe(todayLink, "mousemove", function()
458            {
459                window.status = this.initData.gotoString;
460            }.bind(this), false);
461            Event.observe(todayLink, "mouseout", function()
462            {
463                window.status = "";
464            }.bind(this), false);
465
466            this.todaySpan.appendChild(todayLink);
467        }
468
469        this._appendNavToCaption("left");
470        this._appendNavToCaption("right");
471
472        this.monthSpan = document.createElement("span");
473        this.monthSpan.className = this.initData.themePrefix + "-title-control-normal-style";
474
475        Event.observe(this.monthSpan, "mouseover", function(event)
476        {
477            this._swapImage(this.changeMonthImg, "drop2.gif");
478            this.monthSpan.className = this.initData.themePrefix + "-title-control-select-style";
479            window.status = this.selectMonthMessage;
480        }.bindAsEventListener(this), false);
481
482        Event.observe(this.monthSpan, "mouseout", function(event)
483        {
484            this._swapImage(this.changeMonthImg, "drop1.gif");
485            this.monthSpan.className = this.initData.themePrefix + "-title-control-normal-style";
486            window.status = "";
487        }.bindAsEventListener(this), false);
488
489        Event.observe(this.monthSpan, "click", function(event)
490        {
491            this._popUpMonth();
492            Event.stop(event);
493        }.bind(this), false);
494
495        this.captionSpan.appendChild(this.monthSpan);
496        this._appendNbsp(this.captionSpan);
497
498        this.yearSpan = document.createElement("span");
499        this.yearSpan.className = this.initData.themePrefix + "-title-control-normal-style";
500
501        Event.observe(this.yearSpan, "mouseover", function(event)
502        {
503            this._swapImage(this.changeYearImg, "drop2.gif");
504            this.yearSpan.className = this.initData.themePrefix + "-title-control-select-style";
505            window.status = this.selectYearMessage;
506        }.bindAsEventListener(this), false);
507
508        Event.observe(this.yearSpan, "mouseout", function(event)
509        {
510            this._swapImage(this.changeYearImg, "drop1.gif");
511            this.yearSpan.className = this.initData.themePrefix + "-title-control-normal-style";
512            window.status = "";
513        }.bindAsEventListener(this), false);
514
515        Event.observe(this.yearSpan, "click", function(event)
516        {
517            this._popUpYear();
518            Event.stop(event);
519        }.bind(this), false);
520
521        this.captionSpan.appendChild(this.yearSpan);
522        this._appendNbsp(this.captionSpan);
523
524        this.bPageLoaded = true;
525
526    }
527}
528
529org_apache_myfaces_PopupCalendar.prototype._appendNavToCaption = function(direction)
530{
531    var imgLeft = document.createElement("img");
532    imgLeft.setAttribute("src", this.initData.imgDir + direction + "1.gif");
533    imgLeft.setAttribute("width","10px");
534    imgLeft.setAttribute("height","11px");
535    imgLeft.className = this.initData.themePrefix + "-img-style";
536
537    var spanLeft = document.createElement("span");
538
539    this._createControl(direction, spanLeft, imgLeft);
540
541    this._appendNbsp(spanLeft);
542    spanLeft.appendChild(imgLeft);
543    this._appendNbsp(spanLeft);
544    this.captionSpan.appendChild(spanLeft);
545    this._appendNbsp(spanLeft);
546}
547
548org_apache_myfaces_PopupCalendar.prototype._createControl = function(direction, spanLeft, imgLeft)
549{
550    spanLeft.className = this.initData.themePrefix + "-title-control-normal-style";
551    Event.observe(spanLeft, "mouseover", function(event)
552    {
553        this._swapImage(imgLeft, direction + "2.gif");
554        spanLeft.className = this.initData.themePrefix + "-title-control-select-style";
555        if (direction == "left")
556        {
557            window.status = this.scrollLeftMessage;
558        }
559        else
560        {
561            window.status = this.scrollRightMessage;
562        }
563    }.bindAsEventListener(this), false);
564    Event.observe(spanLeft, "click", function()
565    {
566        if (direction == "left")
567        {
568            this._decMonth();
569        }
570        else
571        {
572            this._incMonth();
573        }
574    }.bind(this), false);
575    Event.observe(spanLeft, "mouseout", function(event)
576    {
577        clearInterval(this.intervalID1);
578        this._swapImage(imgLeft, direction + "1.gif");
579        spanLeft.className = "" + this.initData.themePrefix + "-title-control-normal-style";
580        window.status = "";
581    }.bindAsEventListener(this), false);
582    Event.observe(spanLeft, "mousedown", function()
583    {
584        clearTimeout(this.timeoutID1);
585        this.timeoutID1 = setTimeout((function()
586        {
587            if (direction == "left")
588            {
589                this._startDecMonth();
590            }
591            else
592            {
593                this._startIncMonth();
594            }
595        }).bind(this), 500)
596    }.bind(this), false);
597    Event.observe(spanLeft, "mouseup", function()
598    {
599        clearTimeout(this.timeoutID1);
600        clearInterval(this.intervalID1);
601    }.bind(this), false);
602}
603
604org_apache_myfaces_PopupCalendar.prototype._appendNbsp = function(element)
605{
606    if (element)
607        element.appendChild(document.createTextNode(String.fromCharCode(160)));
608}
609
610org_apache_myfaces_PopupCalendar.prototype._todayIsDate = function()
611{
612    return this.todayDateFormatter.format(this.today);
613}
614
615org_apache_myfaces_PopupCalendar.prototype._hideCalendar = function()
616{
617    this.calendarDiv.style.visibility = "hidden"
618    this.bCalendarHidden = true;
619    if (this.selectMonthDiv.style != null)
620    {
621        this.selectMonthDiv.style.visibility = "hidden";
622    }
623    if (this.selectYearDiv.style != null)
624    {
625        this.selectYearDiv.style.visibility = "hidden";
626    }
627
628    this._hidePopupPostProcess(this.selectMonthDiv);
629    this._hidePopupPostProcess(this.selectYearDiv);
630    this._hidePopupPostProcess(this.calendarDiv);
631}
632
633org_apache_myfaces_PopupCalendar.prototype._padZero = function(num)
634{
635    return (num < 10)? '0' + num : num;
636}
637
638org_apache_myfaces_PopupCalendar.prototype._constructDate = function(d, m, y)
639{
640    var date = new Date(y, m, d, this.selectedDate.hour, this.selectedDate.min, this.selectedDate.sec);
641    return this.stdDateFormatter.format(date);
642}
643
644org_apache_myfaces_PopupCalendar.prototype._closeCalendar = function()
645{
646    this._hideCalendar();
647
648    if (this.myFacesCtlType != "x:inputDate")
649    {
650        this.ctlToPlaceValue.value = this._constructDate(this.selectedDate.date, this.selectedDate.month, this.selectedDate.year)
651        var onchange = this.ctlToPlaceValue.getAttribute("onchange");
652        if (onchange)
653        {
654            this.ctlToPlaceValue.onchange();
655        }
656    }
657    else
658    {
659        document.getElementById(this.myFacesInputDateClientId + ".day").value = this.selectedDate.date;
660        document.getElementById(this.myFacesInputDateClientId + ".month").value = this.selectedDate.month + 1;
661        document.getElementById(this.myFacesInputDateClientId + ".year").value = this.selectedDate.year;
662    }
663}
664
665/*** Month Pulldown ***/
666
667org_apache_myfaces_PopupCalendar.prototype._startDecMonth = function()
668{
669    this.intervalID1 = setInterval((function()
670    {
671        this._decMonth
672    }).bind(this), 80);
673}
674
675org_apache_myfaces_PopupCalendar.prototype._startIncMonth = function()
676{
677    this.intervalID1 = setInterval((function()
678    {
679        this._incMonth
680    }).bind(this), 80);
681}
682
683org_apache_myfaces_PopupCalendar.prototype._incMonth = function()
684{
685    this.selectedDate.month = this.selectedDate.month + 1;
686    if (this.selectedDate.month > 11)
687    {
688        this.selectedDate.month = 0;
689        this.selectedDate.year++;
690    }
691    this._constructCalendar();
692}
693
694org_apache_myfaces_PopupCalendar.prototype._decMonth = function()
695{
696    this.selectedDate.month = this.selectedDate.month - 1;
697    if (this.selectedDate.month < 0)
698    {
699        this.selectedDate.month = 11
700        this.selectedDate.year--
701    }
702    this._constructCalendar()
703}
704
705
706org_apache_myfaces_PopupCalendar.prototype._removeAllChildren = function(element)
707{
708    while (element && element.hasChildNodes())
709        element.removeChild(element.lastChild);
710}
711
712org_apache_myfaces_PopupCalendar.prototype._constructMonth = function()
713{
714    this._popDownYear();
715    if (!this.monthConstructed)
716    {
717
718        var selectMonthTable = document.createElement("table");
719        selectMonthTable.className = this.initData.themePrefix + "-dropdown-month-style";
720
721        this._removeAllChildren(this.selectMonthDiv);
722
723        this.selectMonthDiv.appendChild(selectMonthTable);
724
725        Event.observe(selectMonthTable, "mouseover", function()
726        {
727            clearTimeout(this.timeoutID1);
728        }.bind(this), false);
729        Event.observe(selectMonthTable, "mouseout", function(event)
730        {
731            clearTimeout(this.timeoutID1);
732            this.timeoutID1 = setTimeout((function()
733            {
734                this._popDownMonth()
735            }).bind(this), 100);
736            Event.stop(event);
737        }.bindAsEventListener(this), false);
738
739        var selectMonthTableBody = document.createElement("tbody");
740        selectMonthTable.appendChild(selectMonthTableBody);
741
742        for (i = 0; i < 12; i++)
743        {
744            var sName = this.initData.monthName[i];
745
746            var sNameNode = document.createTextNode(sName);
747
748            var monthRow = document.createElement("tr");
749            selectMonthTableBody.appendChild(monthRow);
750
751            var monthCell = document.createElement("td");
752            monthCell.setAttribute("userData",i);
753            if (i == this.selectedDate.month) {
754                monthCell.className = this.initData.themePrefix + "-bold-style";
755            }
756            monthRow.appendChild(monthCell);
757
758            Event.observe(monthCell, "mouseover", function(event)
759            {
760                var className = this.initData.themePrefix + "-dropdown-select-style";
761                var element = Event.element(event);
762                if (!Element.hasClassName(element, className)) {
763                    Element.addClassName(element, className);
764                }
765            }.bind(this), false);
766
767            Event.observe(monthCell, "mouseout", function(event)
768            {
769                var className = this.initData.themePrefix + "-dropdown-select-style";
770                var element = Event.element(event);
771                if (Element.hasClassName(element, className)) {
772                    Element.removeClassName(element, className);
773                }
774            }.bind(this), false);
775
776            Event.observe(monthCell, "click", function(event)
777            {
778                this.monthConstructed = false;
779                this.selectedDate.month = parseInt(Event.element(event).getAttribute("userData"),10);
780                this._constructCalendar();
781                this._popDownMonth();
782                Event.stop(event);
783            }.bindAsEventListener(this), false);
784
785            this._appendNbsp(monthCell);
786            monthCell.appendChild(sNameNode);
787            this._appendNbsp(monthCell);
788        }
789
790        this.monthConstructed = true;
791    }
792}
793
794org_apache_myfaces_PopupCalendar.prototype._popUpMonth = function()
795{
796    this._constructMonth()
797    this._fixPopupDomOrder(this.selectMonthDiv);
798    this.selectMonthDiv.style.visibility = (this.dom || this.ie)? "visible"    : "show"
799    this.selectMonthDiv.style.left = parseInt(this._formatInt(this.calendarDiv.style.left), 10) + 50 + "px";
800    this.selectMonthDiv.style.top = parseInt(this._formatInt(this.calendarDiv.style.top), 10) + 26 + "px";
801
802    this._showPopupPostProcess(this.selectMonthDiv);
803}
804
805org_apache_myfaces_PopupCalendar.prototype._popDownMonth = function()
806{
807    this.selectMonthDiv.style.visibility = "hidden";
808    this._hidePopupPostProcess(this.selectMonthDiv);
809}
810
811/*** Year Pulldown ***/
812
813org_apache_myfaces_PopupCalendar.prototype._incYear = function()
814{
815    for (i = 0; i < 7; i++)
816    {
817        newYear = (i + this.nStartingYear) + 1;
818
819        this._createAndAddYear(newYear, i);
820    }
821    this.nStartingYear++;
822    this.bClickOnCalendar = true;
823}
824
825org_apache_myfaces_PopupCalendar.prototype._createAndAddYear = function(newYear, i)
826{
827    var parentNode = document.getElementById(this.containerCtl.getAttribute("id")+"y" + i);
828
829    this._removeAllChildren(parentNode);
830
831    if (newYear == this.selectedDate.year)
832    {
833        this._appendNbsp(parentNode);
834        var newYearSpan = document.createElement("span");
835        newYearSpan.setAttribute("userData",newYear);
836        newYearSpan.appendChild(document.createTextNode(newYear));
837        parentNode.appendChild(newYearSpan);
838        this._appendNbsp(parentNode);
839    }
840    else
841    {
842        this._appendNbsp(parentNode);
843        parentNode.appendChild(document.createTextNode(newYear));
844        this._appendNbsp(parentNode);
845    }
846
847    parentNode.setAttribute("userData",newYear);
848}
849
850
851org_apache_myfaces_PopupCalendar.prototype._decYear = function()
852{
853    for (i = 0; i < 7; i++)
854    {
855        newYear = (i + this.nStartingYear) - 1;
856
857        this._createAndAddYear(newYear, i);
858    }
859    this.nStartingYear--;
860    this.bClickOnCalendar = true;
861}
862
863org_apache_myfaces_PopupCalendar.prototype._constructYear = function()
864{
865    this._popDownMonth();
866    var sHTML = "";
867    if (!this.yearConstructed)
868    {
869
870        var selectYearTable = document.createElement("table");
871        selectYearTable.className = this.initData.themePrefix + "-dropdown-year-style";
872
873        this._removeAllChildren(this.selectYearDiv);
874
875        this.selectYearDiv.appendChild(selectYearTable);
876
877        Event.observe(selectYearTable, "mouseover", function()
878        {
879            clearTimeout(this.timeoutID2);
880        }.bind(this), false);
881        Event.observe(selectYearTable, "mouseout", function(event)
882        {
883            clearTimeout(this.timeoutID2);
884            this.timeoutID2 = setTimeout((function()
885            {
886                this._popDownYear()
887            }).bind(this), 100);
888            Event.stop(event);
889        }.bindAsEventListener(this), false);
890
891
892        var selectYearTableBody = document.createElement("tbody");
893        selectYearTable.appendChild(selectYearTableBody);
894
895        var selectYearRowMinus = document.createElement("tr");
896        selectYearTableBody.appendChild(selectYearRowMinus);
897
898        var selectYearCellMinus = document.createElement("td");
899        selectYearCellMinus.setAttribute("align", "center");
900
901        selectYearCellMinus.appendChild(document.createTextNode("-"));
902
903        selectYearRowMinus.appendChild(selectYearCellMinus);
904
905        Event.observe(selectYearCellMinus, "mouseover", function(event)
906        {
907            Event.element(event).className = this.initData.themePrefix + "-dropdown-select-style";
908        }.bindAsEventListener(this), false);
909
910        Event.observe(selectYearCellMinus, "mouseout", function(event)
911        {
912            clearInterval(this.intervalID1);
913            Event.element(event).className = this.initData.themePrefix + "-dropdown-normal-style";
914        }.bindAsEventListener(this), false);
915
916        Event.observe(selectYearCellMinus, "mousedown", function(event)
917        {
918            clearInterval(this.intervalID1);
919            this.intervalID1 = setInterval((function()
920            {
921                this._decYear();
922            }).bind(this), 30);
923            Event.stop(event);
924        }.bindAsEventListener(this), false);
925
926        Event.observe(selectYearCellMinus, "mouseup", function(event)
927        {
928            clearInterval(this.intervalID1);
929            Event.stop(event);
930        }.bindAsEventListener(this), false);
931
932
933        //sHTML = "<tr><td align='center' onmouseover='this.className=\""+this.initData.themePrefix+"-dropdown-select-style\"' onmouseout='clearInterval(this.intervalID1); this.className=\""+this.initData.themePrefix+"-dropdown-normal-style\"' onmousedown='clearInterval(this.intervalID1);this.intervalID1=setInterval(\"_decYear()\",30)' onmouseup='clearInterval(this.intervalID1)'>-</td></tr>";
934
935        this.nStartingYear = this.selectedDate.year - 3;
936        var j = 0;
937        for (i = this.selectedDate.year - 3; i <= (this.selectedDate.year + 3); i++)
938        {
939            var sName = i;
940
941            var sNameNode = document.createTextNode(sName);
942
943            var yearRow = document.createElement("tr");
944            selectYearTableBody.appendChild(yearRow);
945
946            var yearCell = document.createElement("td");
947            yearCell.setAttribute("userData",sName);
948            yearCell.setAttribute("id",this.containerCtl.getAttribute("id")+"y" + j);
949            if (i == this.selectedDate.year) {
950                yearCell.className = this.initData.themePrefix + "-bold-style";
951            }
952            yearRow.appendChild(yearCell);
953
954            Event.observe(yearCell, "mouseover", function(event)
955            {
956                var className = this.initData.themePrefix + "-dropdown-select-style";
957                var element = Event.element(event);
958                if (!Element.hasClassName(element, className)) {
959                    Element.addClassName(element, className);
960                }
961            }.bind(this), false);
962
963            Event.observe(yearCell, "mouseout", function(event)
964            {
965                var className = this.initData.themePrefix + "-dropdown-select-style";
966                var element = Event.element(event);
967                if (Element.hasClassName(element, className)) {
968                    Element.removeClassName(element, className);
969                }
970            }.bind(this), false);
971
972            Event.observe(yearCell, "click", function(event)
973            {
974                var elem = Event.element(event);
975                var sYear = null;
976                this.selectedDate.year = parseInt(this._formatInt(elem.getAttribute("userData"),10));
977                this.yearConstructed = false;
978                this._popDownYear();
979                this._constructCalendar();
980                Event.stop(event);
981            }.bindAsEventListener(this), false);
982
983            this._appendNbsp(yearCell);
984            yearCell.appendChild(sNameNode);
985            this._appendNbsp(yearCell);
986            j++;
987        }
988
989        var selectYearRowPlus = document.createElement("tr");
990        selectYearTableBody.appendChild(selectYearRowPlus);
991
992        var selectYearCellPlus = document.createElement("td");
993        selectYearCellPlus.setAttribute("align", "center");
994
995        selectYearCellPlus.appendChild(document.createTextNode("+"));
996
997        selectYearRowPlus.appendChild(selectYearCellPlus);
998
999        Event.observe(selectYearCellPlus, "mouseover", function(event)
1000        {
1001            Event.element(event).className = this.initData.themePrefix + "-dropdown-select-style";
1002        }.bindAsEventListener(this), false);
1003
1004        Event.observe(selectYearCellPlus, "mouseout", function(event)
1005        {
1006            clearInterval(this.intervalID2);
1007            Event.element(event).className = this.initData.themePrefix + "-dropdown-normal-style";
1008        }.bindAsEventListener(this), false);
1009
1010        Event.observe(selectYearCellPlus, "mousedown", function(event)
1011        {
1012            clearInterval(this.intervalID2);
1013            this.intervalID2 = setInterval((function()
1014            {
1015                this._incYear();
1016            }).bind(this), 30);
1017        }.bindAsEventListener(this), false);
1018
1019        Event.observe(selectYearCellPlus, "mouseup", function(event)
1020        {
1021            clearInterval(this.intervalID2);
1022        }.bindAsEventListener(this), false);
1023
1024        this.yearConstructed = true;
1025    }
1026}
1027
1028org_apache_myfaces_PopupCalendar.prototype._popDownYear = function()
1029{
1030    clearInterval(this.intervalID1);
1031    clearTimeout(this.timeoutID1);
1032    clearInterval(this.intervalID2);
1033    clearTimeout(this.timeoutID2);
1034    this.selectYearDiv.style.visibility = "hidden";
1035    this._hidePopupPostProcess(this.selectYearDiv);
1036}
1037
1038org_apache_myfaces_PopupCalendar.prototype._popUpYear = function()
1039{
1040    var leftOffset;
1041    this._fixPopupDomOrder(this.selectYearDiv);
1042    this._constructYear();
1043    this.selectYearDiv.style.visibility = (this.dom || this.ie) ? "visible" : "show";
1044    leftOffset = parseInt(this._formatInt(this.calendarDiv.style.left), 10) + this.yearSpan.offsetLeft;
1045    if (this.ie)
1046        leftOffset += 6;
1047    this.selectYearDiv.style.left = leftOffset + "px";
1048    this.selectYearDiv.style.top = parseInt(this._formatInt(this.calendarDiv.style.top), 10) + 26 + "px";
1049
1050    this._showPopupPostProcess(this.selectYearDiv);
1051}
1052
1053org_apache_myfaces_PopupCalendar.prototype._appendCell = function(parentElement, value)
1054{
1055    var cell = document.createElement("td");
1056    cell.className = this.initData.themePrefix + "-cell-style";
1057
1058    if (value && value != "")
1059    {
1060        cell.appendChild(document.createTextNode(value));
1061    }
1062    else
1063    {
1064        this._appendNbsp(cell);
1065    }
1066
1067    parentElement.appendChild(cell);
1068}
1069
1070org_apache_myfaces_PopupCalendar.prototype._getDateStyle = function(datePointer)
1071{
1072    var sStyle = this.initData.themePrefix + "-normal-day-style";
1073    //regular day
1074
1075    if ((datePointer == this.dateNow) &&
1076        (this.selectedDate.month == this.monthNow) && (this.selectedDate.year == this.yearNow)) //today
1077    {
1078        sStyle = this.initData.themePrefix + "-current-day-style";
1079    }
1080    else if (dayPointer % 7 == (this.initData.startAt * -1) + 1) //end-of-the-week day
1081    {
1082        sStyle = this.initData.themePrefix + "-end-of-weekday-style";
1083    }
1084
1085    //selected day
1086    if ((datePointer == this.saveSelectedDate.date) &&
1087        (this.selectedDate.month == this.saveSelectedDate.month) &&
1088        (this.selectedDate.year == this.saveSelectedDate.year))
1089    {
1090        sStyle += " " + this.initData.themePrefix + "-selected-day-style";
1091    }
1092
1093    for (k = 0; k < this.holidaysCounter; k++)
1094    {
1095        if ((parseInt(this._formatInt(this.holidays[k].d), 10) == datePointer) && (parseInt(this._formatInt(this.holidays[k].m), 10) == (this.selectedDate.month + 1)))
1096        {
1097            if ((parseInt(this._formatInt(this.holidays[k].y), 10) == 0) || ((parseInt(this._formatInt(this.holidays[k].y), 10) == this.selectedDate.year) && (parseInt(this._formatInt(this.holidays[k].y), 10) != 0)))
1098            {
1099                sStyle += " " + this.initData.themePrefix + "-holiday-style";
1100            }
1101        }
1102    }
1103
1104    return sStyle;
1105}
1106
1107org_apache_myfaces_PopupCalendar.prototype._getHolidayHint = function(datePointer)
1108{
1109    var sHint = "";
1110    for (k = 0; k < this.holidaysCounter; k++)
1111    {
1112        if ((parseInt(this._formatInt(this.holidays[k].d), 10) == datePointer) && (parseInt(this._formatInt(this.holidays[k].m), 10) == (this.selectedDate.month + 1)))
1113        {
1114            if ((parseInt(this._formatInt(this.holidays[k].y), 10) == 0) || ((parseInt(this._formatInt(this.holidays[k].y), 10) == this.selectedDate.year) && (parseInt(this._formatInt(this.holidays[k].y), 10) != 0)))
1115            {
1116                sHint += sHint == ""?this.holidays[k].desc:"\n" + this.holidays[k].desc;
1117            }
1118        }
1119    }
1120
1121    return sHint;
1122}
1123
1124
1125org_apache_myfaces_PopupCalendar.prototype._addWeekCell = function(currentRow, startDate, weekSelectable,
1126    sNormalStyle, sSelectStyle)
1127{
1128    var cell = document.createElement("td");
1129    cell.className = this.initData.themePrefix + "-cell-style";
1130
1131    var weekDate = this.stdDateFormatter.getWeekDate(startDate);
1132    if (weekSelectable)
1133    {
1134        var link = document.createElement("a");
1135        link.className = sNormalStyle;
1136        link.sNormalStyle = sNormalStyle;
1137        link.sSelectStyle = sSelectStyle;
1138        link.setAttribute("href", "#");
1139        link.appendChild(document.createTextNode(weekDate.week + " "));
1140
1141        link.dateObj = this.stdDateFormatter.getDateForWeekDate(weekDate);
1142
1143        cell.appendChild(link);
1144
1145        Event.observe(link, "mousemove", function(event)
1146        {
1147            window.status = this.initData.selectDateMessage.replace(
1148                "[date]",
1149                this._constructDate(link.dateObj));
1150        }.bindAsEventListener(this), false);
1151
1152        Event.observe(link, "mouseout", function(event)
1153        {
1154            var elem = Event.element(event);
1155            elem.className = elem.sNormalStyle;
1156            window.status = "";
1157        }.bindAsEventListener(this), false);
1158
1159        Event.observe(link, "click", function(event)
1160        {
1161            var elem = Event.element(event);
1162            this.selectedDate.year = elem.dateObj.getFullYear();
1163            this.selectedDate.month = elem.dateObj.getMonth();
1164            this.selectedDate.date = elem.dateObj.getDate();
1165            this._closeCalendar();
1166            Event.stop(event);
1167        }.bindAsEventListener(this), false);
1168
1169        Event.observe(link, "mouseover", function(event)
1170        {
1171            var elem = Event.element(event);
1172            elem.className = elem.sSelectStyle;
1173        }.bindAsEventListener(this), false);
1174    }
1175    else
1176    {
1177        var span = document.createElement("span");
1178        span.className=sNormalStyle;
1179        span.appendChild(document.createTextNode(weekDate.week + " "));
1180        cell.appendChild(span);
1181    }
1182
1183    currentRow.appendChild(cell);
1184}
1185
1186org_apache_myfaces_PopupCalendar.prototype._constructCalendar = function()
1187{
1188    var aNumDays = Array(31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
1189
1190    var dateMessage;
1191    var startDate = new Date(this.selectedDate.year, this.selectedDate.month, 1);
1192
1193    if (this.selectedDate.month == 1)
1194    {
1195        // to compute the number of days in february, select first day of march,
1196        // subtract 24 hours then query the day-of-the-month.
1197        var msecs = new Date (this.selectedDate.year, this.selectedDate.month + 1, 1).getTime();
1198        var endDate = new Date (msecs - this._MSECS_PER_DAY);
1199        numDaysInMonth = endDate.getDate();
1200    }
1201    else
1202    {
1203        numDaysInMonth = aNumDays[this.selectedDate.month];
1204    }
1205
1206    datePointer = 0;
1207    dayPointer = startDate.getDay() - this.initData.startAt;
1208
1209    if (dayPointer < 0)
1210        dayPointer = 6;
1211
1212    this._removeAllChildren(this.contentSpan);
1213
1214    var contentTable = document.createElement("table");
1215    contentTable.className = this.initData.themePrefix + "-body-no-border-style";
1216
1217    this.contentSpan.appendChild(contentTable);
1218
1219    var contentBody = document.createElement("tbody");
1220    contentTable.appendChild(contentBody);
1221
1222    var contentRow = document.createElement("tr");
1223    contentBody.appendChild(contentRow);
1224
1225    if (this.initData.showWeekNumber == 1)
1226    {
1227        var showWeekNumberCell = document.createElement("td");
1228        showWeekNumberCell.className = this.initData.themePrefix + "-week-number-style";
1229
1230        contentRow.appendChild(showWeekNumberCell);
1231
1232        showWeekNumberCell.appendChild(document.createTextNode(this.initData.weekString));
1233
1234        var dividerCell = document.createElement("td");
1235        dividerCell.className = this.initData.themePrefix + "-week-divider-style";
1236        if(this.ie) //fix for https://issues.apache.org/jira/browse/TOMAHAWK-1184
1237            dividerCell.setAttribute("rowSpan", "7");
1238        else
1239            dividerCell.setAttribute("rowspan", "7");
1240        dividerCell.className = this.initData.themePrefix + "-weeknumber-div-style";
1241
1242        contentRow.appendChild(dividerCell);
1243
1244        var dividerImg = document.createElement("img");
1245        dividerImg.setAttribute("src", this.initData.imgDir + "divider.gif");
1246        dividerImg.className = this.initData.themePrefix + "-week-divider-style";
1247        dividerCell.appendChild(dividerImg);
1248    }
1249
1250    for (i = 0; i < 7; i++)
1251    {
1252        var dayNameCell = document.createElement("td");
1253        dayNameCell.className = this.initData.themePrefix + "-day-name-style";
1254        contentRow.appendChild(dayNameCell);
1255
1256        dayNameCell.appendChild(document.createTextNode(this.initData.dayName[i]));
1257    }
1258
1259    var currentRow = document.createElement("tr");
1260    contentBody.appendChild(currentRow);
1261
1262    var weekSelectable = this._isWeekSelectable();
1263    var sWeekNormalStyle = this.initData.themePrefix + "-normal-week-style";
1264    var sWeekSelectStyle = sWeekNormalStyle + " " + this.initData.themePrefix + "-would-be-selected-week-style";
1265
1266    if (this.initData.showWeekNumber == 1)
1267    {
1268        this._addWeekCell(currentRow, startDate, weekSelectable, sWeekNormalStyle, sWeekSelectStyle);
1269    }
1270
1271    for (var i = 1; i <= dayPointer; i++)
1272    {
1273        this._appendCell(currentRow);
1274    }
1275
1276    for (datePointer = 1; datePointer <= numDaysInMonth; datePointer++)
1277    {
1278        dayPointer++;
1279        var dateCell = document.createElement("td");
1280        dateCell.className = this.initData.themePrefix + "-cell-style";
1281
1282        currentRow.appendChild(dateCell);
1283
1284        var sStyle = this._getDateStyle(datePointer);
1285        var sHint = this._getHolidayHint(datePointer);
1286
1287        var sSelectStyle = sStyle + " " + this.initData.themePrefix + "-would-be-selected-day-style";
1288        var sNormalStyle = sStyle;
1289
1290        if (this._isDaySelectable())
1291        {
1292
1293            var dateLink = document.createElement("a");
1294            dateLink.className = sStyle;
1295            dateLink.setAttribute("href", "#");
1296            dateLink.setAttribute("title", sHint);
1297
1298            dateLink.sNormalStyle = sNormalStyle;
1299            dateLink.sSelectStyle = sSelectStyle;
1300            dateLink.datePointer = datePointer;
1301
1302            dateCell.appendChild(dateLink);
1303
1304            Event.observe(dateLink, "mousemove", function(event)
1305            {
1306                window.status = this.initData.selectDateMessage.replace("[date]", this._constructDate(datePointer, this.selectedDate.month, this.selectedDate.year));
1307            }.bindAsEventListener(this), false);
1308            Event.observe(dateLink, "mouseout", function(event)
1309            {
1310                var elem = Event.element(event);
1311                elem.className = elem.sNormalStyle;
1312                window.status = "";
1313            }.bindAsEventListener(this), false);
1314            Event.observe(dateLink, "click", function(event)
1315            {
1316                var elem = Event.element(event);
1317                this.selectedDate.date = elem.datePointer;
1318                this._closeCalendar();
1319                Event.stop(event);
1320            }.bindAsEventListener(this), false);
1321            Event.observe(dateLink, "mouseover", function(event)
1322            {
1323                var elem = Event.element(event);
1324                elem.className = elem.sSelectStyle;
1325            }.bindAsEventListener(this), false);
1326
1327            this._appendNbsp(dateLink);
1328            dateLink.appendChild(document.createTextNode(datePointer));
1329            this._appendNbsp(dateLink);
1330        }
1331        else
1332        {
1333            var dateSpan = document.createElement("span");
1334            dateCell.appendChild(dateSpan);
1335
1336            dateSpan.appendChild(document.createTextNode(datePointer));
1337            dateSpan.className = sStyle;
1338            dateSpan.setAttribute("title", sHint);
1339        }
1340
1341        if ((dayPointer + this.initData.startAt) % 7 == this.initData.startAt)
1342        {
1343            currentRow = document.createElement("tr");
1344            contentBody.appendChild(currentRow);
1345
1346            if ((this.initData.showWeekNumber == 1) && (datePointer < numDaysInMonth))
1347            {
1348                var startDate = new Date(this.selectedDate.year, this.selectedDate.month, datePointer + 1);
1349                this._addWeekCell(currentRow, startDate, weekSelectable, sWeekNormalStyle, sWeekSelectStyle);
1350            }
1351        }
1352    }
1353
1354    this._removeAllChildren(this.monthSpan);
1355
1356    this._appendNbsp(this.monthSpan);
1357    this.monthSpan.appendChild(document.createTextNode(this.initData.monthName[this.selectedDate.month]));
1358    this._appendNbsp(this.monthSpan);
1359
1360    this.changeMonthImg = document.createElement("img");
1361    this.changeMonthImg.setAttribute("src", this.initData.imgDir + "drop1.gif");
1362    this.changeMonthImg.setAttribute("width","12px");
1363    this.changeMonthImg.setAttribute("height","10px");
1364    this.changeMonthImg.className = this.initData.themePrefix + "-img-style";
1365
1366    this.monthSpan.appendChild(this.changeMonthImg);
1367
1368    // Year dropdown list (YYYY plus dropdown icon)
1369    this._removeAllChildren(this.yearSpan);
1370    this._appendNbsp(this.yearSpan);
1371    this.yearSpan.appendChild(document.createTextNode(this.selectedDate.year));
1372    this._appendNbsp(this.yearSpan);
1373    this.changeYearImg = document.createElement("img");
1374    this.changeYearImg.setAttribute("src", this.initData.imgDir + "drop1.gif");
1375    this.changeYearImg.setAttribute("width","12px");
1376    this.changeYearImg.setAttribute("height","10px");
1377    this.changeYearImg.className = this.initData.themePrefix + "-img-style";
1378    this.yearSpan.appendChild(this.changeYearImg);
1379
1380    // Accept Month icon
1381    if (this.acceptMonthSpan)
1382    {
1383    this._removeAllChildren(this.acceptMonthSpan);
1384    var acceptMonthImg = document.createElement("img");
1385    acceptMonthImg.setAttribute("src", this.initData.imgDir + "accept.gif");
1386    acceptMonthImg.setAttribute("width","15px");
1387    acceptMonthImg.setAttribute("height","13px");
1388    acceptMonthImg.className = this.initData.themePrefix + "-img-style";
1389    acceptMonthImg.setAttribute("alt", "Accept the current month selection");
1390    this.acceptMonthSpan.appendChild(acceptMonthImg);
1391    }
1392
1393    // Close Popup icon
1394    this._removeAllChildren(this.closeCalendarSpan);
1395    var closeButtonImg = document.createElement("img");
1396    closeButtonImg.setAttribute("src", this.initData.imgDir + "close.gif");
1397    closeButtonImg.setAttribute("width","15px");
1398    closeButtonImg.setAttribute("height","13px");
1399    closeButtonImg.className = this.initData.themePrefix + "-img-style";
1400    closeButtonImg.setAttribute("alt", "Close the calendar");
1401    this.closeCalendarSpan.appendChild(closeButtonImg);
1402
1403    this._recalculateElement(this.calendarDiv);
1404}
1405
1406org_apache_myfaces_PopupCalendar.prototype._popUpCalendar = function(ctl, ctl2, format)
1407{
1408    if (!this.bPageLoaded)
1409    {
1410        // The user has clicked a button before the initialisation of this
1411        // class has completed. Just ignore the click..
1412        return;
1413    }
1414
1415    if (this.calendarDiv.style.visibility == "hidden")
1416    {
1417        this.ctlToPlaceValue = ctl2;
1418        this.dateFormat = format;
1419
1420        this.stdDateFormatter = new org_apache_myfaces_dateformat_SimpleDateFormatter(
1421            this.dateFormat, this.dateFormatSymbols, this.initData.startAt);
1422        var dateSelected = this.stdDateFormatter.parse(ctl2.value);
1423
1424        if (dateSelected)
1425        {
1426            this.selectedDate.sec = dateSelected.getSeconds();
1427            this.selectedDate.min = dateSelected.getMinutes();
1428            this.selectedDate.hour = dateSelected.getHours();
1429            this.selectedDate.date = dateSelected.getDate();
1430            this.selectedDate.month = dateSelected.getMonth();
1431
1432            var yearStr = dateSelected.getYear() + "";
1433
1434            if (yearStr.length < 4)
1435            {
1436                yearStr = (parseInt(yearStr, 10) + 1900) + "";
1437            }
1438
1439            this.selectedDate.year = parseInt(yearStr, 10);
1440        }
1441        else
1442        {
1443            this.selectedDate.date = this.dateNow;
1444            this.selectedDate.month = this.monthNow;
1445            this.selectedDate.year = this.yearNow;
1446        }
1447
1448        this._popUpCalendar_Show(ctl);
1449    }
1450    else
1451    {
1452        this._hideCalendar();
1453        if (this.ctlNow != ctl)
1454        {
1455            this._popUpCalendar(ctl, ctl2, format);
1456        }
1457    }
1458    this.ctlNow = ctl;
1459}
1460
1461org_apache_myfaces_PopupCalendar.prototype._popUpCalendarForInputDate = function(clientId, format)
1462{
1463    if (this.bPageLoaded)
1464    {
1465        this.myFacesCtlType = "x:inputDate";
1466        this.myFacesInputDateClientId = clientId;
1467        this.dateFormat = format;
1468
1469        //Init stdDateFormatter
1470        this.stdDateFormatter = new org_apache_myfaces_dateformat_SimpleDateFormatter(
1471            this.dateFormat, this.dateFormatSymbols, this.initData.startAt);
1472
1473        this.selectedDate.date = document.getElementById(clientId + ".day").value != "" ? parseInt(this._formatInt(document.getElementById(clientId + ".day").value), 10) : this.dateNow;
1474        this.selectedDate.month = document.getElementById(clientId + ".month").value != "-1" ? parseInt(this._formatInt(document.getElementById(clientId + ".month").value), 10) - 1 : this.monthNow;
1475        this.selectedDate.year = document.getElementById(clientId + ".year").value != "" ? parseInt(this._formatInt(document.getElementById(clientId + ".year").value), 10) : this.yearNow;
1476        this.ctlNow = document.getElementById(clientId + ".day");
1477        this._popUpCalendar_Show(document.getElementById(clientId + ".day"));
1478    }
1479}
1480
1481org_apache_myfaces_PopupCalendar.prototype._getStyle = function(ctl, property)
1482{
1483    var value = null;
1484
1485    // local style
1486    if (ctl.style[property]) {
1487    value = ctl.style[property];
1488    }
1489    // IE syntax
1490    else if (ctl.currentStyle && ctl.currentStyle[property]) {
1491    value = ctl.currentStyle[property];
1492    }
1493    // DOM syntax
1494    else if ( document.defaultView && document.defaultView.getComputedStyle ) {
1495    var computed = document.defaultView.getComputedStyle(ctl, '');
1496
1497    if (computed && computed.getPropertyValue(property)) {
1498        value = computed.getPropertyValue(property);
1499    }
1500    }
1501    return value;
1502}
1503
1504org_apache_myfaces_PopupCalendar.prototype._popUpCalendar_Show = function(ctl)
1505{
1506    this.saveSelectedDate.date = this.selectedDate.date;
1507    this.saveSelectedDate.month = this.selectedDate.month;
1508    this.saveSelectedDate.year = this.selectedDate.year;
1509
1510    var leftpos = 0;
1511    var toppos = 0;
1512
1513    var aTag = ctl;
1514    var aCSSPosition = null;
1515    var aTagPositioningisAbsolute = false;
1516    // Added try-catch to the next loop (MYFACES-870)
1517    try
1518    {
1519
1520        do {
1521            aTag = aTag.offsetParent;
1522            leftpos += aTag.offsetLeft;
1523            toppos += aTag.offsetTop;
1524        }
1525        while ((null != aTag.offsetParent ) && ('undefined' !=  aTag.offsetParent ) );
1526    }
1527    catch (ex)
1528    {
1529        // ignore
1530    }
1531
1532    var leftScrollOffset = 0;
1533    var topScrollOffset = 0;
1534
1535    aTag = ctl;
1536    // Added try-catch (MYFACES-870)
1537    try
1538    {
1539        do {
1540            if('undefined' != typeof(aTag.scrollLeft) && null != aTag.scrollLeft)
1541                leftScrollOffset += parseInt(aTag.scrollLeft);
1542            if('undefined' != typeof(aTag.scrollTop) && null != aTag.scrollTop)
1543                topScrollOffset += parseInt(aTag.scrollTop);
1544
1545            aTag = aTag.parentNode;
1546        }
1547        while((aTag.tagName.toUpperCase() != "BODY") && (aTag.tagName.toUpperCase() != "HTML"));
1548        //while ('undefined' != typeof(aTag) && null != aTag);
1549    }
1550    catch (ex)
1551    {
1552        // ignore
1553    }
1554    var bodyRect = this._getVisibleBodyRectangle();
1555    var cal = this.calendarDiv;
1556
1557    var top = 0;
1558    var left = 0
1559
1560    top = ctl.offsetTop + toppos - topScrollOffset + ctl.offsetHeight + 2;
1561    left = ctl.offsetLeft + leftpos - leftScrollOffset;
1562
1563    if(this.initData.popupLeft)
1564    {
1565        left-=cal.offsetWidth;
1566    }
1567
1568    if (left + cal.offsetWidth > bodyRect.right)
1569    {
1570        left = bodyRect.right - cal.offsetWidth;
1571    }
1572    if (top + cal.offsetHeight > bodyRect.bottom)
1573    {
1574        top = bodyRect.bottom - cal.offsetHeight;
1575    }
1576    if (left < bodyRect.left)
1577    {
1578        left = bodyRect.left;
1579    }
1580    if (top < bodyRect.top)
1581    {
1582        top = bodyRect.top;
1583    }
1584
1585    /*we have to remap the popup so that we can handle the positioning in a neutral way*/
1586    if(this.calendarDiv.parentNode != document.body) {
1587        this.calendarDiv.parentNode.removeChild(this.calendarDiv);
1588        document.body.appendChild(this.calendarDiv);
1589    }
1590
1591    this.calendarDiv.style.left = this.initData.fixedX == -1 ? left + "px": this.initData.fixedX;
1592    this.calendarDiv.style.top = this.initData.fixedY == -1 ? top + "px": this.initData.fixedY;
1593    this._constructCalendar(1, this.selectedDate.month, this.selectedDate.year);
1594
1595    this.calendarDiv.style.visibility = (this.dom || this.ie)? "visible" : "show";
1596    this.bCalendarHidden = false;
1597
1598    setTimeout((function()
1599    {
1600        this._showPopupPostProcess(this.calendarDiv);
1601    }).bind(this), 200);
1602
1603    this._showPopupPostProcess(this.calendarDiv);
1604
1605    this.bClickOnCalendar = true;
1606}
1607
1608org_apache_myfaces_PopupCalendar.prototype._getVisibleBodyRectangle = function()
1609{
1610    var visibleRect = new org_apache_myfaces_Rectangle();
1611
1612    if (window.pageYOffset != undefined)
1613    {
1614        //Most non IE
1615        visibleRect.top = window.pageYOffset;
1616        visibleRect.left = window.pageXOffset;
1617    }
1618    else if (document.body && document.body.scrollTop)
1619    {
1620        //IE 6 strict mode
1621        visibleRect.top = document.body.scrollTop;
1622        visibleRect.left = document.body.scrollLeft;
1623    }
1624    else if (document.documentElement && document.documentElement.scrollTop)
1625    {
1626        //Older IE
1627        visibleRect.top = document.documentElement.scrollTop;
1628        visibleRect.left = document.documentElement.scrollLeft;
1629    }
1630
1631    if (window.innerWidth != undefined)
1632    {
1633        //Most non-IE
1634        visibleRect.right = visibleRect.left + window.innerWidth;
1635        visibleRect.bottom = visibleRect.top + window.innerHeight;
1636    }
1637    else if (document.documentElement && document.documentElement.clientHeight)
1638    {
1639        //IE 6 strict mode
1640        visibleRect.right = visibleRect.left + document.documentElement.clientWidth;
1641        visibleRect.bottom = visibleRect.top + document.documentElement.clientHeight;
1642    }
1643    else if (document.body && document.body.clientHeight)
1644    {
1645        //IE 4 compatible
1646        visibleRect.right = visibleRect.left + document.body.clientWidth;
1647        visibleRect.bottom = visibleRect.top + document.body.clientHeight;
1648    }
1649    return visibleRect;
1650}
1651
1652function org_apache_myfaces_Rectangle()
1653{
1654    this.top = 0;
1655    this.left = 0;
1656    this.bottom = 0;
1657    this.right = 0;
1658}
1659
1660org_apache_myfaces_PopupCalendar.prototype._formatInt = function(str)
1661{
1662
1663    if (typeof str == 'string')
1664    {
1665
1666        //truncate 0 for number less than 10
1667        if (str.charAt && str.charAt(0) == "0")
1668        { // <----- Change, added str.charAt for method availability detection (MYFACES)
1669            return str.charAt(1);
1670        }
1671
1672    }
1673    return str;
1674
1675}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.