001.
002.
003.
004.
005.
006.
007.
008.
009.
010.
011.
012.
013.
014.
015.
016.
017.
018.
019.
function
Epoch(name,mode,targetelement,multiselect)
020.
{
021.
this
.state = 0;
022.
this
.name = name;
023.
this
.curDate =
new
Date();
024.
this
.mode = mode;
025.
this
.selectMultiple = (multiselect ==
true
);
026.
027.
028.
029.
this
.selectedDates =
new
Array();
030.
this
.calendar;
031.
this
.calHeading;
032.
this
.calCells;
033.
this
.rows;
034.
this
.cols;
035.
this
.cells =
new
Array();
036.
037.
038.
this
.monthSelect;
039.
this
.yearSelect;
040.
041.
042.
this
.mousein =
false
;
043.
this
.calConfig();
044.
this
.setDays();
045.
this
.displayYear =
this
.displayYearInitial;
046.
this
.displayMonth =
this
.displayMonthInitial;
047.
048.
this
.createCalendar();
049.
050.
if
(
this
.mode ==
'popup'
&& targetelement && targetelement.type ==
'text'
)
051.
{
052.
this
.tgt = targetelement;
053.
this
.calendar.style.position =
'absolute'
;
054.
this
.topOffset =
this
.tgt.offsetHeight;
055.
this
.leftOffset = 0;
056.
this
.calendar.style.top =
this
.getTop(targetelement) +
this
.topOffset +
'px'
;
057.
this
.calendar.style.left =
this
.getLeft(targetelement) +
this
.leftOffset +
'px'
;
058.
document.body.appendChild(
this
.calendar);
059.
this
.tgt.calendar =
this
;
060.
this
.tgt.onfocus =
function
() {
this
.calendar.show();};
061.
this
.tgt.onblur =
function
() {
if
(!
this
.calendar.mousein){
this
.calendar.hide();}};
062.
}
063.
else
064.
{
065.
this
.container = targetelement;
066.
this
.container.appendChild(
this
.calendar);
067.
}
068.
069.
this
.state = 2;
070.
this
.visible ?
this
.show() :
this
.hide();
071.
}
072.
073.
Epoch.prototype.calConfig =
function
()
074.
{
075.
076.
this
.displayYearInitial =
this
.curDate.getFullYear();
077.
this
.displayMonthInitial =
this
.curDate.getMonth();
078.
this
.rangeYearLower = 2012;
079.
this
.rangeYearUpper = 2112;
080.
this
.minDate =
new
Date(2012,0,1);
081.
this
.maxDate =
new
Date(2112,0,1);
082.
this
.startDay = 0;
083.
this
.showWeeks =
true
;
084.
this
.selCurMonthOnly =
false
;
085.
this
.clearSelectedOnChange =
true
;
086.
087.
088.
089.
090.
switch
(
this
.mode)
091.
{
092.
case
'popup'
:
093.
this
.visible =
false
;
094.
break
;
095.
case
'flat'
:
096.
this
.visible =
true
;
097.
098.
break
;
099.
}
100.
this
.setLang();
101.
};
102.
103.
Epoch.prototype.setLang =
function
()
104.
{
105.
this
.daylist =
new
Array(
'Su'
,
'Mo'
,
'Tu'
,
'We'
,
'Th'
,
'Fr'
,
'Sa'
,
'Su'
,
'Mo'
,
'Tu'
,
'We'
,
'Th'
,
'Fr'
,
'Sa'
);
106.
this
.months_sh =
new
Array(
'Jan'
,
'Feb'
,
'Mar'
,
'Apr'
,
'May'
,
'Jun'
,
'Jul'
,
'Aug'
,
'Sep'
,
'Oct'
,
'Nov'
,
'Dec'
);
107.
this
.monthup_title =
'Go to the next month'
;
108.
this
.monthdn_title =
'Go to the previous month'
;
109.
this
.clearbtn_caption =
'Clear'
;
110.
this
.clearbtn_title =
'Clears any dates selected on the calendar'
;
111.
this
.maxrange_caption =
'This is the maximum range'
;
112.
};
113.
114.
Epoch.prototype.getTop =
function
(element)
115.
{
116.
var
oNode = element;
117.
var
iTop = 0;
118.
119.
while
(oNode.tagName !=
'BODY'
) {
120.
iTop += oNode.offsetTop;
121.
oNode = oNode.offsetParent;
122.
}
123.
124.
return
iTop;
125.
};
126.
127.
Epoch.prototype.getLeft =
function
(element)
128.
{
129.
var
oNode = element;
130.
var
iLeft = 0;
131.
132.
while
(oNode.tagName !=
'BODY'
) {
133.
iLeft += oNode.offsetLeft;
134.
oNode = oNode.offsetParent;
135.
}
136.
137.
return
iLeft;
138.
};
139.
140.
Epoch.prototype.show =
function
()
141.
{
142.
this
.calendar.style.display =
'block'
;
143.
this
.visible =
true
;
144.
};
145.
146.
Epoch.prototype.hide =
function
()
147.
{
148.
this
.calendar.style.display =
'none'
;
149.
this
.visible =
false
;
150.
};
151.
152.
Epoch.prototype.toggle =
function
()
153.
{
154.
if
(
this
.visible) {
155.
this
.hide();
156.
}
157.
else
{
158.
this
.show();
159.
}
160.
};
161.
162.
Epoch.prototype.setDays =
function
()
163.
{
164.
this
.daynames =
new
Array();
165.
var
j=0;
166.
for
(
var
i=
this
.startDay; i<
this
.startDay + 7;i++) {
167.
this
.daynames[j++] =
this
.daylist[i];
168.
}
169.
170.
this
.monthDayCount =
new
Array(31,((
this
.curDate.getFullYear() - 2000) % 4 ? 28 : 29),31,30,31,30,31,31,30,31,30,31);
171.
};
172.
173.
Epoch.prototype.setClass =
function
(element,className)
174.
{
175.
element.setAttribute(
'class'
,className);
176.
element.setAttribute(
'className'
,className);
177.
};
178.
179.
Epoch.prototype.createCalendar =
function
()
180.
{
181.
var
tbody, tr, td;
182.
this
.calendar = document.createElement(
'table'
);
183.
this
.calendar.setAttribute(
'id'
,
this
.name+
'_calendar'
);
184.
this
.setClass(
this
.calendar,
'calendar'
);
185.
186.
this
.calendar.onselectstart =
function
() {
return
false
;};
187.
this
.calendar.ondrag =
function
() {
return
false
;};
188.
tbody = document.createElement(
'tbody'
);
189.
190.
191.
tr = document.createElement(
'tr'
);
192.
td = document.createElement(
'td'
);
193.
td.appendChild(
this
.createMainHeading());
194.
tr.appendChild(td);
195.
tbody.appendChild(tr);
196.
197.
198.
tr = document.createElement(
'tr'
);
199.
td = document.createElement(
'td'
);
200.
td.appendChild(
this
.createDayHeading());
201.
tr.appendChild(td);
202.
tbody.appendChild(tr);
203.
204.
205.
tr = document.createElement(
'tr'
);
206.
td = document.createElement(
'td'
);
207.
td.setAttribute(
'id'
,
this
.name+
'_cell_td'
);
208.
this
.calCellContainer = td;
209.
td.appendChild(
this
.createCalCells());
210.
tr.appendChild(td);
211.
tbody.appendChild(tr);
212.
213.
214.
tr = document.createElement(
'tr'
);
215.
td = document.createElement(
'td'
);
216.
td.appendChild(
this
.createFooter());
217.
tr.appendChild(td);
218.
tbody.appendChild(tr);
219.
220.
221.
this
.calendar.appendChild(tbody);
222.
223.
224.
this
.calendar.owner =
this
;
225.
this
.calendar.onmouseover =
function
() {
this
.owner.mousein =
true
;};
226.
this
.calendar.onmouseout =
function
() {
this
.owner.mousein =
false
;};
227.
};
228.
229.
Epoch.prototype.createMainHeading =
function
()
230.
{
231.
232.
var
container = document.createElement(
'div'
);
233.
container.setAttribute(
'id'
,
this
.name+
'_mainheading'
);
234.
this
.setClass(container,
'mainheading'
);
235.
236.
this
.monthSelect = document.createElement(
'select'
);
237.
this
.yearSelect = document.createElement(
'select'
);
238.
var
monthDn = document.createElement(
'input'
), monthUp = document.createElement(
'input'
);
239.
var
opt, i;
240.
241.
for
(i=0;i<12;i++)
242.
{
243.
opt = document.createElement(
'option'
);
244.
opt.setAttribute(
'value'
,i);
245.
if
(
this
.state == 0 &&
this
.displayMonth == i) {
246.
opt.setAttribute(
'selected'
,
'selected'
);
247.
}
248.
opt.appendChild(document.createTextNode(
this
.months_sh[i]));
249.
this
.monthSelect.appendChild(opt);
250.
}
251.
252.
for
(i=
this
.rangeYearLower;i<=
this
.rangeYearUpper;i++)
253.
{
254.
opt = document.createElement(
'option'
);
255.
opt.setAttribute(
'value'
,i);
256.
if
(
this
.state == 0 &&
this
.displayYear == i) {
257.
opt.setAttribute(
'selected'
,
'selected'
);
258.
}
259.
opt.appendChild(document.createTextNode(i));
260.
this
.yearSelect.appendChild(opt);
261.
}
262.
263.
monthUp.setAttribute(
'type'
,
'button'
);
264.
monthUp.setAttribute(
'value'
,
'>'
);
265.
monthUp.setAttribute(
'title'
,
this
.monthup_title);
266.
monthDn.setAttribute(
'type'
,
'button'
);
267.
monthDn.setAttribute(
'value'
,
'<'
);
268.
monthDn.setAttribute(
'title'
,
this
.monthdn_title);
269.
this
.monthSelect.owner =
this
.yearSelect.owner = monthUp.owner = monthDn.owner =
this
;
270.
271.
272.
monthUp.onmouseup =
function
() {
this
.owner.nextMonth();};
273.
monthDn.onmouseup =
function
() {
this
.owner.prevMonth();};
274.
this
.monthSelect.onchange =
function
() {
275.
this
.owner.displayMonth =
this
.value;
276.
this
.owner.displayYear =
this
.owner.yearSelect.value;
277.
this
.owner.goToMonth(
this
.owner.displayYear,
this
.owner.displayMonth);
278.
};
279.
this
.yearSelect.onchange =
function
() {
280.
this
.owner.displayMonth =
this
.owner.monthSelect.value;
281.
this
.owner.displayYear =
this
.value;
282.
this
.owner.goToMonth(
this
.owner.displayYear,
this
.owner.displayMonth);
283.
};
284.
285.
286.
container.appendChild(monthDn);
287.
container.appendChild(
this
.monthSelect);
288.
container.appendChild(
this
.yearSelect);
289.
container.appendChild(monthUp);
290.
return
container;
291.
};
292.
293.
Epoch.prototype.createFooter =
function
()
294.
{
295.
var
container = document.createElement(
'div'
);
296.
var
clearSelected = document.createElement(
'input'
);
297.
clearSelected.setAttribute(
'type'
,
'button'
);
298.
clearSelected.setAttribute(
'value'
,
this
.clearbtn_caption);
299.
clearSelected.setAttribute(
'title'
,
this
.clearbtn_title);
300.
clearSelected.owner =
this
;
301.
clearSelected.onclick =
function
() {
this
.owner.resetSelections(
false
);};
302.
container.appendChild(clearSelected);
303.
return
container;
304.
};
305.
306.
Epoch.prototype.resetSelections =
function
(returnToDefaultMonth)
307.
{
308.
this
.selectedDates =
new
Array();
309.
this
.rows =
new
Array(
false
,
false
,
false
,
false
,
false
,
false
,
false
);
310.
this
.cols =
new
Array(
false
,
false
,
false
,
false
,
false
,
false
,
false
);
311.
if
(
this
.tgt)
312.
{
313.
this
.tgt.value =
''
;
314.
if
(
this
.mode ==
'popup'
) {
315.
this
.hide();
316.
}
317.
}
318.
319.
if
(returnToDefaultMonth ==
true
) {
320.
this
.goToMonth(
this
.displayYearInitial,
this
.displayMonthInitial);
321.
}
322.
else
{
323.
this
.reDraw();
324.
}
325.
};
326.
327.
Epoch.prototype.createDayHeading =
function
()
328.
{
329.
330.
this
.calHeading = document.createElement(
'table'
);
331.
this
.calHeading.setAttribute(
'id'
,
this
.name+
'_caldayheading'
);
332.
this
.setClass(
this
.calHeading,
'caldayheading'
);
333.
var
tbody,tr,td;
334.
tbody = document.createElement(
'tbody'
);
335.
tr = document.createElement(
'tr'
);
336.
this
.cols =
new
Array(
false
,
false
,
false
,
false
,
false
,
false
,
false
);
337.
338.
339.
if
(
this
.showWeeks)
340.
{
341.
td = document.createElement(
'td'
);
342.
td.setAttribute(
'class'
,
'wkhead'
);
343.
td.setAttribute(
'className'
,
'wkhead'
);
344.
tr.appendChild(td);
345.
}
346.
347.
for
(
var
dow=0;dow<7;dow++)
348.
{
349.
td = document.createElement(
'td'
);
350.
td.appendChild(document.createTextNode(
this
.daynames[dow]));
351.
if
(
this
.selectMultiple) {
352.
td.headObj =
new
CalHeading(
this
,td,(dow +
this
.startDay < 7 ? dow +
this
.startDay : dow +
this
.startDay - 7));
353.
}
354.
tr.appendChild(td);
355.
}
356.
tbody.appendChild(tr);
357.
this
.calHeading.appendChild(tbody);
358.
return
this
.calHeading;
359.
};
360.
361.
Epoch.prototype.createCalCells =
function
()
362.
{
363.
this
.rows =
new
Array(
false
,
false
,
false
,
false
,
false
,
false
);
364.
this
.cells =
new
Array();
365.
var
row = -1, totalCells = (
this
.showWeeks ? 48 : 42);
366.
var
beginDate =
new
Date(
this
.displayYear,
this
.displayMonth,1);
367.
var
endDate =
new
Date(
this
.displayYear,
this
.displayMonth,
this
.monthDayCount[
this
.displayMonth]);
368.
var
sdt =
new
Date(beginDate);
369.
sdt.setDate(sdt.getDate() + (
this
.startDay - beginDate.getDay()) - (
this
.startDay - beginDate.getDay() > 0 ? 7 : 0) );
370.
371.
this
.calCells = document.createElement(
'table'
);
372.
this
.calCells.setAttribute(
'id'
,
this
.name+
'_calcells'
);
373.
this
.setClass(
this
.calCells,
'calcells'
);
374.
var
tbody,tr,td;
375.
tbody = document.createElement(
'tbody'
);
376.
for
(
var
i=0;i<totalCells;i++)
377.
{
378.
if
(
this
.showWeeks)
379.
{
380.
if
(i % 8 == 0)
381.
{
382.
row++;
383.
tr = document.createElement(
'tr'
);
384.
td = document.createElement(
'td'
);
385.
if
(
this
.selectMultiple) {
386.
td.weekObj =
new
WeekHeading(
this
,td,sdt.getWeek(),row)
387.
}
388.
else
389.
{
390.
td.setAttribute(
'class'
,
'wkhead'
);
391.
td.setAttribute(
'className'
,
'wkhead'
);
392.
}
393.
td.appendChild(document.createTextNode(sdt.getWeek()));
394.
tr.appendChild(td);
395.
i++;
396.
}
397.
}
398.
else
if
(i % 7 == 0)
399.
{
400.
row++;
401.
tr = document.createElement(
'tr'
);
402.
}
403.
404.
td = document.createElement(
'td'
);
405.
td.appendChild(document.createTextNode(sdt.getDate()));
406.
var
cell =
new
CalCell(
this
,td,sdt,row);
407.
this
.cells.push(cell);
408.
td.cellObj = cell;
409.
sdt.setDate(sdt.getDate() + 1);
410.
tr.appendChild(td);
411.
tbody.appendChild(tr);
412.
}
413.
this
.calCells.appendChild(tbody);
414.
this
.reDraw();
415.
return
this
.calCells;
416.
};
417.
418.
Epoch.prototype.reDraw =
function
()
419.
{
420.
this
.state = 1;
421.
var
i,j;
422.
for
(i=0;i<
this
.cells.length;i++) {
423.
this
.cells[i].selected =
false
;
424.
}
425.
for
(i=0;i<
this
.cells.length;i++)
426.
{
427.
for
(j=0;j<
this
.selectedDates.length;j++) {
428.
if
(
this
.cells[i].date.getUeDay() ==
this
.selectedDates[j].getUeDay() ) {
429.
this
.cells[i].selected =
true
;
430.
}
431.
}
432.
433.
this
.cells[i].setClass();
434.
}
435.
436.
this
.state = 2;
437.
};
438.
439.
Epoch.prototype.deleteCells =
function
()
440.
{
441.
this
.calCellContainer.removeChild(
this
.calCellContainer.firstChild);
442.
this
.cells =
new
Array();
443.
};
444.
445.
Epoch.prototype.goToMonth =
function
(year,month)
446.
{
447.
this
.monthSelect.value =
this
.displayMonth = month;
448.
this
.yearSelect.value =
this
.displayYear = year;
449.
this
.deleteCells();
450.
this
.calCellContainer.appendChild(
this
.createCalCells());
451.
};
452.
453.
Epoch.prototype.nextMonth =
function
()
454.
{
455.
456.
457.
if
(
this
.monthSelect.value < 11) {
458.
this
.monthSelect.value++;
459.
}
460.
else
461.
{
462.
if
(
this
.yearSelect.value <
this
.rangeYearUpper)
463.
{
464.
this
.monthSelect.value = 0;
465.
this
.yearSelect.value++;
466.
}
467.
else
{
468.
alert(
this
.maxrange_caption);
469.
}
470.
}
471.
472.
this
.displayMonth =
this
.monthSelect.value;
473.
this
.displayYear =
this
.yearSelect.value;
474.
475.
476.
this
.deleteCells();
477.
this
.calCellContainer.appendChild(
this
.createCalCells());
478.
};
479.
480.
Epoch.prototype.prevMonth =
function
()
481.
{
482.
483.
if
(
this
.monthSelect.value > 0)
484.
this
.monthSelect.value--;
485.
else
486.
{
487.
if
(
this
.yearSelect.value >
this
.rangeYearLower)
488.
{
489.
this
.monthSelect.value = 11;
490.
this
.yearSelect.value--;
491.
}
492.
else
{
493.
alert(
this
.maxrange_caption);
494.
}
495.
}
496.
497.
498.
this
.displayMonth =
this
.monthSelect.value;
499.
this
.displayYear =
this
.yearSelect.value;
500.
501.
502.
this
.deleteCells();
503.
this
.calCellContainer.appendChild(
this
.createCalCells());
504.
};
505.
506.
Epoch.prototype.addZero =
function
(vNumber)
507.
{
508.
return
((vNumber < 10) ?
'0'
:
''
) + vNumber;
509.
};
510.
511.
Epoch.prototype.addDates =
function
(dates,redraw)
512.
{
513.
var
j,in_sd;
514.
for
(
var
i=0;i<dates.length;i++)
515.
{
516.
in_sd =
false
;
517.
for
(j=0;j<
this
.selectedDates.length;j++)
518.
{
519.
if
(dates[i].getUeDay() ==
this
.selectedDates[j].getUeDay())
520.
{
521.
in_sd =
true
;
522.
break
;
523.
}
524.
}
525.
if
(!in_sd) {
526.
this
.selectedDates.push(dates[i]);
527.
}
528.
}
529.
if
(redraw !=
false
) {
530.
this
.reDraw();
531.
}
532.
};
533.
534.
Epoch.prototype.removeDates =
function
(dates,redraw)
535.
{
536.
var
j;
537.
for
(
var
i=0;i<dates.length;i++)
538.
{
539.
for
(j=0;j<
this
.selectedDates.length;j++)
540.
{
541.
if
(dates[i].getUeDay() ==
this
.selectedDates[j].getUeDay()) {
542.
this
.selectedDates.splice(j,1);
543.
}
544.
}
545.
}
546.
if
(redraw !=
false
) {
547.
this
.reDraw();
548.
}
549.
};
550.
551.
Epoch.prototype.outputDate =
function
(vDate, vFormat)
552.
{
553.
var
vDay =
this
.addZero(vDate.getDate());
554.
var
vMonth =
this
.addZero(vDate.getMonth() + 1);
555.
var
vYearLong =
this
.addZero(vDate.getFullYear());
556.
var
vYearShort =
this
.addZero(vDate.getFullYear().toString().substring(3,4));
557.
var
vYear = (vFormat.indexOf(
'yyyy'
) > -1 ? vYearLong : vYearShort);
558.
var
vHour =
this
.addZero(vDate.getHours());
559.
var
vMinute =
this
.addZero(vDate.getMinutes());
560.
var
vSecond =
this
.addZero(vDate.getSeconds());
561.
return
vFormat.replace(/dd/g, vDay).replace(/mm/g, vMonth).replace(/y{1,4}/g, vYear).replace(/hh/g, vHour).replace(/nn/g, vMinute).replace(/ss/g, vSecond);
562.
};
563.
564.
Epoch.prototype.updatePos =
function
(target)
565.
{
566.
this
.calendar.style.top =
this
.getTop(target) +
this
.topOffset +
'px'
567.
this
.calendar.style.left =
this
.getLeft(target) +
this
.leftOffset +
'px'
568.
}
569.
570.
571.
572.
function
CalHeading(owner,tableCell,dow)
573.
{
574.
this
.owner = owner;
575.
this
.tableCell = tableCell;
576.
this
.dayOfWeek = dow;
577.
578.
579.
this
.tableCell.onclick =
this
.onclick;
580.
}
581.
582.
CalHeading.prototype.onclick =
function
()
583.
{
584.
585.
var
owner =
this
.headObj.owner;
586.
var
sdates = owner.selectedDates;
587.
var
cells = owner.cells;
588.
589.
owner.cols[
this
.headObj.dayOfWeek] = !owner.cols[
this
.headObj.dayOfWeek];
590.
for
(
var
i=0;i<cells.length;i++)
591.
{
592.
if
(cells[i].dayOfWeek ==
this
.headObj.dayOfWeek && (!owner.selCurMonthOnly || cells[i].date.getMonth() == owner.displayMonth && cells[i].date.getFullYear() == owner.displayYear))
593.
{
594.
if
(owner.cols[
this
.headObj.dayOfWeek])
595.
{
596.
if
(owner.selectedDates.arrayIndex(cells[i].date) == -1) {
597.
sdates.push(cells[i].date);
598.
}
599.
}
600.
else
601.
{
602.
for
(
var
j=0;j<sdates.length;j++)
603.
{
604.
if
(cells[i].dayOfWeek == sdates[j].getDay())
605.
{
606.
sdates.splice(j,1);
607.
break
;
608.
}
609.
}
610.
}
611.
cells[i].selected = owner.cols[
this
.headObj.dayOfWeek];
612.
}
613.
}
614.
owner.reDraw();
615.
};
616.
617.
function
WeekHeading(owner,tableCell,week,row)
618.
{
619.
this
.owner = owner;
620.
this
.tableCell = tableCell;
621.
this
.week = week;
622.
this
.tableRow = row;
623.
this
.tableCell.setAttribute(
'class'
,
'wkhead'
);
624.
this
.tableCell.setAttribute(
'className'
,
'wkhead'
);
625.
626.
this
.tableCell.onclick =
this
.onclick;
627.
}
628.
629.
WeekHeading.prototype.onclick =
function
()
630.
{
631.
632.
var
owner =
this
.weekObj.owner;
633.
var
cells = owner.cells;
634.
var
sdates = owner.selectedDates;
635.
var
i,j;
636.
owner.rows[
this
.weekObj.tableRow] = !owner.rows[
this
.weekObj.tableRow];
637.
for
(i=0;i<cells.length;i++)
638.
{
639.
if
(cells[i].tableRow ==
this
.weekObj.tableRow)
640.
{
641.
if
(owner.rows[
this
.weekObj.tableRow] && (!owner.selCurMonthOnly || cells[i].date.getMonth() == owner.displayMonth && cells[i].date.getFullYear() == owner.displayYear))
642.
{
643.
if
(owner.selectedDates.arrayIndex(cells[i].date) == -1) {
644.
sdates.push(cells[i].date);
645.
}
646.
}
647.
else
648.
{
649.
for
(j=0;j<sdates.length;j++)
650.
{
651.
if
(sdates[j].getTime() == cells[i].date.getTime())
652.
{
653.
sdates.splice(j,1);
654.
break
;
655.
}
656.
}
657.
}
658.
}
659.
}
660.
owner.reDraw();
661.
};
662.
663.
664.
function
CalCell(owner,tableCell,dateObj,row)
665.
{
666.
this
.owner = owner;
667.
this
.tableCell = tableCell;
668.
this
.cellClass;
669.
this
.selected =
false
;
670.
this
.date =
new
Date(dateObj);
671.
this
.dayOfWeek =
this
.date.getDay();
672.
this
.week =
this
.date.getWeek();
673.
this
.tableRow = row;
674.
675.
676.
this
.tableCell.onclick =
this
.onclick;
677.
this
.tableCell.onmouseover =
this
.onmouseover;
678.
this
.tableCell.onmouseout =
this
.onmouseout;
679.
680.
681.
this
.setClass();
682.
}
683.
684.
CalCell.prototype.onmouseover =
function
()
685.
{
686.
this
.setAttribute(
'class'
,
this
.cellClass +
' hover'
);
687.
this
.setAttribute(
'className'
,
this
.cellClass +
' hover'
);
688.
};
689.
690.
CalCell.prototype.onmouseout =
function
()
691.
{
692.
this
.cellObj.setClass();
693.
};
694.
695.
CalCell.prototype.onclick =
function
()
696.
{
697.
698.
var
cell =
this
.cellObj;
699.
var
owner = cell.owner;
700.
if
(!owner.selCurMonthOnly || cell.date.getMonth() == owner.displayMonth && cell.date.getFullYear() == owner.displayYear)
701.
{
702.
if
(owner.selectMultiple ==
true
)
703.
{
704.
if
(!cell.selected)
705.
{
706.
if
(owner.selectedDates.arrayIndex(cell.date) == -1) {
707.
owner.selectedDates.push(cell.date);
708.
}
709.
}
710.
else
711.
{
712.
var
tmp = owner.selectedDates;
713.
714.
for
(
var
i=0;i<tmp.length;i++)
715.
{
716.
if
(tmp[i].getUeDay() == cell.date.getUeDay()) {
717.
tmp.splice(i,1);
718.
}
719.
}
720.
}
721.
}
722.
else
723.
{
724.
owner.selectedDates =
new
Array(cell.date);
725.
if
(owner.tgt)
726.
{
727.
owner.tgt.value = owner.selectedDates[0].dateFormat();
728.
if
(owner.mode ==
'popup'
) {
729.
owner.hide();
730.
}
731.
}
732.
}
733.
owner.reDraw();
734.
}
735.
};
736.
737.
CalCell.prototype.setClass =
function
()
738.
{
739.
if
(
this
.selected) {
740.
this
.cellClass =
'cell_selected'
;
741.
}
742.
else
if
(
this
.owner.displayMonth !=
this
.date.getMonth() ) {
743.
this
.cellClass =
'notmnth'
;
744.
}
745.
else
if
(
this
.date.getDay() > 0 &&
this
.date.getDay() < 6) {
746.
this
.cellClass =
'wkday'
;
747.
}
748.
else
{
749.
this
.cellClass =
'wkend'
;
750.
}
751.
752.
if
(
this
.date.getFullYear() ==
this
.owner.curDate.getFullYear() &&
this
.date.getMonth() ==
this
.owner.curDate.getMonth() &&
this
.date.getDate() ==
this
.owner.curDate.getDate()) {
753.
this
.cellClass =
this
.cellClass +
' curdate'
;
754.
}
755.
756.
this
.tableCell.setAttribute(
'class'
,
this
.cellClass);
757.
this
.tableCell.setAttribute(
'className'
,
this
.cellClass);
758.
};
759.
760.
Date.prototype.getDayOfYear =
function
()
761.
{
762.
return
parseInt((
this
.getTime() -
new
Date(
this
.getFullYear(),0,1).getTime())/86400000 + 1);
763.
};
764.
765.
Date.prototype.getWeek =
function
()
766.
{
767.
return
parseInt((
this
.getTime() -
new
Date(
this
.getFullYear(),0,1).getTime())/604800000 + 1);
768.
};
769.
770.
771.
772.
773.
774.
775.
776.
777.
778.
779.
780.
781.
782.
783.
784.
785.
786.
787.
788.
789.
790.
791.
792.
793.
794.
Date.prototype.getUeDay =
function
()
795.
{
796.
return
parseInt(Math.floor((
this
.getTime() -
this
.getTimezoneOffset() * 60000)/86400000));
797.
};
798.
799.
Date.prototype.dateFormat =
function
(format)
800.
{
801.
if
(!format) {
802.
format =
'd/m/Y'
;
803.
}
804.
LZ =
function
(x) {
return
(x < 0 || x > 9 ?
''
:
'0'
) + x};
805.
var
MONTH_NAMES =
new
Array(
'ม.ค.'
,
'ก.พ.'
,
'มี.ค.'
,
'เม.ย.'
,
'พ.ค.'
,
'มิ.ย.'
,
'ก.ค.'
,
'ส.ค.'
,
'ก.ย.'
,
'ต.ค.'
,
'พ.ย.'
,
'ธ.ค.'
,
'ม.ค.'
,
'ก.พ.'
,
'มี.ค.'
,
'เม.ย.'
,
'พ.ค.'
,
'มิ.ย.'
,
'ก.ค.'
,
'ส.ค.'
,
'ก.ย.'
,
'ต.ค.'
,
'พ.ย.'
,
'ธ.ค.'
);
806.
var
DAY_NAMES =
new
Array(
'Sunday'
,
'Monday'
,
'Tuesday'
,
'Wednesday'
,
'Thursday'
,
'Friday'
,
'Saturday'
,
'Sun'
,
'Mon'
,
'Tue'
,
'Wed'
,
'Thu'
,
'Fri'
,
'Sat'
);
807.
format = format +
""
;
808.
var
result=
""
;
809.
var
i_format=0;
810.
var
c=
""
;
811.
var
token=
""
;
812.
var
y=
this
.getFullYear().toString();
813.
var
M=
this
.getMonth()+1;
814.
var
d=
this
.getDate();
815.
var
E=
this
.getDay();
816.
var
H=
this
.getHours();
817.
var
m=
this
.getMinutes();
818.
var
s=
this
.getSeconds();
819.
var
yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
820.
821.
var
value =
new
Object();
822.
823.
value[
'Y'
] = y.toString();
824.
value[
'y'
] = y.substring(2);
825.
value[
'n'
] = M;
826.
value[
'm'
] = LZ(M);
827.
value[
'F'
] = MONTH_NAMES[M-1];
828.
value[
'M'
] = MONTH_NAMES[M+11];
829.
value[
'j'
] = d;
830.
value[
'd'
] = LZ(d);
831.
value[
'D'
] = DAY_NAMES[E+7];
832.
value[
'l'
] = DAY_NAMES[E];
833.
value[
'G'
] = H;
834.
value[
'H'
] = LZ(H);
835.
if
(H==0) {value[
'g'
]=12;}
836.
else
if
(H>12){value[
'g'
]=H-12;}
837.
else
{value[
'g'
]=H;}
838.
value[
'h'
]=LZ(value[
'g'
]);
839.
if
(H > 11) {value[
'a'
]=
'pm'
; value[
'A'
] =
'PM'
;}
840.
else
{ value[
'a'
]=
'am'
; value[
'A'
] =
'AM'
;}
841.
value[
'i'
]=LZ(m);
842.
value[
's'
]=LZ(s);
843.
844.
while
(i_format < format.length) {
845.
c=format.charAt(i_format);
846.
token=
""
;
847.
while
((format.charAt(i_format)==c) && (i_format < format.length)) {
848.
token += format.charAt(i_format++);
849.
}
850.
if
(value[token] !=
null
) { result=result + value[token]; }
851.
else
{ result=result + token; }
852.
}
853.
return
result;
854.
};
855.
856.
Array.prototype.arrayIndex =
function
(searchVal,startIndex)
857.
{
858.
startIndex = (startIndex !=
null
? startIndex : 0);
859.
for
(
var
i=startIndex;i<
this
.length;i++)
860.
{
861.
if
(searchVal ==
this
[i]) {
862.
return
i;
863.
}
864.
}
865.
return
-1;
866.
};
867.