source: trunk/workflow/inc/report/includes/js/calendar.js @ 5307

Revision 5307, 54.5 KB checked in by pereira.jair, 12 years ago (diff)

Ticket #2416 - Inclusao da nova ferramenta de relatorios do workflow.

Line 
1/************************************************************************************************************
2JS Calendar
3Copyright (C) September 2006  DTHMLGoodies.com, Alf Magne Kalleland
4
5This library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Lesser General Public
7License as published by the Free Software Foundation; either
8version 2.1 of the License, or (at your option) any later version.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public
16License along with this library; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
19Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
20written by Alf Magne Kalleland.
21
22Alf Magne Kalleland, 2006
23Owner of DHTMLgoodies.com
24       
25************************************************************************************************************/   
26
27/* Update log:
28(C) www.dhtmlgoodies.com, September 2005
29
30Version 1.2, November 8th - 2005 - Added <iframe> background in IE
31Version 1.3, November 12th - 2005 - Fixed top bar position in Opera 7
32Version 1.4, December 28th - 2005 - Support for Spanish and Portuguese
33Version 1.5, January  18th - 2006 - Fixed problem with next-previous buttons after a month has been selected from dropdown
34Version 1.6, February 22nd - 2006 - Added variable which holds the path to images.
35Format todays date at the bottom by use of the todayStringFormat variable
36Pick todays date by clicking on todays date at the bottom of the calendar
37Version 2.0      May, 25th - 2006         - Added support for time(hour and minutes) and changing year and hour when holding mouse over + and - options. (i.e. instead of click)
38Version 2.1      July, 2nd - 2006         - Added support for more date formats(example: d.m.yyyy, i.e. one letter day and month).
39
40*/
41var languageCode = 'pt-br';
42
43var calendar_display_time = true;
44
45// Format of current day at the bottom of the calendar
46// [todayString] = the value of todayString
47// [dayString] = day of week (examle: mon, tue, wed...)
48// [UCFdayString] = day of week (examle: Mon, Tue, Wed...) ( First letter in uppercase)
49// [day] = Day of month, 1..31
50// [monthString] = Name of current month
51// [year] = Current year
52var todayStringFormat = '[todayString] [UCFdayString]. [day]. [monthString] [year]';
53var pathToImages = 'images/'; // Relative to your HTML file
54var speedOfSelectBoxSliding = 200; // Milliseconds between changing year and hour when holding mouse over "-" and "+" - lower value = faster
55var intervalSelectBox_minutes = 5; // Minute select box - interval between each option (5 = default)
56var calendar_offsetTop = 0; // Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
57var calendar_offsetLeft = 0; // Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
58var calendarDiv = false;
59
60var MSIE = false;
61var Opera = false;
62if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)MSIE=true;
63if(navigator.userAgent.indexOf('Opera')>=0)Opera=true;
64
65
66switch(languageCode){
67    case "pt-br":  /* Brazilian portuguese (pt-br) */
68        var monthArray = ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'];
69        var monthArrayShort = ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'];
70        var dayArray = ['Seg','Ter','Qua','Qui','Sex','S&aacute;b','Dom'];
71        var weekString = 'Sem.';
72        var todayString = 'Hoje &eacute;';
73    break;
74}
75
76var daysInMonthArray = [31,28,31,30,31,30,31,31,30,31,30,31];
77var currentMonth;
78var currentYear;
79var currentHour;
80var currentMinute;
81var calendarContentDiv;
82var returnDateTo;
83var returnFormat;
84var activeSelectBoxMonth;
85var activeSelectBoxYear;
86var activeSelectBoxHour;
87var activeSelectBoxMinute;
88
89var iframeObj = false;
90//// fix for EI frame problem on time dropdowns 09/30/2006
91var iframeObj2 =false;
92function EIS_FIX_EI1(where2fixit)
93{
94    if(!iframeObj2)return;
95    iframeObj2.style.display = 'block';
96    iframeObj2.style.height =document.getElementById(where2fixit).offsetHeight+1;
97    iframeObj2.style.width=document.getElementById(where2fixit).offsetWidth;
98    iframeObj2.style.left=getleftPos(document.getElementById(where2fixit))+1-calendar_offsetLeft;
99    iframeObj2.style.top=getTopPos(document.getElementById(where2fixit))-document.getElementById(where2fixit).offsetHeight-calendar_offsetTop;
100}
101
102function EIS_Hide_Frame()
103{
104    if(iframeObj2)iframeObj2.style.display = 'none';}
105    //// fix for EI frame problem on time dropdowns 09/30/2006
106    var returnDateToYear;
107    var returnDateToMonth;
108    var returnDateToDay;
109    var returnDateToHour;
110    var returnDateToMinute;
111
112    var inputYear;
113    var inputMonth;
114    var inputDay;
115    var inputHour;
116    var inputMinute;
117    var calendarDisplayTime = false;
118
119    var selectBoxHighlightColor = '#D60808'; // Highlight color of select boxes
120    var selectBoxRolloverBgColor = '#E2EBED'; // Background color on drop down lists(rollover)
121
122    var selectBoxMovementInProgress = false;
123    var activeSelectBox = false;
124
125function cancelCalendarEvent()
126{
127    return false;
128}
129function isLeapYear(inputYear)
130{
131    if(inputYear%400==0||(inputYear%4==0&&inputYear%100!=0)) return true;
132    return false;       
133}
134var activeSelectBoxMonth = false;
135var activeSelectBoxDirection = false;
136
137function highlightMonthYear()
138{
139    if(activeSelectBoxMonth)activeSelectBoxMonth.className='';
140    activeSelectBox = this;
141
142    if(this.className=='monthYearActive')
143    {
144        this.className='';     
145    }
146    else
147    {
148        this.className = 'monthYearActive';
149        activeSelectBoxMonth = this;
150    }
151
152    if(this.innerHTML.indexOf('-')>=0 || this.innerHTML.indexOf('+')>=0)
153    {
154        if(this.className=='monthYearActive')
155        selectBoxMovementInProgress = true;
156        else
157        selectBoxMovementInProgress = false;
158        if(this.innerHTML.indexOf('-')>=0)activeSelectBoxDirection = -1; else activeSelectBoxDirection = 1;     
159    }
160    else selectBoxMovementInProgress = false;
161}
162
163function showMonthDropDown()
164{
165    if(document.getElementById('monthDropDown').style.display=='block')
166    {
167        document.getElementById('monthDropDown').style.display='none'; 
168        //// fix for EI frame problem on time dropdowns 09/30/2006
169        EIS_Hide_Frame();
170    }
171    else
172    {
173        document.getElementById('monthDropDown').style.display='block';         
174        document.getElementById('yearDropDown').style.display='none';
175        document.getElementById('hourDropDown').style.display='none';
176        document.getElementById('minuteDropDown').style.display='none';
177        if (MSIE)
178        {
179            EIS_FIX_EI1('monthDropDown')
180        }
181        //// fix for EI frame problem on time dropdowns 09/30/2006
182    }
183}
184
185function showYearDropDown()
186{
187    if(document.getElementById('yearDropDown').style.display=='block')
188    {
189        document.getElementById('yearDropDown').style.display='none';
190        //// fix for EI frame problem on time dropdowns 09/30/2006
191        EIS_Hide_Frame();
192    }
193    else
194    {
195        document.getElementById('yearDropDown').style.display='block';
196        document.getElementById('monthDropDown').style.display='none';
197        document.getElementById('hourDropDown').style.display='none';
198        document.getElementById('minuteDropDown').style.display='none';
199        if (MSIE)
200        {
201            EIS_FIX_EI1('yearDropDown')
202        }
203        //// fix for EI frame problem on time dropdowns 09/30/2006
204    }
205}
206
207function showHourDropDown()
208{
209    if(document.getElementById('hourDropDown').style.display=='block')
210    {
211        document.getElementById('hourDropDown').style.display='none';   
212        //// fix for EI frame problem on time dropdowns 09/30/2006
213        EIS_Hide_Frame();
214    }
215    else
216    {
217        document.getElementById('hourDropDown').style.display='block'; 
218        document.getElementById('monthDropDown').style.display='none'; 
219        document.getElementById('yearDropDown').style.display='none';   
220        document.getElementById('minuteDropDown').style.display='none';
221        if (MSIE)
222        {
223            EIS_FIX_EI1('hourDropDown')
224        }
225        //// fix for EI frame problem on time dropdowns 09/30/2006
226    }
227
228}
229
230function showMinuteDropDown()
231{
232    if(document.getElementById('minuteDropDown').style.display=='block')
233    {
234        document.getElementById('minuteDropDown').style.display='none';
235        //// fix for EI frame problem on time dropdowns 09/30/2006
236        EIS_Hide_Frame();
237    }
238    else
239    {
240        document.getElementById('minuteDropDown').style.display='block';       
241        document.getElementById('monthDropDown').style.display='none'; 
242        document.getElementById('yearDropDown').style.display='none';   
243        document.getElementById('hourDropDown').style.display='none';   
244        if (MSIE)
245        {
246            EIS_FIX_EI1('minuteDropDown')
247        }
248        //// fix for EI frame problem on time dropdowns 09/30/2006
249    }
250}
251
252function selectMonth()
253{
254    document.getElementById('calendar_month_txt').innerHTML = this.innerHTML
255    currentMonth = this.id.replace(/[^\d]/g,'');
256    document.getElementById('monthDropDown').style.display='none';
257    //// fix for EI frame problem on time dropdowns 09/30/2006
258    EIS_Hide_Frame();
259    for(var no=0;no<monthArray.length;no++)
260    {
261        document.getElementById('monthDiv_'+no).style.color='';
262    }
263    this.style.color = selectBoxHighlightColor;
264    activeSelectBoxMonth = this;
265    writeCalendarContent();
266}
267
268function selectHour()
269{
270    document.getElementById('calendar_hour_txt').innerHTML = this.innerHTML
271    currentHour = this.innerHTML.replace(/[^\d]/g,'');
272    document.getElementById('hourDropDown').style.display='none';
273    //// fix for EI frame problem on time dropdowns 09/30/2006
274    EIS_Hide_Frame();
275    if(activeSelectBoxHour)
276    {
277        activeSelectBoxHour.style.color='';
278    }
279    activeSelectBoxHour=this;
280    this.style.color = selectBoxHighlightColor;
281    }
282
283function selectMinute()
284{
285    document.getElementById('calendar_minute_txt').innerHTML = this.innerHTML
286    currentMinute = this.innerHTML.replace(/[^\d]/g,'');
287    document.getElementById('minuteDropDown').style.display='none';
288    //// fix for EI frame problem on time dropdowns 09/30/2006
289    EIS_Hide_Frame();
290    if(activeSelectBoxMinute)
291    {
292        activeSelectBoxMinute.style.color='';
293    }
294    activeSelectBoxMinute=this;
295    this.style.color = selectBoxHighlightColor;
296    }
297
298
299function selectYear()
300{
301    document.getElementById('calendar_year_txt').innerHTML = this.innerHTML
302    currentYear = this.innerHTML.replace(/[^\d]/g,'');
303    document.getElementById('yearDropDown').style.display='none';
304    //// fix for EI frame problem on time dropdowns 09/30/2006
305    EIS_Hide_Frame();
306    if(activeSelectBoxYear)
307    {
308        activeSelectBoxYear.style.color='';
309    }
310    activeSelectBoxYear=this;
311    this.style.color = selectBoxHighlightColor;
312    writeCalendarContent();
313}
314
315function switchMonth()
316{
317    if(this.src.indexOf('left')>=0)
318    {
319        currentMonth=currentMonth-1;;
320        if(currentMonth<0)
321        {
322            currentMonth=11;
323            currentYear=currentYear-1;
324        }
325    }
326    else
327    {
328        currentMonth=currentMonth+1;;
329        if(currentMonth>11)
330        {
331            currentMonth=0;
332            currentYear=currentYear/1+1;
333        }
334    }
335    writeCalendarContent();
336}
337
338function createMonthDiv()
339{
340    var div = document.createElement('DIV');
341    div.className='monthYearPicker';
342    div.id = 'monthPicker';
343
344    for(var no=0;no<monthArray.length;no++)
345    {
346        var subDiv = document.createElement('DIV');
347        subDiv.innerHTML = monthArray[no];
348        subDiv.onmouseover = highlightMonthYear;
349        subDiv.onmouseout = highlightMonthYear;
350        subDiv.onclick = selectMonth;
351        subDiv.id = 'monthDiv_' + no;
352        subDiv.style.width = '56px';
353        subDiv.onselectstart = cancelCalendarEvent;             
354        div.appendChild(subDiv);
355        if(currentMonth && currentMonth==no)
356        {
357            subDiv.style.color = selectBoxHighlightColor;
358            activeSelectBoxMonth = subDiv;
359        }
360    }
361    return div;
362}
363
364function changeSelectBoxYear(e,inputObj)
365{
366    if(!inputObj)inputObj =this;
367    var yearItems = inputObj.parentNode.getElementsByTagName('DIV');
368    if(inputObj.innerHTML.indexOf('-')>=0)
369    {
370        var startYear = yearItems[1].innerHTML/1 -1;
371        if(activeSelectBoxYear)
372        {
373            activeSelectBoxYear.style.color='';
374        }
375    }
376    else
377    {
378        var startYear = yearItems[1].innerHTML/1 +1;
379        if(activeSelectBoxYear)
380        {
381            activeSelectBoxYear.style.color='';
382        }
383    }
384    for(var no=1;no<yearItems.length-1;no++)
385    {
386        yearItems[no].innerHTML = startYear+no-1;       
387        yearItems[no].id = 'yearDiv' + (startYear/1+no/1-1);   
388    }
389    if(activeSelectBoxYear)
390    {
391        activeSelectBoxYear.style.color='';
392        if(document.getElementById('yearDiv'+currentYear))
393        {
394            activeSelectBoxYear = document.getElementById('yearDiv'+currentYear);
395            activeSelectBoxYear.style.color=selectBoxHighlightColor;;
396        }
397    }
398}
399
400function changeSelectBoxHour(e,inputObj)
401{
402    if(!inputObj) inputObj = this;
403    var hourItems = inputObj.parentNode.getElementsByTagName('DIV');
404    if(inputObj.innerHTML.indexOf('-')>=0)
405    {
406        var startHour = hourItems[1].innerHTML/1 -1;
407        if(startHour<0)startHour=0;
408        if(activeSelectBoxHour)
409        {
410            activeSelectBoxHour.style.color='';
411        }
412    }
413    else
414    {
415        var startHour = hourItems[1].innerHTML/1 +1;
416        if(startHour>14)startHour = 14;
417        if(activeSelectBoxHour)
418        {
419            activeSelectBoxHour.style.color='';
420        }
421    }
422    var prefix = '';
423    for(var no=1;no<hourItems.length-1;no++)
424    {
425        if((startHour/1 + no/1) < 11)prefix = '0'; else prefix = '';
426        hourItems[no].innerHTML = prefix + (startHour+no-1);
427        hourItems[no].id = 'hourDiv' + (startHour/1+no/1-1);
428    }
429    if(activeSelectBoxHour)
430    {
431        activeSelectBoxHour.style.color='';
432        if(document.getElementById('hourDiv'+currentHour))
433        {
434            activeSelectBoxHour = document.getElementById('hourDiv'+currentHour);
435            activeSelectBoxHour.style.color=selectBoxHighlightColor;;
436        }
437    }
438}
439
440function updateYearDiv()
441{
442    var div = document.getElementById('yearDropDown');
443    var yearItems = div.getElementsByTagName('DIV');
444    for(var no=1;no<yearItems.length-1;no++)
445    {
446        yearItems[no].innerHTML = currentYear/1 -6 + no;
447        if(currentYear==(currentYear/1 -6 + no))
448        {
449            yearItems[no].style.color = selectBoxHighlightColor;
450            activeSelectBoxYear = yearItems[no];
451        }
452        else
453        {
454            yearItems[no].style.color = '';
455        }
456    }
457}
458
459function updateMonthDiv()
460{
461    for(no=0;no<12;no++)
462    {
463        document.getElementById('monthDiv_' + no).style.color = '';
464    }
465    document.getElementById('monthDiv_' + currentMonth).style.color = selectBoxHighlightColor;
466    activeSelectBoxMonth =      document.getElementById('monthDiv_' + currentMonth);
467}
468
469
470function updateHourDiv()
471{
472    var div = document.getElementById('hourDropDown');
473    var hourItems = div.getElementsByTagName('DIV');
474
475    var addHours = 0;
476    if((currentHour/1 -6 + 1)<0)
477    {
478        addHours = (currentHour/1 -6 + 1)*-1;
479    }
480    for(var no=1;no<hourItems.length-1;no++)
481    {
482        var prefix='';
483        if((currentHour/1 -6 + no + addHours) < 10)prefix='0';
484        hourItems[no].innerHTML = prefix +  (currentHour/1 -6 + no + addHours);
485        if(currentHour==(currentHour/1 -6 + no))
486        {
487            hourItems[no].style.color = selectBoxHighlightColor;
488            activeSelectBoxHour = hourItems[no];
489        }
490        else
491        {
492        hourItems[no].style.color = '';
493        }
494    }
495}
496
497function updateMinuteDiv()
498{
499    for(no=0;no<60;no+=intervalSelectBox_minutes)
500    {
501        var prefix = '';
502        if(no<10)prefix = '0';
503        document.getElementById('minuteDiv_' + prefix + no).style.color = '';
504    }
505    if(document.getElementById('minuteDiv_' + currentMinute))
506    {
507        document.getElementById('minuteDiv_' + currentMinute).style.color = selectBoxHighlightColor;
508        activeSelectBoxMinute = document.getElementById('minuteDiv_' + currentMinute);
509    }
510}
511
512function createYearDiv()
513{
514    if(!document.getElementById('yearDropDown'))
515    {
516        var div = document.createElement('DIV');
517        div.className='monthYearPicker';
518    }
519    else
520    {
521        var div = document.getElementById('yearDropDown');
522        var subDivs = div.getElementsByTagName('DIV');
523        for(var no=0;no<subDivs.length;no++)
524        {
525            subDivs[no].parentNode.removeChild(subDivs[no]);   
526        }
527    }
528    var d = new Date();
529    if(currentYear)
530    {
531        d.setFullYear(currentYear);
532    }
533    var startYear = d.getFullYear()/1 - 5;
534    var subDiv = document.createElement('DIV');
535    subDiv.innerHTML = '&nbsp;&nbsp;- ';
536    subDiv.onclick = changeSelectBoxYear;
537    subDiv.onmouseover = highlightMonthYear;
538    subDiv.onmouseout = function()
539    {
540        selectBoxMovementInProgress = false;
541    }
542    ;
543    subDiv.onselectstart = cancelCalendarEvent;
544    div.appendChild(subDiv);
545
546    for(var no=startYear;no<(startYear+10);no++)
547    {
548        var subDiv = document.createElement('DIV');
549        subDiv.innerHTML = no;
550        subDiv.onmouseover = highlightMonthYear;
551        subDiv.onmouseout = highlightMonthYear;
552        subDiv.onclick = selectYear;
553        subDiv.id = 'yearDiv' + no;
554        subDiv.onselectstart = cancelCalendarEvent;     
555        div.appendChild(subDiv);
556        if(currentYear && currentYear==no)
557        {
558            subDiv.style.color = selectBoxHighlightColor;
559            activeSelectBoxYear = subDiv;
560        }
561    }
562    var subDiv = document.createElement('DIV');
563    subDiv.innerHTML = '&nbsp;&nbsp;+ ';
564    subDiv.onclick = changeSelectBoxYear;
565    subDiv.onmouseover = highlightMonthYear;
566    subDiv.onmouseout = function()
567    {
568        selectBoxMovementInProgress = false;
569    }
570    ;
571    subDiv.onselectstart = cancelCalendarEvent;
572    div.appendChild(subDiv);
573    return div;
574}
575
576/* This function creates the hour div at the bottom bar */
577
578function slideCalendarSelectBox()
579{
580    if(selectBoxMovementInProgress)
581    {
582        if(activeSelectBox.parentNode.id=='hourDropDown')
583        {
584            changeSelectBoxHour(false,activeSelectBox);
585        }
586        if(activeSelectBox.parentNode.id=='yearDropDown')
587        {
588            changeSelectBoxYear(false,activeSelectBox);
589        }
590    }
591    setTimeout('slideCalendarSelectBox()',speedOfSelectBoxSliding);
592}
593
594function createHourDiv()
595{
596    if(!document.getElementById('hourDropDown'))
597    {
598        var div = document.createElement('DIV');
599        div.className='monthYearPicker';
600    }
601    else
602    {
603        var div = document.getElementById('hourDropDown');
604        var subDivs = div.getElementsByTagName('DIV');
605        for(var no=0;no<subDivs.length;no++)
606        {
607            subDivs[no].parentNode.removeChild(subDivs[no]);
608        }
609    }
610    if(!currentHour)currentHour=0;
611    var startHour = currentHour/1;
612    if(startHour>14)startHour=14;
613
614    var subDiv = document.createElement('DIV');
615    subDiv.innerHTML = '&nbsp;&nbsp;- ';
616    subDiv.onclick = changeSelectBoxHour;
617    subDiv.onmouseover = highlightMonthYear;
618    subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};     
619    subDiv.onselectstart = cancelCalendarEvent;
620    div.appendChild(subDiv);
621
622    for(var no=startHour;no<startHour+10;no++)
623    {
624        var prefix = '';
625        if(no/1<10)prefix='0';
626        var subDiv = document.createElement('DIV');
627        subDiv.innerHTML = prefix + no;
628        subDiv.onmouseover = highlightMonthYear;
629        subDiv.onmouseout = highlightMonthYear;
630        subDiv.onclick = selectHour;
631        subDiv.id = 'hourDiv' + no;
632        subDiv.onselectstart = cancelCalendarEvent;     
633        div.appendChild(subDiv);
634        if(currentYear && currentYear==no)
635        {
636            subDiv.style.color = selectBoxHighlightColor;
637            activeSelectBoxYear = subDiv;
638        }
639    }
640    var subDiv = document.createElement('DIV');
641    subDiv.innerHTML = '&nbsp;&nbsp;+ ';
642    subDiv.onclick = changeSelectBoxHour;
643    subDiv.onmouseover = highlightMonthYear;
644    subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};
645    subDiv.onselectstart = cancelCalendarEvent;
646    div.appendChild(subDiv);
647
648    return div;
649}
650/* This function creates the minute div at the bottom bar */
651
652function createMinuteDiv()
653{
654    if(!document.getElementById('minuteDropDown'))
655    {
656        var div = document.createElement('DIV');
657        div.className='monthYearPicker';
658    }
659    else
660    {
661        var div = document.getElementById('minuteDropDown');
662        var subDivs = div.getElementsByTagName('DIV');
663        for(var no=0;no<subDivs.length;no++)
664        {
665            subDivs[no].parentNode.removeChild(subDivs[no]);
666        }
667    }
668    var startMinute = 0;
669    var prefix = '';
670    for(var no=startMinute;no<60;no+=intervalSelectBox_minutes)
671    {
672        if(no<10)prefix='0'; else prefix = '';
673        var subDiv = document.createElement('DIV');
674        subDiv.innerHTML = prefix + no;
675        subDiv.onmouseover = highlightMonthYear;
676        subDiv.onmouseout = highlightMonthYear;
677        subDiv.onclick = selectMinute;
678        subDiv.id = 'minuteDiv_' + prefix +  no;
679        subDiv.onselectstart = cancelCalendarEvent;
680        div.appendChild(subDiv);
681        if(currentYear && currentYear==no)
682        {
683            subDiv.style.color = selectBoxHighlightColor;
684            activeSelectBoxYear = subDiv;
685        }
686    }
687    return div;
688}
689
690function highlightSelect()
691{
692    if(this.className=='selectBoxTime')
693    {
694        this.className = 'selectBoxTimeOver';
695        this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_time_over_cal.gif';
696    }
697    else if(this.className=='selectBoxTimeOver')
698    {
699        this.className = 'selectBoxTime';
700        this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_time_cal.gif';
701    }
702    if(this.className=='selectBox')
703    {
704        this.className = 'selectBoxOver';
705        this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_over_cal.gif';
706    }
707    else if(this.className=='selectBoxOver')
708    {
709        this.className = 'selectBox';
710        this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_cal.gif';
711    }
712}
713
714function highlightArrow()
715{
716    if(this.src.indexOf('over')>=0)
717    {
718        if(this.src.indexOf('left')>=0)this.src = pathToImages + 'left_cal.gif';
719        if(this.src.indexOf('right')>=0)this.src = pathToImages + 'right_cal.gif';
720    }
721    else
722    {
723        if(this.src.indexOf('left')>=0)this.src = pathToImages + 'left_over_cal.gif';
724        if(this.src.indexOf('right')>=0)this.src = pathToImages + 'right_over_cal.gif';
725    }
726}
727
728function highlightClose()
729{
730    if(this.src.indexOf('over')>=0)
731    {
732        this.src = pathToImages + 'close_cal.gif';
733    }
734    else
735    {
736        this.src = pathToImages + 'close_over_cal.gif';
737    }
738}
739
740function closeCalendar()
741{
742    document.getElementById('yearDropDown').style.display='none';
743    document.getElementById('monthDropDown').style.display='none';
744    document.getElementById('hourDropDown').style.display='none';
745    document.getElementById('minuteDropDown').style.display='none';
746
747    calendarDiv.style.display='none';
748    if(iframeObj){
749    iframeObj.style.display='none';
750    //// //// fix for EI frame problem on time dropdowns 09/30/2006
751    EIS_Hide_Frame();}
752    if(activeSelectBoxMonth)activeSelectBoxMonth.className='';
753    if(activeSelectBoxYear)activeSelectBoxYear.className='';
754}
755
756function writeTopBar()
757{
758    var topBar = document.createElement('DIV');
759    topBar.className = 'topBar';
760    topBar.id = 'topBar';
761    calendarDiv.appendChild(topBar);
762
763    // Left arrow
764    var leftDiv = document.createElement('DIV');
765    leftDiv.style.marginRight = '1px';
766    var img = document.createElement('IMG');
767    img.src = pathToImages + 'left_cal.gif';
768    img.onmouseover = highlightArrow;
769    img.onclick = switchMonth;
770    img.onmouseout = highlightArrow;
771    leftDiv.appendChild(img);   
772    topBar.appendChild(leftDiv);
773    if(Opera)leftDiv.style.width = '16px';
774
775    // Right arrow
776    var rightDiv = document.createElement('DIV');
777    rightDiv.style.marginRight = '1px';
778    var img = document.createElement('IMG');
779    img.src = pathToImages + 'right_cal.gif';
780    img.onclick = switchMonth;
781    img.onmouseover = highlightArrow;
782    img.onmouseout = highlightArrow;
783    rightDiv.appendChild(img);
784    if(Opera)rightDiv.style.width = '16px';
785    topBar.appendChild(rightDiv);
786
787    // Month selector
788    var monthDiv = document.createElement('DIV');
789    monthDiv.id = 'monthSelect';
790    monthDiv.onmouseover = highlightSelect;
791    monthDiv.onmouseout = highlightSelect;
792    monthDiv.onclick = showMonthDropDown;
793    var span = document.createElement('SPAN');
794    span.innerHTML = monthArray[currentMonth];
795    span.id = 'calendar_month_txt';
796    monthDiv.appendChild(span);
797    var img = document.createElement('IMG');
798    img.src = pathToImages + 'down_cal.gif';
799    img.style.position = 'absolute';
800    img.style.right = '0px';
801    monthDiv.appendChild(img);
802    monthDiv.className = 'selectBox';
803    if(Opera)
804    {
805        img.style.cssText = 'float:right;position:relative';
806        img.style.position = 'relative';
807        img.style.styleFloat = 'right';
808    }
809    topBar.appendChild(monthDiv);
810    var monthPicker = createMonthDiv();
811    monthPicker.style.left = '37px';
812    monthPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
813    monthPicker.style.width ='60px';
814    monthPicker.id = 'monthDropDown';
815
816    calendarDiv.appendChild(monthPicker);
817
818    // Year selector
819    var yearDiv = document.createElement('DIV');
820    yearDiv.onmouseover = highlightSelect;
821    yearDiv.onmouseout = highlightSelect;
822    yearDiv.onclick = showYearDropDown;
823    var span = document.createElement('SPAN');
824    span.innerHTML = currentYear;
825    span.id = 'calendar_year_txt';
826    yearDiv.appendChild(span);
827    topBar.appendChild(yearDiv);
828    var img = document.createElement('IMG');
829    img.src = pathToImages + 'down_cal.gif';
830    yearDiv.appendChild(img);
831    yearDiv.className = 'selectBox';
832    if(Opera)
833    {
834        yearDiv.style.width = '50px';
835        img.style.cssText = 'float:right';
836        img.style.position = 'relative';
837        img.style.styleFloat = 'right';
838    }
839    var yearPicker = createYearDiv();
840    yearPicker.style.left = '113px';
841    yearPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
842    yearPicker.style.width = '35px';
843    yearPicker.id = 'yearDropDown';
844    calendarDiv.appendChild(yearPicker);
845
846    var img = document.createElement('IMG');
847    img.src = pathToImages + 'close_cal.gif';
848    img.style.styleFloat = 'right';
849    img.onmouseover = highlightClose;
850    img.onmouseout = highlightClose;
851    img.onclick = closeCalendar;
852    topBar.appendChild(img);
853
854    if(!document.all)
855    {
856        img.style.position = 'absolute';
857        img.style.right = '2px';
858    }
859}
860
861function writeCalendarContent()
862{
863    var calendarContentDivExists = true;
864    if(!calendarContentDiv)
865    {
866        calendarContentDiv = document.createElement('DIV');
867        calendarDiv.appendChild(calendarContentDiv);
868        calendarContentDivExists = false;
869    }
870    currentMonth = currentMonth/1;
871    var d = new Date();
872
873    d.setFullYear(currentYear);
874    d.setDate(1);
875    d.setMonth(currentMonth);
876
877    var dayStartOfMonth = d.getDay();
878    if(dayStartOfMonth==0)dayStartOfMonth=7;
879    dayStartOfMonth--;
880
881    document.getElementById('calendar_year_txt').innerHTML = currentYear;
882    document.getElementById('calendar_month_txt').innerHTML = monthArray[currentMonth];
883    document.getElementById('calendar_hour_txt').innerHTML = currentHour;
884    document.getElementById('calendar_minute_txt').innerHTML = currentMinute;
885
886    var existingTable = calendarContentDiv.getElementsByTagName('TABLE');
887    if(existingTable.length>0)
888    {
889        calendarContentDiv.removeChild(existingTable[0]);
890    }
891
892    var calTable = document.createElement('TABLE');
893    calTable.width = '100%';
894    calTable.cellSpacing = '0';
895    calendarContentDiv.appendChild(calTable);
896
897    var calTBody = document.createElement('TBODY');
898    calTable.appendChild(calTBody);
899    var row = calTBody.insertRow(-1);
900    row.className = 'calendar_week_row';
901    var cell = row.insertCell(-1);
902    cell.innerHTML = weekString;
903    cell.className = 'calendar_week_column';
904    cell.style.backgroundColor = selectBoxRolloverBgColor;
905
906    for(var no=0;no<dayArray.length;no++)
907    {
908        var cell = row.insertCell(-1);
909        cell.innerHTML = dayArray[no];
910    }
911
912    var row = calTBody.insertRow(-1);
913    var cell = row.insertCell(-1);
914    cell.className = 'calendar_week_column';
915    cell.style.backgroundColor = selectBoxRolloverBgColor;
916    var week = getWeek(currentYear,currentMonth,1);
917    cell.innerHTML = week;              // Week
918    for(var no=0;no<dayStartOfMonth;no++)
919    {
920        var cell = row.insertCell(-1);
921        cell.innerHTML = '&nbsp;';
922    }
923
924    var colCounter = dayStartOfMonth;
925    var daysInMonth = daysInMonthArray[currentMonth];
926    if(daysInMonth==28)
927    {
928        if(isLeapYear(currentYear)) daysInMonth=29;
929    }
930
931    for(var no=1;no<=daysInMonth;no++)
932    {
933        d.setDate(no-1);
934        if(colCounter>0 && colCounter%7==0)
935        {
936            var row = calTBody.insertRow(-1);
937            var cell = row.insertCell(-1);
938            cell.className = 'calendar_week_column';
939            var week = getWeek(currentYear,currentMonth,no);
940            cell.innerHTML = week; // Week
941            cell.style.backgroundColor = selectBoxRolloverBgColor;
942        }
943        var cell = row.insertCell(-1);
944        if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay)
945        {
946            cell.className='activeDay';
947        }
948        cell.innerHTML = no;
949        cell.onclick = pickDate;
950        colCounter++;
951    }
952
953    if(!document.all){
954        if(calendarContentDiv.offsetHeight)
955        document.getElementById('topBar').style.top = calendarContentDiv.offsetHeight + document.getElementById('timeBar').offsetHeight + document.getElementById('topBar').offsetHeight -1 + 'px';
956        else
957        {
958           document.getElementById('topBar').style.top = '';
959          document.getElementById('topBar').style.bottom = '0px';
960        }
961    }
962
963    if(iframeObj)
964    {
965        if(!calendarContentDivExists)setTimeout('resizeIframe()',350);else setTimeout('resizeIframe()',10);
966    }
967}
968
969function resizeIframe()
970{
971    iframeObj.style.width = calendarDiv.offsetWidth + 'px';
972    iframeObj.style.height = calendarDiv.offsetHeight + 'px' ;
973}
974
975function pickTodaysDate()
976{
977    var d = new Date();
978    currentMonth = d.getMonth();
979    currentYear = d.getFullYear();
980    pickDate(false,d.getDate());
981}
982
983function pickDate(e,inputDay)
984{
985    var month = currentMonth/1 +1;
986    if(month<10)month = '0' + month;
987    var day;
988    if(!inputDay && this)day = this.innerHTML; else day = inputDay;
989
990    if(day/1<10)day = '0' + day;
991    if(returnFormat)
992    {
993        returnFormat = returnFormat.replace('dd',day);
994        returnFormat = returnFormat.replace('mm',month);
995        returnFormat = returnFormat.replace('yyyy',currentYear);
996        returnFormat = returnFormat.replace('hh',currentHour);
997        returnFormat = returnFormat.replace('ii',currentMinute);
998        returnFormat = returnFormat.replace('d',day/1);
999        returnFormat = returnFormat.replace('m',month/1);
1000        returnDateTo.value = returnFormat;
1001        try
1002        {
1003            returnDateTo.onchange();
1004        }
1005        catch(e)
1006        {
1007        }
1008    }
1009    else
1010    {
1011        for(var no=0;no<returnDateToYear.options.length;no++)
1012        {
1013            if(returnDateToYear.options[no].value==currentYear)
1014            {
1015                returnDateToYear.selectedIndex=no;
1016                break;
1017            }
1018        }
1019        for(var no=0;no<returnDateToMonth.options.length;no++)
1020        {
1021            if(returnDateToMonth.options[no].value==parseInt(month))
1022            {
1023                returnDateToMonth.selectedIndex=no;
1024                break;
1025            }
1026        }
1027        for(var no=0;no<returnDateToDay.options.length;no++)
1028        {
1029            if(returnDateToDay.options[no].value==parseInt(day))
1030            {
1031                returnDateToDay.selectedIndex=no;
1032                break;
1033            }
1034        }
1035        if(calendarDisplayTime)
1036        {
1037            for(var no=0;no<returnDateToHour.options.length;no++)
1038            {
1039                if(returnDateToHour.options[no].value==parseInt(currentHour))
1040                {
1041                    returnDateToHour.selectedIndex=no;
1042                    break;
1043                }
1044            }
1045            for(var no=0;no<returnDateToMinute.options.length;no++)
1046            {
1047                if(returnDateToMinute.options[no].value==parseInt(currentMinute))
1048                {
1049                    returnDateToMinute.selectedIndex=no;
1050                    break;
1051                }
1052            }
1053        }
1054    }
1055    closeCalendar();
1056}
1057
1058// This function is from http://www.codeproject.com/csharp/gregorianwknum.asp
1059// Only changed the month add
1060function getWeek(year,month,day)
1061{
1062    day = day/1;
1063    year = year/1;
1064    month = month/1 + 1; //use 1-12
1065    var a = Math.floor((14-(month))/12);
1066    var y = year+4800-a;
1067    var m = (month)+(12*a)-3;
1068    var jd = day + Math.floor(((153*m)+2)/5) + (365*y) + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) - 32045;      // (gregorian calendar)
1069    var d4 = (jd+31741-(jd%7))%146097%36524%1461;
1070    var L = Math.floor(d4/1460);
1071    var d1 = ((d4-L)%365)+L;
1072    NumberOfWeek = Math.floor(d1/7) + 1;
1073    return NumberOfWeek;
1074}
1075
1076function writeTimeBar()
1077{
1078    var timeBar = document.createElement('DIV');
1079    timeBar.id = 'timeBar';
1080    timeBar.className = 'timeBar';     
1081    var subDiv = document.createElement('DIV');
1082    subDiv.innerHTML = 'Time:';
1083    //timeBar.appendChild(subDiv);
1084    // Year selector
1085    var hourDiv = document.createElement('DIV');
1086    hourDiv.onmouseover = highlightSelect;
1087    hourDiv.onmouseout = highlightSelect;
1088    hourDiv.onclick = showHourDropDown;
1089    hourDiv.style.width = '30px';
1090    var span = document.createElement('SPAN');         
1091    span.innerHTML = currentHour;
1092    span.id = 'calendar_hour_txt';
1093    hourDiv.appendChild(span);
1094    timeBar.appendChild(hourDiv);
1095    var img = document.createElement('IMG');
1096    img.src = pathToImages + 'down_time_cal.gif';
1097    hourDiv.appendChild(img);
1098    hourDiv.className = 'selectBoxTime';
1099    if(Opera)
1100    {
1101        hourDiv.style.width = '30px';
1102        img.style.cssText = 'float:right';
1103        img.style.position = 'relative';
1104        img.style.styleFloat = 'right';
1105    }
1106    var hourPicker = createHourDiv();
1107    hourPicker.style.left = '130px';
1108    //hourPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
1109    hourPicker.style.width = '35px';
1110    hourPicker.id = 'hourDropDown';
1111    calendarDiv.appendChild(hourPicker);
1112
1113    // Add Minute picker
1114    // Year selector
1115    var minuteDiv = document.createElement('DIV');
1116    minuteDiv.onmouseover = highlightSelect;
1117    minuteDiv.onmouseout = highlightSelect;
1118    minuteDiv.onclick = showMinuteDropDown;
1119    minuteDiv.style.width = '30px';
1120    var span = document.createElement('SPAN');
1121    span.innerHTML = currentMinute;
1122    span.id = 'calendar_minute_txt';
1123    minuteDiv.appendChild(span);
1124    timeBar.appendChild(minuteDiv);
1125    var img = document.createElement('IMG');
1126    img.src = pathToImages + 'down_time_cal.gif';
1127    minuteDiv.appendChild(img);
1128    minuteDiv.className = 'selectBoxTime';
1129    if(Opera)
1130    {
1131        minuteDiv.style.width = '30px';
1132        img.style.cssText = 'float:right';
1133        img.style.position = 'relative';
1134        img.style.styleFloat = 'right';
1135    }
1136    var minutePicker = createMinuteDiv();
1137    minutePicker.style.left = '167px';
1138    //minutePicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
1139    minutePicker.style.width = '35px';
1140    minutePicker.id = 'minuteDropDown';
1141    calendarDiv.appendChild(minutePicker);
1142
1143    return timeBar;
1144    }
1145
1146function writeBottomBar()
1147{
1148    var d = new Date();
1149    var bottomBar = document.createElement('DIV');
1150    bottomBar.id = 'bottomBar';
1151    bottomBar.style.cursor = 'pointer';
1152    bottomBar.className = 'todaysDate';
1153    // var todayStringFormat = '[todayString] [dayString] [day] [monthString] [year]';  ;;
1154
1155    var subDiv = document.createElement('DIV');
1156    subDiv.onclick = pickTodaysDate;
1157    subDiv.id = 'todaysDateString';
1158    subDiv.style.width = (calendarDiv.offsetWidth - 95) + 'px';
1159    var day = d.getDay();
1160    if(day==0)day = 7;
1161    day--;
1162
1163    var bottomString = todayStringFormat;
1164    bottomString = bottomString.replace('[monthString]',monthArrayShort[d.getMonth()]);
1165    bottomString = bottomString.replace('[day]',d.getDate());
1166    bottomString = bottomString.replace('[year]',d.getFullYear());
1167    bottomString = bottomString.replace('[dayString]',dayArray[day].toLowerCase());
1168    bottomString = bottomString.replace('[UCFdayString]',dayArray[day]);
1169    bottomString = bottomString.replace('[todayString]',todayString);
1170
1171    subDiv.innerHTML = todayString + ': ' + d.getDate() + '. ' + monthArrayShort[d.getMonth()] + ', ' +  d.getFullYear() ;
1172    subDiv.innerHTML = bottomString ;
1173    bottomBar.appendChild(subDiv);
1174
1175    var timeDiv = writeTimeBar();
1176    bottomBar.appendChild(timeDiv);
1177    calendarDiv.appendChild(bottomBar);
1178}
1179
1180function getTopPos(inputObj)
1181{
1182    var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
1183    while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
1184    return returnValue + calendar_offsetTop;
1185}
1186
1187function getleftPos(inputObj)
1188{
1189    var returnValue = inputObj.offsetLeft;
1190    while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
1191    return returnValue + calendar_offsetLeft;
1192}
1193
1194function positionCalendar(inputObj)
1195{
1196    calendarDiv.style.left = getleftPos(inputObj) + 'px';
1197    calendarDiv.style.top = getTopPos(inputObj) + 'px';
1198    if(iframeObj)
1199    {
1200        iframeObj.style.left = calendarDiv.style.left;
1201        iframeObj.style.top =  calendarDiv.style.top;
1202        //// fix for EI frame problem on time dropdowns 09/30/2006
1203        iframeObj2.style.left = calendarDiv.style.left;
1204        iframeObj2.style.top =  calendarDiv.style.top;
1205    }
1206}
1207
1208function initCalendar()
1209{
1210    if(MSIE)
1211    {
1212        iframeObj = document.createElement('IFRAME');
1213        iframeObj.style.filter = 'alpha(opacity=0)';
1214        iframeObj.style.position = 'absolute';
1215        iframeObj.border='0px';
1216        iframeObj.style.border = '0px';
1217        iframeObj.style.backgroundColor = '#FF0000';
1218        //// fix for EI frame problem on time dropdowns 09/30/2006
1219        iframeObj2 = document.createElement('IFRAME');
1220        iframeObj2.style.position = 'absolute';
1221        iframeObj2.border='0px';
1222        iframeObj2.style.border = '0px';
1223        iframeObj2.style.height = '1px';
1224        iframeObj2.style.width = '1px';
1225        document.body.appendChild(iframeObj2);
1226        //// fix for EI frame problem on time dropdowns 09/30/2006
1227        // Added fixed for HTTPS
1228        iframeObj2.src = 'blank.html';
1229        iframeObj.src = 'blank.html';
1230        document.body.appendChild(iframeObj);
1231    }
1232
1233    calendarDiv = document.createElement('DIV');
1234    calendarDiv.id = 'calendarDiv';
1235    calendarDiv.style.zIndex = 1000;
1236    slideCalendarSelectBox();
1237
1238    document.body.appendChild(calendarDiv);
1239    writeBottomBar();   
1240    writeTopBar();
1241    if(!currentYear)
1242    {
1243        var d = new Date();
1244        currentMonth = d.getMonth();
1245        currentYear = d.getFullYear();
1246    }
1247    writeCalendarContent();
1248}
1249
1250function setTimeProperties()
1251{
1252    if(!calendarDisplayTime)
1253    {
1254        document.getElementById('timeBar').style.display='none';
1255        document.getElementById('timeBar').style.visibility='hidden';
1256        document.getElementById('todaysDateString').style.width = '100%';
1257    }
1258    else
1259    {
1260        document.getElementById('timeBar').style.display='block';
1261        document.getElementById('timeBar').style.visibility='visible';
1262        document.getElementById('hourDropDown').style.top = document.getElementById('calendar_minute_txt').parentNode.offsetHeight + calendarContentDiv.offsetHeight + document.getElementById('topBar').offsetHeight + 'px';
1263        document.getElementById('minuteDropDown').style.top = document.getElementById('calendar_minute_txt').parentNode.offsetHeight + calendarContentDiv.offsetHeight + document.getElementById('topBar').offsetHeight + 'px';
1264        document.getElementById('minuteDropDown').style.right = '50px';
1265        document.getElementById('hourDropDown').style.right = '50px';
1266        document.getElementById('todaysDateString').style.width = '115px';
1267    }
1268}
1269
1270function calendarSortItems(a,b)
1271{
1272    return a/1 - b/1;
1273}
1274
1275
1276function displayCalendar(inputField,format,buttonObj,displayTime,timeInput)
1277{
1278    if(displayTime) calendarDisplayTime=true; else calendarDisplayTime = false;
1279    if(inputField.value.length==10)
1280    {
1281        if(!format.match(/^[0-9]*?$/gi))
1282        {
1283            var items = inputField.value.split(/[^0-9]/gi);
1284            var positionArray = new Array();
1285            positionArray['m'] = format.indexOf('mm');
1286            if(positionArray['m']==-1)positionArray['m'] = format.indexOf('m');
1287            positionArray['d'] = format.indexOf('dd');
1288            if(positionArray['d']==-1)positionArray['d'] = format.indexOf('d');
1289            positionArray['y'] = format.indexOf('yyyy');
1290            positionArray['h'] = format.indexOf('hh');
1291            positionArray['i'] = format.indexOf('ii');
1292            var positionArrayNumeric = Array();
1293            positionArrayNumeric[0] = positionArray['m'];
1294            positionArrayNumeric[1] = positionArray['d'];
1295            positionArrayNumeric[2] = positionArray['y'];
1296            positionArrayNumeric[3] = positionArray['h'];
1297            positionArrayNumeric[4] = positionArray['i'];
1298            positionArrayNumeric = positionArrayNumeric.sort(calendarSortItems);
1299            var itemIndex = -1;
1300            currentHour = '00';
1301            currentMinute = '00';
1302            for(var no=0;no<positionArrayNumeric.length;no++)
1303            {
1304                if(positionArrayNumeric[no]==-1)continue;
1305                itemIndex++;
1306                if(positionArrayNumeric[no]==positionArray['m'])
1307                {
1308                    currentMonth = items[itemIndex]-1;
1309                    continue;
1310                }
1311                if(positionArrayNumeric[no]==positionArray['y'])
1312                {
1313                    currentYear = items[itemIndex];
1314                    continue;
1315                }
1316                if(positionArrayNumeric[no]==positionArray['d'])
1317                {
1318                    tmpDay = items[itemIndex];
1319                    continue;
1320                }
1321                if(positionArrayNumeric[no]==positionArray['h'])
1322                {
1323                    currentHour = items[itemIndex];
1324                    continue;
1325                }
1326                if(positionArrayNumeric[no]==positionArray['i'])
1327                {
1328                    currentMinute = items[itemIndex];
1329                    continue;
1330                }
1331            }
1332
1333            currentMonth = currentMonth / 1;
1334            tmpDay = tmpDay / 1;
1335        }
1336        else
1337        {
1338            var monthPos = format.indexOf('mm');
1339            currentMonth = inputField.value.substr(monthPos,2)/1 -1;   
1340            var yearPos = format.indexOf('yyyy');
1341            currentYear = inputField.value.substr(yearPos,4);           
1342            var dayPos = format.indexOf('dd');
1343            tmpDay = inputField.value.substr(dayPos,2);         
1344            var hourPos = format.indexOf('hh');
1345            if(hourPos>=0)
1346            {
1347                tmpHour = inputField.value.substr(hourPos,2);   
1348                currentHour = tmpHour;
1349            }
1350            else
1351            {
1352            currentHour = '00';
1353            }
1354            var minutePos = format.indexOf('ii');
1355            if(minutePos>=0)
1356            {
1357                tmpMinute = inputField.value.substr(minutePos,2);       
1358                currentMinute = tmpMinute;
1359            }
1360            else
1361            {
1362                currentMinute = '00';
1363            }
1364        }
1365    }
1366    else
1367    {
1368        var d = new Date();
1369        currentMonth = d.getMonth();
1370        currentYear = d.getFullYear();
1371        currentHour = '08';
1372        currentMinute = '00';
1373        tmpDay = d.getDate();
1374    }
1375    inputYear = currentYear;
1376    inputMonth = currentMonth;
1377    inputDay = tmpDay/1;
1378    if(!calendarDiv)
1379    {
1380        initCalendar();
1381    }
1382    else
1383    {
1384        if(calendarDiv.style.display=='block')
1385        {
1386            closeCalendar();
1387            return false;
1388        }
1389    writeCalendarContent();
1390    }
1391    returnFormat = format;
1392    returnDateTo = inputField;
1393    positionCalendar(buttonObj);
1394    calendarDiv.style.visibility = 'visible';   
1395    calendarDiv.style.display = 'block';       
1396    if(iframeObj)
1397    {
1398        iframeObj.style.display = '';
1399        iframeObj.style.height = '140px';
1400        iframeObj.style.width = '195px';
1401        iframeObj2.style.display = '';
1402        iframeObj2.style.height = '140px';
1403        iframeObj2.style.width = '195px';
1404    }
1405    setTimeProperties();       
1406    updateYearDiv();
1407    updateMonthDiv();
1408    updateMinuteDiv();
1409    updateHourDiv();
1410}
1411
1412function displayCalendarSelectBox(yearInput,monthInput,dayInput,hourInput,minuteInput,buttonObj)
1413{
1414    if(!hourInput)calendarDisplayTime=false; else calendarDisplayTime = true;
1415
1416    currentMonth = monthInput.options[monthInput.selectedIndex].value/1-1;
1417    currentYear = yearInput.options[yearInput.selectedIndex].value;
1418    if(hourInput)
1419    {
1420        currentHour = hourInput.options[hourInput.selectedIndex].value;
1421        inputHour = currentHour/1;
1422    }
1423    if(minuteInput)
1424    {
1425        currentMinute = minuteInput.options[minuteInput.selectedIndex].value;
1426        inputMinute = currentMinute/1;
1427    }
1428
1429    inputYear = yearInput.options[yearInput.selectedIndex].value;
1430    inputMonth = monthInput.options[monthInput.selectedIndex].value/1 - 1;
1431    inputDay = dayInput.options[dayInput.selectedIndex].value/1;
1432
1433    if(!calendarDiv)
1434    {
1435        initCalendar();
1436    }
1437    else
1438    {
1439        writeCalendarContent();
1440    }
1441
1442    returnDateToYear = yearInput;
1443    returnDateToMonth = monthInput;
1444    returnDateToDay = dayInput;
1445    returnDateToHour = hourInput;       
1446    returnDateToMinute = minuteInput;   
1447
1448    returnFormat = false;
1449    returnDateTo = false;
1450    positionCalendar(buttonObj);
1451    calendarDiv.style.visibility = 'visible';   
1452    calendarDiv.style.display = 'block';
1453    if(iframeObj)
1454    {
1455    iframeObj.style.display = '';
1456    iframeObj.style.height = calendarDiv.offsetHeight + 'px';
1457    iframeObj.style.width = calendarDiv.offsetWidth + 'px';     
1458    //// fix for EI frame problem on time dropdowns 09/30/2006
1459    iframeObj2.style.display = '';
1460    iframeObj2.style.height = calendarDiv.offsetHeight + 'px';
1461    iframeObj2.style.width = calendarDiv.offsetWidth + 'px'
1462    }
1463    setTimeProperties();
1464    updateYearDiv();
1465    updateMonthDiv();
1466    updateHourDiv();
1467    updateMinuteDiv();
1468}
1469
1470// colocar no evento onKeyUp passando o objeto como parametro
1471function formata_dt(val)
1472{
1473    var pass = val.value;
1474    var expr = /[0123456789]/;
1475
1476    for (i=0; i<pass.length; i++)
1477    {
1478        // charAt -> retorna o caractere posicionado no índice especificado
1479        var lchar = val.value.charAt(i);
1480        var nchar = val.value.charAt(i+1);
1481
1482        if (i==0)
1483        {
1484            // search -> retorna um valor inteiro, indicando a posição do inicio da primeira
1485            // ocorrência de expReg dentro de instStr. Se nenhuma ocorrencia for encontrada o método retornara -1
1486            // instStr.search(expReg);
1487            if ((lchar.search(expr) != 0) || (lchar>3))
1488            {
1489                val.value = "";
1490            }
1491
1492        }
1493        else if (i==1)
1494        {
1495            if (lchar.search(expr) != 0)
1496            {
1497                // substring(indice1,indice2)
1498                // indice1, indice2 -> será usado para delimitar a string
1499                var tst1 = val.value.substring(0,(i));
1500                val.value = tst1;
1501                continue;
1502            }
1503            if ((nchar != '/') && (nchar != ''))
1504            {
1505                var tst1 = val.value.substring(0, (i)+1);
1506
1507                if(nchar.search(expr) != 0) var tst2 = val.value.substring(i+2, pass.length);
1508                else var tst2 = val.value.substring(i+1, pass.length);
1509
1510                val.value = tst1 + '/' + tst2;
1511            }
1512        }
1513        else if (i==4)
1514        {
1515            if (lchar.search(expr) != 0)
1516            {
1517                var tst1 = val.value.substring(0, (i));
1518                val.value = tst1;
1519                continue;
1520            }
1521
1522            if ((nchar != '/') && (nchar != ''))
1523            {
1524                var tst1 = val.value.substring(0, (i)+1);
1525                if(nchar.search(expr) != 0) var tst2 = val.value.substring(i+2, pass.length);
1526                else var tst2 = val.value.substring(i+1, pass.length);
1527                val.value = tst1 + '/' + tst2;
1528            }
1529        }
1530        if (i>=6)
1531        {
1532            if (lchar.search(expr) != 0)
1533            {
1534                var tst1 = val.value.substring(0, (i));
1535                val.value = tst1;
1536            }
1537        }
1538    }
1539
1540    if(pass.length==10)
1541    {
1542        dia = (val.value.substring(0,2));
1543        mes = (val.value.substring(3,5));
1544        ano = (val.value.substring(6,10));
1545
1546        cons = true;
1547
1548        // verifica se foram digitados números
1549        if (isNaN(dia) || isNaN(mes) || isNaN(ano))
1550        {
1551            alert("Preencha a data somente com números.");
1552            val.value = "";
1553            val.focus();
1554            return false;
1555        }
1556
1557        // verifica o dia valido para cada mes
1558        if ((dia < "01")||(dia < "01" || dia > "30") && (mes == "04" || mes == "06" ||  mes == "09" || mes == "11" ) ||  dia > "31")
1559        {
1560            cons = false;
1561        }
1562
1563        // verifica se o mes e valido
1564        if (mes < "01" || mes > "12" )
1565        {
1566            cons = false;
1567        }
1568
1569        // verifica se e ano bissexto
1570        if (mes == "02" && ( dia < "01" || dia > "29" || ( dia > "28" && (parseInt(ano / 4) != ano / 4))))
1571        {
1572            cons = false;
1573        }
1574
1575        if (cons == false)
1576        {
1577            alert("A data inserida não é válida: " + val.value);
1578            val.value = "";
1579            val.focus();
1580            return false;
1581        }
1582    }
1583    if(pass.length>10)
1584    val.value = val.value.substring(0, 10);
1585    return true;
1586}
1587/**
1588* @autor : Ricardo e Rodrigo
1589* @data : 28/12/2007
1590* @Objetivo : Validar Mes e ano
1591* @chamada da função: onKeyUp="formata_mes_ano(this);"
1592*/
1593function formata_mes_ano(val)
1594{
1595    var pass = val.value;
1596    var expr = /[0123456789]/;
1597
1598    for (i=0; i<pass.length; i++)
1599    {
1600        // charAt -> retorna o caractere posicionado no índice especificado
1601        var lchar = val.value.charAt(i);
1602        var nchar = val.value.charAt(i+1);
1603
1604        if (i==0)
1605        {
1606            // search -> retorna um valor inteiro, indicando a posição do inicio da primeira
1607            // ocorrência de expReg dentro de instStr. Se nenhuma ocorrencia for encontrada o método retornara -1
1608            // instStr.search(expReg);
1609            if ((lchar.search(expr) != 0) || (lchar>1))
1610            {
1611                val.value = "";
1612            }
1613
1614        }
1615        else if (i==1)
1616        {
1617            if (val.value.substring(0, 2)>12)
1618            {
1619                val.value = val.value.substring(0, (i));
1620            }
1621            if (lchar.search(expr) != 0)
1622            {
1623                // substring(indice1,indice2)
1624                // indice1, indice2 -> será usado para delimitar a string
1625                var tst1 = val.value.substring(0,(i));
1626                val.value = tst1;
1627                continue;
1628            }
1629            if ((nchar != '/') && (nchar != ''))
1630            {
1631                var tst1 = val.value.substring(0, (i)+1);//conferir este valor;
1632
1633                if(nchar.search(expr) != 0) var tst2 = val.value.substring(i+2, pass.length);
1634                else var tst2 = val.value.substring(i+1, pass.length);
1635
1636                val.value = tst1 + '/' + tst2;
1637            }
1638        }
1639        if (i>=4)
1640        {
1641            if (lchar.search(expr) != 0)
1642            {
1643                var tst1 = val.value.substring(0, (i));
1644                val.value = tst1;
1645            }
1646        }
1647    }
1648
1649    if(pass.length==7)
1650    {
1651        mes = (val.value.substring(0,2));
1652        ano = (val.value.substring(3,7));
1653
1654        cons = true;
1655
1656        // verifica se foram digitados números
1657        if (isNaN(mes) || isNaN(ano))
1658        {
1659            alert("Preencha a data somente com números.");
1660            val.value = "";
1661            val.focus();
1662            return false;
1663        }
1664
1665        // verifica se o mes e valido
1666        if (mes < "01" || mes > "12" )
1667        {
1668            cons = false;
1669        }
1670
1671        if (cons == false)
1672        {
1673            alert("A data inserida não é válida: " + val.value);
1674            val.value = "";
1675            val.focus();
1676            return false;
1677        }
1678    }
1679    if(pass.length>7)
1680    val.value = val.value.substring(0, 7);
1681    return true;
1682}
Note: See TracBrowser for help on using the repository browser.