calendar.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. var fixedX = -1 // x position (-1 if to appear below control)
  2. var fixedY = -1 // y position (-1 if to appear below control)
  3. var startAt = 1 // 0 - sunday ; 1 - monday
  4. var showWeekNumber = 0 // 0 - don't show; 1 - show
  5. var showToday = 0 // 0 - don't show; 1 - show
  6. var imgDir = "../images/calendar/" // directory for images ... e.g. var imgDir="/img/"
  7. var gotoString = "Go To Current Month"
  8. var todayString = "Today is"
  9. var weekString = "Wk"
  10. var scrollLeftMessage = "选择上个月."
  11. var scrollRightMessage = "选择下个月."
  12. var selectMonthMessage = "点这里选择一个月份."
  13. var selectYearMessage = "点这里选择年."
  14. var selectDateMessage = "选择日期: [date] " // do not replace [date], it will be replaced by date.
  15. var crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear, nStartingMonth
  16. var bPageLoaded=false
  17. var ie = false;
  18. var dom=document.getElementById
  19. var ns4=document.layers
  20. var today = new Date()
  21. var dateNow = today.getDate()
  22. var monthNow = today.getMonth()
  23. var yearNow = today.getYear()
  24. var imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif")
  25. var img = new Array()
  26. var bShow = false;
  27. if((navigator.userAgent.toLowerCase().indexOf("opera") == -1) && (navigator.userAgent.toLowerCase().indexOf("msie") != -1))
  28. {
  29. ie = true;
  30. }
  31. /* hides <select> and <applet> objects (for IE only) */
  32. function hideElement( elmID, overDiv )
  33. {
  34. if( ie )
  35. {
  36. for( i = 0; i < document.all.tags( elmID ).length; i++ )
  37. {
  38. obj = document.all.tags( elmID )[i];
  39. if( !obj || !obj.offsetParent )
  40. {
  41. continue;
  42. }
  43. // Find the element's offsetTop and offsetLeft relative to the BODY tag.
  44. objLeft = obj.offsetLeft;
  45. objTop = obj.offsetTop;
  46. objParent = obj.offsetParent;
  47. while( objParent.tagName.toUpperCase() != "BODY" )
  48. {
  49. objLeft += objParent.offsetLeft;
  50. objTop += objParent.offsetTop;
  51. objParent = objParent.offsetParent;
  52. }
  53. objHeight = obj.offsetHeight;
  54. objWidth = obj.offsetWidth;
  55. if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
  56. else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
  57. else if( overDiv.offsetTop >= ( objTop + objHeight ));
  58. else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
  59. else
  60. {
  61. obj.style.visibility = "hidden";
  62. }
  63. }
  64. }
  65. }
  66. /*
  67. * unhides <select> and <applet> objects (for IE only)
  68. */
  69. function showElement( elmID )
  70. {
  71. if( ie )
  72. {
  73. for( i = 0; i < document.all.tags( elmID ).length; i++ )
  74. {
  75. obj = document.all.tags( elmID )[i];
  76. if( !obj || !obj.offsetParent )
  77. {
  78. continue;
  79. }
  80. obj.style.visibility = "";
  81. }
  82. }
  83. }
  84. function HolidayRec (d, m, y, desc)
  85. {
  86. this.d = d
  87. this.m = m
  88. this.y = y
  89. this.desc = desc
  90. }
  91. var HolidaysCounter = 0
  92. var Holidays = new Array()
  93. function addHoliday (d, m, y, desc)
  94. {
  95. Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
  96. }
  97. if (dom)
  98. {
  99. for (i=0;i<imgsrc.length;i++)
  100. {
  101. img[i] = new Image
  102. img[i].src = imgDir + imgsrc[i]
  103. }
  104. 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='关闭'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='content'></span></td></tr>")
  105. if (showToday==1)
  106. {
  107. document.write ("<tr bgcolor=#f0f0f0><td style='padding:5px' align=center><span id='lblToday'></span></td></tr>")
  108. }
  109. 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>");
  110. }
  111. var monthName = new Array("01","02","03","04","05","06","07","08","09","10","11","12")
  112. var monthName2 = new Array("01","02","03","04","05","06","07","08","09","10","11","12")
  113. if (startAt==0)
  114. {
  115. dayName = new Array ("日","一","二","三","四","五","六")
  116. }
  117. else
  118. {
  119. dayName = new Array ("一","二","三","四","五","六","日")
  120. }
  121. var styleAnchor="text-decoration:none;color:black;"
  122. var styleLightBorder="border-style:solid;border-width:1px;border-color:#a0a0a0;"
  123. function swapImage(srcImg, destImg){
  124. if (ie) { document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
  125. }
  126. function init() {
  127. if (!ns4)
  128. {
  129. if (!ie) { yearNow += 1900 }
  130. crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar
  131. hideCalendar()
  132. crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth : document.selectMonth
  133. crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear
  134. monthConstructed=false;
  135. yearConstructed=false;
  136. if (showToday==1)
  137. {
  138. 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>"
  139. }
  140. 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)'>&nbsp<IMG id='changeLeft' SRC='"+imgDir+"left1.gif' width=10 height=11 BORDER=0>&nbsp</span>&nbsp;"
  141. 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)'>&nbsp<IMG id='changeRight' SRC='"+imgDir+"right1.gif' width=10 height=11 BORDER=0>&nbsp</span>&nbsp"
  142. 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>&nbsp;"
  143. 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>&nbsp;"
  144. document.getElementById("caption").innerHTML = sHTML1
  145. bPageLoaded=true
  146. }
  147. }
  148. function hideCalendar() {
  149. crossobj.visibility="hidden"
  150. if (crossMonthObj != null){crossMonthObj.visibility="hidden"}
  151. if (crossYearObj != null){crossYearObj.visibility="hidden"}
  152. showElement( 'SELECT' );
  153. showElement( 'APPLET' );
  154. }
  155. function padZero(num) {
  156. return (num < 10)? '0' + num : num ;
  157. }
  158. function constructDate(d,m,y)
  159. {
  160. sTmp = dateFormat
  161. sTmp = sTmp.replace ("dd","<e>")
  162. sTmp = sTmp.replace ("d","<d>")
  163. sTmp = sTmp.replace ("<e>",padZero(d))
  164. sTmp = sTmp.replace ("<d>",d)
  165. sTmp = sTmp.replace ("mmmm","<p>")
  166. sTmp = sTmp.replace ("mmm","<o>")
  167. sTmp = sTmp.replace ("mm","<n>")
  168. sTmp = sTmp.replace ("m","<m>")
  169. sTmp = sTmp.replace ("<m>",m+1)
  170. sTmp = sTmp.replace ("<n>",padZero(m+1))
  171. sTmp = sTmp.replace ("<o>",monthName[m])
  172. sTmp = sTmp.replace ("<p>",monthName2[m])
  173. sTmp = sTmp.replace ("yyyy",y)
  174. return sTmp.replace ("yy",padZero(y%100))
  175. }
  176. function closeCalendar() {
  177. var sTmp
  178. hideCalendar();
  179. ctlToPlaceValue.value = constructDate(dateSelected,monthSelected,yearSelected)
  180. }
  181. /*** Month Pulldown ***/
  182. function StartDecMonth()
  183. {
  184. intervalID1=setInterval("decMonth()",80)
  185. }
  186. function StartIncMonth()
  187. {
  188. intervalID1=setInterval("incMonth()",80)
  189. }
  190. function incMonth () {
  191. monthSelected++
  192. if (monthSelected>11) {
  193. monthSelected=0
  194. yearSelected++
  195. }
  196. constructCalendar()
  197. }
  198. function decMonth () {
  199. monthSelected--
  200. if (monthSelected<0) {
  201. monthSelected=11
  202. yearSelected--
  203. }
  204. constructCalendar()
  205. }
  206. function upMonth() {
  207. if(nStartingMonth > 0)
  208. {
  209. nStartingMonth --;
  210. for (i=0; i<6; i++)
  211. {
  212. newMonth = (i + nStartingMonth);
  213. if (newMonth == monthSelected)
  214. txtMonth = "&nbsp;<B>" + monthName[newMonth] + "</B>&nbsp;";
  215. else
  216. txtMonth = "&nbsp;" + monthName[newMonth] + "&nbsp;";
  217. document.getElementById("m"+i).innerHTML = txtMonth;
  218. }
  219. }
  220. bShow=true
  221. }
  222. function downMonth() {
  223. if(nStartingMonth < 6)
  224. {
  225. nStartingMonth ++;
  226. for (i=0; i<6; i++)
  227. {
  228. newMonth = (i + nStartingMonth);
  229. if (newMonth == monthSelected)
  230. txtMonth = "&nbsp;<B>" + monthName[newMonth] + "</B>&nbsp;";
  231. else
  232. txtMonth = "&nbsp;" + monthName[newMonth] + "&nbsp;";
  233. document.getElementById("m"+i).innerHTML = txtMonth;
  234. }
  235. }
  236. bShow=true
  237. }
  238. function selectMonth(nMonth) {
  239. monthSelected=parseInt(nMonth+nStartingMonth);
  240. monthConstructed=false;
  241. constructCalendar();
  242. popDownMonth();
  243. }
  244. function constructMonth() {
  245. popDownYear()
  246. if (!monthConstructed) {
  247. sHTML = "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"upMonth()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"
  248. j=0;
  249. i=(monthSelected-3);
  250. if(i < 0)
  251. i=0;
  252. if(i > 6)
  253. i=6;
  254. nStartingMonth = i;
  255. for (ii=0; ii<6; ii++, i++, j++) {
  256. sName = monthName[i];
  257. if (i==monthSelected){
  258. sName = "<B>" + sName + "</B>"
  259. }
  260. sHTML += "<tr><td id='m" + j + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectMonth(" + j + ");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
  261. }
  262. sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"downMonth()\",30)' onmouseup='clearInterval(intervalID2)'>+</td></tr>"
  263. document.getElementById("selectMonth").innerHTML = "<table width=32 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>"
  264. monthConstructed=true
  265. }
  266. }
  267. function popUpMonth() {
  268. constructMonth()
  269. crossMonthObj.visibility = (dom||ie)? "visible" : "show"
  270. crossMonthObj.left = parseInt(crossobj.left) + 50
  271. crossMonthObj.top = parseInt(crossobj.top) + 26
  272. hideElement( 'SELECT', document.getElementById("selectMonth") );
  273. hideElement( 'APPLET', document.getElementById("selectMonth") );
  274. }
  275. function popDownMonth() {
  276. crossMonthObj.visibility= "hidden"
  277. }
  278. /*** Year Pulldown ***/
  279. function incYear() {
  280. for (i=0; i<6; i++){
  281. newYear = (i+nStartingYear)+1
  282. if (newYear==yearSelected)
  283. { txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" }
  284. else
  285. { txtYear = "&nbsp;" + newYear + "&nbsp;" }
  286. document.getElementById("y"+i).innerHTML = txtYear
  287. }
  288. nStartingYear ++;
  289. bShow=true
  290. }
  291. function decYear() {
  292. for (i=0; i<6; i++){
  293. newYear = (i+nStartingYear)-1
  294. if (newYear==yearSelected)
  295. { txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" }
  296. else
  297. { txtYear = "&nbsp;" + newYear + "&nbsp;" }
  298. document.getElementById("y"+i).innerHTML = txtYear
  299. }
  300. nStartingYear --;
  301. bShow=true
  302. }
  303. function selectYear(nYear) {
  304. yearSelected=parseInt(nYear+nStartingYear);
  305. yearConstructed=false;
  306. constructCalendar();
  307. popDownYear();
  308. }
  309. function constructYear() {
  310. popDownMonth()
  311. sHTML = ""
  312. if (!yearConstructed) {
  313. 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>"
  314. j = 0
  315. nStartingYear = yearSelected-3
  316. for (i=(yearSelected-3); i<(yearSelected+3); i++) {
  317. sName = i;
  318. if (i==yearSelected){
  319. sName = "<B>" + sName + "</B>"
  320. }
  321. sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
  322. j ++;
  323. }
  324. 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>"
  325. document.getElementById("selectYear").innerHTML = "<table width=45 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>"
  326. yearConstructed = true
  327. }
  328. }
  329. function popDownYear() {
  330. clearInterval(intervalID1)
  331. clearTimeout(timeoutID1)
  332. clearInterval(intervalID2)
  333. clearTimeout(timeoutID2)
  334. crossYearObj.visibility= "hidden"
  335. }
  336. function popUpYear() {
  337. var leftOffset
  338. constructYear()
  339. crossYearObj.visibility = (dom||ie)? "visible" : "show"
  340. leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft
  341. if (ie)
  342. {
  343. leftOffset += 6
  344. }
  345. crossYearObj.left = leftOffset
  346. crossYearObj.top = parseInt(crossobj.top) + 26
  347. }
  348. /*** calendar ***/
  349. function WeekNbr(n) {
  350. // Algorithm used:
  351. // From Klaus Tondering's Calendar document (The Authority/Guru)
  352. // hhtp://www.tondering.dk/claus/calendar.html
  353. // a = (14-month) / 12
  354. // y = year + 4800 - a
  355. // m = month + 12a - 3
  356. // J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045
  357. // d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
  358. // L = d4 / 1460
  359. // d1 = ((d4 - L) mod 365) + L
  360. // WeekNumber = d1 / 7 + 1
  361. year = n.getFullYear();
  362. month = n.getMonth() + 1;
  363. if (startAt == 0) {
  364. day = n.getDate() + 1;
  365. }
  366. else {
  367. day = n.getDate();
  368. }
  369. a = Math.floor((14-month) / 12);
  370. y = year + 4800 - a;
  371. m = month + 12 * a - 3;
  372. b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
  373. J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
  374. d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
  375. L = Math.floor(d4 / 1460);
  376. d1 = ((d4 - L) % 365) + L;
  377. week = Math.floor(d1/7) + 1;
  378. return week;
  379. }
  380. function constructCalendar () {
  381. var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)
  382. var dateMessage
  383. var startDate = new Date (yearSelected,monthSelected,1)
  384. var endDate
  385. if (monthSelected==1)
  386. {
  387. endDate = new Date (yearSelected,monthSelected+1,1);
  388. endDate = new Date (endDate - (24*60*60*1000));
  389. numDaysInMonth = endDate.getDate()
  390. }
  391. else
  392. {
  393. numDaysInMonth = aNumDays[monthSelected];
  394. }
  395. datePointer = 0
  396. dayPointer = startDate.getDay() - startAt
  397. if (dayPointer<0)
  398. {
  399. dayPointer = 6
  400. }
  401. sHTML = "<table border=0 style='font-family:verdana;font-size:10px;'><tr>"
  402. if (showWeekNumber==1)
  403. {
  404. 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>"
  405. }
  406. for (i=0; i<7; i++) {
  407. sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>"
  408. }
  409. sHTML +="</tr><tr>"
  410. if (showWeekNumber==1)
  411. {
  412. sHTML += "<td align=right>" + WeekNbr(startDate) + "&nbsp;</td>"
  413. }
  414. for ( var i=1; i<=dayPointer;i++ )
  415. {
  416. sHTML += "<td>&nbsp;</td>"
  417. }
  418. for ( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
  419. {
  420. dayPointer++;
  421. sHTML += "<td align=right class=xyz>"
  422. sStyle=styleAnchor
  423. if ((datePointer==odateSelected) && (monthSelected==omonthSelected) && (yearSelected==oyearSelected))
  424. { sStyle+=styleLightBorder }
  425. sHint = ""
  426. for (k=0;k<HolidaysCounter;k++)
  427. {
  428. if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
  429. {
  430. if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
  431. {
  432. sStyle+="background-color:#FFDDDD;"
  433. sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
  434. }
  435. }
  436. }
  437. var regexp= /\"/g
  438. sHint=sHint.replace(regexp,"&quot;")
  439. dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "
  440. if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
  441. { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer+";closeCalendar();'>&nbsp;<font color=#ff0000>" + datePointer + "</font>&nbsp;</a>"}
  442. else if (dayPointer % 7 == (startAt * -1)+1)
  443. { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;<font color=#909090>" + datePointer + "</font>&nbsp;</a>" }
  444. else
  445. { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>" }
  446. sHTML += ""
  447. if ((dayPointer+startAt) % 7 == startAt) {
  448. sHTML += "</tr><tr>"
  449. if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
  450. {
  451. sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + "&nbsp;</td>"
  452. }
  453. }
  454. }
  455. document.getElementById("content").innerHTML = sHTML
  456. document.getElementById("spanMonth").innerHTML = "&nbsp;" + monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
  457. document.getElementById("spanYear").innerHTML = "&nbsp;" + yearSelected + "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
  458. }
  459. function popUpCalendar(ctl, ctl2, format) {
  460. var leftpos=0
  461. var toppos=0
  462. if (bPageLoaded)
  463. {
  464. if ( crossobj.visibility == "hidden" ) {
  465. ctlToPlaceValue = ctl2
  466. dateFormat=format;
  467. formatChar = " "
  468. aFormat = dateFormat.split(formatChar)
  469. if (aFormat.length<3)
  470. {
  471. formatChar = "/"
  472. aFormat = dateFormat.split(formatChar)
  473. if (aFormat.length<3)
  474. {
  475. formatChar = "."
  476. aFormat = dateFormat.split(formatChar)
  477. if (aFormat.length<3)
  478. {
  479. formatChar = "-"
  480. aFormat = dateFormat.split(formatChar)
  481. if (aFormat.length<3)
  482. {
  483. // invalid date format
  484. formatChar=""
  485. }
  486. }
  487. }
  488. }
  489. tokensChanged = 0
  490. if ( formatChar != "" )
  491. {
  492. // use user's date
  493. aData = ctl2.value.split(formatChar)
  494. for (i=0;i<3;i++)
  495. {
  496. if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
  497. {
  498. dateSelected = parseInt(aData[i], 10)
  499. tokensChanged ++
  500. }
  501. else if ((aFormat[i]=="m") || (aFormat[i]=="mm"))
  502. {
  503. monthSelected = parseInt(aData[i], 10) - 1
  504. tokensChanged ++
  505. }
  506. else if (aFormat[i]=="yyyy")
  507. {
  508. yearSelected = parseInt(aData[i], 10)
  509. tokensChanged ++
  510. }
  511. else if (aFormat[i]=="mmm")
  512. {
  513. for (j=0; j<12; j++)
  514. {
  515. if (aData[i]==monthName[j])
  516. {
  517. monthSelected=j
  518. tokensChanged ++
  519. }
  520. }
  521. }
  522. else if (aFormat[i]=="mmmm")
  523. {
  524. for (j=0; j<12; j++)
  525. {
  526. if (aData[i]==monthName2[j])
  527. {
  528. monthSelected=j
  529. tokensChanged ++
  530. }
  531. }
  532. }
  533. }
  534. }
  535. if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))
  536. {
  537. dateSelected = dateNow
  538. monthSelected = monthNow
  539. yearSelected = yearNow
  540. }
  541. odateSelected=dateSelected
  542. omonthSelected=monthSelected
  543. oyearSelected=yearSelected
  544. aTag = ctl
  545. do {
  546. aTag = aTag.offsetParent;
  547. leftpos += aTag.offsetLeft;
  548. toppos += aTag.offsetTop;
  549. } while(aTag.tagName!="BODY");
  550. crossobj.left = fixedX==-1 ? ctl.offsetLeft + leftpos : fixedX
  551. crossobj.top = fixedY==-1 ? ctl.offsetTop + toppos + ctl.offsetHeight + 2 : fixedY
  552. constructCalendar (1, monthSelected, yearSelected);
  553. crossobj.visibility=(dom||ie)? "visible" : "show"
  554. hideElement( 'SELECT', document.getElementById("calendar") );
  555. hideElement( 'APPLET', document.getElementById("calendar") );
  556. bShow = true;
  557. }
  558. else
  559. {
  560. hideCalendar()
  561. if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, format)}
  562. }
  563. ctlNow = ctl
  564. }
  565. }
  566. document.onkeypress = function hidecal1 () {
  567. if (event.keyCode==27)
  568. {
  569. hideCalendar()
  570. }
  571. }
  572. document.onclick = function hidecal2 () {
  573. if (!bShow)
  574. {
  575. hideCalendar()
  576. }
  577. bShow = false
  578. }
  579. if(ie)
  580. {
  581. init()
  582. }
  583. else
  584. {
  585. window.onload=init
  586. }// JavaScript Document