/01.Source/01.CORE/js/popcalendar/popcalendar.js

http://creative-portal.googlecode.com/ · JavaScript · 601 lines · 510 code · 63 blank · 28 comment · 213 complexity · b9f3b48cbf13952974ca5cf30173410d MD5 · raw file

  1. // ------------------------------------------------------------------------ //
  2. // PopCalendar 1.5 //
  3. // Copyright (c) 2009 alquanto.de //
  4. // <http://www.alquanto.net/> //
  5. // ------------------------------------------------------------------------ //
  6. if( typeof( nv_formatString ) == 'undefined' ) var nv_formatString = "mm/dd/yyyy";
  7. if( typeof( nv_gotoString ) == 'undefined' ) var nv_gotoString = "Go To Current Month";
  8. if( typeof( nv_todayString ) == 'undefined' ) var nv_todayString = "Today is";
  9. if( typeof( nv_weekShortString ) == 'undefined' ) var nv_weekShortString = "Wk";
  10. if( typeof( nv_weekString ) == 'undefined' ) var nv_weekString = "calendar week";
  11. if( typeof( nv_scrollLeftMessage ) == 'undefined' ) var nv_scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically.";
  12. if( typeof( nv_scrollRightMessage ) == 'undefined' ) var nv_scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically.";
  13. if( typeof( nv_selectMonthMessage ) == 'undefined' ) var nv_selectMonthMessage = "Click to select a month.";
  14. if( typeof( nv_selectYearMessage ) == 'undefined' ) var nv_selectYearMessage = "Click to select a year.";
  15. if( typeof( nv_selectDateMessage ) == 'undefined' ) var nv_selectDateMessage = "Select [date] as date.";
  16. if( typeof( nv_aryMonth ) == 'undefined' ) var nv_aryMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  17. if( typeof( nv_aryMS ) == 'undefined' ) var nv_aryMS = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  18. if( typeof( nv_aryDayNS ) == 'undefined' ) var nv_aryDayNS = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
  19. if( typeof( nv_aryDayName ) == 'undefined' ) var nv_aryDayName = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
  20. if( typeof( nv_my_ofs ) == 'undefined' ) var nv_my_ofs = 7;
  21. if( typeof( nv_siteroot ) == 'undefined' ) var nv_siteroot = '/';
  22. var popCalendar = {
  23. enablePast : true, // true - enabled ; false - disabled
  24. fixedX : -1, // x position (-1 if to appear below control)
  25. fixedY : -1, // y position (-1 if to appear below control)
  26. startAt : 1, // 0 - sunday ; 1 - monday, ...
  27. showWeekNumber : false, // false - don't show; true - show
  28. showToday : true, // false - don't show; true - show
  29. showDayLetter : false, // false - use 2-3 letter day abbreviations; true - show only one letter for a day
  30. theme : "default", // directory for images and styles
  31. hideElements : false, // InternetExplorer <6 overlaps selectboxes and applets BEFORE the popCalendar. so hide these temporarily?
  32. o: null, om: null, oy: null, monthSelected: null, yearSelected: null, dateSelected: null, omonthSelected: null, oyearSelected: null, odateSelected: null, yearConstructed: null, intervalID1: null, intervalID2: null, timeoutID1: null, timeoutID2: null, ctlToPlaceValue: null, ctlNow: null, dateFormat: null, nStartingYear: null, curX: 0, curY: 0,
  33. visYear: 0, visMonth: 0,
  34. bPageLoaded : false,
  35. ie : (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)),
  36. ie7 : (/msie 7/i.test(navigator.userAgent)),
  37. $ : function() {
  38. var e = new Array();
  39. for (var i = 0; i < arguments.length; i++) {
  40. var element = arguments[i];
  41. if (typeof element == 'string')
  42. element = document.getElementById(element);
  43. if (arguments.length == 1)
  44. return element;
  45. e.push(element);
  46. }
  47. return e;
  48. },
  49. today : new Date(),
  50. dateNow : null,
  51. monthNow : null,
  52. yearNow : null,
  53. bShow : false,
  54. // hides <select> and <applet> objects (for IE only)
  55. hideElement: function(elmID, overDiv) {
  56. if(this.ie && !this.ie7) {
  57. for(var i = 0; i < document.all.tags( elmID ).length; i++) {
  58. var obj = document.all.tags( elmID )[i];
  59. if(!obj || !obj.offsetParent) continue;
  60. // Find the element's offsetTop and offsetLeft relative to the BODY tag.
  61. objLeft = obj.offsetLeft;
  62. objTop = obj.offsetTop;
  63. objParent = obj.offsetParent;
  64. while(objParent.tagName.toUpperCase() != 'BODY') {
  65. objLeft += objParent.offsetLeft;
  66. objTop += objParent.offsetTop;
  67. objParent = objParent.offsetParent;
  68. }
  69. objHeight = obj.offsetHeight;
  70. objWidth = obj.offsetWidth;
  71. if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
  72. else if((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
  73. else if(overDiv.offsetTop >= (objTop + objHeight + obj.height));
  74. else if(overDiv.offsetLeft >= (objLeft + objWidth));
  75. else {
  76. obj.style.visibility = 'hidden';
  77. }
  78. }
  79. }
  80. },
  81. // unhides <select> and <applet> objects (for IE only)
  82. showElement: function(elmID) {
  83. if(this.ie && !this.ie7) {
  84. for(var i = 0; i < document.all.tags( elmID ).length; i++) {
  85. var obj = document.all.tags(elmID)[i];
  86. if(!obj || !obj.offsetParent) continue;
  87. obj.style.visibility = '';
  88. }
  89. }
  90. },
  91. // helper-functions:
  92. getLeft: function(l) {
  93. if (l.offsetParent) return (l.offsetLeft + this.getLeft(l.offsetParent));
  94. else return (l.offsetLeft);
  95. },
  96. getTop: function(l) {
  97. if (l.offsetParent) return (l.offsetTop + this.getTop(l.offsetParent));
  98. else return (l.offsetTop);
  99. },
  100. /**
  101. * Initialize the calendar. This Function must be called before show()
  102. * @param boolean installEventHandlers install event handlers to hide the calendar
  103. */
  104. init: function(installEventHandlers) {
  105. var ofs = this.today.getTimezoneOffset() / 60;
  106. this.today.setHours(this.today.getHours() + ofs + nv_my_ofs);
  107. this.dateNow = this.today.getDate();
  108. this.monthNow = this.today.getMonth();
  109. this.yearNow = this.today.getFullYear();
  110. document.write('<div onclick="popCalendar.bShow=true" id="pcIDcalendar" style="visibility:none"><table style="width:' + (this.showWeekNumber ? 250 : 220) + 'px;"><tr><td><div id="pcIDcaption" unselectable="on"></div></td></tr><tr><td><div id="pcIDcontent">.</div></td></tr>');
  111. if (this.showToday) document.write ('<tr><td><div id="pcIDfooter"></div></td></tr>');
  112. document.write('</table></div><div id="pcIDselectMonth"></div><div id="pcIDselectYear"></div>');
  113. this.o = this.$('pcIDcalendar');
  114. popCalendar.hide();
  115. this.om = this.$('pcIDselectMonth');
  116. this.oy = this.$('pcIDselectYear');
  117. this.yearConstructed = false;
  118. var s = '<div id="pcIDleft"><a href="javascript:void(0)" onclick="popCalendar.decMonth()" onmouseout="clearInterval(popCalendar.intervalID1);" onmousedown="clearTimeout(popCalendar.timeoutID1);popCalendar.timeoutID1=setTimeout(\'popCalendar.StartDecMonth()\',500)" onmouseup="clearTimeout(popCalendar.timeoutID1);clearInterval(popCalendar.intervalID1)" title="'+nv_scrollLeftMessage+'">&nbsp;&nbsp;&nbsp;</a></div>';
  119. s += '<div id="pcIDright"><a href="javascript:void(0)" onclick="popCalendar.incMonth()" onmouseout="clearInterval(popCalendar.intervalID1);" onmousedown="clearTimeout(popCalendar.timeoutID1);popCalendar.timeoutID1=setTimeout(\'popCalendar.StartIncMonth()\',500)" onmouseup="clearTimeout(popCalendar.timeoutID1);clearInterval(popCalendar.intervalID1)" title="'+nv_scrollRightMessage+'">&nbsp;&nbsp;&nbsp;</a></div>';
  120. s += '<div id="pcIDMonth" onclick="popCalendar.popUpMonth()" title="'+nv_selectMonthMessage+'"></div>';
  121. s += '<div id="pcIDYear" onclick="popCalendar.popUpYear()" title="' +nv_selectYearMessage+'"></div>';
  122. this.$('pcIDcaption').innerHTML = s;
  123. if (!installEventHandlers) { // hide calendar when enter has been pressed
  124. document.onkeypress = function (event) {
  125. if (!event) event = window.event;
  126. if (event.keyCode == 27) popCalendar.hide();
  127. };
  128. document.onclick = function () { // hide calendar when ...
  129. if (!popCalendar.bShow) popCalendar.hide();
  130. popCalendar.bShow = false;
  131. };
  132. }
  133. var c = document.createElement('link'); // insert CSS in header-section:
  134. with (c) { type = 'text/css'; rel = 'stylesheet'; href = nv_siteroot + 'js/popcalendar/calendar_themes/' + this.theme+'/style.css'; media = 'screen'; }
  135. document.getElementsByTagName("head")[0].appendChild(c);
  136. this.bPageLoaded=true;
  137. },
  138. hide: function() {
  139. this.o.style.visibility = 'hidden';
  140. if (this.om != null) this.om.style.visibility = 'hidden';
  141. if (this.oy != null) this.oy.style.visibility = 'hidden';
  142. if (this.hideElements) {
  143. this.showElement('SELECT');
  144. this.showElement('APPLET');
  145. }
  146. },
  147. // holidays...
  148. HolidaysCounter: 0,
  149. Holidays: new Array(),
  150. HolidayRec: function(d, m, y, desc) {
  151. this.d = d; this.m = m; this.y = y; this.desc = desc;
  152. },
  153. addHoliday: function(d, m, y, desc) {
  154. this.Holidays[this.HolidaysCounter++] = new this.HolidayRec (d, m, y, desc);
  155. },
  156. padZero: function(num) {
  157. return (num < 10) ? '0' + num : num;
  158. },
  159. constructDate: function(d,m,y) {
  160. var s = this.dateFormat;
  161. s = s.replace('dd','<e>');
  162. s = s.replace('d','<d>');
  163. s = s.replace('<e>',this.padZero(d));
  164. s = s.replace('<d>',d);
  165. s = s.replace('mmmm','<p>');
  166. s = s.replace('mmm','<o>');
  167. s = s.replace('mm','<n>');
  168. s = s.replace('m','<m>');
  169. s = s.replace('<m>',m+1);
  170. s = s.replace('<n>',this.padZero(m+1));
  171. s = s.replace('<o>',nv_aryMonth[m]);
  172. s = s.replace('<p>',nv_aryMS[m]);
  173. s = s.replace('yyyy',y);
  174. s = s.replace('yy',this.padZero(y%100));
  175. s = s.replace('hh',this.hour);
  176. s = s.replace('xx',this.minute);
  177. s = s.replace('ss',this.second);
  178. return s.replace ('yy',this.padZero(y%100));
  179. },
  180. close: function(day) {
  181. this.hide();
  182. if (day) this.dateSelected = day;
  183. this.ctlToPlaceValue.value = this.constructDate(this.dateSelected, this.monthSelected, this.yearSelected);
  184. },
  185. setToday: function() {
  186. this.dateSelected = this.dateNow;
  187. this.monthSelected = this.monthNow;
  188. this.yearSelected = this.yearNow;
  189. this.construct();
  190. },
  191. StartDecMonth: function() { // Month Pulldown
  192. this.intervalID1 = setInterval('popCalendar.decMonth()',80);
  193. },
  194. StartIncMonth: function() {
  195. this.intervalID1 = setInterval('popCalendar.incMonth()',80);
  196. },
  197. incMonth: function() {
  198. this.monthSelected++;
  199. if (this.monthSelected > 11) {this.monthSelected = 0; this.yearSelected++;}
  200. this.construct();
  201. },
  202. decMonth: function() {
  203. this.monthSelected--;
  204. if (this.monthSelected < 0) {this.monthSelected = 11; this.yearSelected--;}
  205. this.construct();
  206. },
  207. constructMonth: function() {
  208. this.popDownYear();
  209. var s = '';
  210. for (i=0; i<12; i++) {
  211. var sName = nv_aryMonth[i];
  212. if (i == this.monthSelected) sName = '<strong>' + sName + '</strong>';
  213. s += '<li><a href="javascript:void(0);" onclick="popCalendar.monthSelected=' + i + ';popCalendar.construct();popCalendar.popDownMonth();event.cancelBubble=true">' + sName + '</a></li>';
  214. }
  215. this.om.innerHTML = '<ul onmouseover="clearTimeout(popCalendar.timeoutID1)" onmouseout="clearTimeout(popCalendar.timeoutID1);popCalendar.timeoutID1=setTimeout(\'popCalendar.popDownMonth()\',100);event.cancelBubble=true">' + s + '</ul>';
  216. },
  217. popUpMonth: function() {
  218. var leftOffset;
  219. if (this.visMonth == 1) {
  220. this.popDownMonth();
  221. this.visMonth--;
  222. } else {
  223. this.constructMonth();
  224. this.om.style.visibility = 'visible';
  225. leftOffset = parseInt(this.o.style.left) + this.$('pcIDMonth').offsetLeft;
  226. if (this.ie) leftOffset += 1;
  227. this.om.style.left = leftOffset + 'px';
  228. this.om.style.top = parseInt(this.o.style.top) + 19 + 'px';
  229. if (this.hideElements) {
  230. this.hideElement('SELECT', this.om);
  231. this.hideElement('APPLET', this.om);
  232. }
  233. this.visMonth++;
  234. }
  235. },
  236. popDownMonth: function() {
  237. this.om.style.visibility = 'hidden';
  238. this.visMonth = 0;
  239. },
  240. incYear: function() { // Year Pulldown
  241. for (var i=0; i<7; i++) {
  242. var newYear = (i + this.nStartingYear) + 1;
  243. this.$('pcY'+i).innerHTML = (newYear == this.yearSelected) ? '<strong>'+newYear+'</strong>' : newYear;
  244. }
  245. this.nStartingYear++; this.bShow=true;
  246. },
  247. decYear: function() {
  248. for (var i=0; i<7; i++) {
  249. var newYear = (i + this.nStartingYear) - 1;
  250. this.$('pcY'+i).innerHTML = (newYear == this.yearSelected) ? '<strong>'+newYear+'</strong>' : newYear;
  251. }
  252. this.nStartingYear--; this.bShow=true;
  253. },
  254. selectYear: function(nYear) {
  255. this.yearSelected = parseInt(nYear + this.nStartingYear);
  256. this.yearConstructed = false;
  257. this.construct();
  258. this.popDownYear();
  259. },
  260. constructYear: function() {
  261. this.popDownMonth();
  262. var s = '';
  263. if (!this.yearConstructed) {
  264. s = '<li><a href="javascript:void(0);" onmouseout="clearInterval(popCalendar.intervalID1);" onmousedown="clearInterval(popCalendar.intervalID1);popCalendar.intervalID1=setInterval(\'popCalendar.decYear()\',30)" onmouseup="clearInterval(popCalendar.intervalID1)">-</a></li>';
  265. var j = 0;
  266. this.nStartingYear = this.yearSelected - 3;
  267. for ( var i = (this.yearSelected-3); i <= (this.yearSelected+3); i++ ) {
  268. var sName = i;
  269. if (i == this.yearSelected) sName = '<strong>' + sName + '</strong>';
  270. s += '<li><a href="javascript:void(0);" id="pcY' + j + '" onclick="popCalendar.selectYear('+j+');event.cancelBubble=true">' + sName + '</a></li>';
  271. j++;
  272. }
  273. s += '<li><a href="javascript:void(0);" onmouseout="clearInterval(popCalendar.intervalID2);" onmousedown="clearInterval(popCalendar.intervalID2);popCalendar.intervalID2=setInterval(\'popCalendar.incYear()\',30)" onmouseup="clearInterval(popCalendar.intervalID2)">+</a></li>';
  274. this.oy.innerHTML = '<ul onmouseover="clearTimeout(popCalendar.timeoutID2)" onmouseout="clearTimeout(popCalendar.timeoutID2);popCalendar.timeoutID2=setTimeout(\'popCalendar.popDownYear()\',100)">' + s + '</ul>';
  275. this.yearConstructed = true;
  276. }
  277. },
  278. popDownYear: function() {
  279. clearInterval(this.intervalID1);
  280. clearTimeout(this.timeoutID1);
  281. clearInterval(this.intervalID2);
  282. clearTimeout(this.timeoutID2);
  283. this.oy.style.visibility= 'hidden';
  284. this.visYear = 0;
  285. },
  286. popUpYear: function() {
  287. var leftOffset;
  288. if (this.visYear==1) {
  289. this.popDownYear();
  290. this.visYear--;
  291. } else {
  292. this.constructYear();
  293. this.oy.style.visibility = 'visible';
  294. leftOffset = parseInt(this.o.style.left) + this.$('pcIDYear').offsetLeft;
  295. if (this.ie) leftOffset += 1;
  296. this.oy.style.left = leftOffset + 'px';
  297. this.oy.style.top = parseInt(this.o.style.top) + 19 + 'px';
  298. this.visYear++;
  299. }
  300. },
  301. WeekNbr: function(n) { // construct calendar
  302. // Algorithm used from Klaus Tondering's Calendar document (The Authority/Guru)
  303. // http://www.tondering.dk/claus/calendar.html
  304. if (n == null) n = new Date (this.yearSelected,this.monthSelected,1);
  305. var year = n.getFullYear();
  306. var month = n.getMonth() + 1;
  307. if (this.startAt == 0) {
  308. var day = n.getDate() + 1;
  309. } else {
  310. var day = n.getDate();
  311. }
  312. var a = Math.floor((14-month) / 12);
  313. var y = year + 4800 - a;
  314. var m = month + 12 * a - 3;
  315. var b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
  316. var J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
  317. var d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
  318. var L = Math.floor(d4 / 1460);
  319. var d1 = ((d4 - L) % 365) + L;
  320. var week = Math.floor(d1/7) + 1;
  321. return week;
  322. },
  323. construct : function() {
  324. var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31);
  325. var startDate = new Date (this.yearSelected,this.monthSelected,1);
  326. var endDate;
  327. if (this.monthSelected==1) { // get days of February
  328. endDate = new Date (this.yearSelected,this.monthSelected+1,1);
  329. endDate = new Date (endDate - (24*60*60*1000));
  330. var numDaysInMonth = endDate.getDate();
  331. } else {
  332. var numDaysInMonth = aNumDays[this.monthSelected];
  333. }
  334. var dayPointer = startDate.getDay() - this.startAt;
  335. if (dayPointer<0) dayPointer = 6;
  336. var s = '<table><thead><tr>'; // dayheader
  337. if (this.showWeekNumber) { // spacer for Weeknumbers
  338. s += '<th><acronym title="'+nv_weekString+'">' + nv_weekShortString + '</acronym></th>';
  339. }
  340. for (var i = 0; i<7; i++) { // render daynames
  341. if (this.showDayLetter)
  342. s += '<th>' + nv_aryDayNS[(i+this.startAt) % 7].charAt(0) + '</th>';
  343. else
  344. s += '<th>' + nv_aryDayNS[(i+this.startAt) % 7] + '</th>';
  345. }
  346. s += '</tr></thead><tbody><tr>';
  347. if (this.showWeekNumber) {
  348. s += '<td class="pcWeekNumber">' + this.WeekNbr(this.startDate) + '</td>';
  349. }
  350. for ( var i=1; i<=dayPointer; i++ ) {
  351. s += '<td>&nbsp;</td>';
  352. }
  353. for (var datePointer=1; datePointer <= numDaysInMonth; datePointer++) {
  354. dayPointer++;
  355. var sClass = '';
  356. var selDayAction = '';
  357. var sHint = '';
  358. for (var k=0; k < this.HolidaysCounter; k++) { // insert holidays
  359. if ((parseInt(this.Holidays[k].d) == datePointer)&&(parseInt(this.Holidays[k].m) == (this.monthSelected+1))) {
  360. if ((parseInt(this.Holidays[k].y)==0)||((parseInt(this.Holidays[k].y)==this.yearSelected)&&(parseInt(this.Holidays[k].y)!=0))) {
  361. sClass = 'pcDayHoliday ';
  362. sHint += sHint=="" ? this.Holidays[k].desc : "\n"+this.Holidays[k].desc;
  363. }
  364. }
  365. }
  366. sHint = sHint.replace('/\"/g', '&quot;');
  367. if ((datePointer == this.odateSelected) && (this.monthSelected == this.omonthSelected) && (this.yearSelected == this.oyearSelected)) {
  368. sClass+='pcDaySelected'; // selected day
  369. } else if ((datePointer == this.dateNow) && (this.monthSelected == this.monthNow) && (this.yearSelected == this.yearNow)) {
  370. sClass+='pcToday'; // today
  371. } else if (
  372. (dayPointer % 7 == (this.startAt * -1)+1)
  373. || ((dayPointer % 7 == (this.startAt * -1)+7 && this.startAt==1) || (dayPointer % 7 == this.startAt && this.startAt==0)) )
  374. {
  375. sClass+='pcWeekend'; // sunday
  376. } else {
  377. sClass+='pcDay'; // every other day
  378. }
  379. if (!this.enablePast &&
  380. ( this.yearSelected < this.yearNow ||
  381. (this.yearSelected == this.yearNow && this.monthSelected < this.monthNow) ||
  382. (this.yearSelected == this.yearNow && this.monthSelected == this.monthNow && datePointer < this.dateNow)
  383. )) {
  384. sClass+='Past'; // all CSS-classes with past-style are suffixed with "Past":
  385. } else {
  386. selDayAction = 'href="javascript:void(0);" onclick="javascript:popCalendar.close('+datePointer+');"';
  387. }
  388. // create HTML:
  389. s += '<td class="' + sClass + '"><a title="'+sHint+'" '+selDayAction+'>'+datePointer+'</a></td>';
  390. if ((dayPointer+this.startAt) % 7 == this.startAt) {
  391. s += '</tr>';
  392. if (datePointer < numDaysInMonth) {
  393. s += '<tr>'; // open next table row, if we are not at the and of actual month
  394. if (this.showWeekNumber) {
  395. s += '<td class="pcWeekNumber">' + (this.WeekNbr(new Date(this.yearSelected,this.monthSelected,datePointer+1))) + '</td>';
  396. }
  397. }
  398. }
  399. }
  400. if (dayPointer % 7 != 0) s += '</tr>'; // close last opened table row
  401. s+='</tbody></table>';
  402. this.$('pcIDcontent').innerHTML = s;
  403. this.$('pcIDMonth').innerHTML = '<a href="javascript:void(0)">' + nv_aryMonth[this.monthSelected] + '</a>';
  404. this.$('pcIDYear').innerHTML = '<a href="javascript:void(0)">' + this.yearSelected + '</a>';
  405. },
  406. /**
  407. * Main function, shows the calendar.
  408. *
  409. * @param btn The "button" which (de-)activates the calendar
  410. * @param ctl The field to receive the selected date; element or ID-string
  411. * @param format Format of the date-string; optional; see constructDate()
  412. * @param past allow dates in the past; optional; yes=true, no=false
  413. * @param x x-position of the calendar; optional; -1 for directly below btn
  414. * @param y y-position of the calendar; optional; -1 for directly below btn
  415. * @param start Start of the week; optional; Monday=1 or Sunday=0
  416. */
  417. show: function(btn, ctl, format, past, x, y, start) {
  418. if (start != null) this.startAt = start;
  419. if (!format) format = nv_formatString;
  420. if (!btn) btn = this;
  421. if (!ctl) ctl = btn;
  422. this.enablePast = (past != null) ? past : this.enablePast;
  423. this.fixedX = (x != null) ? x : -1;
  424. this.fixedY = (y != null) ? y : -1;
  425. if (this.showToday)
  426. this.$('pcIDfooter').innerHTML = nv_todayString+' <a title="'+nv_gotoString+'" href="javascript:void(0);" onclick="javascript:popCalendar.setToday();">'+ nv_aryDayName[(this.today.getDay()) % 7]+', '+this.dateNow+' '+nv_aryMS[this.monthNow]+' '+this.yearNow+'</a>';
  427. this.popUp(btn, ctl, format);
  428. },
  429. popUp: function(btn, ctl, format) {
  430. var formatChar = '';
  431. var aFormat = new Array();
  432. if (typeof(btn)=='string') btn = this.$(btn);
  433. if (typeof(ctl)=='string') ctl = this.$(ctl);
  434. if (this.bPageLoaded) {
  435. if (this.o.style.visibility == 'hidden') {
  436. this.ctlToPlaceValue = ctl;
  437. this.dateFormat = format || this.dateFormat;
  438. formatChar = ' ';
  439. aFormat = this.dateFormat.split(formatChar);
  440. if (aFormat.length < 3) {
  441. formatChar = '/';
  442. aFormat = this.dateFormat.split(formatChar);
  443. if (aFormat.length < 3) {
  444. formatChar = '.';
  445. aFormat = this.dateFormat.split(formatChar);
  446. if (aFormat.length < 3) {
  447. formatChar = '-';
  448. aFormat = this.dateFormat.split(formatChar);
  449. if (aFormat.length < 3) {
  450. formatChar = ''; // invalid date format
  451. }
  452. }
  453. }
  454. }
  455. var tokensChanged = 0;
  456. var aData;
  457. if (formatChar != "") {
  458. aData = ctl.value.split(formatChar); // use user's date
  459. for (var i=0; i<3; i++) {
  460. if ((aFormat[i] == "d") || (aFormat[i] == "dd")) {
  461. this.dateSelected = parseInt(aData[i], 10);
  462. tokensChanged++;
  463. } else if ((aFormat[i] == "m") || (aFormat[i] == "mm")) {
  464. this.monthSelected = parseInt(aData[i], 10) - 1;
  465. tokensChanged++;
  466. } else if (aFormat[i] == "yyyy") {
  467. this.yearSelected = parseInt(aData[i], 10);
  468. tokensChanged++;
  469. } else if (aFormat[i] == "mmm") {
  470. for (j=0; j<12; j++) {
  471. if (aData[i] == nv_aryMonth[j]) {
  472. this.monthSelected=j;
  473. tokensChanged++;
  474. }
  475. }
  476. } else if (aFormat[i] == "mmmm") {
  477. for (j=0; j<12; j++) {
  478. if (aData[i] == nv_aryMS[j]) {
  479. this.monthSelected = j;
  480. tokensChanged++;
  481. }
  482. }
  483. }
  484. }
  485. }
  486. var TimeFormatChar = ':';
  487. var timeString = ctl.value.split(" ");
  488. if (timeString[1] !=null) {
  489. var timeTokens = timeString[1].split(':');
  490. if(timeTokens[0].length==2) {
  491. this.hour = timeTokens[0];
  492. }
  493. if (timeTokens[1].length==2) {
  494. this.minute = timeTokens[1];
  495. }
  496. if (timeTokens[2].length==2) {
  497. this.second= timeTokens[2];
  498. }
  499. } else {
  500. this.hour=00;
  501. this.minute=00;
  502. this.second=00;
  503. }
  504. if ((tokensChanged != 3) ||
  505. isNaN(this.dateSelected) ||
  506. isNaN(this.monthSelected) ||
  507. this.monthSelected<0 ||
  508. isNaN(this.yearSelected)) {
  509. this.dateSelected = this.dateNow;
  510. this.monthSelected = this.monthNow;
  511. this.yearSelected = this.yearNow;
  512. }
  513. this.odateSelected = this.dateSelected;
  514. this.omonthSelected = this.monthSelected;
  515. this.oyearSelected = this.yearSelected;
  516. if (typeof jQuery != 'undefined') { // use jQuery if available
  517. this.o.style.top = (this.fixedY == -1) ? $(btn).position().top + btn.offsetHeight + 'px' : this.fixedY + 'px' ;
  518. this.o.style.left= (this.fixedX == -1) ? $(btn).position().left + 'px' : this.fixedX + 'px';
  519. } else {
  520. this.o.style.top = (this.fixedY == -1) ? btn.offsetTop + this.getTop(btn.offsetParent) + btn.offsetHeight + 2 + 'px' : this.fixedY + 'px' ;
  521. this.o.style.left= (this.fixedX == -1) ? btn.offsetLeft + this.getLeft(btn.offsetParent) + 'px' : this.fixedX + 'px';
  522. }
  523. this.construct (1, this.monthSelected, this.yearSelected);
  524. this.o.style.visibility = "visible";
  525. if (this.hideElements) {
  526. this.hideElement('SELECT', this.$('pcIDcalendar'));
  527. this.hideElement('APPLET', this.$('pcIDcalendar'));
  528. }
  529. this.bShow = true;
  530. } else {
  531. popCalendar.hide();
  532. if (this.ctlNow!=btn) this.popUp(btn, ctl, format);
  533. }
  534. this.ctlNow = btn;
  535. }
  536. }
  537. }
  538. popCalendar.init();