Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2698 lines
84 KiB

  1. <!-- ---------------------------------------------------------------------
  2. //
  3. // Copyright 1999 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: calendar.htc
  6. //
  7. // Description: The calendar behavior provides an easy, declarative way
  8. // to add a standard calendar control to web pages and html
  9. // based applications. It provides a variety of properties
  10. // to customize the look and feel along with a strong set
  11. // events and functionality.
  12. //
  13. //
  14. // Changes for SR UI
  15. //
  16. // 1. Range for bold dates (min,max)
  17. // 2. Create an array of bold/valid dates
  18. // 3. New style for bold dates and navigation to only bold dates
  19. // 4. Selection of only bold dates
  20. // 5. Prev/Next month navigation for valid bold months
  21. //
  22. //-------------------------------------------------------------------- -->
  23. <SCRIPT ID="CalResource" LANGUAGE=JavaScript SRC="calendar.js"></SCRIPT>
  24. <SCRIPT LANGUAGE="javascript">
  25. //------------------------------------------------------------------------
  26. // Attach to element events
  27. //------------------------------------------------------------------------
  28. element.attachEvent("onselectstart", fnOnSelectStart)
  29. element.attachEvent("onclick", fnOnClick)
  30. element.attachEvent("onkeydown", fnOnKeyDown)
  31. element.attachEvent("onpropertychange", fnOnPropertyChange)
  32. element.attachEvent("onreadystatechange", fnOnReadyStateChange)
  33. var Jan_Text = 'January';
  34. var Feb_Text = 'February';
  35. var Mar_Text = 'March';
  36. var Apr_Text = 'April';
  37. var May_Text = 'May';
  38. var Jun_Text = 'June';
  39. var Jul_Text = 'July';
  40. var Aug_Text = 'August';
  41. var Sep_Text = 'September';
  42. var Oct_Text = 'October';
  43. var Nov_Text = 'November';
  44. var Dec_Text = 'December';
  45. var Sun_Text = ' ';
  46. var Mon_Text = ' ';
  47. var Tue_Text = ' ';
  48. var Wed_Text = ' ';
  49. var Thu_Text = ' ';
  50. var Fri_Text = ' ';
  51. var Sat_Text = ' ';
  52. var gaMonthNames = new Array(
  53. new Array(Jan_Text,
  54. Feb_Text,
  55. Mar_Text,
  56. Apr_Text,
  57. May_Text,
  58. Jun_Text,
  59. Jul_Text,
  60. Aug_Text,
  61. Sep_Text,
  62. Oct_Text,
  63. Nov_Text,
  64. Dec_Text),
  65. new Array(Jan_Text,
  66. Feb_Text,
  67. Mar_Text,
  68. Apr_Text,
  69. May_Text,
  70. Jun_Text,
  71. Jul_Text,
  72. Aug_Text,
  73. Sep_Text,
  74. Oct_Text,
  75. Nov_Text,
  76. Dec_Text)
  77. );
  78. var gaDayNames = new Array(
  79. new Array(Sun_Text,
  80. Mon_Text,
  81. Tue_Text,
  82. Wed_Text,
  83. Thu_Text,
  84. Fri_Text,
  85. Sat_Text),
  86. new Array(Sun_Text,
  87. Mon_Text,
  88. Tue_Text,
  89. Wed_Text,
  90. Thu_Text,
  91. Fri_Text,
  92. Sat_Text),
  93. new Array(Sun_Text,
  94. Mon_Text,
  95. Tue_Text,
  96. Wed_Text,
  97. Thu_Text,
  98. Fri_Text,
  99. Sat_Text)
  100. );
  101. var gaMonthDays = new Array(
  102. /* Jan */ 31, /* Feb */ 29, /* Mar */ 31, /* Apr */ 30,
  103. /* May */ 31, /* Jun */ 30, /* Jul */ 31, /* Aug */ 31,
  104. /* Sep */ 30, /* Oct */ 31, /* Nov */ 30, /* Dec */ 31 )
  105. var StyleInfo = null // Style sheet with rules for this calendar
  106. var goStyle = new Object() // A hash of style sheet rules that apply to this calendar
  107. var gaDayCell = new Array() // an array of the table cells for days
  108. var goDayTitleRow = null // The table row containing days of the week
  109. var goYearSelect = null // The year select control
  110. var goMonthSelect = null // The month select control
  111. var goCurrentDayCell = null // The cell for the currently selected day
  112. var giStartDayIndex = 0 // The index in gaDayCell for the first day of the month
  113. var gbLoading = true // Flag for if the behavior is loading
  114. var giDay // day of the month (1 to 31)
  115. var giMonth // month of the year (1 to 12)
  116. var giYear // year (1900 to 2099)
  117. var giMonthLength = 0 // month length (0,1)
  118. var giDayLength = 0 // day length (0 to 2)
  119. var giFirstDay = 0 // first day of the week (0 to 6)
  120. var gsGridCellEffect = 'raised' // Grid cell effect
  121. var gsGridLinesColor = 'black' // Grid line color
  122. var gbShowDateSelectors = false // Show date selectors (0,1)
  123. var gbShowDays = true // Show the days of the week titles (0,1)
  124. var gbShowTitle = true // Show the title (0,1)
  125. var gbShowHorizontalGrid = true // Show the horizontal grid (0,1)
  126. var gbShowVerticalGrid = true // Show the vertical grid (0,1)
  127. var gbValueIsNull = false // There is no value selected (0,1)
  128. var gbReadOnly = false // The user can not interact with the control
  129. var giMinYear = 1900 // Minimum year (1 is the lowest possible value)
  130. var giMaxYear = 2099 // Maximum year
  131. var gaValidDate = new Array()
  132. var gbMinDateSet = false
  133. var gbMaxDateSet = false
  134. var gdMinDate = null
  135. var gdMaxDate = null
  136. var giValidDateCount = 0
  137. var goButtonLeft = null;
  138. var goButtonRight = null;
  139. var gbValidDateChanged = false ;
  140. var gbDayNameChanged = false ;
  141. var gbMonthNameChanged = false ;
  142. // Load the property values defined on the element to replace defaults
  143. fnGetPropertyDefaults()
  144. // Create the style sheets needed for the calendar display
  145. fnCreateStyleSheets()
  146. // Insert the HTML elements needed for the calendar display
  147. fnCreateCalendarHTML()
  148. // Update the title with the month and year
  149. fnUpdateTitle()
  150. // Get locale day month names
  151. fnSetLocaleDayMonthNames()
  152. // Fill in the days of the week
  153. fnUpdateDayTitles()
  154. // Build the month select control
  155. fnBuildMonthSelect()
  156. // Build the year select control
  157. fnBuildYearSelect()
  158. // Fill in the cells with the days of the month and set style values
  159. fnFillInCells()
  160. //------------------------------------------------------------------------
  161. //
  162. // Function: fnSetMinDate/fnSetMaxDate
  163. //
  164. // Synopsis: Sets the min date
  165. //
  166. // Arguments: Requires a date Value
  167. //
  168. // Returns:
  169. //
  170. // Notes: none
  171. //
  172. //------------------------------------------------------------------------
  173. function fnSetMinDate(sValue)
  174. {
  175. var aValue = sValue.split('/')
  176. // ensure valid valuse for month, day, and year
  177. aValue[0]++ ; aValue[0]-- ; aValue[1]++ ; aValue[1]-- ; aValue[2]++ ; aValue[2]-- ;
  178. if ( isNaN(aValue[0]) || isNaN(aValue[1]) || isNaN(aValue[2]) ) throw 450
  179. gdMinDate = new Object();
  180. gdMinDate.day = aValue[0];
  181. gdMinDate.month = aValue[1];
  182. gdMinDate.year = aValue[2];
  183. gbMinDateSet = true ;
  184. }
  185. function fnSetMaxDate(sValue)
  186. {
  187. var aValue = sValue.split('/')
  188. // ensure valid values for month, day, and year
  189. aValue[0]++ ; aValue[0]-- ; aValue[1]++ ; aValue[1]-- ; aValue[2]++ ; aValue[2]-- ;
  190. if ( isNaN(aValue[0]) || isNaN(aValue[1]) || isNaN(aValue[2]) ) throw 450
  191. gdMaxDate = new Object();
  192. gdMaxDate.day = aValue[0];
  193. gdMaxDate.month = aValue[1];
  194. gdMaxDate.year = aValue[2];
  195. gbMaxDateSet = true ;
  196. }
  197. //------------------------------------------------------------------------
  198. //
  199. // Function: fnAddValidDate
  200. //
  201. // Synopsis: Adds a valid day to the gaValidDay array which is used
  202. // to select valid dates
  203. //
  204. // Arguments: Requires a date Value
  205. //
  206. // Returns:
  207. //
  208. // Notes: none
  209. //
  210. //------------------------------------------------------------------------
  211. function fnAddValidDate(sValue)
  212. {
  213. var aValue = sValue.split('/')
  214. // ensure valid values for month, day, and year
  215. aValue[0]++ ; aValue[0]-- ; aValue[1]++ ; aValue[1]-- ; aValue[2]++ ; aValue[2]-- ;
  216. if ( isNaN(aValue[0]) || isNaN(aValue[1]) || isNaN(aValue[2]) ) throw 450
  217. gaValidDate[giValidDateCount] = new Object();
  218. gaValidDate[giValidDateCount].day = aValue[0];
  219. gaValidDate[giValidDateCount].month = aValue[1];
  220. gaValidDate[giValidDateCount].year = aValue[2];
  221. giValidDateCount++;
  222. gbValidDateChanged = true ;
  223. }
  224. // **********************************************************************
  225. // PROPERTY GET/SET FUNCTIONS
  226. // **********************************************************************
  227. //------------------------------------------------------------------------
  228. //
  229. // Function: fnGetDay / fnPutDay
  230. //
  231. // Synopsis: The day property is used to set the day of the month. The
  232. // valid range is from 1 to the maximum day of the selected
  233. // month & year. If a number is given outside that range, it
  234. // is set to the closest valid value. Invalid input will cause
  235. // an exception.
  236. //
  237. // Arguments: The put method requires an integer value for the day
  238. //
  239. // Returns: The get method will return the selected day of the month
  240. // If the valueIsNull property is set, null is returned
  241. //
  242. // Notes: none
  243. //
  244. //------------------------------------------------------------------------
  245. function fnGetDay()
  246. {
  247. return (gbValueIsNull) ? null : giDay
  248. }
  249. function fnPutDay(iDay)
  250. {
  251. if (gbLoading) return // return if the behavior is loading
  252. iDay = parseInt(iDay)
  253. if (isNaN(iDay)) throw 450
  254. fnSetDate(iDay, giMonth, giYear)
  255. }
  256. //------------------------------------------------------------------------
  257. //
  258. // Function: fnGetMonth / fnPutMonth
  259. //
  260. // Synopsis: The month property is used to set the month of the year.
  261. // The valid range is from 1 to 12. If a value is given
  262. // outside that range, it is set to the closest valid value.
  263. // Invalid input will cause an exception.
  264. //
  265. // Arguments: The put method requires an integer value for the month
  266. //
  267. // Returns: The get method will return the selected month value
  268. // If the valueIsNull property is set, null is returned
  269. //
  270. // Notes: Setting the year can cause the selected "day" value to be
  271. // reduced to the highest day in the selected month if needed.
  272. //
  273. //------------------------------------------------------------------------
  274. function fnGetMonth()
  275. {
  276. return (gbValueIsNull) ? null : giMonth
  277. }
  278. function fnPutMonth(iMonth)
  279. {
  280. if (gbLoading) return // return if the behavior is loading
  281. iMonth = parseInt(iMonth)
  282. if (isNaN(iMonth)) throw 450
  283. fnSetDate(giDay, iMonth, giYear)
  284. }
  285. //------------------------------------------------------------------------
  286. //
  287. // Function: fnGetYear / fnPutYear
  288. //
  289. // Synopsis: The year property is used to set the current year.
  290. // The valid range is from minYear to maxYear. If a value is given
  291. // outside that range, it is set to the closest valid value.
  292. // Invalid input will cause an exception.
  293. //
  294. // Arguments: The put method requires an integer value for the year
  295. //
  296. // Returns: The get method will return the selected year value
  297. // If the valueIsNull property is set, null is returned.
  298. //
  299. // Notes: Setting the year can cause the selected "day" value to be
  300. // reduced to the highest day in the selected month if needed.
  301. //
  302. //------------------------------------------------------------------------
  303. function fnGetYear()
  304. {
  305. return (gbValueIsNull) ? null : giYear
  306. }
  307. function fnPutYear(iYear)
  308. {
  309. if (gbLoading) return // return if the behavior is loading
  310. iYear = parseInt(iYear)
  311. if (isNaN(iYear)) throw 450
  312. fnSetDate(giDay, giMonth, iYear)
  313. }
  314. //------------------------------------------------------------------------
  315. //
  316. // Function: fnGetMonthLength / fnPutMonthLength
  317. //
  318. // Synopsis: The monthLength property is used to adjust the length of
  319. // the month name used in the title and month selection control.
  320. //
  321. // Arguments: The put method requires a value of 'short' or 'long'
  322. //
  323. // Returns: The get method will return a value of 'short' or 'long'
  324. //
  325. // Notes: none
  326. //
  327. //------------------------------------------------------------------------
  328. function fnGetMonthLength()
  329. {
  330. if (giMonthLength == 0) return "short"
  331. if (giMonthLength == 1) return "long"
  332. }
  333. function fnPutMonthLength(sLength)
  334. {
  335. if (gbLoading) return // return if the behavior is loading
  336. switch (sLength.toLowerCase())
  337. {
  338. case "short" :
  339. if (giMonthLength == 0) return
  340. giMonthLength = 0
  341. break;
  342. case "long" :
  343. if (giMonthLength == 1) return
  344. giMonthLength = 1
  345. break;
  346. default :
  347. throw 450
  348. return
  349. }
  350. fnUpdateTitle()
  351. fnBuildMonthSelect()
  352. }
  353. //------------------------------------------------------------------------
  354. //
  355. // Function: fnGetDayName / fnPutDayName
  356. //
  357. // Synopsis: Sets day names according to the locale
  358. //
  359. // Arguments: number from 0-6 sets Sunday -> Saturday
  360. //
  361. // Returns: Name of day
  362. //
  363. // Notes: none
  364. //
  365. //------------------------------------------------------------------------
  366. function fnGetDayName(num)
  367. {
  368. return gaDayNames[0][num];
  369. }
  370. function fnPutDayName(num,str)
  371. {
  372. gaDayNames[0][num] = str ;
  373. gbDayNameChanged = true ;
  374. }
  375. //------------------------------------------------------------------------
  376. //
  377. // Function: fnGetMonthName / fnPutMonthName
  378. //
  379. // Synopsis: Sets Month names according to the locale
  380. //
  381. // Arguments: number from 0-11 sets Jan -> Dec
  382. //
  383. // Returns: Name of Month
  384. //
  385. // Notes: none
  386. //
  387. //------------------------------------------------------------------------
  388. function fnGetMonthName(num)
  389. {
  390. return gaMonthNames[0][num];
  391. }
  392. function fnPutMonthName(num,str)
  393. {
  394. gaMonthNames[0][num] = str ;
  395. gbMonthNameChanged = true ;
  396. }
  397. //------------------------------------------------------------------------
  398. //
  399. // Function: fnGetDayLength / fnPutDayLength
  400. //
  401. // Synopsis: The dayLength property is used to adjust the length of
  402. // the day names in the calendar grid.
  403. //
  404. // Arguments: The put method requires a value of 'short', 'medium',
  405. // or 'long'
  406. //
  407. // Returns: The get method will return a value of 'short', 'medium',
  408. // or 'long'
  409. //
  410. // Notes: none
  411. //
  412. //------------------------------------------------------------------------
  413. function fnGetDayLength()
  414. {
  415. if (giDayLength == 0) return "short"
  416. if (giDayLength == 1) return "medium"
  417. if (giDayLength == 2) return "long"
  418. }
  419. function fnPutDayLength(sLength)
  420. {
  421. if (gbLoading) return // return if the behavior is loading
  422. switch (sLength.toLowerCase())
  423. {
  424. case "short" :
  425. if (giDayLength == 0) return
  426. giDayLength = 0
  427. break;
  428. case "medium" :
  429. if (giDayLength == 1) return
  430. giDayLength = 1
  431. break;
  432. case "long" :
  433. if (giDayLength == 2) return
  434. giDayLength = 2
  435. break;
  436. default :
  437. throw 450
  438. return
  439. }
  440. fnUpdateDayTitles()
  441. // Used to force a table resize if needed
  442. goStyle['DaySelected'].borderStyle = 'solid'
  443. }
  444. //------------------------------------------------------------------------
  445. //
  446. // Function: fnGetFirstDay / fnPutFirstDay
  447. //
  448. // Synopsis: The firstDay property is used to adjust the first day of
  449. // the week on the calendar grid. Valid values are 1 to 7
  450. // where 1 is Sunday and 7 is Saturday. Setting to an invalid
  451. // value will cause an exception.
  452. //
  453. // Arguments: The put method requires a value from 1 to 7
  454. //
  455. // Returns: The get method will return a value from 1 to 7
  456. //
  457. // Notes: none
  458. //
  459. //------------------------------------------------------------------------
  460. function fnGetFirstDay()
  461. {
  462. return giFirstDay
  463. }
  464. function fnPutFirstDay(iFirstDay)
  465. {
  466. if (gbLoading) return // return if the behavior is loading
  467. if ((iFirstDay < 0) || (iFirstDay > 6)) throw 450
  468. if (giFirstDay == iFirstDay) return
  469. giFirstDay = iFirstDay
  470. fnUpdateDayTitles()
  471. fnFillInCells()
  472. }
  473. //------------------------------------------------------------------------
  474. //
  475. // Function: fnGetGridCellEffect / fnPutGridCellEffect
  476. //
  477. // Synopsis: The gridCellEffect property is used to modify the 3D effect
  478. // in the calendar grid (excluding day titles). It can take
  479. // values of 'raised', 'flat', or 'sunken'. Other values will
  480. // cause an exception.
  481. //
  482. // Arguments: The put method requires a value of 'raised', 'flat', or
  483. // 'sunken'.
  484. //
  485. // Returns: The get method will return a value of 'raised', 'flat', or
  486. // 'sunken'.
  487. //
  488. // Notes: none
  489. //
  490. //------------------------------------------------------------------------
  491. function fnGetGridCellEffect()
  492. {
  493. return gsGridCellEffect
  494. }
  495. function fnPutGridCellEffect(sEffect)
  496. {
  497. if (gbLoading) return // return if the behavior is loading
  498. switch (sEffect.toLowerCase())
  499. {
  500. case "raised" :
  501. if (gsGridCellEffect == 'raised') return
  502. gsGridCellEffect = 'raised'
  503. fnUpdateGridColors()
  504. break
  505. case "flat" :
  506. if (gsGridCellEffect == 'flat') return
  507. gsGridCellEffect = 'flat'
  508. fnUpdateGridColors()
  509. break
  510. case "sunken" :
  511. if (gsGridCellEffect == 'sunken') return
  512. gsGridCellEffect = 'sunken'
  513. fnUpdateGridColors()
  514. break
  515. default :
  516. throw 450
  517. }
  518. }
  519. //------------------------------------------------------------------------
  520. //
  521. // Function: fnGetGridLinesColor / fnPutGridLinesColor
  522. //
  523. // Synopsis: The gridLinesColor property is used to change the color of
  524. // the calendar grid when the gridCellEffect property is set
  525. // to 'flat'. It can be any valid HTML color value.
  526. //
  527. // Arguments: The put method requires a HTML color value
  528. //
  529. // Returns: The get method will return a HTML color value
  530. //
  531. // Notes: No error checking is performed. Invalid values may result
  532. // in unexpected rendering.
  533. //
  534. //------------------------------------------------------------------------
  535. function fnGetGridLinesColor()
  536. {
  537. return gsGridLinesColor
  538. }
  539. function fnPutGridLinesColor(sGridLinesColor)
  540. {
  541. if (gbLoading) return // return if the behavior is loading
  542. gsGridLinesColor = sGridLinesColor
  543. fnUpdateGridColors()
  544. }
  545. //------------------------------------------------------------------------
  546. //
  547. // Function: fnGetShowVerticalGrid / fnPutShowVerticalGrid
  548. //
  549. // Synopsis: The showVerticalGrid property is used to toggle the
  550. // visibility of vertical lines in the calendar grid.
  551. //
  552. // Arguments: The put method requires true or false value for visibility
  553. //
  554. // Returns: The get method will return a true or false value
  555. //
  556. // Notes: none
  557. //
  558. //------------------------------------------------------------------------
  559. function fnGetShowVerticalGrid()
  560. {
  561. return gbShowVerticalGrid
  562. }
  563. function fnPutShowVerticalGrid(bShowVerticalGrid)
  564. {
  565. if (gbLoading) return // return if the behavior is loading
  566. if ((bShowVerticalGrid) != gbShowVerticalGrid)
  567. {
  568. gbShowVerticalGrid = (bShowVerticalGrid) ? true : false
  569. fnFireOnPropertyChange("propertyName", "showVerticalGrid")
  570. fnUpdateGridColors()
  571. }
  572. }
  573. //------------------------------------------------------------------------
  574. //
  575. // Function: fnGetShowHorizontalGrid / fnPutShowHorizontalGrid
  576. //
  577. // Synopsis: The showHorizontalGrid property is used to toggle the
  578. // visibility of horizontal lines in the calendar grid.
  579. //
  580. // Arguments: The put method requires true or false value for visibility
  581. //
  582. // Returns: The get method will return a true or false value
  583. //
  584. // Notes: none
  585. //
  586. //------------------------------------------------------------------------
  587. function fnGetShowHorizontalGrid()
  588. {
  589. return gbShowHorizontalGrid
  590. }
  591. function fnPutShowHorizontalGrid(bShowHorizontalGrid)
  592. {
  593. if (gbLoading) return // return if the behavior is loading
  594. if ((bShowHorizontalGrid) != gbShowHorizontalGrid)
  595. {
  596. gbShowHorizontalGrid = (bShowHorizontalGrid) ? true : false
  597. fnFireOnPropertyChange("propertyName", "showHorizontalGrid")
  598. fnUpdateGridColors()
  599. }
  600. }
  601. //------------------------------------------------------------------------
  602. //
  603. // Function: fnGetShowDateSelectors / fnPutShowDateSelectors
  604. //
  605. // Synopsis: The showDateSelectors property toggles the visibility of
  606. // the month and year select controls.
  607. //
  608. // Arguments: The put method requires true or false value for visibility
  609. //
  610. // Returns: The get method will return a true or false value
  611. //
  612. // Notes: none
  613. //
  614. //------------------------------------------------------------------------
  615. function fnGetShowDateSelectors()
  616. {
  617. return gbShowDateSelectors
  618. }
  619. function fnPutShowDateSelectors(bShowDateSelectors)
  620. {
  621. if (gbLoading) return // return if the behavior is loading
  622. gbShowDateSelectors = (bShowDateSelectors) ? true : false
  623. element.children[0].rows[0].cells[1].style.display = (gbShowDateSelectors) ? '' : 'none'
  624. element.children[0].rows[0].style.display = (gbShowDateSelectors || gbShowTitle) ? '' : 'none'
  625. }
  626. //------------------------------------------------------------------------
  627. //
  628. // Function: fnGetShowDays / fnPutShowDays
  629. //
  630. // Synopsis: The showDays property toggles the visibility of
  631. // the day of the week titles row in the calendar grid.
  632. //
  633. // Arguments: The put method requires true or false value for visibility
  634. //
  635. // Returns: The get method will return a true or false value
  636. //
  637. // Notes: none
  638. //
  639. //------------------------------------------------------------------------
  640. function fnGetShowDays()
  641. {
  642. return gbShowDays
  643. }
  644. function fnPutShowDays(bShowDays)
  645. {
  646. if (gbLoading) return // return if the behavior is loading
  647. gbShowDays = (bShowDays) ? true : false
  648. goDayTitleRow.style.display = (gbShowDays) ? '' : 'none'
  649. }
  650. //------------------------------------------------------------------------
  651. //
  652. // Function: fnGetShowTitle / fnPutShowTitle
  653. //
  654. // Synopsis: the showTitle property toggles the visibility of the month
  655. // and year title at the top of the calendar.
  656. //
  657. // Arguments: The put method requires true or false value for visibility
  658. //
  659. // Returns: The get method will return a true or false value
  660. //
  661. // Notes: none
  662. //
  663. //------------------------------------------------------------------------
  664. function fnGetShowTitle()
  665. {
  666. return gbShowTitle
  667. }
  668. function fnPutShowTitle(bShowTitle)
  669. {
  670. if (gbLoading) return // return if the behavior is loading
  671. gbShowTitle = (bShowTitle) ? true : false
  672. element.children[0].rows[0].style.display = (gbShowDateSelectors || gbShowTitle) ? '' : 'none'
  673. fnUpdateTitle()
  674. }
  675. //------------------------------------------------------------------------
  676. //
  677. // Function: fnGetValue / fnPutValue
  678. //
  679. // Synopsis: The value property returns the day, month, and year in the
  680. // format: {day}/{month}/{year}
  681. // example: 25/02/1998
  682. // An invalid value will cause an exception.
  683. //
  684. // Arguments: The put method requires a string in the format described
  685. // above
  686. //
  687. // Returns: The get method will return the current date value
  688. //
  689. // Notes: The day and month are returned in the two digit format.
  690. // The year is returned in a four digit format.
  691. //
  692. //------------------------------------------------------------------------
  693. function fnGetValue()
  694. {
  695. var sValue
  696. if (gbValueIsNull) return null
  697. sValue = ((giDay < 10) ? '0' + giDay : giDay) + '/' +
  698. ((giMonth < 10) ? '0' + giMonth : giMonth) + '/'
  699. if (giYear < 10) return sValue + '000' + giYear
  700. if (giYear < 100) return sValue + '00' + giYear
  701. if (giYear < 1000) return sValue + '0' + giYear
  702. return sValue + giYear
  703. }
  704. function fnPutValue(sValue)
  705. {
  706. if (gbLoading) return // return if the behavior is loading
  707. var aValue = sValue.split('/')
  708. // ensure valid values for month, day, and year
  709. aValue[0]++ ; aValue[0]-- ; aValue[1]++ ; aValue[1]-- ; aValue[2]++ ; aValue[2]-- ;
  710. if ( isNaN(aValue[0]) || isNaN(aValue[1]) || isNaN(aValue[2]) ) throw 450
  711. fnSetDate(aValue[0], aValue[1], aValue[2])
  712. }
  713. //------------------------------------------------------------------------
  714. //
  715. // Function: fnGetValueIsNull / fnPutValueIsNull
  716. //
  717. // Synopsis: The valueIsNull property set the calendar so that no day
  718. // is selected. Changing any date property, setting one of
  719. // the date select controls, or clicking on a day will result
  720. // in the valueIsNull property getting set to false.
  721. //
  722. // Arguments: The put method requires a string in the format described
  723. // above
  724. //
  725. // Returns: The get method will return the current date value
  726. //
  727. // Notes: The day and month are returned in the two digit format.
  728. // The year is returned in a four digit format.
  729. //
  730. //------------------------------------------------------------------------
  731. function fnGetValueIsNull()
  732. {
  733. return gbValueIsNull
  734. }
  735. function fnPutValueIsNull(bValueIsNull)
  736. {
  737. if (gbLoading) return // return if the behavior is loading
  738. if ((bValueIsNull) != gbValueIsNull)
  739. {
  740. gbValueIsNull = (bValueIsNull) ? true : false
  741. fnFireOnPropertyChange("propertyName", "readOnly")
  742. }
  743. goCurrentDayCell.className = (bValueIsNull) ?
  744. 'Day_' + uniqueID : 'DaySelected_' + uniqueID
  745. }
  746. //------------------------------------------------------------------------
  747. //
  748. // Function: fnGetReadOnly / fnPutReadOnly
  749. //
  750. // Synopsis: The readOnly property can be set to true or false to
  751. // disable user date selection by clicking on days or through
  752. // the select controls
  753. //
  754. // Arguments: The put method requires a true/false value
  755. //
  756. // Returns: The get method will return true or false
  757. //
  758. // Notes: none
  759. //
  760. //------------------------------------------------------------------------
  761. function fnGetReadOnly()
  762. {
  763. return (gbReadOnly) ? true : false
  764. }
  765. function fnPutReadOnly(bReadOnly)
  766. {
  767. if (gbLoading) return // return if the behavior is loading
  768. if ((bReadOnly) != gbReadOnly)
  769. {
  770. gbReadOnly = (bReadOnly) ? true : false
  771. fnFireOnPropertyChange("propertyName", "readOnly")
  772. }
  773. element.children[0].rows[0].cells[1].children[0].children[0].disabled = gbReadOnly
  774. element.children[0].rows[0].cells[1].children[0].children[1].disabled = gbReadOnly
  775. }
  776. // **********************************************************************
  777. // CALENDAR INITIALIZATION FUNCTIONS
  778. // **********************************************************************
  779. //------------------------------------------------------------------------
  780. //
  781. // Function: fnCreateCalendarHTML
  782. //
  783. // Synopsis: This function adds the HTML code to the main document that
  784. // is required to display the calendar. It contains nested
  785. // tables and all style information is inherited from the
  786. // style sheet properties.
  787. //
  788. // Arguments: none
  789. //
  790. // Returns: none
  791. //
  792. // Notes: none
  793. //
  794. //------------------------------------------------------------------------
  795. function fnCreateCalendarHTML()
  796. {
  797. var row, cell
  798. //
  799. // Only calendar days direction fixed as LTR as Arabic/Hebrew will have days in same order
  800. //
  801. element.innerHTML =
  802. '<table border=0 width=100% border=0 cellspacing=0 cellpadding=0 class=WholeCalendar_' + uniqueID + '> ' +
  803. ' <tr bgcolor=\"808080\"> ' +
  804. ' <td><button id=mlb style=\"cursor: hand;\" title=\"' + L_PreviousMonth_ToolTip + '\" class=NavButton_' + uniqueID + '>&lt;</button></td> ' +
  805. ' <td class=Title_' + uniqueID + '></td> ' +
  806. ' <td class=DateControls_' + uniqueID + '> ' +
  807. ' <nobr> <select></select> ' +
  808. ' <select></select> </nobr> </td> ' +
  809. ' <td><button id=mrb style=\"cursor: hand;\" title=\"' + L_NextMonth_ToolTip + '\" class=NavButton_' + uniqueID + '>&gt;</button></td> ' +
  810. ' </tr> ' +
  811. ' <tr> <td colspan=5><div tabindex=0> ' +
  812. ' <table id=calgrid class=CalTable_' + uniqueID + ' cellspacing=0 border=0> ' +
  813. ' <tr><td nowrap class=DayTitle_' + uniqueID + '></td>' +
  814. ' <td nowrap class=DayTitle_' + uniqueID + '></td>' +
  815. ' <td nowrap class=DayTitle_' + uniqueID + '></td>' +
  816. ' <td nowrap class=DayTitle_' + uniqueID + '></td>' +
  817. ' <td nowrap class=DayTitle_' + uniqueID + '></td>' +
  818. ' <td nowrap class=DayTitle_' + uniqueID + '></td>' +
  819. ' <td nowrap class=DayTitle_' + uniqueID + '></td></tr>' +
  820. ' <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>' +
  821. ' <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>' +
  822. ' <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>' +
  823. ' <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>' +
  824. ' <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>' +
  825. ' <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>' +
  826. ' </table> ' +
  827. ' </div></tr> ' +
  828. '</table> ';
  829. goDayTitleRow = element.children[0].rows[1].cells[0].children[0].children[0].rows[0]
  830. goMonthSelect = element.children[0].rows[0].cells[2].children[0].children[0]
  831. goYearSelect = element.children[0].rows[0].cells[2].children[0].children[1]
  832. goButtonLeft = element.children[0].rows[0].cells[0].children[0]
  833. goButtonRight = element.children[0].rows[0].cells[3].children[0]
  834. goButtonLeft.attachEvent("onclick", fnButtonLeftClick)
  835. goButtonRight.attachEvent("onclick", fnButtonRightClick)
  836. for (row=1; row < 7; row++)
  837. for (cell=0; cell < 7; cell++)
  838. gaDayCell[((row-1)*7) + cell] = element.children[0].rows[1].cells[0].children[0].children[0].rows[row].cells[cell]
  839. }
  840. //------------------------------------------------------------------------
  841. //
  842. // Function: fnCreateStyleSheets
  843. //
  844. // Synopsis: The calendar uses a style sheet to control the rendering
  845. // of the different calendar elements. This function creates
  846. // the style sheet in the main document using a unique name.
  847. //
  848. // Arguments: none
  849. //
  850. // Returns:
  851. //
  852. // Notes:
  853. //
  854. //------------------------------------------------------------------------
  855. function fnCreateStyleSheets()
  856. {
  857. var StyleInfo
  858. if (! element.document.body.BehaviorStyleSheet)
  859. {
  860. element.document.body.BehaviorStyleSheet = element.document.createStyleSheet()
  861. }
  862. StyleInfo = element.document.body.BehaviorStyleSheet
  863. StyleInfo.addRule( '.WholeCalendar_' + uniqueID,
  864. 'background-color : white ;'+
  865. 'border : 1px solid black ;'+
  866. 'cursor : default ;'+
  867. 'width : 100% ;'+
  868. 'height : 100% ;'
  869. )
  870. goStyle['WholeCalendar'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  871. StyleInfo.addRule( '.Title_' + uniqueID,
  872. 'color : white ;'+ // cal--title-color
  873. 'font-family : Arial ;'+ // cal--title-font-family
  874. 'font-size : 10pt ;'+ // cal--title-font-size
  875. 'font-weight : bold ;'+ // cal--title-font-weight
  876. 'text-align : center ;'+ // cal--title-text-align
  877. 'height : 1 ;'+
  878. 'width : 100% ;'
  879. )
  880. goStyle['Title'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  881. fnLoadCSSDefault('cal--title-background-color', 'calTitleBackgroundColor', goStyle['Title'], 'backgroundColor')
  882. fnLoadCSSDefault('cal--title-color', 'calTitleColor', goStyle['Title'], 'color')
  883. fnLoadCSSDefault('cal--title-font-family', 'calTitleFontFamily', goStyle['Title'], 'fontFamily')
  884. fnLoadCSSDefault('cal--title-font-size', 'calTitleFontSize', goStyle['Title'], 'fontSize')
  885. fnLoadCSSDefault('cal--title-font-weight', 'calTitleFontWeight', goStyle['Title'], 'fontWeight')
  886. fnLoadCSSDefault('cal--title-text-align', 'calTitleTextAlign', goStyle['Title'], 'textAlign')
  887. StyleInfo.addRule( '.NavButton_' + uniqueID,
  888. 'color : white ;'+ // cal--navButton-color
  889. 'font-family : Arial ;'+ // cal--navButton-font-family
  890. 'font-size : 10pt ;'+ // cal--navButton-font-size
  891. 'font-weight : bold ;'+ // cal--navButton-font-weight
  892. 'text-align : center ;'+ // cal--navButton-text-align
  893. 'padding : 2px ;' // cal--navButton-padding
  894. )
  895. goStyle['NavButton'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  896. fnLoadCSSDefault('cal--navButton-background-color', 'calNavButtonBackgroundColor', goStyle['NavButton'], 'backgroundColor')
  897. fnLoadCSSDefault('cal--navButton-color', 'calNavButtonColor', goStyle['NavButton'], 'color')
  898. fnLoadCSSDefault('cal--navButton-font-family', 'calNavButtonFontFamily', goStyle['NavButton'], 'fontFamily')
  899. fnLoadCSSDefault('cal--navButton-font-size', 'calNavButtonFontSize', goStyle['NavButton'], 'fontSize')
  900. fnLoadCSSDefault('cal--navButton-font-weight', 'calNavButtonFontWeight', goStyle['NavButton'], 'fontWeight')
  901. fnLoadCSSDefault('cal--navButton-text-align', 'calNavButtonTextAlign', goStyle['NavButton'], 'textAlign')
  902. fnLoadCSSDefault('cal--navButton-padding', 'calNavButtonPadding', goStyle['NavButton'], 'padding')
  903. StyleInfo.addRule( '.DateControls_' + uniqueID,
  904. 'text-align : right ;'
  905. )
  906. goStyle['DateControls'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  907. StyleInfo.addRule( '.CalTable_' + uniqueID,
  908. 'border : 0 solid black ;'+
  909. 'width : 100% ;'+
  910. 'height : 100% ;'
  911. )
  912. goStyle['CalTable'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  913. StyleInfo.addRule( '.DayTitle_' + uniqueID,
  914. 'background-color : lightgrey ;'+ // dayTitle-background-color
  915. 'color : black ;'+ // dayTitle-color
  916. 'font-family : Arial ;'+ // dayTitle-font-family
  917. 'font-size : 8pt ;'+ // dayTitle-font-size
  918. 'font-weight : bold ;'+ // dayTitle-font-weight
  919. 'text-align : center ;'+ // dayTitle-text-align
  920. 'border-width : 1px ;'+
  921. 'border-style : solid ;'+
  922. 'border-left-color : white ;'+
  923. 'border-top-color : white ;'+
  924. 'border-right-color : black ;'+
  925. 'border-bottom-color : black ;'+
  926. 'width : 14% ;'+
  927. 'height : 1 ;'
  928. )
  929. goStyle['DayTitle'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  930. fnLoadCSSDefault('cal--dayTitle-background-color', 'calDayTitleBackgroundColor', goStyle['DayTitle'], 'backgroundColor')
  931. fnLoadCSSDefault('cal--dayTitle-color', 'calDayTitleColor', goStyle['DayTitle'], 'color')
  932. fnLoadCSSDefault('cal--dayTitle-font-family', 'calDayTitleFontFamily', goStyle['DayTitle'], 'fontFamily')
  933. fnLoadCSSDefault('cal--dayTitle-font-size', 'calDayTitleFontSize', goStyle['DayTitle'], 'fontSize')
  934. fnLoadCSSDefault('cal--dayTitle-font-weight', 'calDayTitleFontWeight', goStyle['DayTitle'], 'fontWeight')
  935. fnLoadCSSDefault('cal--dayTitle-text-align', 'calDayTitleTextAlign', goStyle['DayTitle'], 'textAlign')
  936. StyleInfo.addRule( '.OffDay_' + uniqueID,
  937. 'background-color : lightgrey ;'+ // cal--offMonth-background-color
  938. 'color : #7F7F7F ;'+ // cal--offMonth-color
  939. 'font-family : Arial ;'+ // cal--offMonth-font-family
  940. 'font-size : 8pt ;'+ // cal--offMonth-font-size
  941. 'font-weight : normal ;'+ // cal--offMonth-font-weight
  942. 'text-align : right ;'+ // cal--offMonth-text-align
  943. 'vertical-align : text-top ;'+ // cal--offMonth-vertical-align
  944. 'border-width : 1px ;'+
  945. 'border-style : solid ;'+
  946. 'border-left-color : white ;'+
  947. 'border-top-color : white ;'+
  948. 'border-right-color : black ;'+
  949. 'border-bottom-color : black ;'+
  950. 'width : 14% ;'+
  951. 'cursor : default ;'
  952. )
  953. goStyle['OffDay'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  954. fnLoadCSSDefault('cal--offMonth-background-color', 'calOffMonthBackgroundColor', goStyle['OffDay'], 'backgroundColor')
  955. fnLoadCSSDefault('cal--offMonth-color', 'calOffMonthColor', goStyle['OffDay'], 'color')
  956. fnLoadCSSDefault('cal--offMonth-font-family', 'calOffMonthFontFamily', goStyle['OffDay'], 'fontFamily')
  957. fnLoadCSSDefault('cal--offMonth-font-size', 'calOffMonthFontSize', goStyle['OffDay'], 'fontSize')
  958. fnLoadCSSDefault('cal--offMonth-font-weight', 'calOffMonthFontWeight', goStyle['OffDay'], 'fontWeight')
  959. fnLoadCSSDefault('cal--offMonth-text-align', 'calOffMonthTextAlign', goStyle['OffDay'], 'textAlign')
  960. fnLoadCSSDefault('cal--offMonth-vertical-align', 'calOffMonthVerticalAlign', goStyle['OffDay'], 'verticalAlign')
  961. StyleInfo.addRule( '.Day_' + uniqueID,
  962. 'background-color : lightgrey ;'+ // cal--currentMonth-background-color
  963. 'color : #00009F ;'+ // cal--currentMonth-color
  964. 'font-family : Arial ;'+ // cal--currentMonth-font-family
  965. 'font-size : 8pt ;'+ // cal--currentMonth-font-size
  966. 'font-weight : normal ;'+ // cal--currentMonth-font-weight
  967. 'text-align : right ;'+ // cal--currentMonth-text-align
  968. 'vertical-align : text-top ;'+ // cal--currentMonth-vertical-align
  969. 'border-width : 1px ;'+
  970. 'border-style : solid ;'+
  971. 'border-left-color : white ;'+
  972. 'border-top-color : white ;'+
  973. 'border-right-color : black ;'+
  974. 'border-bottom-color : black ;'+
  975. 'width : 14% ;'+
  976. 'cursor : default ;'
  977. )
  978. goStyle['Day'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  979. fnLoadCSSDefault('cal--currentMonth-background-color', 'calCurrentMonthBackgroundColor', goStyle['Day'], 'backgroundColor')
  980. fnLoadCSSDefault('cal--currentMonth-color', 'calCurrentMonthColor', goStyle['Day'], 'color')
  981. fnLoadCSSDefault('cal--currentMonth-font-family', 'calCurrentMonthFontFamily', goStyle['Day'], 'fontFamily')
  982. fnLoadCSSDefault('cal--currentMonth-font-size', 'calCurrentMonthFontSize', goStyle['Day'], 'fontSize')
  983. fnLoadCSSDefault('cal--currentMonth-font-weight', 'calCurrentMonthFontWeight', goStyle['Day'], 'fontWeight')
  984. fnLoadCSSDefault('cal--currentMonth-text-align', 'calCurrentMonthTextAlign', goStyle['Day'], 'textAlign')
  985. fnLoadCSSDefault('cal--currentMonth-vertical-align', 'calCurrentMonthVerticalAlign', goStyle['Day'], 'verticalAlign')
  986. StyleInfo.addRule( '.DaySelected_' + uniqueID,
  987. 'background-color : #7F7F7F ;'+ // cal--selectedDay-background-color
  988. 'color : yellow ;'+ // cal--selectedDay-color
  989. 'font-family : Arial ;'+ // cal--selectedDay-font-family
  990. 'font-size : 8pt ;'+ // cal--selectedDay-font-size
  991. 'font-weight : bold ;'+ // cal--selectedDay-font-weight
  992. 'text-align : right ;'+ // cal--selectedMonth-text-align
  993. 'vertical-align : text-top ;'+ // cal--selectedMonth-vertical-align
  994. 'border-width : 3px ;'+
  995. 'border-style : solid ;'+
  996. 'border-left-color : black ;'+
  997. 'border-top-color : black ;'+
  998. 'border-right-color : #BFBFBF ;'+
  999. 'border-bottom-color : #BFBFBF ;'+
  1000. 'width : 14% ;'+
  1001. 'cursor : hand ;'
  1002. )
  1003. goStyle['DaySelected'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  1004. fnLoadCSSDefault('cal--selectedDay-background-color', 'calSelectedDayBackgroundColor', goStyle['DaySelected'], 'backgroundColor')
  1005. fnLoadCSSDefault('cal--selectedDay-color', 'calSelectedDayColor', goStyle['DaySelected'], 'color')
  1006. fnLoadCSSDefault('cal--selectedDay-font-family', 'calSelectedDayFontFamily', goStyle['DaySelected'], 'fontFamily')
  1007. fnLoadCSSDefault('cal--selectedDay-font-size', 'calSelectedDayFontSize', goStyle['DaySelected'], 'fontSize')
  1008. fnLoadCSSDefault('cal--selectedDay-font-weight', 'calSelectedDayFontWeight', goStyle['DaySelected'], 'fontWeight')
  1009. fnLoadCSSDefault('cal--selectedDay-text-align', 'calSelectedDayTextAlign', goStyle['DaySelected'], 'textAlign')
  1010. fnLoadCSSDefault('cal--selectedDay-vertical-align', 'calSelectedDayVerticalAlign', goStyle['DaySelected'], 'verticalAlign')
  1011. StyleInfo.addRule( '.DayValid_' + uniqueID,
  1012. 'background-color : lightgrey ;'+ // cal--currentMonth-background-color
  1013. 'color : yellow ;'+ // cal--currentMonth-color
  1014. 'font-family : Arial ;'+ // cal--currentMonth-font-family
  1015. 'font-size : 8pt ;'+ // cal--currentMonth-font-size
  1016. 'font-weight : bold ;'+ // cal--currentMonth-font-weight
  1017. 'text-align : right ;'+ // cal--currentMonth-text-align
  1018. 'vertical-align : text-top ;'+ // cal--currentMonth-vertical-align
  1019. 'border-width : 1px ;'+
  1020. 'border-style : solid ;'+
  1021. 'border-left-color : white ;'+
  1022. 'border-top-color : white ;'+
  1023. 'border-right-color : black ;'+
  1024. 'border-bottom-color : black ;'+
  1025. 'width : 14% ;'+
  1026. 'cursor : hand ;'
  1027. )
  1028. goStyle['DayValid'] = StyleInfo.rules[StyleInfo.rules.length - 1].style
  1029. fnLoadCSSDefault('cal--validDay-background-color', 'calvalidDayBackgroundColor', goStyle['DayValid'], 'backgroundColor')
  1030. fnLoadCSSDefault('cal--validDay-color', 'calvalidDayColor', goStyle['DayValid'], 'color')
  1031. fnLoadCSSDefault('cal--validDay-font-family', 'calvalidDayFontFamily', goStyle['DayValid'], 'fontFamily')
  1032. fnLoadCSSDefault('cal--validDay-font-size', 'calvalidDayFontSize', goStyle['DayValid'], 'fontSize')
  1033. fnLoadCSSDefault('cal--validDay-font-weight', 'calvalidDayFontWeight', goStyle['DayValid'], 'fontWeight')
  1034. fnLoadCSSDefault('cal--validDay-text-align', 'calvalidDayTextAlign', goStyle['DayValid'], 'textAlign')
  1035. fnLoadCSSDefault('cal--validDay-vertical-align', 'calvalidDayVerticalAlign', goStyle['DayValid'], 'verticalAlign')
  1036. }
  1037. //------------------------------------------------------------------------
  1038. //
  1039. // Function: fnLoadCSSDefault
  1040. //
  1041. // Synopsis: This helper function checks to see if a CSS property
  1042. // extension was used to specify a custom style for the
  1043. // calendar. If so, the style style object.
  1044. //
  1045. // Arguments: sCSSProp The CSS property extension used by the
  1046. // page author
  1047. // sScriptProp The scriptable property name to add to the
  1048. // style Name of the style rule
  1049. // sStyleRuleProp Name of the CSS property on the style rule
  1050. //
  1051. // Returns: none
  1052. //
  1053. // Notes: none
  1054. //
  1055. //------------------------------------------------------------------------
  1056. function fnLoadCSSDefault(sCSSProp, sScriptProp, oStyleRule, sStyleRuleProp)
  1057. {
  1058. if (element.currentStyle[sCSSProp])
  1059. {
  1060. oStyleRule[sStyleRuleProp] = element.currentStyle[sCSSProp]
  1061. }
  1062. element.style[sScriptProp] = oStyleRule[sStyleRuleProp]
  1063. }
  1064. //------------------------------------------------------------------------
  1065. //
  1066. // Function: fnGetPropertyDefaults
  1067. //
  1068. // Synopsis: When the for the properties.
  1069. // If so, error checking is performed and the state of the
  1070. // calendar is updated.
  1071. //
  1072. // Arguments: none
  1073. //
  1074. // Returns: none
  1075. //
  1076. // Notes: none
  1077. //
  1078. //------------------------------------------------------------------------
  1079. function fnGetPropertyDefaults()
  1080. {
  1081. var x
  1082. var oDate = new Date()
  1083. giDay = oDate.getDate()
  1084. giMonth = oDate.getMonth() + 1
  1085. giYear = oDate.getYear()
  1086. // The JavaScript Date.getYear function returns a 2 digit date representation
  1087. // for dates in the 1900's and a 4 digit date for 2000 and beyond.
  1088. if (giYear < 100) giYear += 1900
  1089. // BUGBUG : Need to fill in day/month/year loading and error checking
  1090. if (element.year)
  1091. {
  1092. if (! isNaN(parseInt(element.year))) giYear = parseInt(element.year)
  1093. if (giYear < giMinYear) giYear = giMinYear
  1094. if (giYear > giMaxYear) giYear = giMaxYear
  1095. }
  1096. fnCheckLeapYear(giYear)
  1097. if (element.month)
  1098. {
  1099. if (! isNaN(parseInt(element.month))) giMonth = parseInt(element.month)
  1100. if (giMonth < 1) giMonth = 1
  1101. if (giMonth > 12) giMonth = 12
  1102. }
  1103. if (element.day)
  1104. {
  1105. if (! isNaN(parseInt(element.day))) giDay = parseInt(element.day)
  1106. if (giDay < 1) giDay = 1
  1107. if (giDay > gaMonthDays[giMonth - 1]) giDay = gaMonthDays[giMonth - 1]
  1108. }
  1109. if (element.monthLength)
  1110. {
  1111. switch (element.monthLength.toLowerCase())
  1112. {
  1113. case 'short' :
  1114. giMonthLength = 0
  1115. break
  1116. case 'long' :
  1117. giMonthLength = 1
  1118. break
  1119. }
  1120. }
  1121. if (element.dayLength)
  1122. {
  1123. switch (element.dayLength.toLowerCase())
  1124. {
  1125. case 'short' :
  1126. giDayLength = 0
  1127. break
  1128. case 'medium' :
  1129. giDayLength = 1
  1130. break
  1131. case 'long' :
  1132. giDayLength = 1
  1133. break
  1134. }
  1135. }
  1136. if (element.firstDay)
  1137. {
  1138. if ((element.firstDay >= 0) && (element.firstDay <= 6))
  1139. giFirstDay = element.firstDay
  1140. }
  1141. if (element.gridCellEffect)
  1142. {
  1143. switch (element.gridCellEffect.toLowerCase())
  1144. {
  1145. case 'raised' :
  1146. giGridCellEffect = 'raised'
  1147. break
  1148. case 'flat' :
  1149. giGridCellEffect = 'flat'
  1150. break
  1151. case 'sunken' :
  1152. giGridCellEffect = 'sunken'
  1153. break
  1154. }
  1155. }
  1156. if (element.gridLinesColor)
  1157. gsGridLinesColor = element.gridLinesColor
  1158. if (element.showDateSelectors)
  1159. gbShowDateSelectors = (element.showDateSelectors) ? true : false
  1160. if (element.showDays)
  1161. gbShowDays = (element.showDays) ? true : false
  1162. if (element.showTitle)
  1163. gbShowTitle = (element.showTitle) ? true : false
  1164. if (element.showHorizontalGrid)
  1165. gbShowHorizontalGrid = (element.showHorizontalGrid) ? true : false
  1166. if (element.showVerticalGrid)
  1167. gbShowVerticalGrid = (element.showVerticalGrid) ? true : false
  1168. if (element.valueIsNull)
  1169. gbValueIsNull = (element.valueIsNull) ? true : false
  1170. if (element.name)
  1171. gsName = element.name
  1172. if (element.readOnly)
  1173. gbReadOnly = (element.readOnly) ? true : false
  1174. }
  1175. // **********************************************************************
  1176. // CALENDAR CONTROL FUNCTIONS
  1177. // **********************************************************************
  1178. //------------------------------------------------------------------------
  1179. //
  1180. // Function: fnSetDate
  1181. //
  1182. // Synopsis: The fnSetDate function is used internally to set the day,
  1183. // month, and year values.
  1184. //
  1185. // Arguments: iDay The new day
  1186. // iMonth The new month
  1187. // iYear The new year
  1188. //
  1189. // Returns: none
  1190. //
  1191. // Notes: It does some error checking and some minor performance
  1192. // optimizations if the month & year are not being changed.
  1193. //
  1194. //------------------------------------------------------------------------
  1195. function fnSetDate(iDay, iMonth, iYear)
  1196. {
  1197. var bValueChange = false
  1198. var nValidDays = 0
  1199. var aValidDate = new Array()
  1200. if (gbValueIsNull)
  1201. {
  1202. gbValueIsNull = false
  1203. fnFireOnPropertyChange("propertyName", "valueIsNull")
  1204. }
  1205. //
  1206. // Update day names if they have changed
  1207. //
  1208. if ( gbDayNameChanged )
  1209. {
  1210. gbDayNameChanged = false ;
  1211. fnUpdateDayTitles();
  1212. };
  1213. //
  1214. // Update month names if they have changed
  1215. //
  1216. if ( gbMonthNameChanged )
  1217. {
  1218. gbMonthNameChanged = false ;
  1219. fnUpdateTitle();
  1220. };
  1221. if (iYear < giMinYear) iYear = giMinYear
  1222. if (iYear > giMaxYear) iYear = giMaxYear
  1223. if (giYear != iYear)
  1224. {
  1225. fnCheckLeapYear(iYear)
  1226. }
  1227. if (iMonth < 1) iMonth = 1
  1228. if (iMonth > 12) iMonth = 12
  1229. //
  1230. // Use current month iMonth
  1231. //
  1232. if (iDay < 1) iDay = 1
  1233. if (iDay > gaMonthDays[iMonth - 1]) iDay = gaMonthDays[iMonth - 1]
  1234. if ((giDay == iDay) && (giMonth == iMonth) && (giYear == iYear))
  1235. {
  1236. if ( gbValidDateChanged )
  1237. fnFillInCells();
  1238. gbValidDateChanged = false ;
  1239. return
  1240. }
  1241. else
  1242. bValueChange = true
  1243. if (giDay != iDay)
  1244. {
  1245. giDay = iDay
  1246. fnFireOnPropertyChange("propertyName", "day")
  1247. }
  1248. //
  1249. // Make a list of the valid days in the current month for use in searching
  1250. // and set the flag that valid days exist in the current month
  1251. //
  1252. if ( fnValidDaysExistInCurMonth(iYear,iMonth) )
  1253. {
  1254. nValidDays = 0 ;
  1255. for ( i = 0 ; i < giValidDateCount ; i++ )
  1256. {
  1257. if ( gaValidDate[i].year != iYear )
  1258. continue ;
  1259. if ( gaValidDate[i].month != iMonth )
  1260. continue ;
  1261. aValidDate[nValidDays] = new Object();
  1262. aValidDate[nValidDays].year = gaValidDate[i].year;
  1263. aValidDate[nValidDays].month = gaValidDate[i].month;
  1264. aValidDate[nValidDays].day = gaValidDate[i].day;
  1265. nValidDays++;
  1266. }
  1267. if ( nValidDays > 0 )
  1268. bCheckValid = true ;
  1269. }
  1270. if ((giYear == iYear) && (giMonth == iMonth))
  1271. {
  1272. if ( fnValidDaysExistInCurDay(giDay,aValidDate,nValidDays))
  1273. {
  1274. goCurrentDayCell.className = 'DayValid_' + uniqueID
  1275. }
  1276. else
  1277. {
  1278. goCurrentDayCell.className = 'Day_' + uniqueID
  1279. }
  1280. goCurrentDayCell = gaDayCell[giStartDayIndex + iDay - 1]
  1281. goCurrentDayCell.className = 'DaySelected_' + uniqueID
  1282. if ( gbValidDateChanged )
  1283. fnFillInCells();
  1284. }
  1285. else
  1286. {
  1287. if (giYear != iYear)
  1288. {
  1289. giYear = iYear
  1290. fnFireOnPropertyChange("propertyName", "year")
  1291. fnUpdateYearSelect()
  1292. }
  1293. if (giMonth != iMonth)
  1294. {
  1295. giMonth = iMonth
  1296. fnFireOnPropertyChange("propertyName", "month")
  1297. fnUpdateMonthSelect()
  1298. }
  1299. fnFillInCells()
  1300. }
  1301. gbValidDateChanged = false ;
  1302. fnUpdateTitle()
  1303. if (bValueChange) fnFireOnPropertyChange("propertyName", "value")
  1304. }
  1305. //------------------------------------------------------------------------
  1306. //
  1307. // Function: fnUpdateTitle
  1308. //
  1309. // Synopsis: This function updates the title with the currently selected
  1310. // month and year. The month is displayed in the format
  1311. // specified by the monthLength option
  1312. //
  1313. // Arguments: none
  1314. //
  1315. // Returns: none
  1316. //
  1317. // Notes: none
  1318. //
  1319. //------------------------------------------------------------------------
  1320. function fnUpdateTitle()
  1321. {
  1322. var oTitleCell = element.children[0].rows[0].cells[1]
  1323. if (gbShowTitle)
  1324. {
  1325. // Ignoring giMonthLength -- title is always the string returned from GetDateFormat
  1326. oTitleCell.innerText = ObjSystemRestore.GetYearMonthStr( giYear, giMonth );
  1327. }
  1328. else
  1329. oTitleCell.innerText = ' '
  1330. }
  1331. //------------------------------------------------------------------------
  1332. //
  1333. // Function: fnUpdateDayTitles
  1334. //
  1335. // Synopsis: This function updates the titles for the days of the week.
  1336. // They are displayed in the format specified by the dayLength
  1337. // option beginning with the day of the week specified by the
  1338. // firstDay option.
  1339. //
  1340. // Arguments: none
  1341. //
  1342. // Returns: none
  1343. //
  1344. // Notes: none
  1345. //
  1346. //------------------------------------------------------------------------
  1347. function fnUpdateDayTitles()
  1348. {
  1349. var dayTitleRow = element.children[0].rows[1].cells[0].children[0].children[0].rows[0]
  1350. var iCell = 0
  1351. for (i=giFirstDay ; i < 7 ; i++)
  1352. {
  1353. goDayTitleRow.cells[iCell++].innerText = gaDayNames[giDayLength][i]
  1354. }
  1355. for (i=0; i < giFirstDay; i++)
  1356. {
  1357. goDayTitleRow.cells[iCell++].innerText = gaDayNames[giDayLength][i]
  1358. }
  1359. }
  1360. //------------------------------------------------------------------------
  1361. //
  1362. // Function: fnUpdateMonthSelect
  1363. //
  1364. // Synopsis: When the month changes, this function is called to select
  1365. // the correct month in the month select control.
  1366. //
  1367. // Arguments: none
  1368. //
  1369. // Returns: none
  1370. //
  1371. // Notes: none
  1372. //
  1373. //------------------------------------------------------------------------
  1374. function fnUpdateMonthSelect()
  1375. {
  1376. goMonthSelect.options[ giMonth - 1 ].selected = true
  1377. }
  1378. //------------------------------------------------------------------------
  1379. //
  1380. // Function: fnBuildMonthSelect
  1381. //
  1382. // Synopsis: When the calendar is created, this function inserts the
  1383. // month values into the select control and selects the
  1384. // current month.
  1385. //
  1386. // Arguments: none
  1387. //
  1388. // Returns: none
  1389. //
  1390. // Notes: none
  1391. //
  1392. //------------------------------------------------------------------------
  1393. function fnBuildMonthSelect()
  1394. {
  1395. var newMonthSelect
  1396. newMonthSelect = element.document.createElement("SELECT")
  1397. goMonthSelect.parentElement.replaceChild(newMonthSelect, goMonthSelect)
  1398. goMonthSelect = newMonthSelect
  1399. for (i=0 ; i < 12; i++)
  1400. {
  1401. e = element.document.createElement("OPTION")
  1402. e.text = gaMonthNames[giMonthLength][i]
  1403. goMonthSelect.options.add(e)
  1404. }
  1405. goMonthSelect.options[ giMonth - 1 ].selected = true
  1406. goMonthSelect.attachEvent("onchange", fnMonthSelectOnChange)
  1407. goMonthSelect.style.display = 'none';
  1408. }
  1409. //------------------------------------------------------------------------
  1410. //
  1411. // Function: fnMonthSelectOnChange
  1412. //
  1413. // Synopsis: When the user changes the month using the month select
  1414. // control, this function handles the onSelectChange event
  1415. // to update the date.
  1416. //
  1417. // Arguments: none
  1418. //
  1419. // Returns: none
  1420. //
  1421. // Notes: none
  1422. //
  1423. //------------------------------------------------------------------------
  1424. function fnMonthSelectOnChange()
  1425. {
  1426. iMonth = goMonthSelect.selectedIndex + 1
  1427. fnSetDate(giDay, iMonth, giYear)
  1428. }
  1429. //------------------------------------------------------------------------
  1430. //
  1431. // Function: fnButtonLeftClick
  1432. //
  1433. // Synopsis: Left click is to decrement month using the ValidDays list
  1434. // to find the next valid month, if none exists just return
  1435. //
  1436. // Arguments: none
  1437. //
  1438. // Returns: none
  1439. //
  1440. // Notes: none
  1441. //
  1442. //------------------------------------------------------------------------
  1443. function fnButtonLeftClick()
  1444. {
  1445. var bFoundMonth = false ;
  1446. var bMonthSearch = true ;
  1447. var oNewDate = new Object();
  1448. var iDay = 1 ;
  1449. var iMonth = giMonth ;
  1450. var iYear = giYear ;
  1451. //
  1452. // Check if there is a valid date in the next month or months after till MaxDate
  1453. //
  1454. while (bMonthSearch) {
  1455. iMonth = iMonth - 1
  1456. if ( iMonth == 0 )
  1457. {
  1458. iMonth = 12 ;
  1459. iYear = iYear - 1 ;
  1460. };
  1461. if ( fnValidDaysExistInCurMonth(iYear,iMonth) )
  1462. {
  1463. bFoundMonth = true ;
  1464. bMonthSearch = false ;
  1465. }
  1466. oNewDate.day = 1 ;
  1467. oNewDate.month = iMonth;
  1468. oNewDate.year = iYear ;
  1469. if ( fnCompareDate(oNewDate,gdMinDate) <= 0 )
  1470. bMonthSearch = false ;
  1471. };
  1472. if ( bFoundMonth ) {
  1473. //
  1474. // Select the last valid day in the selected month
  1475. //
  1476. nValidDays = 0 ;
  1477. for ( i = 0 ; i < giValidDateCount ; i++ )
  1478. {
  1479. if ( gaValidDate[i].year != iYear )
  1480. continue ;
  1481. if ( gaValidDate[i].month != iMonth )
  1482. continue ;
  1483. if ( gaValidDate[i].day > iDay )
  1484. iDay = gaValidDate[i].day ;
  1485. };
  1486. fnSetDate(iDay, iMonth, iYear);
  1487. }
  1488. }
  1489. //------------------------------------------------------------------------
  1490. //
  1491. // Function: fnButtonRightClick
  1492. //
  1493. // Synopsis: Right click is to increment month using the ValidDays list
  1494. // to find the next valid month, if none exists just return
  1495. //
  1496. // Arguments: none
  1497. //
  1498. // Returns: none
  1499. //
  1500. // Notes: none
  1501. //
  1502. //------------------------------------------------------------------------
  1503. function fnButtonRightClick()
  1504. {
  1505. var bFoundMonth = false ;
  1506. var bMonthSearch = true ;
  1507. var oNewDate = new Object();
  1508. var iDay = 40 ;
  1509. var iMonth = giMonth ;
  1510. var iYear = giYear ;
  1511. //
  1512. // Check if there is a valid date in the next month or months after till MaxDate
  1513. //
  1514. while (bMonthSearch) {
  1515. iMonth = iMonth + 1
  1516. if ( iMonth == 13 )
  1517. {
  1518. iMonth = 1 ;
  1519. iYear = iYear + 1 ;
  1520. };
  1521. if ( fnValidDaysExistInCurMonth(iYear,iMonth) )
  1522. {
  1523. bFoundMonth = true ;
  1524. bMonthSearch = false ;
  1525. }
  1526. oNewDate.day = 1 ;
  1527. oNewDate.month = iMonth;
  1528. oNewDate.year = iYear ;
  1529. if ( fnCompareDate(oNewDate,gdMaxDate) >= 0 )
  1530. bMonthSearch = false ;
  1531. };
  1532. if ( bFoundMonth ) {
  1533. //
  1534. // Select the first valid day in the selected month
  1535. //
  1536. nValidDays = 0 ;
  1537. for ( i = 0 ; i < giValidDateCount ; i++ )
  1538. {
  1539. if ( gaValidDate[i].year != iYear )
  1540. continue ;
  1541. if ( gaValidDate[i].month != iMonth )
  1542. continue ;
  1543. if ( gaValidDate[i].day < iDay )
  1544. iDay = gaValidDate[i].day ;
  1545. };
  1546. fnSetDate(iDay, iMonth, iYear);
  1547. }
  1548. }
  1549. //------------------------------------------------------------------------
  1550. //
  1551. // Function: fnUpdateYearSelect
  1552. //
  1553. // Synopsis: When the year changes, this function is called to select
  1554. // the correct year in the year select control.
  1555. //
  1556. // Arguments: none
  1557. //
  1558. // Returns: none
  1559. //
  1560. // Notes: none
  1561. //
  1562. //------------------------------------------------------------------------
  1563. function fnUpdateYearSelect()
  1564. {
  1565. goYearSelect.options[ giYear - giMinYear ].selected = true
  1566. }
  1567. //------------------------------------------------------------------------
  1568. //
  1569. // Function: fnBuildYearSelect
  1570. //
  1571. // Synopsis: When the calendar is created, this function inserts the
  1572. // year values into the select control and selects the
  1573. // current year.
  1574. //
  1575. // Arguments: none
  1576. //
  1577. // Returns: none
  1578. //
  1579. // Notes: none
  1580. //
  1581. //------------------------------------------------------------------------
  1582. function fnBuildYearSelect()
  1583. {
  1584. var newYearSelect
  1585. newYearSelect = element.document.createElement("SELECT")
  1586. goYearSelect.parentElement.replaceChild(newYearSelect, goYearSelect)
  1587. goYearSelect = newYearSelect
  1588. for (i=giMinYear; i <= giMaxYear; i++)
  1589. {
  1590. e = element.document.createElement("OPTION")
  1591. e.text = i
  1592. goYearSelect.options.add(e)
  1593. }
  1594. goYearSelect.options[ giYear - giMinYear ].selected = true
  1595. goYearSelect.attachEvent("onchange", fnYearSelectOnChange)
  1596. goYearSelect.style.display = 'none'
  1597. }
  1598. //------------------------------------------------------------------------
  1599. //
  1600. // Function: fnYearSelectOnChange
  1601. //
  1602. // Synopsis: When the user changes the year using the year select
  1603. // control, this function handles the onSelectChange event
  1604. // to update the date.
  1605. //
  1606. // Arguments: none
  1607. //
  1608. // Returns: none
  1609. //
  1610. // Notes: none
  1611. //
  1612. //------------------------------------------------------------------------
  1613. function fnYearSelectOnChange()
  1614. {
  1615. iYear = goYearSelect.selectedIndex + giMinYear
  1616. fnSetDate(giDay, giMonth, iYear)
  1617. }
  1618. //------------------------------------------------------------------------
  1619. //
  1620. // Function: fnCheckLeapYear
  1621. //
  1622. // Synopsis: When the year changes, this function must be called to
  1623. // ensure that February has the correct count for the number
  1624. // of days.
  1625. //
  1626. // Arguments: year
  1627. //
  1628. // Returns: none
  1629. //
  1630. // Notes: none
  1631. //
  1632. //------------------------------------------------------------------------
  1633. function fnCheckLeapYear(iYear)
  1634. {
  1635. gaMonthDays[1] = (((!(iYear % 4)) && (iYear % 100) ) || !(iYear % 400)) ? 29 : 28
  1636. }
  1637. //------------------------------------------------------------------------
  1638. //
  1639. // Function: fnFillInCells
  1640. //
  1641. // Synopsis: This method works through the table and sets the day and
  1642. // style needed.
  1643. //
  1644. // Arguments: none
  1645. //
  1646. // Returns: none
  1647. //
  1648. // Notes: none
  1649. //
  1650. //------------------------------------------------------------------------
  1651. function fnFillInCells()
  1652. {
  1653. var iDayCell = 0
  1654. var iLastMonthIndex, iNextMonthIndex
  1655. var iLastMonthTotalDays
  1656. var iStartDay
  1657. var bCheckValid = false
  1658. var nValidDays = 0
  1659. var aValidDate = new Array()
  1660. fnCheckLeapYear(giYear)
  1661. iLastMonthDays = gaMonthDays[ ((giMonth - 1 == 0) ? 12 : giMonth - 1) - 1]
  1662. iNextMonthDays = gaMonthDays[ ((giMonth + 1 == 13) ? 1 : giMonth + 1) - 1]
  1663. iLastMonthYear = (giMonth == 1) ? giYear - 1 : giYear
  1664. iLastMonth = (giMonth == 1) ? 12 : giMonth - 1
  1665. iNextMonthYear = (giMonth == 12) ? giYear + 1 : giYear
  1666. iNextMonth = (giMonth == 12) ? 1 : giMonth + 1
  1667. var oDate = new Date(giYear, (giMonth - 1), 1)
  1668. iStartDay = oDate.getDay() - giFirstDay
  1669. if (iStartDay < 1) iStartDay += 7
  1670. iStartDay = iLastMonthDays - iStartDay + 1
  1671. //
  1672. // Days before beginning of the month
  1673. //
  1674. for (i = iStartDay ; i <= iLastMonthDays ; i++ , iDayCell++)
  1675. {
  1676. gaDayCell[iDayCell].innerText = i ;
  1677. if (gaDayCell[iDayCell].className != 'OffDay_' + uniqueID)
  1678. gaDayCell[iDayCell].className = 'OffDay_' + uniqueID
  1679. gaDayCell[iDayCell].day = i
  1680. gaDayCell[iDayCell].month = iLastMonth
  1681. gaDayCell[iDayCell].year = iLastMonthYear
  1682. }
  1683. giStartDayIndex = iDayCell
  1684. //
  1685. // Make a list of the valid days in the current month for use in searching
  1686. // and set the flag that valid days exist in the current month
  1687. //
  1688. if ( fnValidDaysExistInCurMonth(giYear,giMonth) )
  1689. {
  1690. nValidDays = 0 ;
  1691. for ( i = 0 ; i < giValidDateCount ; i++ )
  1692. {
  1693. if ( gaValidDate[i].year != giYear )
  1694. continue ;
  1695. if ( gaValidDate[i].month != giMonth )
  1696. continue ;
  1697. aValidDate[nValidDays] = new Object();
  1698. aValidDate[nValidDays].year = gaValidDate[i].year;
  1699. aValidDate[nValidDays].month = gaValidDate[i].month;
  1700. aValidDate[nValidDays].day = gaValidDate[i].day;
  1701. nValidDays++;
  1702. }
  1703. if ( nValidDays > 0 )
  1704. bCheckValid = true ;
  1705. }
  1706. //
  1707. // Current month days
  1708. //
  1709. for (i = 1 ; i <= gaMonthDays[giMonth - 1] ; i++, iDayCell++)
  1710. {
  1711. gaDayCell[iDayCell].innerText = i ;
  1712. if (giDay == i)
  1713. {
  1714. goCurrentDayCell = gaDayCell[iDayCell]
  1715. gaDayCell[iDayCell].className = 'DaySelected_' + uniqueID
  1716. gaDayCell[iDayCell].innerHTML = '<DIV TABINDEX=-1>' + i + '</DIV>';
  1717. }
  1718. else if ( fnValidDaysExistInCurDay(i,aValidDate,nValidDays))
  1719. {
  1720. gaDayCell[iDayCell].className = 'DayValid_' + uniqueID
  1721. gaDayCell[iDayCell].innerHTML = '<DIV TABINDEX=-1>' + i + '</DIV>';
  1722. }
  1723. else
  1724. {
  1725. if (gaDayCell[iDayCell].className != 'Day_' + uniqueID)
  1726. gaDayCell[iDayCell].className = 'Day_' + uniqueID
  1727. }
  1728. gaDayCell[iDayCell].day = i
  1729. gaDayCell[iDayCell].month = giMonth
  1730. gaDayCell[iDayCell].year = giYear
  1731. }
  1732. //
  1733. // Days after end of the month
  1734. //
  1735. for (i = 1 ; iDayCell < 42 ; i++, iDayCell++)
  1736. {
  1737. gaDayCell[iDayCell].innerText = i
  1738. if (gaDayCell[iDayCell].className != 'OffDay_' + uniqueID)
  1739. gaDayCell[iDayCell].className = 'OffDay_' + uniqueID
  1740. gaDayCell[iDayCell].day = i
  1741. gaDayCell[iDayCell].month = iNextMonth
  1742. gaDayCell[iDayCell].year = iNextMonthYear
  1743. }
  1744. }
  1745. function fnValidDaysExistInCurYear(nCurYear)
  1746. {
  1747. var bExists = false ;
  1748. if ( nCurYear < gdMinDate.year ) return false ;
  1749. if ( nCurYear > gdMaxDate.year ) return false ;
  1750. for ( i = 0 ; i < giValidDateCount ; i++ )
  1751. {
  1752. if ( gaValidDate[i].year == nCurYear )
  1753. {
  1754. bExists = true ;
  1755. break ;
  1756. }
  1757. }
  1758. return bExists ;
  1759. }
  1760. function fnValidDaysExistInCurMonth(nCurYear,nCurMonth)
  1761. {
  1762. var bExists = false ;
  1763. for ( i = 0 ; i < giValidDateCount ; i++ )
  1764. {
  1765. if ( gaValidDate[i].year != nCurYear )
  1766. continue ;
  1767. if ( gaValidDate[i].month == nCurMonth )
  1768. {
  1769. bExists = true ;
  1770. break ;
  1771. }
  1772. }
  1773. return bExists ;
  1774. }
  1775. function fnValidDaysExistInCurDay(nCurDay,aList,nCount)
  1776. {
  1777. var i ;
  1778. var bExists = false ;
  1779. if ( nCount < 1 ) return bExists ;
  1780. for ( i = 0 ; i < nCount ; i++ )
  1781. {
  1782. if ( aList[i].day == nCurDay )
  1783. {
  1784. bExists = true ;
  1785. break ;
  1786. }
  1787. }
  1788. return bExists ;
  1789. }
  1790. function fnAlertDate(d1)
  1791. {
  1792. alert('Date = ' + d1.year + '-' + d1.month + '-' + d1.day);
  1793. }
  1794. //------------------------------------------------------------------------
  1795. //
  1796. // Function: fnCompareDate
  1797. //
  1798. // Synopsis: Compares two dates
  1799. //
  1800. // Arguments: none
  1801. //
  1802. // Returns: -1,0,1
  1803. //
  1804. // Notes: none
  1805. //
  1806. //------------------------------------------------------------------------
  1807. function fnCompareDate(d1,d2)
  1808. {
  1809. //
  1810. // d1 < d2 then -1
  1811. // d1 = d2 then 0
  1812. // d1 > d2 then 1
  1813. //
  1814. var a1 = fnConvertDateToNumber(d1);
  1815. var a2 = fnConvertDateToNumber(d2);
  1816. if ( a1 < a2 ) return -1
  1817. if ( a1 == a2 ) return 0
  1818. return 1
  1819. }
  1820. //------------------------------------------------------------------------
  1821. //
  1822. // Function: fnConvertDateToNumber
  1823. //
  1824. // Synopsis: Converts date to number
  1825. //
  1826. // Arguments: none
  1827. //
  1828. // Returns: number
  1829. //
  1830. // Notes: none
  1831. //
  1832. //------------------------------------------------------------------------
  1833. function fnConvertDateToNumber(d1)
  1834. {
  1835. var value = d1.year * 500 + d1.month * 40 + d1.day
  1836. return (value) ;
  1837. }
  1838. //------------------------------------------------------------------------
  1839. //
  1840. // Function: fnSetLocaleDayMonthNames
  1841. //
  1842. // Synopsis: Sets month day names based on locale
  1843. //
  1844. // Arguments: none
  1845. //
  1846. // Returns:
  1847. //
  1848. // Notes: none
  1849. //
  1850. //------------------------------------------------------------------------
  1851. function fnSetLocaleDayMonthNames()
  1852. {
  1853. //
  1854. // Start with Sunday Jan 2nd, 2000 for getting day names for the current user locale
  1855. // and set them in the calendar
  1856. //
  1857. var i = 0 ;
  1858. var nLowResScreenHeight = 540 ;
  1859. //
  1860. // Get day names
  1861. //
  1862. if ( screen.height <= nLowResScreenHeight )
  1863. {
  1864. fnPutDayName(0,L_ShortSunday_Text);
  1865. fnPutDayName(1,L_ShortMonday_Text);
  1866. fnPutDayName(2,L_ShortTuesday_Text);
  1867. fnPutDayName(3,L_ShortWednesday_Text);
  1868. fnPutDayName(4,L_ShortThursday_Text);
  1869. fnPutDayName(5,L_ShortFriday_Text);
  1870. fnPutDayName(6,L_ShortSaturday_Text);
  1871. }
  1872. else
  1873. {
  1874. for ( i = 0 ; i < 7 ; i++ )
  1875. {
  1876. var oStartDate = new Date(2000,0,2+i)
  1877. var str = ObjSystemRestore.GetLocaleDateFormat(oStartDate.getVarDate(),"ddd");
  1878. fnPutDayName(i,str);
  1879. };
  1880. };
  1881. //
  1882. // Start with Sunday Jan 1st, 2000 for getting month names for the current user locale
  1883. // and set them in the calendar
  1884. //
  1885. for ( i = 0 ; i < 12 ; i++ )
  1886. {
  1887. var oStartDate = new Date(2000,i,1)
  1888. var str = ObjSystemRestore.GetLocaleDateFormat(oStartDate.getVarDate(),"MMMM");
  1889. fnPutMonthName(i,str);
  1890. };
  1891. //
  1892. // Set first day of the week
  1893. //
  1894. giFirstDay = ObjSystemRestore.FirstDayOfWeek ;
  1895. }
  1896. // **********************************************************************
  1897. // EVENT HANDLERS
  1898. // **********************************************************************
  1899. //------------------------------------------------------------------------
  1900. //
  1901. // Function: fnOnClick
  1902. //
  1903. // Synopsis: When the user clicks on the calendar, change the date if
  1904. // needed
  1905. //
  1906. // Arguments: none
  1907. //
  1908. // Returns: none
  1909. //
  1910. // Notes: none
  1911. //
  1912. //------------------------------------------------------------------------
  1913. function fnOnClick()
  1914. {
  1915. var e = window.event.srcElement
  1916. if (e.tagName == "DIV" && e.parentElement.tagName == "TD" )
  1917. {
  1918. e = e.parentElement ;
  1919. }
  1920. if (e.tagName == "TD")
  1921. {
  1922. if (gbReadOnly || (!e.day)) return // The calendar is read only
  1923. if ((e.year < giMinYear) || (e.year > giMaxYear)) return
  1924. //
  1925. // Do not allow selection of OffDay's
  1926. //
  1927. if (e.className == 'OffDay_' + uniqueID) return
  1928. //
  1929. // Do not allow selection of Days
  1930. //
  1931. if (e.className == 'Day_' + uniqueID) return
  1932. //
  1933. // Set selected date
  1934. //
  1935. fnSetDate(e.day, e.month, e.year)
  1936. }
  1937. }
  1938. //------------------------------------------------------------------------
  1939. //
  1940. // Function: fnOnKeyDown
  1941. //
  1942. // Synopsis: Trap key press events for navigation
  1943. //
  1944. // Arguments: none
  1945. //
  1946. // Returns: none
  1947. //
  1948. // Notes: none
  1949. //
  1950. //------------------------------------------------------------------------
  1951. function fnOnKeyDown()
  1952. {
  1953. var e = window.event.srcElement;
  1954. var ArrowPressed = false;
  1955. var found = false;
  1956. if (window.event.keyCode >= 37 && window.event.keyCode <= 40)
  1957. {
  1958. for (row=1; row < 7; row++)
  1959. {
  1960. for (cell=0; cell < 7; cell++)
  1961. {
  1962. if (gaDayCell[((row-1)*7) + cell].className == "DaySelected_" + uniqueID)
  1963. {
  1964. found = true;
  1965. break;
  1966. }
  1967. }
  1968. if (found == true)
  1969. break;
  1970. }
  1971. if (found == false)
  1972. {
  1973. window.event.returnValue = false;
  1974. return;
  1975. }
  1976. // navigate up/down/right/left
  1977. found = false;
  1978. while (found == false)
  1979. {
  1980. if (window.event.keyCode == 38)
  1981. row--;
  1982. if (window.event.keyCode == 37)
  1983. if (cell==0) // left wrap
  1984. {
  1985. row--;
  1986. cell=6;
  1987. }
  1988. else cell--;
  1989. if (window.event.keyCode == 40)
  1990. row++;
  1991. if (window.event.keyCode == 39)
  1992. if (cell==6) // right wrap
  1993. {
  1994. row++;
  1995. cell=0;
  1996. }
  1997. else cell++;
  1998. if (row < 1 || row > 6 || cell < 0 || cell > 6)
  1999. break;
  2000. if (gaDayCell[((row-1)*7) + cell].className == "DayValid_" + uniqueID)
  2001. found = true;
  2002. }
  2003. if (found == false)
  2004. {
  2005. window.event.returnValue = false;
  2006. return;
  2007. }
  2008. e = gaDayCell[(row-1)*7+cell];
  2009. ArrowPressed = true;
  2010. window.event.returnValue = true;
  2011. }
  2012. if (ArrowPressed == true)
  2013. {
  2014. if (gbReadOnly || (!e.day)) return // The calendar is read only
  2015. if ((e.year < giMinYear) || (e.year > giMaxYear)) return
  2016. //
  2017. // Do not allow selection of OffDay's
  2018. //
  2019. if (e.className == 'OffDay_' + uniqueID) return
  2020. //
  2021. // Do not allow selection of Days
  2022. //
  2023. if (e.className == 'Day_' + uniqueID) return
  2024. //
  2025. // Set selected date
  2026. //
  2027. fnSetDate(e.day, e.month, e.year)
  2028. e.focus()
  2029. }
  2030. window.event.cancelBubble = true ;
  2031. }
  2032. //------------------------------------------------------------------------
  2033. //
  2034. // Function: fnOnSelectStart
  2035. //
  2036. // Synopsis: This cancels selection when the user clicks and drags the
  2037. // mouse on the calendar. It can still be selected if the
  2038. // the SelectStart begins outside this element.
  2039. //
  2040. // Arguments: none
  2041. //
  2042. // Returns: none
  2043. //
  2044. // Notes: none
  2045. //
  2046. //------------------------------------------------------------------------
  2047. function fnOnSelectStart()
  2048. {
  2049. window.event.returnValue = false
  2050. window.event.cancelBubble = true
  2051. }
  2052. //------------------------------------------------------------------------
  2053. //
  2054. // Function: fnOnReadyStateChange
  2055. //
  2056. // Synopsis: When the behavior is completely loaded, set the global
  2057. // loading flag to false.
  2058. //
  2059. // Arguments: none
  2060. //
  2061. // Returns: none
  2062. //
  2063. // Notes: To improve load time, we do not want the put methods on
  2064. // properties to be called. We also need to keep events from
  2065. // getting fired while the behavior is loading.
  2066. //
  2067. //------------------------------------------------------------------------
  2068. function fnOnReadyStateChange()
  2069. {
  2070. gbLoading = (readyState != "complete")
  2071. }
  2072. //------------------------------------------------------------------------
  2073. //
  2074. // Function: fnOnPropertyChange
  2075. //
  2076. // Synopsis: When a property changes on the element, this function will
  2077. // check it to see if part of the calendar needs to be changed
  2078. // as a result.
  2079. //
  2080. // Arguments: none
  2081. //
  2082. // Returns: none
  2083. //
  2084. // Notes: This is currently only checking extended style
  2085. // properties to alter the calendar style sheet rules.
  2086. //
  2087. //------------------------------------------------------------------------
  2088. function fnOnPropertyChange()
  2089. {
  2090. if (window.event.propertyName.substring(0, 5) == 'style')
  2091. {
  2092. switch (window.event.propertyName)
  2093. {
  2094. case 'style.calTitleBackgroundColor' :
  2095. goStyle['WholeCalendar'].backgroundColor = style.calTitleBackgroundColor
  2096. goStyle['Title'].backgroundColor = style.calTitleBackgroundColor
  2097. break
  2098. case 'style.calTitleColor' :
  2099. goStyle['Title'].color = style.calTitleColor
  2100. break
  2101. case 'style.calTitleFontFamily' :
  2102. goStyle['Title'].fontFamily = style.calTitleFontFamily
  2103. break
  2104. case 'style.calTitleFontSize' :
  2105. goStyle['Title'].fontSize = style.calTitleFontSize
  2106. break
  2107. case 'style.calTitleFontWeight' :
  2108. goStyle['Title'].fontWeight = style.calTitleFontWeight
  2109. break
  2110. case 'style.calTitleTextAlign' :
  2111. goStyle['Title'].textAlign = style.calTitleTextAlign
  2112. break
  2113. case 'style.calDayTitleBackgroundColor' :
  2114. goStyle['DayTitle'].backgroundColor = style.calDayTitleBackgroundColor
  2115. break
  2116. case 'style.calDayTitleColor' :
  2117. goStyle['DayTitle'].color = style.calDayTitleColor
  2118. break
  2119. case 'style.calDayTitleFontFamily' :
  2120. goStyle['DayTitle'].fontFamily = style.calDayTitleFontFamily
  2121. break
  2122. case 'style.calDayTitleFontSize' :
  2123. goStyle['DayTitle'].fontSize = style.calDayTitleFontSize
  2124. break
  2125. case 'style.calDayTitleFontWeight' :
  2126. goStyle['DayTitle'].fontWeight = style.calDayTitleFontWeight
  2127. break
  2128. case 'style.calDayTitleTextAlign' :
  2129. goStyle['DayTitle'].textAlign = style.calDayTitleTextAlign
  2130. break
  2131. case 'style.calOffMonthBackgroundColor' :
  2132. goStyle['OffDay'].backgroundColor = style.calOffMonthBackgroundColor
  2133. break
  2134. case 'style.calOffMonthColor' :
  2135. goStyle['OffDay'].color = style.calOffMonthColor
  2136. break
  2137. case 'style.calOffMonthFontFamily' :
  2138. goStyle['OffDay'].fontFamily = style.calOffMonthFontFamily
  2139. break
  2140. case 'style.calOffMonthFontSize' :
  2141. goStyle['OffDay'].fontSize = style.calOffMonthFontSize
  2142. break
  2143. case 'style.calOffMonthFontWeight' :
  2144. goStyle['OffDay'].fontWeight = style.calOffMonthFontWeight
  2145. break
  2146. case 'style.calOffMonthTextAlign' :
  2147. goStyle['OffDay'].textAlign = style.calOffMonthTextAlign
  2148. break
  2149. case 'style.calOffMonthVerticalAlign' :
  2150. goStyle['OffDay'].verticalAlign = style.calOffMonthVerticalAlign
  2151. break
  2152. case 'style.calCurrentMonthBackgroundColor' :
  2153. goStyle['Day'].backgroundColor = style.calCurrentMonthBackgroundColor
  2154. break
  2155. case 'style.calCurrentMonthColor' :
  2156. goStyle['Day'].color = style.calCurrentMonthColor
  2157. break
  2158. case 'style.calCurrentMonthFontFamily' :
  2159. goStyle['Day'].fontFamily = style.calCurrentMonthFontFamily
  2160. break
  2161. case 'style.calCurrentMonthFontSize' :
  2162. goStyle['Day'].fontSize = style.calCurrentMonthFontSize
  2163. break
  2164. case 'style.calCurrentMonthFontWeight' :
  2165. goStyle['Day'].fontWeight = style.calCurrentMonthFontWeight
  2166. break
  2167. case 'style.calCurrentMonthTextAlign' :
  2168. goStyle['Day'].textAlign = style.calCurrentMonthTextAlign
  2169. break
  2170. case 'style.calCurrentMonthVerticalAlign' :
  2171. goStyle['Day'].verticalAlign = style.calCurrentMonthVerticalAlign
  2172. break
  2173. case 'style.calSelectedDayBackgroundColor' :
  2174. goStyle['DaySelected'].backgroundColor = style.calSelectedDayBackgroundColor
  2175. break
  2176. case 'style.calSelectedDayColor' :
  2177. goStyle['DaySelected'].color = style.calSelectedDayColor
  2178. break
  2179. case 'style.calSelectedDayFontFamily' :
  2180. goStyle['DaySelected'].fontFamily = style.calSelectedDayFontFamily
  2181. break
  2182. case 'style.calSelectedDayFontSize' :
  2183. goStyle['DaySelected'].fontSize = style.calSelectedDayFontSize
  2184. break
  2185. case 'style.calSelectedDayFontWeight' :
  2186. goStyle['DaySelected'].fontWeight = style.calSelectedDayFontWeight
  2187. break
  2188. case 'style.calSelectedDayTextAlign' :
  2189. goStyle['DaySelected'].textAlign = style.calSelectedDayTextAlign
  2190. break
  2191. case 'style.calSelectedDayVerticalAlign' :
  2192. goStyle['DaySelected'].verticalAlign = style.calSelectedDayVerticalAlign
  2193. break
  2194. }
  2195. }
  2196. }
  2197. // **********************************************************************
  2198. // HELPER FUNCTIONS
  2199. // **********************************************************************
  2200. //------------------------------------------------------------------------
  2201. //
  2202. // Function: fnFireOnPropertyChange
  2203. //
  2204. // Synopsis:
  2205. //
  2206. // Arguments:
  2207. //
  2208. // Returns:
  2209. //
  2210. // Notes:
  2211. //
  2212. //------------------------------------------------------------------------
  2213. function fnFireOnPropertyChange(name1, value1)
  2214. {
  2215. var evObj = createEventObject()
  2216. evObj.setAttribute(name1, value1)
  2217. onPropertyChange.fire(evObj)
  2218. }
  2219. //------------------------------------------------------------------------
  2220. //
  2221. // Function: fnUpdateGridColors
  2222. //
  2223. // Synopsis: This is a helper function for the calendar grid rendering
  2224. // properties. It handles setting the style rules to create
  2225. // the desired effects.
  2226. //
  2227. // Arguments: none
  2228. //
  2229. // Returns: none
  2230. //
  2231. // Notes: none
  2232. //
  2233. //------------------------------------------------------------------------
  2234. function fnUpdateGridColors()
  2235. {
  2236. switch (gsGridCellEffect)
  2237. {
  2238. case "raised" :
  2239. goStyle['OffDay'].borderLeftColor = 'white'
  2240. goStyle['OffDay'].borderTopColor = 'white'
  2241. goStyle['OffDay'].borderRightColor = 'black'
  2242. goStyle['OffDay'].borderBottomColor = 'black'
  2243. goStyle['Day'].borderLeftColor = 'white'
  2244. goStyle['Day'].borderTopColor = 'white'
  2245. goStyle['Day'].borderRightColor = 'black'
  2246. goStyle['Day'].borderBottomColor = 'black'
  2247. goStyle['DaySelected'].borderLeftColor = 'white'
  2248. goStyle['DaySelected'].borderTopColor = 'white'
  2249. goStyle['DaySelected'].borderRightColor = 'black'
  2250. goStyle['DaySelected'].borderBottomColor = 'black'
  2251. break
  2252. case "flat" :
  2253. goStyle['OffDay'].borderLeftColor = goStyle['OffDay'].backgroundColor
  2254. goStyle['OffDay'].borderTopColor = goStyle['OffDay'].backgroundColor
  2255. goStyle['OffDay'].borderRightColor = (gbShowVerticalGrid) ? gsGridLinesColor : goStyle['Day'].backgroundColor
  2256. goStyle['OffDay'].borderBottomColor = (gbShowHorizontalGrid) ? gsGridLinesColor : goStyle['Day'].backgroundColor
  2257. goStyle['Day'].borderLeftColor = goStyle['Day'].backgroundColor
  2258. goStyle['Day'].borderTopColor = goStyle['Day'].backgroundColor
  2259. goStyle['Day'].borderRightColor = (gbShowVerticalGrid) ? gsGridLinesColor : goStyle['Day'].backgroundColor
  2260. goStyle['Day'].borderBottomColor = (gbShowHorizontalGrid) ? gsGridLinesColor : goStyle['Day'].backgroundColor
  2261. goStyle['DaySelected'].borderLeftColor = goStyle['DaySelected'].backgroundColor
  2262. goStyle['DaySelected'].borderTopColor = goStyle['DaySelected'].backgroundColor
  2263. goStyle['DaySelected'].borderRightColor = (gbShowVerticalGrid) ? gsGridLinesColor : goStyle['Day'].backgroundColor
  2264. goStyle['DaySelected'].borderBottomColor = (gbShowHorizontalGrid) ? gsGridLinesColor : goStyle['Day'].backgroundColor
  2265. break
  2266. case "sunken" :
  2267. goStyle['OffDay'].borderLeftColor = 'black'
  2268. goStyle['OffDay'].borderTopColor = 'black'
  2269. goStyle['OffDay'].borderRightColor = 'white'
  2270. goStyle['OffDay'].borderBottomColor = 'white'
  2271. goStyle['Day'].borderLeftColor = 'black'
  2272. goStyle['Day'].borderTopColor = 'black'
  2273. goStyle['Day'].borderRightColor = 'white'
  2274. goStyle['Day'].borderBottomColor = 'white'
  2275. goStyle['DaySelected'].borderLeftColor = 'black'
  2276. goStyle['DaySelected'].borderTopColor = 'black'
  2277. goStyle['DaySelected'].borderRightColor = 'white'
  2278. goStyle['DaySelected'].borderBottomColor = 'white'
  2279. break
  2280. default :
  2281. throw 450
  2282. }
  2283. }
  2284. </script>
  2285. <public:property put=fnPutDayName get=fnGetDayName name="dayName">
  2286. <public:property put=fnPutMonthName get=fnGetMonthName name="monthName">
  2287. <public:property put=fnPutDay get=fnGetDay name="day">
  2288. <public:property put=fnPutMonth get=fnGetMonth name="month">
  2289. <public:property put=fnPutYear get=fnGetYear name="year">
  2290. <public:property put=fnPutMonthLength get=fnGetMonthLength name="monthLength">
  2291. <public:property put=fnPutDayLength get=fnGetDayLength name="dayLength">
  2292. <public:property put=fnPutFirstDay get=fnGetFirstDay name="firstDay">
  2293. <public:property put=fnPutGridCellEffect get=fnGetGridCellEffect name="gridCellEffect">
  2294. <public:property put=fnPutGridLinesColor get=fnGetGridLinesColor name="gridLinesColor">
  2295. <public:property put=fnPutShowDateSelectors get=fnGetShowDateSelectors name="showDateSelectors">
  2296. <public:property put=fnPutShowDays get=fnGetShowDays name="showDays">
  2297. <public:property put=fnPutShowTitle get=fnGetShowTitle name="showTitle">
  2298. <public:property put=fnPutShowVerticalGrid get=fnGetShowVerticalGrid name="showVerticalGrid">
  2299. <public:property put=fnPutShowHorizontalGrid get=fnGetShowHorizontalGrid name="showHorizontalGrid">
  2300. <public:property put=fnPutValue get=fnGetValue name="value">
  2301. <public:property put=fnPutValueIsNull get=fnGetValueIsNull name="valueIsNull">
  2302. <public:property put=fnPutReadOnly get=fnGetReadOnly name="readOnly">
  2303. <public:property put=fnSetMinDate name="minDate">
  2304. <public:property put=fnSetMaxDate name="maxDate">
  2305. <public:property put=fnAddValidDate name="addValidDate">
  2306. <public:event id="onChange" name="onchange">
  2307. <public:event id="onPropertyChange" name="onpropertychange">
  2308. <public:event id="onError" name="onerror">