001.
002.
003.
004.
var fixedX = -1
005.
var fixedY = -1
006.
var startAt = 1
007.
var showWeekNumber = 1
008.
var showToday = 1
009.
var imgDir =
"../image/calendar/"
010.
var gotoString =
"Go To Current Month"
011.
var todayString =
"Today is"
012.
var weekString =
"Week"
013.
var scrollLeftMessage =
"Click to scroll to previous month. Hold mouse button to scroll automatically."
014.
var scrollRightMessage =
"Click to scroll to next month. Hold mouse button to scroll automatically."
015.
var selectMonthMessage =
"Click to select a month."
016.
var selectYearMessage =
"Click to select a year."
017.
var selectDateMessage =
"Select [date] as date."
018.
var monthName =
new
Array(
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
)
019.
020.
var gotoThaiString =
"ไปยังเดือนปัจจุบัน"
021.
var todayThaiString =
"วันนี้วัน"
022.
var weekThaiString =
"สัปดาห์"
023.
var scrollLeftThaiMessage =
"กดเพื่อเลื่อนไปเดือนที่แล้ว , กดค้างไว้เพื่อเลื่อนอัตโนมัติ"
024.
var scrollRightThaiMessage =
"กดเพื่อเลื่อนไปเดือนถัดไป , กดค้างไว้เพื่อเลื่อนอัตโนมัติ"
025.
var selectMonthThaiMessage =
"กดเพื่อเลือกวัน"
026.
var selectYearThaiMessage =
"กดเพื่อเลือกปี"
027.
var selectDateThaiMessage =
"เลือก [date] "
028.
var tmonthName =
new
Array(
"มกราคม"
,
"กุมภาพันธ์"
,
"มีนาคม"
,
"เมษายน"
,
"พฤษภาคม"
,
"มิถุนายน"
,
"กรกฏาคม"
,
"สิงหาคม"
,
"กันยายน"
,
"ตุลาคม"
,
"พฤศจิกายน"
,
"ธันวาคม"
)
029.
var tmonthNameSub =
new
Array(
"ม.ค."
,
"ก.พ."
,
"มี.ค."
,
"เม.ย."
,
"พ.ค."
,
"มิ.ย."
,
"ก.ค."
,
"ส.ค."
,
"ก.ย."
,
"ต.ค."
,
"พ.ย."
,
"ธ.ค."
)
030.
031.
var styleAnchor =
"text-decoration:none;color:black;"
032.
var styleLightBorder =
"border-style:solid;border-width:1px;border-color:#a0a0a0;"
033.
var imgsrc =
new
Array(
"drop1.gif"
,
"drop2.gif"
,
"left1.gif"
,
"left2.gif"
,
"right1.gif"
,
"right2.gif"
)
034.
035.
036.
var crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear
037.
var bPageLoaded =
false
038.
var ie = document.all
039.
var dom = document.getElementById
040.
var ns4 = document.layers
041.
var today =
new
Date()
042.
var dateNow = today.getDate()
043.
var monthNow = today.getMonth()
044.
var yearNow = today.getYear()
045.
var img =
new
Array()
046.
var bShow =
false
;
047.
var HolidaysCounter = 0
048.
var Holidays =
new
Array()
049.
var nowLang =
"E"
050.
051.
function initPopupCalendar() {
052.
if
(dom) {
053.
for
(i = 0; i < imgsrc.length; i++) {
054.
img[i] =
new
Image
055.
img[i].src = imgDir + imgsrc[i]
056.
}
057.
058.
059.
060.
document.write(
"<div id='mask' style='position:absolute;visibility:hidden;'><iframe src='' width='0' height='0' frameborder=0 id='framemask'></iframe></div>"
);
061.
document.write(
"<div id='monthmask' style='position:absolute;visibility:hidden;'><iframe src='' width='0' height='0' frameborder=0 id='framemonthmask'></iframe></div>"
);
062.
document.write(
"<div id='yearmask' style='position:absolute;visibility:hidden;'><iframe src='' width='0' height='0' frameborder=0 id='frameyearmask'></iframe></div>"
);
063.
064.
065.
document.write(
"<div onclick='bShow=true' id='calendar'style='z-index:+999;position:absolute;visibility:hidden;'><table width="
+ ((showWeekNumber == 1) ? 250 : 220) +
" style='font-family:arial;font-size:11px;border-width:1;border-style:solid;border-color:#a0a0a0;font-family:arial; font-size:11px}' bgcolor='#ffffff'><tr bgcolor='#0000aa'><td><table width='"
+ ((showWeekNumber == 1) ? 248 : 218) +
"'><tr><td style='padding:2px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:hideCalendar()'><IMG SRC='"
+ imgDir +
"close.gif' WIDTH='15' HEIGHT='13' BORDER='0' ALT='Close'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='calendar_content'></span></td></tr>"
)
066.
if
(showToday == 1) {
067.
document.write(
"<tr bgcolor=#f0f0f0><td style='padding:5px' align=center><span id='lblToday'></span></td></tr>"
)
068.
}
069.
document.write(
"</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>"
);
070.
}
071.
if
(startAt == 0) {
072.
dayName =
new
Array(
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
)
073.
tdayName =
new
Array(
"อา."
,
"จ."
,
"อ."
,
"พ."
,
"พฤ."
,
"ศ."
,
"ส."
)
074.
fullTName =
new
Array(
"อาทิตย์"
,
"จันทร์"
,
"อังคาร"
,
"พุธ"
,
"พฤหัสบดี"
,
"ศุกร์"
,
"เสาร์"
)
075.
}
076.
else
{
077.
dayName =
new
Array(
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
,
"Sun"
)
078.
tdayName =
new
Array(
"จ."
,
"อ."
,
"พ."
,
"พฤ."
,
"ศ."
,
"ส."
,
"อา."
)
079.
fullTName =
new
Array(
"จันทร์"
,
"อังคาร"
,
"พุธ"
,
"พฤหัสบดี"
,
"ศุกร์"
,
"เสาร์"
,
"อาทิตย์"
)
080.
}
081.
document.onkeypress = function hidecal1() {
082.
if
(
event
.keyCode == 27) {
083.
hideCalendar()
084.
}
085.
}
086.
document.onclick = function hidecal2() {
087.
if
(!bShow) {
088.
hideCalendar()
089.
}
090.
bShow =
false
091.
}
092.
if
(ie) {
093.
init1()
094.
}
095.
else
{
096.
window.onload = init1
097.
}
098.
}
099.
100.
101.
function hideElement(elmID, overDiv) {
102.
103.
104.
if
(ie) {
105.
var obj = document.getElementById(elmID);
106.
if
(obj !=
null
) {
107.
obj.style.visibility =
""
;
108.
obj.style.top = overDiv.offsetTop;
109.
obj.style.left = overDiv.offsetLeft;
110.
var frame = document.getElementById(
"frame"
+ elmID);
111.
if
(frame !=
null
) {
112.
frame.width = overDiv.offsetWidth;
113.
frame.height = overDiv.offsetHeight;
114.
}
115.
}
116.
}
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
}
152.
153.
154.
function showElement(elmID) {
155.
156.
157.
if
(ie) {
158.
var obj =
null
;
159.
obj = document.getElementById(
"mask"
);
160.
if
(obj !=
null
) { obj.style.visibility =
"hidden"
; }
161.
obj = document.getElementById(
"monthmask"
);
162.
if
(obj !=
null
) { obj.style.visibility =
"hidden"
; }
163.
obj = document.getElementById(
"yearmask"
);
164.
if
(obj !=
null
) { obj.style.visibility =
"hidden"
; }
165.
}
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
}
180.
181.
function HolidayRec(d, m, y, desc) {
182.
this
.d = d
183.
this
.m = m
184.
this
.y = y
185.
this
.desc = desc
186.
}
187.
188.
function addHoliday(d, m, y, desc) {
189.
Holidays[HolidaysCounter++] =
new
HolidayRec(d, m, y, desc)
190.
}
191.
192.
function swapImage(srcImg, destImg) {
193.
if
(ie) { document.getElementById(srcImg).setAttribute(
"src"
, imgDir + destImg) }
194.
}
195.
196.
function init1() {
197.
if
(!ns4) {
198.
if
(!ie) { yearNow += 1900 }
199.
200.
crossobj = (dom) ? document.getElementById(
"calendar"
).style : ie ? document.all.calendar : document.calendar
201.
hideCalendar()
202.
crossMonthObj = (dom) ? document.getElementById(
"selectMonth"
).style : ie ? document.all.selectMonth : document.selectMonth
203.
crossYearObj = (dom) ? document.getElementById(
"selectYear"
).style : ie ? document.all.selectYear : document.selectYear
204.
monthConstructed =
false
;
205.
yearConstructed =
false
;
206.
207.
208.
209.
210.
211.
212.
213.
214.
}
215.
}
216.
217.
function init2() {
218.
if
(!ns4) {
219.
if
(!ie) { yearNow += 1900 }
220.
if
(showToday == 1) {
221.
if
(nowLang ==
"T"
) {
222.
document.getElementById(
"lblToday"
).innerHTML =
"<a onmousemove='window.status=\""
+ gotoThaiString +
"\"' onmouseout='window.status=\"\"' title='"
+ gotoThaiString +
"' style='"
+ styleAnchor +
"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>"
+ todayThaiString + fullTName[(today.getDay() - startAt == -1) ? 6 : (today.getDay() - startAt)] +
"ที่ "
+ dateNow +
" "
+ tmonthNameSub[monthNow] +
" "
+ (yearNow + 543) +
"</a>"
223.
}
else
{
224.
document.getElementById(
"lblToday"
).innerHTML = todayString +
" <a onmousemove='window.status=\""
+ gotoString +
"\"' onmouseout='window.status=\"\"' title='"
+ gotoString +
"' style='"
+ styleAnchor +
"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>"
+ dayName[(today.getDay() - startAt == -1) ? 6 : (today.getDay() - startAt)] +
", "
+ dateNow +
" "
+ monthName[monthNow].substring(0, 3) +
" "
+ yearNow +
"</a>"
225.
}
226.
}
227.
228.
if
(nowLang ==
"T"
) {
229.
sHTML1 =
"<span id='spanLeft' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""
+ scrollLeftThaiMessage +
"\"' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)' onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> <IMG id='changeLeft' SRC='"
+ imgDir +
"left1.gif' width=10 height=11 BORDER=0> </span> "
230.
sHTML1 +=
"<span id='spanRight' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""
+ scrollRightThaiMessage +
"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)' onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> <IMG id='changeRight' SRC='"
+ imgDir +
"right1.gif' width=10 height=11 BORDER=0> </span> "
231.
sHTML1 +=
"<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""
+ selectMonthThaiMessage +
"\"' onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='popUpMonth()'></span> "
232.
sHTML1 +=
"<span id='spanYear' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""
+ selectYearThaiMessage +
"\"' onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='popUpYear()'></span> "
233.
}
else
{
234.
sHTML1 =
"<span id='spanLeft' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""
+ scrollLeftMessage +
"\"' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)' onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> <IMG id='changeLeft' SRC='"
+ imgDir +
"left1.gif' width=10 height=11 BORDER=0> </span> "
235.
sHTML1 +=
"<span id='spanRight' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""
+ scrollRightMessage +
"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)' onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> <IMG id='changeRight' SRC='"
+ imgDir +
"right1.gif' width=10 height=11 BORDER=0> </span> "
236.
sHTML1 +=
"<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""
+ selectMonthMessage +
"\"' onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='popUpMonth()'></span> "
237.
sHTML1 +=
"<span id='spanYear' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""
+ selectYearMessage +
"\"' onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='popUpYear()'></span> "
238.
}
239.
document.getElementById(
"caption"
).innerHTML = sHTML1
240.
bPageLoaded =
true
241.
}
242.
}
243.
244.
function hideCalendar() {
245.
crossobj.visibility =
"hidden"
246.
if
(crossMonthObj !=
null
) { crossMonthObj.visibility =
"hidden"
}
247.
if
(crossYearObj !=
null
) { crossYearObj.visibility =
"hidden"
}
248.
showElement(
'SELECT'
);
249.
showElement(
'APPLET'
);
250.
}
251.
252.
function padZero(num) {
253.
return
(num < 10) ?
'0'
+ num : num;
254.
}
255.
256.
function constructDate(d, m, y) {
257.
sTmp = dateFormat
258.
sTmp = sTmp.replace(
"dd"
,
"<e>"
)
259.
sTmp = sTmp.replace(
"d"
,
"<d>"
)
260.
sTmp = sTmp.replace(
"<e>"
, padZero(d))
261.
sTmp = sTmp.replace(
"<d>"
, d)
262.
sTmp = sTmp.replace(
"mmm"
,
"<o>"
)
263.
sTmp = sTmp.replace(
"mm"
,
"<n>"
)
264.
sTmp = sTmp.replace(
"m"
,
"<m>"
)
265.
sTmp = sTmp.replace(
"<m>"
, m + 1)
266.
sTmp = sTmp.replace(
"<n>"
, padZero(m + 1))
267.
sTmp = sTmp.replace(
"<o>"
, monthName[m])
268.
if
(nowLang ==
"T"
) {
269.
y += 543;
270.
}
271.
return
sTmp.replace(
"yyyy"
, y)
272.
}
273.
274.
function closeCalendar() {
275.
var sTmp
276.
hideCalendar();
277.
var selDate = constructDate(dateSelected, monthSelected, yearSelected)
278.
if
((yearSelected - 0) < 2400) {
279.
yearSelected = (yearSelected - 0) + 543;
280.
}
281.
monthSelected++;
282.
283.
ctlToPlaceValue.value = selDate;
284.
285.
}
286.
287.
288.
function StartDecMonth() {
289.
intervalID1 = setInterval(
"decMonth()"
, 80)
290.
}
291.
292.
function StartIncMonth() {
293.
intervalID1 = setInterval(
"incMonth()"
, 80)
294.
}
295.
296.
function incMonth() {
297.
monthSelected++
298.
if
(monthSelected > 11) {
299.
monthSelected = 0
300.
yearSelected++
301.
}
302.
constructCalendar()
303.
hideElement(
'mask'
, document.getElementById(
"calendar"
));
304.
}
305.
306.
function decMonth() {
307.
monthSelected--
308.
if
(monthSelected < 0) {
309.
monthSelected = 11
310.
yearSelected--
311.
}
312.
constructCalendar()
313.
hideElement(
'mask'
, document.getElementById(
"calendar"
));
314.
}
315.
316.
function constructMonth() {
317.
popDownYear()
318.
if
(!monthConstructed) {
319.
sHTML =
""
320.
for
(i = 0; i < 12; i++) {
321.
if
(nowLang ==
"T"
) {
322.
sName = tmonthName[i];
323.
}
else
{
324.
sName = monthName[i];
325.
}
326.
if
(i == monthSelected) {
327.
sName =
"<B>"
+ sName +
"</B>"
328.
}
329.
sHTML +=
"<tr><td id='m"
+ i +
"' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='monthConstructed=false;monthSelected="
+ i +
";constructCalendar();popDownMonth();event.cancelBubble=true'> "
+ sName +
" </td></tr>"
330.
}
331.
332.
document.getElementById(
"selectMonth"
).innerHTML =
"<table width=70 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='#FFFFDD' cellspacing=0 onmouseover='clearTimeout(timeoutID1)' onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>"
+ sHTML +
"</table>"
333.
monthConstructed =
true
334.
}
335.
}
336.
337.
function popUpMonth() {
338.
constructMonth()
339.
crossMonthObj.visibility = (dom || ie) ?
"visible"
:
"show"
340.
crossMonthObj.left = parseInt(crossobj.left) + 50
341.
crossMonthObj.top = parseInt(crossobj.top) + 26
342.
343.
hideElement(
'monthmask'
, document.getElementById(
"selectMonth"
));
344.
345.
346.
}
347.
348.
function popDownMonth() {
349.
crossMonthObj.visibility =
"hidden"
350.
showElement();
351.
hideElement(
'mask'
, document.getElementById(
"calendar"
));
352.
}
353.
354.
355.
function incYear() {
356.
for
(i = 0; i < 7; i++) {
357.
newYear = (i + nStartingYear) + 1
358.
if
(newYear == yearSelected) {
359.
if
(nowLang ==
"T"
) {
360.
newYear += 543;
361.
}
362.
txtYear =
" <B>"
+ newYear +
"</B> "
363.
}
else
{
364.
if
(nowLang ==
"T"
) {
365.
newYear += 543;
366.
}
367.
txtYear =
" "
+ newYear +
" "
368.
}
369.
document.getElementById(
"y"
+ i).innerHTML = txtYear
370.
}
371.
nStartingYear++;
372.
bShow =
true
373.
}
374.
375.
function decYear() {
376.
for
(i = 0; i < 7; i++) {
377.
newYear = (i + nStartingYear) - 1
378.
if
(newYear == yearSelected) {
379.
if
(nowLang ==
"T"
) {
380.
newYear += 543;
381.
}
382.
txtYear =
" <B>"
+ newYear +
"</B> "
383.
}
else
{
384.
if
(nowLang ==
"T"
) {
385.
newYear += 543;
386.
}
387.
txtYear =
" "
+ newYear +
" "
388.
}
389.
document.getElementById(
"y"
+ i).innerHTML = txtYear
390.
}
391.
nStartingYear--;
392.
bShow =
true
393.
}
394.
395.
396.
397.
function selectYear(nYear) {
398.
yearSelected = parseInt(nYear + nStartingYear);
399.
yearConstructed =
false
;
400.
constructCalendar();
401.
popDownYear();
402.
}
403.
404.
function constructYear() {
405.
popDownMonth()
406.
sHTML =
""
407.
if
(!yearConstructed) {
408.
sHTML =
"<tr><td align='center' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"
409.
j = 0
410.
nStartingYear = yearSelected - 3
411.
for
(i = (yearSelected - 3); i <= (yearSelected + 3); i++) {
412.
sName = i;
413.
if
(nowLang ==
"T"
) {
414.
sName += 543;
415.
}
416.
if
(i == yearSelected) {
417.
sName =
"<B>"
+ sName +
"</B>"
418.
}
419.
sHTML +=
"<tr><td id='y"
+ j +
"' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectYear("
+ j +
");event.cancelBubble=true'> "
+ sName +
" </td></tr>"
420.
j++;
421.
}
422.
sHTML +=
"<tr><td align='center' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)' onmouseup='clearInterval(intervalID2)'>+</td></tr>"
423.
document.getElementById(
"selectYear"
).innerHTML =
"<table width=44 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='#FFFFDD' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"
+ sHTML +
"</table>"
424.
yearConstructed =
true
425.
}
426.
}
427.
428.
function popDownYear() {
429.
clearInterval(intervalID1)
430.
clearTimeout(timeoutID1)
431.
clearInterval(intervalID2)
432.
clearTimeout(timeoutID2)
433.
crossYearObj.visibility =
"hidden"
434.
435.
436.
showElement();
437.
hideElement(
'mask'
, document.getElementById(
"calendar"
));
438.
439.
}
440.
441.
function popUpYear() {
442.
var leftOffset
443.
constructYear()
444.
crossYearObj.visibility = (dom || ie) ?
"visible"
:
"show"
445.
leftOffset = parseInt(crossobj.left) + document.getElementById(
"spanYear"
).offsetLeft
446.
if
(ie) {
447.
leftOffset += 6
448.
}
449.
crossYearObj.left = leftOffset
450.
crossYearObj.top = parseInt(crossobj.top) + 26
451.
452.
hideElement(
'yearmask'
, document.getElementById(
"selectYear"
));
453.
}
454.
455.
function WeekNbr(n) {
456.
457.
458.
459.
460.
461.
462.
463.
464.
465.
466.
467.
468.
year = n.getFullYear();
469.
month = n.getMonth() + 1;
470.
if
(startAt == 0) {
471.
day = n.getDate() + 1;
472.
}
473.
else
{
474.
day = n.getDate();
475.
}
476.
a = Math.floor((14 - month) / 12);
477.
y = year + 4800 - a;
478.
m = month + 12 * a - 3;
479.
b = Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400);
480.
J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
481.
d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
482.
L = Math.floor(d4 / 1460);
483.
d1 = ((d4 - L) % 365) + L;
484.
week = Math.floor(d1 / 7) + 1;
485.
return
week;
486.
}
487.
488.
function constructCalendar() {
489.
var aNumDays = Array(31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
490.
var dateMessage
491.
var startDate =
new
Date(yearSelected, monthSelected, 1)
492.
var endDate
493.
if
(monthSelected == 1) {
494.
endDate =
new
Date(yearSelected, monthSelected + 1, 1);
495.
endDate =
new
Date(endDate - (24 * 60 * 60 * 1000));
496.
numDaysInMonth = endDate.getDate()
497.
}
498.
else
{
499.
numDaysInMonth = aNumDays[monthSelected];
500.
}
501.
datePointer = 0
502.
dayPointer = startDate.getDay() - startAt
503.
if
(dayPointer < 0) {
504.
dayPointer = 6
505.
}
506.
sHTML =
"<table border=0 style='font-family:verdana;font-size:10px;'><tr>"
507.
if
(showWeekNumber == 1) {
508.
if
(nowLang ==
"T"
) {
509.
sHTML +=
"<td width=27><b>"
+ weekThaiString +
"</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><img src='"
+ imgDir +
"divider.gif' width=1></td>"
510.
}
else
{
511.
sHTML +=
"<td width=27><b>"
+ weekString +
"</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><img src='"
+ imgDir +
"divider.gif' width=1></td>"
512.
}
513.
}
514.
for
(i = 0; i < 7; i++) {
515.
if
(nowLang ==
"T"
) {
516.
sHTML +=
"<td width='27' align='right'><B>"
+ tdayName[i] +
"</B></td>"
517.
}
else
{
518.
sHTML +=
"<td width='27' align='right'><B>"
+ dayName[i] +
"</B></td>"
519.
}
520.
}
521.
sHTML +=
"</tr><tr>"
522.
if
(showWeekNumber == 1) {
523.
sHTML +=
"<td align=right>"
+ WeekNbr(startDate) +
" </td>"
524.
}
525.
for
(var i = 1; i <= dayPointer; i++) {
526.
sHTML +=
"<td> </td>"
527.
}
528.
for
(datePointer = 1; datePointer <= numDaysInMonth; datePointer++) {
529.
dayPointer++;
530.
sHTML +=
"<td align=right>"
531.
sStyle = styleAnchor
532.
if
((datePointer == odateSelected) && (monthSelected == omonthSelected) && (yearSelected == oyearSelected))
533.
{ sStyle += styleLightBorder }
534.
sHint =
""
535.
for
(k = 0; k < HolidaysCounter; k++) {
536.
if
((parseInt(Holidays[k].d) == datePointer) && (parseInt(Holidays[k].m) == (monthSelected + 1))) {
537.
if
((parseInt(Holidays[k].y) == 0) || ((parseInt(Holidays[k].y) == yearSelected) && (parseInt(Holidays[k].y) != 0))) {
538.
sStyle +=
"background-color:#FFDDDD;"
539.
sHint += sHint ==
""
? Holidays[k].desc :
"\n"
+ Holidays[k].desc
540.
}
541.
}
542.
}
543.
var regexp = /\"/g
544.
sHint = sHint.replace(regexp,
"""
)
545.
dateMessage =
"onmousemove='window.status=\""
+ selectDateMessage.replace(
"[date]"
, constructDate(datePointer, monthSelected, yearSelected)) +
"\"' onmouseout='window.status=\"\"' "
546.
if
((datePointer == dateNow) && (monthSelected == monthNow) && (yearSelected == yearNow))
547.
{ sHTML +=
"<b><a "
+ dateMessage +
" title=\""
+ sHint +
"\" style='"
+ sStyle +
"' href='javascript:dateSelected="
+ datePointer +
";closeCalendar();'><font color=#ff0000> "
+ datePointer +
"</font> </a></b>"
}
548.
else
if
(dayPointer % 7 == (startAt * -1) + 1)
549.
{ sHTML +=
"<a "
+ dateMessage +
" title=\""
+ sHint +
"\" style='"
+ sStyle +
"' href='javascript:dateSelected="
+ datePointer +
";closeCalendar();'> <font color=#909090>"
+ datePointer +
"</font> </a>"
}
550.
else
551.
{ sHTML +=
"<a "
+ dateMessage +
" title=\""
+ sHint +
"\" style='"
+ sStyle +
"' href='javascript:dateSelected="
+ datePointer +
";closeCalendar();'> "
+ datePointer +
" </a>"
}
552.
553.
sHTML +=
""
554.
if
((dayPointer + startAt) % 7 == startAt) {
555.
sHTML +=
"</tr><tr>"
556.
if
((showWeekNumber == 1) && (datePointer < numDaysInMonth)) {
557.
sHTML +=
"<td align=right>"
+ (WeekNbr(
new
Date(yearSelected, monthSelected, datePointer + 1))) +
" </td>"
558.
}
559.
}
560.
}
561.
document.getElementById(
"calendar_content"
).innerHTML = sHTML
562.
if
(nowLang ==
"T"
) {
563.
document.getElementById(
"spanMonth"
).innerHTML =
" "
+ tmonthName[monthSelected] +
" <IMG id='changeMonth' SRC='"
+ imgDir +
"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
564.
document.getElementById(
"spanYear"
).innerHTML =
" "
+ (yearSelected + 543) +
" <IMG id='changeYear' SRC='"
+ imgDir +
"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
565.
}
else
{
566.
document.getElementById(
"spanMonth"
).innerHTML =
" "
+ monthName[monthSelected] +
" <IMG id='changeMonth' SRC='"
+ imgDir +
"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
567.
document.getElementById(
"spanYear"
).innerHTML =
" "
+ yearSelected +
" <IMG id='changeYear' SRC='"
+ imgDir +
"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
568.
}
569.
}
570.
571.
function popUpCalendar(ctl) {
572.
573.
var ctl2 = ctl;
574.
var format=
"dd/mm/yyyy"
;
575.
var lang =
"T"
;
576.
var leftpos = 0
577.
var toppos = 0
578.
579.
if
(lang !=
null
&& lang ==
"T"
) {
580.
nowLang =
"T"
;
581.
}
else
{
582.
nowLang =
"E"
;
583.
}
584.
585.
init2();
586.
587.
if
(bPageLoaded) {
588.
if
(crossobj.visibility ==
"hidden"
) {
589.
ctlToPlaceValue = ctl2
590.
dateFormat = format;
591.
formatChar =
" "
592.
aFormat = dateFormat.split(formatChar)
593.
if
(aFormat.length < 3) {
594.
formatChar =
"/"
595.
aFormat = dateFormat.split(formatChar)
596.
if
(aFormat.length < 3) {
597.
formatChar =
"."
598.
aFormat = dateFormat.split(formatChar)
599.
if
(aFormat.length < 3) {
600.
formatChar =
"-"
601.
aFormat = dateFormat.split(formatChar)
602.
if
(aFormat.length < 3) {
603.
604.
formatChar =
""
605.
}
606.
}
607.
}
608.
}
609.
tokensChanged = 0
610.
if
(formatChar !=
""
) {
611.
612.
aData = ctl2.value.split(formatChar)
613.
for
(i = 0; i < 3; i++) {
614.
if
((aFormat[i] ==
"d"
) || (aFormat[i] ==
"dd"
)) {
615.
dateSelected = parseInt(aData[i], 10)
616.
tokensChanged++
617.
}
618.
else
if
((aFormat[i] ==
"m"
) || (aFormat[i] ==
"mm"
)) {
619.
monthSelected = parseInt(aData[i], 10) - 1
620.
tokensChanged++
621.
}
622.
else
if
(aFormat[i] ==
"yyyy"
) {
623.
if
(nowLang ==
"T"
) {
624.
aData[i] -= 543;
625.
}
626.
yearSelected = parseInt(aData[i], 10)
627.
tokensChanged++
628.
}
629.
else
if
(aFormat[i] ==
"mmm"
) {
630.
for
(j = 0; j < 12; j++) {
631.
if
(aData[i] == monthName[j]) {
632.
monthSelected = j
633.
tokensChanged++
634.
}
635.
}
636.
}
637.
}
638.
}
639.
if
((tokensChanged != 3) || isNaN(dateSelected) || isNaN(monthSelected) || isNaN(yearSelected)) {
640.
dateSelected = dateNow
641.
monthSelected = monthNow
642.
yearSelected = yearNow
643.
}
644.
odateSelected = dateSelected
645.
omonthSelected = monthSelected
646.
oyearSelected = yearSelected
647.
aTag = ctl
648.
649.
do
{
650.
aTag = aTag.offsetParent;
651.
if
(!aTag) {
break
; }
652.
leftpos += aTag.offsetLeft;
653.
toppos += aTag.offsetTop;
654.
}
while
(aTag.tagName !=
"BODY"
);
655.
crossobj.left = fixedX == -1 ? ctl.offsetLeft + leftpos : fixedX
656.
crossobj.top = fixedY == -1 ? ctl.offsetTop + toppos + ctl.offsetHeight + 2 : fixedY
657.
constructCalendar(1, monthSelected, yearSelected);
658.
crossobj.visibility = (dom || ie) ?
"visible"
:
"show"
659.
hideElement(
'mask'
, document.getElementById(
"calendar"
));
660.
661.
662.
bShow =
true
;
663.
}
664.
else
{
665.
hideCalendar()
666.
if
(ctlNow != ctl) { popUpCalendar(ctl) }
667.
}
668.
ctlNow = ctl
669.
}
670.
}