/aspnet/scw.js

http://genericgrid.codeplex.com · JavaScript · 1890 lines · 1085 code · 247 blank · 558 comment · 154 complexity · 3c64a195c5bf823c8c14eea2f1c98cf7 MD5 · raw file

Large files are truncated click here to view the full file

  1. // *****************************************************************************
  2. // Simple Calendar Widget - Cross-Browser Javascript pop-up calendar.
  3. //
  4. // Copyright (C) 2005-2007 Anthony Garrett
  5. //
  6. // This library is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU Lesser General Public
  8. // License as published by the Free Software Foundation; either
  9. // version 2.1 of the License, or (at your option) any later version.
  10. //
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. // Lesser General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Lesser General Public
  17. // License along with this library; if not, it is available at
  18. // the GNU web site (http://www.gnu.org/) or by writing to the
  19. // Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. // Boston, MA 02110-1301 USA
  21. //
  22. // *****************************************************************************
  23. //
  24. // Contact: Sorry, I can't offer support for this but if you find a problem
  25. // (or just want to tell me how useful you find it), please send
  26. // me an email at scwfeedback@tarrget.info (Note the two Rs in
  27. // tarrget). I will try to fix problems quickly but this is a
  28. // spare time thing for me.
  29. //
  30. // Credits: I wrote this from scratch myself but I couldn't have done it
  31. // without the superb "JavaScript The Definitive Guide" by David
  32. // Flanagan (Pub. O'Reilly ISBN 0-596-00048-0). I also recognise
  33. // a contribution from my experience with PopCalendar 4.1 by
  34. // Liming(Victor) Weng.
  35. //
  36. // Link back: Please give me credit and link back to my page. To ensure that
  37. // search engines give my page a higher ranking you can add the
  38. // following HTML to any indexed page on your web site:
  39. //
  40. // <A HREF="http://www.tarrget.info/calendar/scw.htm">
  41. // Simple Calendar Widget by Anthony Garrett
  42. // </A>
  43. //
  44. // Features: Easily customised
  45. // (output date format, colours, language, year range and
  46. // week start day)
  47. // Accepts a date as input
  48. // (see comments below for formats).
  49. // Cross-browser code tested against;
  50. // Internet Explorer 6.0.28 Mozilla 1.7.1
  51. // Opera 7.52+ Firefox 0.9.1+
  52. // Konqueror 3.4.0 Flock 0.4.9
  53. //
  54. // How to add the Calendar to your page:
  55. // This script needs to be defined for your page so, immediately
  56. // after the BODY tag add the following line;
  57. //
  58. // <script type='Text/JavaScript' src='scw.js'></script>
  59. //
  60. // Your root directory of the web site should also contain an empty
  61. // file called "scwblank.html". See
  62. // http://www.tarrget.info/calendar/IEnightmare.html
  63. // for a full explanation.
  64. //
  65. // How to use the Calendar once it is defined for your page:
  66. //
  67. // Simply choose an event to trigger the calendar (like an onClick
  68. // or an onMouseOver) and an element to work on (for the calendar
  69. // to take its initial date from and write its output date to) then
  70. // write it like this;
  71. //
  72. // <<event>>="scwShow(<<element>>,event);"
  73. //
  74. // e.g. onClick="scwShow(scwID('myElement'),event);"
  75. // or onMouseOver="scwShow(this,event);"
  76. //
  77. // NOTE: If you wish to use the calendar with an Anchor tag, do
  78. // not use the syntax: href="javascript:scwShow(...)"
  79. // Instead you should use the following;
  80. //
  81. // <a href="#" onclick="scwShow(<<element>>,event);return false;">
  82. // <<your text>>
  83. // </a>
  84. //
  85. // If you are using a text node then specify the text's parent node
  86. // in the function call. The date should be the only text under that
  87. // node;
  88. //
  89. // e.g. <p onclick="scwShow(this,event);"><<date>></p>
  90. //
  91. // You can also disable days of the week by adding arguments to the
  92. // call to scwShow. The values should be Sunday = 0 through to
  93. // Saturday = 6. A call to scwShow with Friday and Monday disabled
  94. // would look something like this;
  95. //
  96. // scwShow(<<element>>,event,5,1);
  97. //
  98. // Finally you can use the following technique to run a function
  99. // when the calendar closes:
  100. //
  101. // scwNextAction=<<function>>.runsAfterSCW(this,<<arguments>>);
  102. // scwShow(<<element>>,event <<,optional arguments above>>);
  103. //
  104. // Where <<function>> is a function defined on the calling page
  105. // and <<arguments>> is the list of arguments being passed to that
  106. // function.
  107. //
  108. // No event? No problem!
  109. //
  110. // Normally the calendar will be triggered by an event but if you wish to
  111. // control it in code and the event is not available to you, simply pass
  112. // an element as the second parameter;
  113. //
  114. // E.G. scwShow(<<target element>>,<<source element>>);
  115. // as in: scwShow(this,this);
  116. //
  117. // ------------------------------------------------------------------
  118. // Here's an extremely trivial but fully functioning example page
  119. // showing two of the ways to trigger the calendar;
  120. //
  121. // <html>
  122. // <head><title>Basic Example</title></head>
  123. // <body>
  124. // <script type='text/JavaScript' src='scw.js'></script>
  125. // <p onclick='scwShow(this,event);'>06-Dec-2006</p>
  126. // <input onclick='scwShow(this,event);' value='07-Dec-2006' />
  127. // <br/><br/>
  128. // <a href='#' onclick='scwShow(this,event);return false;'>
  129. // 08-Dec-2006
  130. // </a>
  131. // </body>
  132. // </html>
  133. //
  134. // *****************************************************************************
  135. //
  136. // See http://www.tarrget.info/calendar/scw.htm for a complete version history
  137. //
  138. // Version Date By Description
  139. // ======= ==== =============== ===========
  140. // 3.58 2007-04-04 Anthony Garrett Resolved an error caused when the date
  141. // range does not include the current year.
  142. // Thanks to Steve Davis for letting me know.
  143. //
  144. // Fixed "Today" selector display which
  145. // was incorrectly visible when year range
  146. // ended last year. (Also the result of
  147. // investigations based on Steve Davis'
  148. // feedback).
  149. //
  150. // 3.59 2007-06-13 Anthony Garrett Added Verdana to font list of
  151. // calendar's CSS. Resolves rendering
  152. // bug in Safari Beta 3 for Windows.
  153. //
  154. // 3.60 2007-07-31 Anthony Garrett Fixed javascript error that occurred
  155. // when the target element had no value
  156. // attribute. The error had no impact
  157. // on the behaviour of the script. Thanks
  158. // to John Phelps for reporting this bug.
  159. //
  160. // 3.70 2007-09-21 Anthony Garrett Updated the event trapping to make it
  161. // less intrusive on the page body.
  162. // NOTE: This requires that a calendar's
  163. // second parameter should be the calling
  164. // event (not the calling object as in
  165. // previous versions).
  166. // Thanks to Steve Davis for the bug report
  167. // that led to this change.
  168. //
  169. // Fixed a bug that caused undelimited
  170. // dates to be handled incorrectly. They
  171. // are now parsed against the full date
  172. // output format then checked for validity.
  173. // Thanks to Dan Wood for raising this bug.
  174. //
  175. // Replaced the date input sequence user
  176. // configuration setting with parsing the
  177. // sequence from the full format. New users
  178. // are often confused by the sequence and
  179. // in practice (to allow the calendar's date
  180. // output to be used for input) the sequence
  181. // must always match the full format element
  182. // order.
  183. //
  184. // Extended IFRAME backing to all calendar objects
  185. // in order to improve calendar display over
  186. // some embedded applets and objects. Thanks to
  187. // Stanko Kupcevic for his feedback on this.
  188. // NOTE: It is not possible to protect any
  189. // JavaScript object displayed over an
  190. // embedded DYNAMIC (and, therefore refreshed)
  191. // object because browsers usually do not
  192. // directly control the screen handling within
  193. // the object. The best advice therefore remains
  194. // to design pages in such a way that the calendar
  195. // does not overlap embedded objects.
  196. //
  197. // 3.71 2008-12-14 Anthony Garrett Restored the ability to use an element
  198. // as the second parameter when opening a
  199. // calendar while retaining the option
  200. // of passing an event. Thanks to Thierry Blind
  201. // and Sergey Snovsky for the feedback.
  202. //
  203. // 3.72 2008-02-24 Anthony Garrett Trapped calls to script with only a
  204. // NAME attribute is set for the target
  205. // element when the script really requires
  206. // an ID attribute. This is the most
  207. // frequent mistake reported to me.
  208. //
  209. // 3.73 2008-04-11 Anthony Garrett Corrected the input month name parsing
  210. // so that it set the calendar to the
  211. // right month when long month names used.
  212. // Thanks to Ben Diamand for this bug report.
  213. //
  214. // 3.80 2008-04-29 Anthony Garrett Added optional auto-positioning of the
  215. // calendar when its normal position would
  216. // go off the visible area.
  217. // Thanks to Chandramouli Iyer for this
  218. // suggestion.
  219. //
  220. // 3.90 2008-05-05 Anthony Garrett Added an optional "Clear" button for
  221. // use when handling a read-only text
  222. // input element. Thanks to Sanjay Gangwal
  223. // for his suggestion.
  224. // *****************************************************************************
  225. // ************************************
  226. // Start of Simple Calendar Widget Code
  227. // ************************************
  228. // This date is used throughout to determine today's date.
  229. var scwDateNow = new Date(Date.parse(new Date().toDateString()));
  230. //******************************************************************************
  231. //------------------------------------------------------------------------------
  232. // Customisation section
  233. //------------------------------------------------------------------------------
  234. //******************************************************************************
  235. // Set the bounds for the calendar here...
  236. // If you want the year to roll forward you can use something like this...
  237. // var scwBaseYear = scwDateNow.getFullYear()-5;
  238. // alternatively, hard code a date like this...
  239. // var scwBaseYear = 1990;
  240. var scwBaseYear = scwDateNow.getFullYear()-10;
  241. // How many years do want to be valid and to show in the drop-down list?
  242. var scwDropDownYears = 20;
  243. // All language-dependent changes can be made here...
  244. // If you wish to work in a single language (other than English) then
  245. // just replace the English (in the function scwSetLanguage below) with
  246. // your own text.
  247. // Using multiple languages:
  248. // In order to keep this script to a resonable size I have not included
  249. // languages here. You can set language fields in a function that you
  250. // should call scwSetLanguage the script will use your languages.
  251. // I have included all the translations that have been sent to me in
  252. // such a function on the demonstration page.
  253. var scwLanguage;
  254. function scwSetDefaultLanguage()
  255. {try
  256. {scwSetLanguage();}
  257. catch (exception)
  258. {// English
  259. scwToday = 'Today:';
  260. scwClear = 'Clear';
  261. scwDrag = 'click here to drag';
  262. scwArrMonthNames = ['Jan','Feb','Mar','Apr','May','Jun',
  263. 'Jul','Aug','Sep','Oct','Nov','Dec'];
  264. scwArrWeekInits = ['S','M','T','W','T','F','S'];
  265. scwInvalidDateMsg = 'The entered date is invalid.\n';
  266. scwOutOfRangeMsg = 'The entered date is out of range.';
  267. scwDoesNotExistMsg = 'The entered date does not exist.';
  268. scwInvalidAlert = ['Invalid date (',') ignored.'];
  269. scwDateDisablingError = ['Error ',' is not a Date object.'];
  270. scwRangeDisablingError = ['Error ',
  271. ' should consist of two elements.'];
  272. }
  273. };
  274. // Note: Always start the scwArrWeekInits array with your string for
  275. // Sunday whatever scwWeekStart (below) is set to.
  276. // scwWeekStart determines the start of the week in the display
  277. // Set it to: 0 (Zero) for Sunday, 1 (One) for Monday etc..
  278. var scwWeekStart = 1;
  279. // The week start day for the display is taken as the week start
  280. // for week numbering. This ensures that only one week number
  281. // applies to one line of the calendar table.
  282. // [ISO 8601 begins the week with Day 1 = Monday.]
  283. // If you want to see week numbering on the calendar, set
  284. // this to true. If not, false.
  285. var scwWeekNumberDisplay = false;
  286. // Week numbering rules are generally based on a day in the week
  287. // that determines the first week of the year. ISO 8601 uses
  288. // Thursday (day four when Sunday is day zero). You can alter
  289. // the base day here.
  290. // See http://www.cl.cam.ac.uk/~mgk25/iso-time.html for more information
  291. var scwWeekNumberBaseDay = 4;
  292. // Each of the calendar's alert message types can be disabled
  293. // independently here.
  294. var scwShowInvalidDateMsg = true,
  295. scwShowOutOfRangeMsg = true,
  296. scwShowDoesNotExistMsg = true,
  297. scwShowInvalidAlert = true,
  298. scwShowDateDisablingError = true,
  299. scwShowRangeDisablingError = true;
  300. // Set the allowed input date delimiters here...
  301. // E.g. To set the rising slash, hyphen, full-stop (aka stop or point),
  302. // comma and space as delimiters use
  303. // var scwArrDelimiters = ['/','-','.',',',' '];
  304. var scwArrDelimiters = ['/','-','.',',',' '];
  305. // Set the format for the displayed 'Today' date and for the output
  306. // date here.
  307. //
  308. // The format is described using delimiters of your choice (as set
  309. // in scwArrDelimiters above) and case insensitive letters D, M and Y.
  310. //
  311. // NOTE: If no delimiters are input then the date output format is used
  312. // to parse the value. This allows less flexiblility in the input
  313. // value than using delimiters but an accurately entered date
  314. // remains parsable.
  315. //
  316. // Definition Returns
  317. // ---------- -------
  318. // D date in the month without zero filling
  319. // DD date in the month left zero filled
  320. // M month number without zero filling
  321. // MM month number left zero filled
  322. // MMM month string from scwArrMonthNames
  323. // YY year number in two digits
  324. // YYYY year number in four digits
  325. // Displayed "Today" date format
  326. var scwDateDisplayFormat = 'dd-mm-yy'; // e.g. 'MMM-DD-YYYY' for the US
  327. // Output date format
  328. //var scwDateOutputFormat = 'DD MMM YYYY'; // e.g. 'MMM-DD-YYYY' for the US
  329. var scwDateOutputFormat = 'dd/mm/yyyy'; // e.g. 'MMM-DD-YYYY' for the US
  330. // Note: The delimiters used should be in scwArrDelimiters.
  331. // scwZindex controls how the pop-up calendar interacts with the rest
  332. // of the page. It is usually adequate to leave it as 1 (One) but I
  333. // have made it available here to help anyone who needs to alter the
  334. // level in order to ensure that the calendar displays correctly in
  335. // relation to all other elements on the page.
  336. var scwZindex = 1000;
  337. // Personally I like the fact that entering 31-Sep-2005 displays
  338. // 1-Oct-2005, however you may want that to be an error. If so,
  339. // set scwBlnStrict = true. That will cause an error message to
  340. // display and the selected month is displayed without a selected
  341. // day. Thanks to Brad Allan for his feedback prompting this feature.
  342. var scwBlnStrict = false;
  343. // If you are using ReadOnly or Disabled fields to return the date
  344. // value into, it can be useful to show a button on the calendar
  345. // that allows the value to be cleared. If you want to do that,
  346. // set scwClearButton = true;
  347. var scwClearButton = true;
  348. // The calendar will position itself aligned with the bottom left
  349. // corner of the target element. If automatic positioning is turned
  350. // on with scwAutoPosition = true then if that would cause the
  351. // calendar to display off the visible screen, it is shifted to
  352. // a position that is visible.
  353. var scwAutoPosition = true;
  354. // If you wish to disable any displayed day, e.g. Every Monday,
  355. // you can do it by setting the following array. The array elements
  356. // match the displayed cells.
  357. //
  358. // You could put something like the following in your calling page
  359. // to disable all weekend days;
  360. //
  361. // for (var i=0;i<scwEnabledDay.length;i++)
  362. // {if (i%7%6==0) scwEnabledDay[i] = false;}
  363. //
  364. // The above approach will allow you to disable days of the week
  365. // for the whole of your page easily. If you need to set different
  366. // disabled days for a number of date input fields on your page
  367. // there is an easier way: You can pass additional arguments to
  368. // scwShow. The syntax is described at the top of this script in
  369. // the section:
  370. // "How to use the Calendar once it is defined for your page:"
  371. //
  372. // It is possible to use these two approaches in combination.
  373. var scwEnabledDay = [true, true, true, true, true, true, true,
  374. true, true, true, true, true, true, true,
  375. true, true, true, true, true, true, true,
  376. true, true, true, true, true, true, true,
  377. true, true, true, true, true, true, true,
  378. true, true, true, true, true, true, true];
  379. // You can disable any specific date (e.g. 24-Jan-2006 or Today) by
  380. // creating an element of the array scwDisabledDates as a date object
  381. // with the value you want to disable. Date ranges can be disabled
  382. // by placing an array of two values (Start and End) into an element
  383. // of this array.
  384. var scwDisabledDates = new Array();
  385. // e.g. To disable 10-Dec-2005:
  386. // scwDisabledDates[0] = new Date(2005,11,10);
  387. //
  388. // or a range from 2004-Dec-25 to 2005-Jan-01:
  389. // scwDisabledDates[1] = [new Date(2004,11,25),new Date(2005,0,1)];
  390. //
  391. // Remember that Javascript months are Zero-based.
  392. // The disabling by date and date range does prevent the current day
  393. // from being selected. Disabling days of the week does not so you can set
  394. // the scwActiveToday value to false to prevent selection.
  395. var scwActiveToday = true;
  396. // Dates that are out of the displayed month are shown at the start
  397. // (unless the month starts on the first day of the week) and end of each
  398. // month.
  399. //
  400. // Set scwOutOfMonthDisable to true to disable these dates (or false
  401. // to allow their selection).
  402. //
  403. // Set scwOutOfMonthHide to true to hide these dates (or false
  404. // to make them visible).
  405. var scwOutOfMonthDisable = false;
  406. var scwOutOfMonthHide = false;
  407. // Dates that are out of the specified range can be displayed at the start
  408. // of the very first month and end of the very last. Set
  409. // scwOutOfRangeDisable to true to disable these dates (or false to
  410. // allow their selection).
  411. var scwOutOfRangeDisable = true;
  412. // If you want a special format for the cell that contains the current day
  413. // set this to true. This sets a thin border around the cell in the colour
  414. // set by scwTodayCellBorderColour.
  415. var scwFormatTodayCell = true;
  416. var scwTodayCellBorderColour = 'red';
  417. // You can allow the calendar to be dragged around the screen by
  418. // using the setting scwAllowDrag to true.
  419. // I can't say I recommend it because of the danger of the user
  420. // forgetting which date field the calendar will update when there
  421. // are multiple date fields on a page.
  422. var scwAllowDrag = false;
  423. // Closing the calendar by clicking on it (rather than elsewhere on the
  424. // main page) can be inconvenient. The scwClickToHide boolean value
  425. // controls this feature.
  426. var scwClickToHide = false;
  427. // I have made every effort to isolate the pop-up script from any
  428. // CSS defined on the main page but if you have anything set that
  429. // affects the pop-up (or you may want to change the way it looks)
  430. // then you can address it in the following style sheets.
  431. document.writeln(
  432. '<style type="text/css">' +
  433. '.scw {padding:1px;vertical-align:middle;}' +
  434. 'iframe.scw {position:absolute;z-index:' + scwZindex +
  435. ';top:0px;left:0px;visibility:hidden;' +
  436. 'width:1px;height:1px;}' +
  437. 'table.scw {padding:0px;visibility:hidden;' +
  438. 'position:absolute;cursor:default;' +
  439. 'width:200px;top:0px;left:0px;' +
  440. 'z-index:' + (scwZindex+1) +
  441. ';text-align:center;}' +
  442. '</style>' );
  443. // This style sheet can be extracted from the script and edited into regular
  444. // CSS (by removing all occurrences of + and '). That can be used as the
  445. // basis for themes. Classes are described in comments within the style
  446. // sheet.
  447. document.writeln(
  448. '<style type="text/css">' +
  449. '/* IMPORTANT: The SCW calendar script requires all ' +
  450. ' the classes defined here.' +
  451. '*/' +
  452. 'table.scw {padding: 1px;' +
  453. 'vertical-align:middle;' +
  454. 'border: ridge 2px;' +
  455. 'font-size: 8pt;' +
  456. 'font-family: ' +
  457. 'Verdana,Arial,Helvetica,Sans-Serif;'+
  458. 'font-weight: bold;}' +
  459. 'td.scwDrag,' +
  460. 'td.scwHead {padding: 0px 0px;' +
  461. 'text-align: center;}' +
  462. 'td.scwDrag {font-size: 8pt;}' +
  463. 'select.scwHead {margin: 3px 1px;' +
  464. 'text-align: center;}' +
  465. 'input.scwHead {height: 22px;' +
  466. 'width: 22px;' +
  467. 'vertical-align:middle;' +
  468. 'text-align: center;' +
  469. 'margin: 2px 1px;' +
  470. 'font-weight: bold;' +
  471. 'font-size: 8pt;' +
  472. 'font-family: fixedSys;}' +
  473. 'td.scwWeekNumberHead,' +
  474. 'td.scwWeek {padding: 0px;' +
  475. 'text-align: center;' +
  476. 'font-weight: bold;}' +
  477. 'td.scwNow,' +
  478. 'td.scwNowHover,' +
  479. 'td.scwNow:hover,' +
  480. 'td.scwNowDisabled {padding: 0px;' +
  481. 'text-align: center;' +
  482. 'vertical-align:middle;' +
  483. 'font-size: 7pt;' +
  484. 'font-weight: normal;}' +
  485. 'table.scwCells {text-align: center;' +
  486. 'font-size: 6pt;' +
  487. 'width: 96%;}' +
  488. 'td.scwCells,' +
  489. 'td.scwCellsHover,' +
  490. 'td.scwCells:hover,' +
  491. 'td.scwCellsDisabled,' +
  492. 'td.scwCellsExMonth,' +
  493. 'td.scwCellsExMonthHover,' +
  494. 'td.scwCellsExMonth:hover,' +
  495. 'td.scwCellsExMonthDisabled,' +
  496. 'td.scwCellsWeekend,' +
  497. 'td.scwCellsWeekendHover,' +
  498. 'td.scwCellsWeekend:hover,' +
  499. 'td.scwCellsWeekendDisabled,' +
  500. 'td.scwInputDate,' +
  501. 'td.scwInputDateHover,' +
  502. 'td.scwInputDate:hover,' +
  503. 'td.scwInputDateDisabled,' +
  504. 'td.scwWeekNo,' +
  505. 'td.scwWeeks {padding: 3px;' +
  506. 'width: 16px;' +
  507. 'height: 16px;' +
  508. 'border-width: 1px;' +
  509. 'border-style: solid;' +
  510. 'font-weight: bold;' +
  511. 'vertical-align: middle;}' +
  512. '/* Blend the colours into your page here... */' +
  513. '/* Calendar background */' +
  514. 'table.scw {background-color: white;}' +
  515. '/* Drag Handle */' +
  516. 'td.scwDrag {background-color: #9999CC;' +
  517. 'color: #CCCCFF;}' +
  518. '/* Week number heading */' +
  519. 'td.scwWeekNumberHead {color: navy;}' +
  520. '/* Week day headings */' +
  521. 'td.scwWeek {color: navy;}' +
  522. '/* Week numbers */' +
  523. 'td.scwWeekNo {background-color: #776677;' +
  524. 'color: #CCCCCC;}' +
  525. '/* Enabled Days */' +
  526. '/* Week Day */' +
  527. 'td.scwCells {background-color: #F3F3F3;' +
  528. 'color: #000000;}' +
  529. '/* Day matching the input date */' +
  530. 'td.scwInputDate {background-color: #CC9999;' +
  531. 'color: #FF0000;}' +
  532. '/* Weekend Day */' +
  533. 'td.scwCellsWeekend {background-color: #F3F3F3;' +
  534. 'color: #CC6666;}' +
  535. '/* Day outside the current month */' +
  536. 'td.scwCellsExMonth {background-color: #CCCCCC;' +
  537. 'color: #666666;}' +
  538. '/* Today selector */' +
  539. 'td.scwNow {background-color: #6666CC;' +
  540. 'color: #FFFFFF;}' +
  541. '/* Clear Button */' +
  542. 'td.scwClear {padding: 0px;}' +
  543. 'input.scwClear {padding: 0px;' +
  544. 'text-align: center;' +
  545. 'font-size: 6pt;}' +
  546. '/* MouseOver/Hover formatting ' +
  547. ' If you want to "turn off" any of the formatting ' +
  548. ' then just set to the same as the standard format' +
  549. ' above.' +
  550. ' ' +
  551. ' Note: The reason that the following are' +
  552. ' implemented using both a class and a :hover' +
  553. ' pseudoclass is because Opera handles the rendering' +
  554. ' involved in the class swap very poorly and IE6 ' +
  555. ' (and below) only implements pseudoclasses on the' +
  556. ' anchor tag.' +
  557. '*/' +
  558. '/* Active cells */' +
  559. 'td.scwCells:hover,' +
  560. 'td.scwCellsHover {background-color: #FFFF00;' +
  561. 'cursor: pointer;' +
  562. 'color: #000000;}' +
  563. '/* Day matching the input date */' +
  564. 'td.scwInputDate:hover,' +
  565. 'td.scwInputDateHover {background-color: #FFFF00;' +
  566. 'cursor: pointer;' +
  567. 'color: #000000;}' +
  568. '/* Weekend cells */' +
  569. 'td.scwCellsWeekend:hover,' +
  570. 'td.scwCellsWeekendHover {background-color: #FFFF00;' +
  571. 'cursor: pointer;' +
  572. 'color: #000000;}' +
  573. '/* Day outside the current month */' +
  574. 'td.scwCellsExMonth:hover,' +
  575. 'td.scwCellsExMonthHover {background-color: #FFFF00;' +
  576. 'cursor: pointer;' +
  577. 'color: #000000;}' +
  578. '/* Today selector */' +
  579. 'td.scwNow:hover,' +
  580. 'td.scwNowHover {color: #FFFF00;' +
  581. 'cursor: pointer;' +
  582. 'font-weight: bold;}' +
  583. '/* Disabled cells */' +
  584. '/* Week Day */' +
  585. '/* Day matching the input date */' +
  586. 'td.scwInputDateDisabled {background-color: #999999;' +
  587. 'color: #000000;}' +
  588. 'td.scwCellsDisabled {background-color: #999999;' +
  589. 'color: #000000;}' +
  590. '/* Weekend Day */' +
  591. 'td.scwCellsWeekendDisabled {background-color: #999999;' +
  592. 'color: #CC6666;}' +
  593. '/* Day outside the current month */' +
  594. 'td.scwCellsExMonthDisabled {background-color: #999999;' +
  595. 'color: #666666;}' +
  596. 'td.scwNowDisabled {background-color: #6666CC;' +
  597. 'color: #FFFFFF;}' +
  598. '</style>'
  599. );
  600. //******************************************************************************
  601. //------------------------------------------------------------------------------
  602. // End of customisation section
  603. //------------------------------------------------------------------------------
  604. //******************************************************************************
  605. // Variables required by both scwShow and scwShowMonth
  606. var scwTargetEle,
  607. scwTriggerEle,
  608. scwMonthSum = 0,
  609. scwBlnFullInputDate = false,
  610. scwPassEnabledDay = new Array(),
  611. scwSeedDate = new Date(),
  612. scwParmActiveToday = true,
  613. scwWeekStart = scwWeekStart%7,
  614. scwToday,
  615. scwClear,
  616. scwDrag,
  617. scwArrMonthNames,
  618. scwArrWeekInits,
  619. scwInvalidDateMsg,
  620. scwOutOfRangeMsg,
  621. scwDoesNotExistMsg,
  622. scwInvalidAlert,
  623. scwDateDisablingError,
  624. scwRangeDisablingError;
  625. // Add a method to format a date into the required pattern
  626. Date.prototype.scwFormat =
  627. function(scwFormat)
  628. {var charCount = 0,
  629. codeChar = '',
  630. result = '';
  631. for (var i=0;i<=scwFormat.length;i++)
  632. {if (i<scwFormat.length && scwFormat.charAt(i)==codeChar)
  633. {// If we haven't hit the end of the string and
  634. // the format string character is the same as
  635. // the previous one, just clock up one to the
  636. // length of the current element definition
  637. charCount++;
  638. }
  639. else {switch (codeChar)
  640. {case 'y': case 'Y':
  641. result += (this.getFullYear()%Math.
  642. pow(10,charCount)).toString().
  643. scwPadLeft(charCount);
  644. break;
  645. case 'm': case 'M':
  646. // If we find an M, check the number of them to
  647. // determine whether to get the month number or
  648. // the month name.
  649. result += (charCount<3)
  650. ?(this.getMonth()+1).
  651. toString().scwPadLeft(charCount)
  652. :scwArrMonthNames[this.getMonth()];
  653. break;
  654. case 'd': case 'D':
  655. // If we find a D, get the date and format it
  656. result += this.getDate().toString().
  657. scwPadLeft(charCount);
  658. break;
  659. default:
  660. // Copy any unrecognised characters across
  661. while (charCount-- > 0) {result += codeChar;}
  662. }
  663. if (i<scwFormat.length)
  664. {// Store the character we have just worked on
  665. codeChar = scwFormat.charAt(i);
  666. charCount = 1;
  667. }
  668. }
  669. }
  670. return result;
  671. };
  672. // Add a method to left pad zeroes
  673. String.prototype.scwPadLeft =
  674. function(padToLength)
  675. {var result = '';
  676. for (var i=0;i<(padToLength - this.length);i++) {result += '0';}
  677. return (result + this);
  678. };
  679. // Set up a closure so that any next function can be triggered
  680. // after the calendar has been closed AND that function can take
  681. // arguments.
  682. Function.prototype.runsAfterSCW =
  683. function() {var func = this,
  684. args = new Array(arguments.length);
  685. for (var i=0;i<args.length;++i) {args[i] = arguments[i];}
  686. return function()
  687. {// concat/join the two argument arrays
  688. for (var i=0;i<arguments.length;++i) {args[args.length] = arguments[i];}
  689. return (args.shift()==scwTriggerEle)?func.apply(this, args):null;
  690. };
  691. };
  692. // Set up some shortcuts
  693. function scwID(id)
  694. {if (document.getElementById(id) || (!document.getElementById(id) && document.getElementsByName(id).length==0))
  695. // IF An ID attribute is assigned
  696. // OR No ID attribute is assigned but using IE and Opera
  697. // (which will find the NAME attribute value using getElementById)
  698. // OR No element has this ID or NAME attribute value
  699. // (used internally by the script)
  700. // THEN Return the required element.
  701. {return document.getElementById(id);}
  702. else {if (document.getElementsByName(id).length==1)
  703. // IF No ID attribute is assigned
  704. // AND Using a standards-based browser
  705. // AND Only one element has the NAME attribute set to the value
  706. // THEN Return the required element (using the NAME attribute value).
  707. {return document.getElementsByName(id)[0];}
  708. else {if (document.getElementsByName(id).length>1)
  709. { // IF No ID attribute is assigned
  710. // AND using a standards-based browser
  711. // AND more than one element has the NAME attribute set to the value
  712. // THEN alert developer to fix the fault.
  713. alert( 'SCW' +
  714. ' \nCannot uniquely identify element named: ' + id +
  715. '.\nMore than one identical NAME attribute defined' +
  716. '.\nSolution: Assign the required element a unique ID attribute value.');
  717. }
  718. }
  719. }
  720. };
  721. // Use a global variable for the return value from the next action
  722. // IE fails to pass the function through if the target element is in
  723. // a form and scwNextAction is not defined.
  724. var scwNextActionReturn, scwNextAction;
  725. // ****************************************************************************
  726. // Start of Function Library
  727. //
  728. // Exposed functions:
  729. //
  730. // scwShow Entry point for display of calendar,
  731. // called in main page.
  732. // showCal Legacy name of scwShow:
  733. // Passes only legacy arguments,
  734. // not the optional day disabling arguments.
  735. //
  736. // scwShowMonth Displays a month on the calendar,
  737. // Called when a month is set or changed.
  738. //
  739. // scwBeginDrag Controls calendar dragging.
  740. //
  741. // scwCancel Called when the calendar background is clicked:
  742. // Calls scwStopPropagation and may call scwHide.
  743. // scwHide Hides the calendar, called on various events.
  744. // scwStopPropagation Stops the propagation of an event.
  745. //
  746. // ****************************************************************************
  747. function showCal(scwEle,scwSource) {scwShow(scwEle,scwSource);};
  748. function scwShow(scwEle,scwSource)
  749. {if (!scwSource) {scwSource = window.event;}
  750. if (scwSource.tagName) // Second parameter isn't an event it's an element
  751. {var scwSourceEle = scwSource;
  752. if (scwID('scwIE')) {window.event.cancelBubble = true;}
  753. else {scwSourceEle.parentNode.addEventListener('click',scwStopPropagation,false);}
  754. }
  755. else // Second parameter is an event
  756. {var scwSourceEle = (scwSource.target)
  757. ?scwSource.target
  758. :scwSource.srcElement;
  759. // Stop the click event that opens the calendar from bubbling up to
  760. // the document-level event handler that hides it!
  761. if (scwSource.stopPropagation) {scwSource.stopPropagation();}
  762. else {scwSource.cancelBubble = true;}
  763. }
  764. scwTriggerEle = scwSourceEle;
  765. // Take any parameters that there might be from the third onwards as
  766. // day numbers to be disabled 0 = Sunday through to 6 = Saturday.
  767. scwParmActiveToday = true;
  768. for (var i=0;i<7;i++)
  769. {scwPassEnabledDay[(i+7-scwWeekStart)%7] = true;
  770. for (var j=2;j<arguments.length;j++)
  771. {if (arguments[j]==i)
  772. {scwPassEnabledDay[(i+7-scwWeekStart)%7] = false;
  773. if (scwDateNow.getDay()==i) {scwParmActiveToday = false;}
  774. }
  775. }
  776. }
  777. // If no value is preset then the seed date is
  778. // Today (when today is in range) OR
  779. // The middle of the date range.
  780. scwSeedDate = scwDateNow;
  781. // Find the date and Strip space characters from start and
  782. // end of date input.
  783. var scwDateValue = '';
  784. if (scwEle.value) {scwDateValue = scwEle.value.replace(/^\s+/,'').replace(/\s+$/,'');}
  785. else {if (typeof scwEle.value == 'undefined')
  786. {var scwChildNodes = scwEle.childNodes;
  787. for (var i=0;i<scwChildNodes.length;i++)
  788. {if (scwChildNodes[i].nodeType == 3)
  789. {scwDateValue = scwChildNodes[i].nodeValue.replace(/^\s+/,'').replace(/\s+$/,'');
  790. if (scwDateValue.length > 0)
  791. {scwTriggerEle.scwTextNode = scwChildNodes[i];
  792. scwTriggerEle.scwLength = scwChildNodes[i].nodeValue.length;
  793. break;
  794. }
  795. }
  796. }
  797. }
  798. }
  799. // Set the language-dependent elements
  800. scwSetDefaultLanguage();
  801. scwID('scwDragText').innerHTML = scwDrag;
  802. scwID('scwMonths').options.length = 0;
  803. for (var i=0;i<scwArrMonthNames.length;i++)
  804. {scwID('scwMonths').options[i] = new Option(scwArrMonthNames[i],scwArrMonthNames[i]);}
  805. scwID('scwYears').options.length = 0;
  806. for (var i=0;i<scwDropDownYears;i++)
  807. {scwID('scwYears').options[i] = new Option((scwBaseYear+i),(scwBaseYear+i));}
  808. for (var i=0;i<scwArrWeekInits.length;i++)
  809. {scwID('scwWeekInit' + i).innerHTML = scwArrWeekInits[(i+scwWeekStart)%scwArrWeekInits.length];}
  810. if (((new Date(scwBaseYear + scwDropDownYears, 0, 0)) > scwDateNow &&
  811. (new Date(scwBaseYear, 0, 0)) < scwDateNow) ||
  812. (scwClearButton && (scwEle.readOnly || scwEle.disabled))
  813. ) {scwID('scwFoot').style.display = '';
  814. scwID('scwNow').innerHTML = scwToday + ' ' + scwDateNow.scwFormat(scwDateDisplayFormat);
  815. scwID('scwClearButton').value = scwClear;
  816. if ((new Date(scwBaseYear + scwDropDownYears, 0, 0)) > scwDateNow &&
  817. (new Date(scwBaseYear, 0, 0)) < scwDateNow
  818. ) {scwID('scwNow').style.display = '';
  819. if (scwClearButton && (scwEle.readOnly || scwEle.disabled))
  820. {scwID('scwClear').style.display = '';
  821. scwID('scwClear').style.textAlign = 'left';
  822. scwID('scwNow').style.textAlign = 'right';
  823. }
  824. else {scwID('scwClear').style.display = 'none';
  825. scwID('scwNow').style.textAlign = 'center';
  826. }
  827. }
  828. else {scwID('scwClear').style.textAlign = 'center';
  829. scwID('scwClear').style.display = '';
  830. scwID('scwNow').style.display = 'none';
  831. }
  832. }
  833. else {scwID('scwFoot').style.display = 'none';}
  834. if (scwDateValue.length==0)
  835. {// If no value is entered and today is within the range,
  836. // use today's date, otherwise use the middle of the valid range.
  837. scwBlnFullInputDate=false;
  838. if ((new Date(scwBaseYear+scwDropDownYears,0,0))<scwSeedDate ||
  839. (new Date(scwBaseYear,0,1)) >scwSeedDate
  840. )
  841. {scwSeedDate = new Date(scwBaseYear + Math.floor(scwDropDownYears / 2), 5, 1);}
  842. }
  843. else
  844. {function scwInputFormat()
  845. {var scwArrSeed = new Array(),
  846. scwArrInput = scwDateValue.split(new RegExp('[\\'+scwArrDelimiters.join('\\')+']+','g'));
  847. // "Escape" all the user defined date delimiters above -
  848. // several delimiters will need it and it does no harm for
  849. // the others.
  850. // Strip any empty array elements (caused by delimiters)…