CTimePickerIE5.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2016
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /*
  13. CTimePickerIE5.js
  14. This script is used to provide interactivity for the selectTime prompt control
  15. */
  16. //Constructor to create a selectTime component
  17. // oSubmit: the field used to submit values to the server
  18. // oForm: the field used to store processed user input
  19. // oHours: hours form control
  20. // oMinutes: minutes form control
  21. // oSeconds: seconds form control
  22. // oMilliseconds: milliseconds form control
  23. // oAMPM: AM/PM form control
  24. // oImgTest: the image used for error checking
  25. // sRef: the name of this object
  26. // iType: 0 = 12 hour clock, right AM/PM,
  27. // 1 = 12 hour clock, left AM/PM
  28. // 2 = 24 hour clock, no AM/PM
  29. // iDisplay: determine the display
  30. // 0 = h:m:s:ms
  31. // 1 = h:m:s
  32. // 2 = h:m
  33. // bInline:
  34. // false = edit box
  35. // true = inline control, add clock
  36. // sTimeZone: string representing the timezones
  37. // sHourFormat: (hh = 01, h = 1)
  38. // sMinuteFormat: (mm = 01, m = 1)
  39. // sSecondFormat: (ss = 01, s = 1)
  40. // iMode: (0 = static, 1 = live clock)
  41. // sClock: the name of the inline clock
  42. // sTime: default time (e.g. "h:min:s.ms")
  43. // bRequired: boolean, specify if user input is required
  44. // sSubmitType: 'default' will submit as a standard form
  45. // 'XML' will convert the submission to XML and submit
  46. function CTimePicker(oSubmit, oForm, oHours, oMinutes, oSeconds, oMilliseconds, oAMPM, oImgTest, oClockBox, oEditBox, sRef, iType, iDisplay, bInline, sTimeZone, sHourFormat, sMinuteFormat, sSecondFormat, iMode, sClock, sTime, bRequired, sSubmitType, sCVId, sbaseId,
  47. oTimeControl)
  48. {
  49. this.setCVId(sCVId);
  50. //the name of the variable that is to be submitted
  51. this.m_oSubmit = oSubmit;
  52. this.m_oForm = oForm;
  53. this.id = sbaseId;
  54. //references to objects in the control
  55. this.m_oHours = oHours;
  56. this.m_oMinutes = oMinutes;
  57. this.m_oSeconds = oSeconds;
  58. this.m_oMilliseconds = oMilliseconds;
  59. this.m_oAMPM = oAMPM;
  60. //containers used to disable the control
  61. this.m_oClockBox = oClockBox;
  62. this.m_oEditBox = oEditBox;
  63. this.m_sRef = sRef;
  64. //specify whether the user must enter a date or not
  65. this.m_bRequired = bRequired;
  66. this.m_bDisabled = false;
  67. //indicate whether the control has valid data
  68. this.m_bValid = false;
  69. //submit as XML or as a standard html form
  70. this.m_sSubmitType = sSubmitType;
  71. //the type of clock
  72. //0 = 12 hour clock, right AM/PM
  73. //1 = 12 hour clock, left AM/PM
  74. //2 = 24 hour clock, no AM/PM
  75. if (iType == null)
  76. {
  77. if (g_24HourClock.toString().toLowerCase() == "true")
  78. {
  79. iType = 2;
  80. }
  81. else
  82. {
  83. if (g_AMPMLocation == 'left')
  84. {
  85. iType = 1;
  86. }
  87. else
  88. {
  89. iType = 0;
  90. }
  91. }
  92. }
  93. this.m_iType = iType;
  94. //what is being displayed
  95. //0 = h:m:s:ms
  96. //1 = h:m:s
  97. //2 = h:m
  98. this.m_iDisplay = iDisplay;
  99. // boolean flags for user input
  100. this.m_bCheckedHour = false;
  101. this.m_bCheckedMin = false;
  102. this.m_bCheckedSec = false;
  103. this.m_bCheckedMillis = false;
  104. //set the default time
  105. this.setValue(sTime);
  106. //get the names of the controls to be
  107. //used to determine the selected control
  108. //this is done once in the constructor, so that the
  109. //value does not need to be determined each time
  110. this.m_sHoursName = this.m_oHours.name;
  111. this.m_sMinutesName = this.m_oMinutes.name;
  112. if (this.m_iDisplay <= 1)
  113. {
  114. this.m_sSecondsName = this.m_oSeconds.name;
  115. }
  116. else
  117. {
  118. this.m_sSecondsName = "null";
  119. }
  120. if (this.m_iDisplay == 0)
  121. {
  122. this.m_sMillisecondsName = this.m_oMilliseconds.name;
  123. }
  124. else
  125. {
  126. this.m_sMillisecondsName = "null";
  127. }
  128. if ((this.m_iType == 0) || (this.m_iType == 1))
  129. {
  130. this.m_sAMPMName = this.m_oAMPM.name;
  131. }
  132. else
  133. {
  134. this.m_sAMPMName = "null";
  135. }
  136. //is this control being used with an inline calendar
  137. //or as an edit box
  138. //false = edit box
  139. //true = inline control (clock with edit box)
  140. this.m_bInline = bInline;
  141. if (this.m_bInline==true)
  142. {
  143. this.m_oClock = eval (sClock);
  144. }
  145. else
  146. {
  147. this.m_oClock = null;
  148. }
  149. //string representing the timezones
  150. this.m_sTimeZone = sTimeZone;
  151. //Hour Format
  152. //hh = 01
  153. //h = 1
  154. this.m_sHourFormat = g_hourFormatMedium;
  155. //Minute Format
  156. //mm = 01
  157. //m = 1
  158. this.m_sMinuteFormat = g_minuteFormatMedium;
  159. //Second Format
  160. //ss = 01
  161. //s = 1
  162. this.m_sSecondFormat = g_secondFormatMedium;
  163. //set the default control
  164. this.m_oCurrentFocus = this.m_oHours;
  165. //skin folder
  166. this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  167. //images for handling errors
  168. this.m_oImgCheckDate = oImgTest;
  169. if (this.m_oImgCheckDate != null)
  170. {
  171. this.m_oImgErrorFalse = new Image();
  172. this.m_oImgErrorFalse.src = this.m_sSkin + "/prompting/images/error_timed_small_off.gif";
  173. this.m_oImgErrorTrue = new Image();
  174. this.m_oImgErrorTrue.src = this.m_sSkin + "/prompting/images/error_timed_small.gif";
  175. }
  176. //Mode
  177. //0 = static
  178. //1 = live
  179. this.m_iMode = iMode;
  180. if (this.m_iMode==1)
  181. {
  182. this.funcInt = setInterval( this.drawLiveTime.bind(this), 1000 );
  183. }
  184. //draw the current time
  185. this.refreshTime();
  186. //initialize the form control
  187. this.updateSubmitField();
  188. this.m_oTimeControl = oTimeControl;
  189. }
  190. CTimePicker.prototype = new CPromptControl();
  191. //process the input and convert into the proper format
  192. function CTimePicker_updateSubmitField()
  193. {
  194. //return a valid time data type
  195. //00:00:00.000
  196. //hours
  197. var sHours = this.m_dTime.getHours().toString();
  198. if (sHours.length == 1)
  199. {
  200. sHours = '0' + sHours;
  201. }
  202. var sMinutes = this.m_dTime.getMinutes().toString();
  203. if (sMinutes.length == 1)
  204. {
  205. sMinutes = '0' + sMinutes;
  206. }
  207. var sSeconds = this.m_dTime.getSeconds().toString();
  208. if (sSeconds.length == 1)
  209. {
  210. sSeconds = '0' + sSeconds;
  211. }
  212. var sMilliseconds = this.m_dTime.getMilliseconds().toString();
  213. if (sMilliseconds.length == 2)
  214. {
  215. sMilliseconds = '0' + sMilliseconds;
  216. }
  217. else if (sMilliseconds.length == 1)
  218. {
  219. sMilliseconds = '00' + sMilliseconds;
  220. }
  221. this.m_oForm.value = sHours + K_PRMT_sCOLON + sMinutes + K_PRMT_sCOLON + sSeconds + K_PRMT_sDOT + sMilliseconds;
  222. }
  223. //render the values for the control based on display settings
  224. function CTimePicker_refreshTime()
  225. {
  226. this.checkData();
  227. if (this.m_bValid)
  228. {
  229. this.updateSubmitField();
  230. }
  231. //determine what needs to be displayed
  232. this.drawHours();
  233. this.drawMinutes();
  234. if (this.m_iDisplay <= 1)
  235. {
  236. this.drawSeconds();
  237. }
  238. if (this.m_iDisplay == 0)
  239. {
  240. this.drawMilliseconds();
  241. }
  242. if ((this.m_iType == 0) || (this.m_iType == 1))
  243. {
  244. this.drawAMPM();
  245. }
  246. }
  247. //render hours
  248. function CTimePicker_drawHours()
  249. {
  250. var inputHours = this.m_oHours.value;
  251. var iHours = this.iGetCurrentHours();
  252. var sHours = iHours.toString();
  253. if ((this.m_sHourFormat == 'hh') && (sHours.length == 1)) {
  254. sHours = '0' + sHours;
  255. }
  256. this.m_oHours.value = sHours;
  257. this.m_oHours.id = this.id + "_prmtTime_HOURS";
  258. this.m_oHours.className = "clsSelectTimeControl pcl";
  259. if (this.m_oClock!=null) {
  260. this.m_oClock.clockSetTime(this.m_dTime.getHours(), this.m_dTime.getMinutes(), this.m_dTime.getSeconds());
  261. }
  262. if (this.m_bCheckedHour && inputHours != iHours.toString()) {
  263. this.m_bCheckedHour = false;
  264. // console.log("dif in enter value, input Hours " + inputHours + ", iHours.toString()" + iHours.toString())
  265. var v_sMsg = PMT_UIM_INVALID_HOURS_CHANGED.replace(/\^1/, MIN_HOURS).replace(/\^2/,MAX_HOURS).replace(/\^3/, iHours);
  266. var oEditBox = this.m_oEditBox;
  267. PRMTUtils.f_showARIAMessageAlert(oEditBox, this.m_sRef, this.m_sSkin, v_sMsg);
  268. }
  269. }
  270. //render minutes
  271. function CTimePicker_drawMinutes()
  272. {
  273. var inputMinutes = this.m_oMinutes.value;
  274. var iMinutes = this.iGetCurrentMinutes();
  275. var sMinutes = iMinutes.toString();
  276. if ((this.m_sMinuteFormat == 'mm') && (sMinutes.length == 1)) {
  277. sMinutes = '0' + sMinutes;
  278. }
  279. this.m_oMinutes.value = sMinutes;
  280. this.m_oMinutes.id = this.id + "_prmtTime_MINUTES";
  281. this.m_oMinutes.className = "clsSelectTimeControl pcl";
  282. if (this.m_oClock!=null) {
  283. this.m_oClock.clockSetTime(this.m_dTime.getHours(), this.m_dTime.getMinutes(), this.m_dTime.getSeconds());
  284. }
  285. if (this.m_bCheckedMin && inputMinutes != iMinutes.toString()) {
  286. this.m_bCheckedMin = false;
  287. // console.log("dif in enter value, input Minutes " + inputMinutes + ", iMinutes.toString()" + iMinutes.toString())
  288. var v_sMsg = PMT_UIM_INVALID_MINUTES_CHANGED.replace(/\^1/, MIN_MINUTES).replace(/\^2/,MAX_MINUTES).replace(/\^3/,iMinutes);
  289. var oEditBox = this.m_oEditBox;
  290. PRMTUtils.f_showARIAMessageAlert(oEditBox, this.m_sRef, this.m_sSkin, v_sMsg);
  291. }
  292. }
  293. //render seconds
  294. function CTimePicker_drawSeconds()
  295. {
  296. var inputSeconds = this.m_oSeconds.value;
  297. var iSeconds = this.iGetCurrentSeconds();
  298. var sSeconds = iSeconds.toString();
  299. if (this.m_sSecondFormat == 'ss' && (sSeconds.length == 1)) {
  300. sSeconds = '0' + sSeconds;
  301. }
  302. this.m_oSeconds.value = sSeconds;
  303. this.m_oSeconds.id = this.id + "_prmtTime_SECONDS";
  304. this.m_oSeconds.className = "clsSelectTimeControl pcl";
  305. if (this.m_oClock!=null) {
  306. this.m_oClock.clockSetTime(this.m_dTime.getHours(), this.m_dTime.getMinutes(), this.m_dTime.getSeconds());
  307. }
  308. if (this.m_bCheckedSec && inputSeconds != iSeconds.toString()) {
  309. this.m_bCheckedSec = false;
  310. // console.log("dif in enter value, inputSeconds " + inputSeconds + ", iSeconds.toString()" + iSeconds.toString())
  311. var v_sMsg = PMT_UIM_INVALID_SECONDS_CHANGED.replace(/\^1/, MIN_SECONDS).replace(/\^2/,MAX_SECONDS).replace(/\^3/,iSeconds);
  312. var oEditBox = this.m_oEditBox;
  313. PRMTUtils.f_showARIAMessageAlert(oEditBox, this.m_sRef, this.m_sSkin, v_sMsg);
  314. }
  315. }
  316. //render milliseconds
  317. function CTimePicker_drawMilliseconds()
  318. {
  319. var inputMilliseconds = this.m_oMilliseconds.value;
  320. var iMilliseconds = this.iGetCurrentMilliseconds();
  321. var sMilliseconds = iMilliseconds.toString();
  322. if (sMilliseconds.length == 2) {
  323. sMilliseconds = '0' + sMilliseconds;
  324. }
  325. else if (sMilliseconds.length == 1) {
  326. sMilliseconds = '00' + sMilliseconds;
  327. }
  328. this.m_oMilliseconds.value = sMilliseconds;
  329. this.m_oMilliseconds.id = this.id + "_prmtTime_MILLISECONDS";
  330. this.m_oMilliseconds.className = "clsSelectTimeControl pcl";
  331. if (this.m_bCheckedMillis && inputMilliseconds != iMilliseconds.toString()) {
  332. // console.log("dif in enter value, inputMilliseconds " + inputMilliseconds + ", iMilliseconds.toString()" + iMilliseconds.toString())
  333. this.m_bCheckedMillis = false;
  334. var v_sMsg = PMT_UIM_INVALID_MILLISECONDS_CHANGED.replace(/\^1/, MIN_MILLISECONDS).replace(/\^2/,MAX_MILLISECONDS).replace(/\^3/,iMilliseconds);
  335. var oEditBox = this.m_oEditBox;
  336. PRMTUtils.f_showARIAMessageAlert(oEditBox, this.m_sRef, this.m_sSkin, v_sMsg);
  337. }
  338. }
  339. //render AM/PM
  340. function CTimePicker_drawAMPM()
  341. {
  342. this.m_oAMPM.value = this.sGetCurrentAMPM();
  343. this.m_oAMPM.id = this.id + "_prmtTime_AMPM";
  344. this.m_oAMPM.className = "clsSelectTimeControl pcl";
  345. }
  346. //render live time
  347. function CTimePicker_drawLiveTime()
  348. {
  349. this.m_dTime = new Date();
  350. if (this.m_oClock !=null )
  351. {
  352. //this.m_oClock.drawLiveTime();
  353. }
  354. this.refreshTime();
  355. }
  356. //stop live time
  357. function CTimePicker_stopLiveTime()
  358. {
  359. if (this.m_iMode==1)
  360. {
  361. if (this.m_oClock !=null )
  362. {
  363. this.m_oClock.stopLiveTime();
  364. }
  365. if ( this.m_iDisplay > 1 )
  366. {
  367. // Can't change the seconds in the UI, so reset to 0.
  368. this.m_dTime.setSeconds(0);
  369. }
  370. if ( this.m_iDisplay > 0 )
  371. {
  372. // Can't change the milliseconds in the UI, so reset to 0.
  373. this.m_dTime.setMilliseconds(0);
  374. }
  375. this.m_iMode=0;
  376. clearInterval(this.funcInt);
  377. }
  378. }
  379. //change hours
  380. function CTimePicker_setCurrentHours(iValue)
  381. {
  382. this.stopLiveTime();
  383. if ((iValue >= MIN_HOURS) && (iValue <= MAX_HOURS))
  384. {
  385. this.m_dTime.setHours(iValue);
  386. }
  387. }
  388. //change minutes
  389. function CTimePicker_setCurrentMinutes(iValue)
  390. {
  391. this.stopLiveTime();
  392. if (iValue >= MIN_MINUTES && iValue <= MAX_MINUTES)
  393. {
  394. this.m_dTime.setMinutes(iValue);
  395. }
  396. }
  397. //change seconds
  398. function CTimePicker_setCurrentSeconds(iValue)
  399. {
  400. this.stopLiveTime();
  401. if (iValue >= MIN_SECONDS && iValue <= MAX_SECONDS)
  402. {
  403. this.m_dTime.setSeconds(iValue);
  404. }
  405. }
  406. //change milliseconds
  407. function CTimePicker_setCurrentMilliseconds(iValue)
  408. {
  409. this.stopLiveTime();
  410. if (iValue >= MIN_MILLISECONDS && iValue <= MAX_MILLISECONDS)
  411. {
  412. this.m_dTime.setMilliseconds(iValue);
  413. }
  414. }
  415. //change AM/PM
  416. function CTimePicker_setCurrentAMPM(sValue)
  417. {
  418. this.stopLiveTime();
  419. var sCurAMPM = this.sGetCurrentAMPM();
  420. //check to see if the current setting is the new setting
  421. if (sValue == sCurAMPM)
  422. {
  423. return;
  424. }
  425. else
  426. {
  427. var iHours = this.m_dTime.getHours();
  428. if (sValue == g_pmString)
  429. {
  430. if (iHours < 12)
  431. {
  432. iHours = iHours + 12;
  433. this.setCurrentHours(iHours);
  434. }
  435. }
  436. else if (sValue == g_amString)
  437. {
  438. if (iHours > 11)
  439. {
  440. iHours = iHours - 12;
  441. this.setCurrentHours(iHours);
  442. }
  443. }
  444. }
  445. }
  446. //return hours
  447. function CTimePicker_iGetCurrentHours()
  448. {
  449. //2 = 24 hour clock, no AM/PM
  450. if (this.m_iType == 2)
  451. {
  452. return this.m_dTime.getHours();
  453. } else
  454. {
  455. var iHours = this.m_dTime.getHours();
  456. if (iHours > 12)
  457. {
  458. iHours = iHours - 12;
  459. }
  460. if (iHours == 0)
  461. {
  462. iHours = 12;
  463. }
  464. return iHours;
  465. }
  466. }
  467. //return minutes
  468. function CTimePicker_iGetCurrentMinutes()
  469. {
  470. return this.m_dTime.getMinutes();
  471. }
  472. //return seconds
  473. function CTimePicker_iGetCurrentSeconds()
  474. {
  475. return this.m_dTime.getSeconds();
  476. }
  477. //return milliseconds
  478. function CTimePicker_iGetCurrentMilliseconds()
  479. {
  480. return this.m_dTime.getMilliseconds();
  481. }
  482. //return AM/PM
  483. function CTimePicker_sGetCurrentAMPM()
  484. {
  485. if (this.m_iType == 2)
  486. {
  487. return K_PRMT_sEMPTY;
  488. }
  489. else
  490. {
  491. if (this.m_dTime.getHours() > 11)
  492. {
  493. return g_pmString;
  494. }
  495. else
  496. {
  497. return g_amString;
  498. }
  499. }
  500. }
  501. function CTimePicker_bisValidHours(hours) {
  502. var iHours = parseInt(this.m_oHours.value,10);
  503. return (bNumbersOnly(hours) && iHours >= MIN_HOURS && iHours <= MAX_HOURS);
  504. }
  505. function CTimePicker_bisValidMinutes(min) {
  506. var iMinutes = parseInt(this.m_oMinutes.value,10);
  507. return ( bNumbersOnly(min) && iMinutes >= MIN_MINUTES && iMinutes <= MAX_MINUTES );
  508. }
  509. function CTimePicker_bisValidSeconds(min) {
  510. var iSeconds = parseInt(this.m_oSeconds.value,10);
  511. return ( bNumbersOnly(min) && iSeconds >= MIN_SECONDS && iSeconds <= MAX_SECONDS );
  512. }
  513. function CTimePicker_bisValidMilliseconds(milliseconds) {
  514. var iMilliseconds = parseInt(this.m_oMilliseconds.value,10);
  515. return ( bNumbersOnly(milliseconds) && iMilliseconds >= MIN_MILLISECONDS && iMilliseconds <= MAX_MILLISECONDS );
  516. }
  517. function CTimePicker_bCheckTime()
  518. {
  519. //check hours
  520. if ( !this.bisValidHours(this.m_oHours.value) ) {
  521. return false;
  522. }
  523. if ( !this.bisValidMinutes(this.m_oMinutes.value) ) {
  524. return false;
  525. }
  526. if (this.m_iDisplay <= 1) {
  527. if ( !this.bisValidSeconds(this.m_oSeconds.value) ) {
  528. return false;
  529. }
  530. }
  531. if (this.m_iDisplay == 0) {
  532. if ( !this.bisValidMilliseconds(this.m_oSeconds.value) ) {
  533. return false;
  534. }
  535. }
  536. return true;
  537. }
  538. //handle focus to the particular field
  539. function CTimePicker_setCurrentFocus(obj)
  540. {
  541. this.m_oCurrentFocus = obj;
  542. this.m_oCurrentFocus.select();
  543. }
  544. //determine which field currently has focus
  545. function CTimePicker_oGetCurrentFocus()
  546. {
  547. return this.m_oCurrentFocus;
  548. }
  549. //increment the time up by one for the field with focus
  550. function CTimePicker_timeUp()
  551. {
  552. var sCurrentFocus = this.m_oCurrentFocus.name;
  553. switch (sCurrentFocus)
  554. {
  555. case this.m_sHoursName:
  556. var iCurHours = this.m_dTime.getHours();
  557. if ( iCurHours == MAX_HOURS)
  558. {
  559. this.setCurrentHours(MIN_HOURS);
  560. }
  561. else
  562. {
  563. this.setCurrentHours(this.m_dTime.getHours() + 1);
  564. }
  565. if (this.m_iType != 2)
  566. {
  567. this.drawAMPM();
  568. }
  569. this.drawHours();
  570. break;
  571. case this.m_sMinutesName:
  572. if (this.iGetCurrentMinutes() == MAX_MINUTES)
  573. {
  574. this.setCurrentMinutes(MIN_MINUTES);
  575. }
  576. else
  577. {
  578. this.setCurrentMinutes(this.iGetCurrentMinutes() + 1);
  579. }
  580. this.drawMinutes();
  581. break;
  582. case this.m_sSecondsName:
  583. if (this.iGetCurrentSeconds() == MAX_SECONDS)
  584. {
  585. this.setCurrentSeconds(MIN_SECONDS);
  586. }
  587. else
  588. {
  589. this.setCurrentSeconds(this.iGetCurrentSeconds() + 1);
  590. }
  591. this.drawSeconds();
  592. break;
  593. case this.m_sMillisecondsName:
  594. if (this.iGetCurrentMilliseconds() == MAX_MILLISECONDS)
  595. {
  596. this.setCurrentMilliseconds(MIN_MILLISECONDS);
  597. }
  598. else
  599. {
  600. this.setCurrentMilliseconds(this.iGetCurrentMilliseconds() + 1);
  601. }
  602. this.drawMilliseconds();
  603. break;
  604. case this.m_sAMPMName:
  605. if (this.sGetCurrentAMPM() == g_amString)
  606. {
  607. this.setCurrentAMPM(g_pmString);
  608. }
  609. else
  610. {
  611. this.setCurrentAMPM(g_amString);
  612. }
  613. this.drawAMPM();
  614. break;
  615. default:
  616. alert ('problem with CTimePicker_timeUp()');
  617. break;
  618. }
  619. this.updateSubmitField();
  620. if (!PRMTUtils.f_isMobileDevice()) {
  621. this.m_oCurrentFocus.select();
  622. }
  623. }
  624. //decrement the time down by one for the field with focus
  625. function CTimePicker_timeDown()
  626. {
  627. var sCurrentFocus = this.m_oCurrentFocus.name;
  628. switch (sCurrentFocus)
  629. {
  630. case this.m_sHoursName:
  631. var iCurHours = this.m_dTime.getHours();
  632. if ( iCurHours == MIN_HOURS)
  633. {
  634. this.setCurrentHours(MAX_HOURS);
  635. }
  636. else
  637. {
  638. this.setCurrentHours(this.m_dTime.getHours() - 1);
  639. }
  640. if (this.m_iType != 2)
  641. {
  642. this.drawAMPM();
  643. }
  644. this.drawHours();
  645. break;
  646. case this.m_sMinutesName:
  647. if (this.iGetCurrentMinutes() == MIN_MINUTES)
  648. {
  649. this.setCurrentMinutes(MAX_MINUTES);
  650. }
  651. else
  652. {
  653. this.setCurrentMinutes(this.iGetCurrentMinutes() - 1);
  654. }
  655. this.drawMinutes();
  656. break;
  657. case this.m_sSecondsName:
  658. if (this.iGetCurrentSeconds() == MIN_SECONDS)
  659. {
  660. this.setCurrentSeconds(MAX_SECONDS);
  661. }
  662. else
  663. {
  664. this.setCurrentSeconds(this.iGetCurrentSeconds() - 1);
  665. }
  666. this.drawSeconds();
  667. break;
  668. case this.m_sMillisecondsName:
  669. if (this.iGetCurrentMilliseconds() == MIN_MILLISECONDS)
  670. {
  671. this.setCurrentMilliseconds(MAX_MILLISECONDS);
  672. }
  673. else
  674. {
  675. this.setCurrentMilliseconds(this.iGetCurrentMilliseconds() - 1);
  676. }
  677. this.drawMilliseconds();
  678. break;
  679. case this.m_sAMPMName:
  680. if (this.sGetCurrentAMPM() == g_amString)
  681. {
  682. this.setCurrentAMPM(g_pmString);
  683. }
  684. else
  685. {
  686. this.setCurrentAMPM(g_amString);
  687. }
  688. this.drawAMPM();
  689. break;
  690. default:
  691. alert ('problem with CTimePicker_timeUp()');
  692. break;
  693. }
  694. this.updateSubmitField();
  695. if (!PRMTUtils.f_isMobileDevice()) {
  696. this.m_oCurrentFocus.select();
  697. }
  698. }
  699. /* key event handling */
  700. function CTimePicker_keyPress(evt,obj)
  701. {
  702. //trap event
  703. evt = (evt) ? evt : ((event) ? event : null);
  704. if (evt)
  705. {
  706. var keyCode = parseInt(((evt.keyCode) ? evt.keyCode : evt.which),10);
  707. switch (keyCode)
  708. {
  709. //up
  710. case 38:
  711. this.timeUp();
  712. this.setCurrentFocus(obj);
  713. break;
  714. //down
  715. case 40:
  716. this.timeDown();
  717. this.setCurrentFocus(obj);
  718. break;
  719. default:
  720. break;
  721. }
  722. if (this.bCheckTime() == false)
  723. {
  724. this.checkTimeFail();
  725. }
  726. else
  727. {
  728. this.checkTimePass();
  729. this.updateSubmitField();
  730. }
  731. }
  732. return true;
  733. }
  734. //render control in validated state
  735. function CTimePicker_checkTimePass()
  736. {
  737. if ((this.m_oImgCheckDate != null) && (this.m_oImgCheckDate.src != this.m_oImgErrorFalse.src))
  738. {
  739. this.m_oImgCheckDate.src = this.m_oImgErrorFalse.src;
  740. }
  741. this.notify(gPASS, this);
  742. }
  743. //render control in error state
  744. function CTimePicker_checkTimeFail()
  745. {
  746. if (this.m_oImgCheckDate != null)
  747. {
  748. this.m_oImgCheckDate.src = this.m_oImgErrorTrue.src + '?' + Math.random();
  749. }
  750. this.notify(gFAIL, this);
  751. }
  752. //test the hour
  753. function CTimePicker_bCheckHour()
  754. {
  755. this.m_bCheckedHour = true;
  756. if ( this.bisValidHours(this.m_oHours.value) ) {
  757. var iValue = parseInt(this.m_oHours.value,10);
  758. this.m_oHours.className = "clsSelectTimeControl pcl";
  759. this.checkTimePass();
  760. //2 = 24 hour clock, no AM/PM
  761. if (this.m_iType == 2)
  762. {
  763. this.setCurrentHours(iValue);
  764. }
  765. else
  766. {
  767. if ((iValue > 0) && (iValue < 12) && (this.sGetCurrentAMPM() == g_pmString))
  768. {
  769. iValue = iValue + 12;
  770. this.setCurrentHours(iValue);
  771. }
  772. else if ((iValue > 0) && (iValue < 12) && (this.sGetCurrentAMPM() == g_amString))
  773. {
  774. this.setCurrentHours(iValue);
  775. }
  776. else if (iValue > 12)
  777. {
  778. this.setCurrentHours(iValue);
  779. }
  780. else if ((iValue == 12) && (this.sGetCurrentAMPM() == g_amString))
  781. {
  782. this.setCurrentHours(0);
  783. }
  784. else if ((iValue == 12) && (this.sGetCurrentAMPM() == g_pmString))
  785. {
  786. this.setCurrentHours(12);
  787. }
  788. }
  789. return true;
  790. }
  791. else
  792. {
  793. this.m_oHours.className = "clsSelectTimeControlParseError";
  794. this.checkTimeFail();
  795. return false;
  796. }
  797. }
  798. //test the minute
  799. function CTimePicker_bCheckMinute()
  800. {
  801. this.m_bCheckedMin = true;
  802. if ( this.bisValidMinutes(this.m_oMinutes.value) ) {
  803. var iValue = parseInt(this.m_oMinutes.value,10);
  804. this.m_oMinutes.className = "clsSelectTimeControl pcl";
  805. this.setCurrentMinutes(iValue);
  806. this.checkTimePass();
  807. return true;
  808. }
  809. else
  810. {
  811. this.m_oMinutes.className = "clsSelectTimeControlParseError";
  812. this.checkTimeFail();
  813. return false;
  814. }
  815. }
  816. //test the second
  817. function CTimePicker_bCheckSecond()
  818. {
  819. this.m_bCheckedSec = true;
  820. if ( this.bisValidSeconds(this.m_oSeconds.value) ) {
  821. var iValue = parseInt(this.m_oSeconds.value,10);
  822. this.m_oSeconds.className = "clsSelectTimeControl pcl";
  823. this.setCurrentSeconds(iValue);
  824. this.checkTimePass();
  825. return true;
  826. }
  827. else
  828. {
  829. this.m_oSeconds.className = "clsSelectTimeControlParseError";
  830. this.checkTimeFail();
  831. return false;
  832. }
  833. }
  834. //test the millisecond
  835. function CTimePicker_bCheckMillisecond()
  836. {
  837. this.m_bCheckedMillis = true;
  838. if ( this.bisValidMilliseconds(this.m_oMilliseconds.value) ) {
  839. var iValue = parseInt(this.m_oMilliseconds.value,10);
  840. this.m_oMilliseconds.className = "clsSelectTimeControl pcl";
  841. this.setCurrentMilliseconds(iValue);
  842. this.checkTimePass();
  843. return true;
  844. }
  845. else
  846. {
  847. this.m_oMilliseconds.className = "clsSelectTimeControlParseError";
  848. this.checkTimeFail();
  849. return false;
  850. }
  851. }
  852. //check AM/PM
  853. function CTimePicker_bCheckAMPM()
  854. {
  855. var sValue = this.m_oAMPM.value;
  856. var myAMPattern = new RegExp("^" + g_amString.substring(0,1), "i"); //ignore case
  857. var myPMPattern = new RegExp("^" + g_pmString.substring(0,1), "i"); //ignore case
  858. //is there a match?
  859. if (sValue.match(myAMPattern))
  860. {
  861. this.m_oAMPM.className = "clsSelectTimeControl pcl";
  862. this.setCurrentAMPM(g_amString);
  863. this.checkTimePass();
  864. return true;
  865. }
  866. else if (sValue.match(myPMPattern))
  867. {
  868. this.m_oAMPM.className = "clsSelectTimeControl pcl";
  869. this.setCurrentAMPM(g_pmString);
  870. this.checkTimePass();
  871. return true;
  872. }
  873. else
  874. {
  875. this.m_oAMPM.className = "clsSelectTimeControlParseError";
  876. this.checkTimeFail();
  877. return false;
  878. }
  879. }
  880. //return a formatted string of the time
  881. // iDisplay: determine the display
  882. // 0 = h:m:s:ms
  883. // 1 = h:m:s
  884. // 2 = h:m
  885. function CTimePicker_sGetFormatTime()
  886. {
  887. return getFormatTime(this.m_dTime, this.m_iDisplay);
  888. }
  889. //return the time in SQL format
  890. function CTimePicker_sGetSQLTime()
  891. {
  892. var sValue = K_PRMT_sEMPTY;
  893. sValue = this.m_oForm.value;
  894. return sValue;
  895. }
  896. //validate the input into the control
  897. function CTimePicker_checkData()
  898. {
  899. if ((this.m_bRequired == true) && ((this.m_oForm.value==K_PRMT_sEMPTY)||(this.bCheckTime() ==false)))
  900. {
  901. this.m_bValid = false;
  902. this.checkTimeFail();
  903. return false;
  904. }
  905. if ((this.m_bDisabled == false) && (this.bCheckTime() == false))
  906. {
  907. this.m_bValid = false;
  908. this.checkTimeFail();
  909. return false;
  910. }
  911. else
  912. {
  913. this.m_bValid = true;
  914. this.checkTimePass();
  915. // because the checkData of control is not notified
  916. if (SYSTEMPROPERTY_TREE_CACHE_ENABLED)
  917. {
  918. if (this.m_oTimeControl)
  919. {
  920. this.m_oTimeControl.cacheControlValue(this.m_oTimeControl._type_);
  921. }
  922. }
  923. return true;
  924. }
  925. }
  926. //perform any special processing for the server.
  927. function CTimePicker_preProcess()
  928. {
  929. if (this.m_sSubmitType == K_PRMT_sXML)
  930. {
  931. var sURLValues = K_PRMT_sEMPTY;
  932. if (this.m_bDisabled!=true)
  933. {
  934. sURLValues += '<selectOption';
  935. sURLValues += ' displayValue="' + this.sGetFormatTime() +'"';
  936. sURLValues += ' useValue="' + this.sGetSQLTime() +'"';
  937. sURLValues += ' selected="true" />';
  938. }
  939. addSelectChoices(this.m_oSubmit, sURLValues);
  940. }
  941. else
  942. {
  943. if (this.m_bDisabled != true)
  944. {
  945. this.m_oSubmit.value = this.sGetSQLTime();
  946. }
  947. else
  948. {
  949. //this control is disabled
  950. this.m_oSubmit.value = K_PRMT_sEMPTY;
  951. }
  952. }
  953. }
  954. function CTimePicker_enable()
  955. {
  956. this.m_bDisabled = false;
  957. if ( this.m_oClockBox )
  958. {
  959. PRMTUtils.f_removeClass( this.m_oClockBox.parentNode, "clsClockDisabled" );
  960. }
  961. PRMTUtils.f_removeClass( this.m_oClockBox, "clsClockDisabled" );
  962. PRMTUtils.f_removeClass( this.m_oEditBox, "clsClockDisabled" );
  963. PRMTUtils.f_removeClass( this.m_oHours, "clsClockDisabled" );
  964. PRMTUtils.f_removeClass( this.m_oMinutes, "clsClockDisabled" );
  965. PRMTUtils.f_removeClass( this.m_oSeconds, "clsClockDisabled" );
  966. PRMTUtils.f_removeClass( this.m_oMilliseconds, "clsClockDisabled" );
  967. PRMTUtils.f_removeClass( this.m_oAMPM, "clsClockDisabled" );
  968. }
  969. function CTimePicker_disable()
  970. {
  971. this.m_bDisabled = true;
  972. this.stopLiveTime();
  973. if ( this.m_oClockBox )
  974. {
  975. PRMTUtils.f_addClass( this.m_oClockBox.parentNode, "clsClockDisabled" );
  976. }
  977. PRMTUtils.f_addClass( this.m_oClockBox, "clsClockDisabled" );
  978. PRMTUtils.f_addClass( this.m_oEditBox, "clsClockDisabled" );
  979. PRMTUtils.f_addClass( this.m_oHours, "clsClockDisabled" );
  980. PRMTUtils.f_addClass( this.m_oMinutes, "clsClockDisabled" );
  981. PRMTUtils.f_addClass( this.m_oSeconds, "clsClockDisabled" );
  982. PRMTUtils.f_addClass( this.m_oMilliseconds, "clsClockDisabled" );
  983. PRMTUtils.f_addClass( this.m_oAMPM, "clsClockDisabled" );
  984. }
  985. function CTimePicker_toggleDisable(bState)
  986. {
  987. if (this.isRequired() == false)
  988. {
  989. if (bState == false)
  990. {
  991. this.disable();
  992. }
  993. else
  994. {
  995. this.enable();
  996. }
  997. }
  998. }
  999. //return interval data type
  1000. function CTimePicker_sGetValue()
  1001. {
  1002. return this.sGetSQLTime();
  1003. }
  1004. //return locale formatted value
  1005. function CTimePicker_sGetFormatValue()
  1006. {
  1007. return this.sGetFormatTime();
  1008. }
  1009. //set the value of the control
  1010. function CTimePicker_setValue(sTime)
  1011. {
  1012. if (sTime != null)
  1013. {
  1014. this.m_dTime = dParseTime (sTime);
  1015. }
  1016. else
  1017. {
  1018. //default to 12:00am
  1019. this.resetTime();
  1020. }
  1021. //draw the current time
  1022. this.refreshTime();
  1023. //initialize the form control
  1024. this.updateSubmitField();
  1025. }
  1026. //set the time to 12:00am
  1027. function CTimePicker_resetTime()
  1028. {
  1029. this.m_dTime = new Date();
  1030. this.m_dTime.setHours(0);
  1031. this.m_dTime.setMinutes(0);
  1032. this.m_dTime.setSeconds(0);
  1033. this.m_dTime.setMilliseconds(0);
  1034. }
  1035. function CTimePicker_hasValue()
  1036. {
  1037. if (this.m_oForm.value == K_PRMT_sEMPTY)
  1038. {
  1039. return false;
  1040. }
  1041. else
  1042. {
  1043. return true;
  1044. }
  1045. }
  1046. function CTimePicker_checkFail()
  1047. {
  1048. this.checkTimeFail();
  1049. }
  1050. //Prototypes to assign methods to new instances of the object
  1051. CTimePicker.prototype.updateSubmitField = CTimePicker_updateSubmitField;
  1052. CTimePicker.prototype.refreshTime = CTimePicker_refreshTime;
  1053. CTimePicker.prototype.drawHours = CTimePicker_drawHours;
  1054. CTimePicker.prototype.drawMinutes = CTimePicker_drawMinutes;
  1055. CTimePicker.prototype.drawSeconds = CTimePicker_drawSeconds;
  1056. CTimePicker.prototype.drawMilliseconds = CTimePicker_drawMilliseconds;
  1057. CTimePicker.prototype.drawAMPM = CTimePicker_drawAMPM;
  1058. CTimePicker.prototype.drawLiveTime = CTimePicker_drawLiveTime;
  1059. CTimePicker.prototype.stopLiveTime = CTimePicker_stopLiveTime;
  1060. CTimePicker.prototype.setCurrentHours = CTimePicker_setCurrentHours;
  1061. CTimePicker.prototype.setCurrentMinutes = CTimePicker_setCurrentMinutes;
  1062. CTimePicker.prototype.setCurrentSeconds = CTimePicker_setCurrentSeconds;
  1063. CTimePicker.prototype.setCurrentMilliseconds = CTimePicker_setCurrentMilliseconds;
  1064. CTimePicker.prototype.setCurrentAMPM = CTimePicker_setCurrentAMPM;
  1065. CTimePicker.prototype.iGetCurrentHours = CTimePicker_iGetCurrentHours;
  1066. CTimePicker.prototype.iGetCurrentMinutes = CTimePicker_iGetCurrentMinutes;
  1067. CTimePicker.prototype.iGetCurrentSeconds = CTimePicker_iGetCurrentSeconds;
  1068. CTimePicker.prototype.iGetCurrentMilliseconds = CTimePicker_iGetCurrentMilliseconds;
  1069. CTimePicker.prototype.sGetCurrentAMPM = CTimePicker_sGetCurrentAMPM;
  1070. CTimePicker.prototype.bCheckTime = CTimePicker_bCheckTime;
  1071. CTimePicker.prototype.bisValidHours = CTimePicker_bisValidHours;
  1072. CTimePicker.prototype.bisValidMinutes = CTimePicker_bisValidMinutes;
  1073. CTimePicker.prototype.bisValidSeconds = CTimePicker_bisValidSeconds;
  1074. CTimePicker.prototype.bisValidMilliseconds = CTimePicker_bisValidMilliseconds;
  1075. CTimePicker.prototype.setCurrentFocus = CTimePicker_setCurrentFocus;
  1076. CTimePicker.prototype.oGetCurrentFocus = CTimePicker_oGetCurrentFocus;
  1077. CTimePicker.prototype.timeUp = CTimePicker_timeUp;
  1078. CTimePicker.prototype.timeDown = CTimePicker_timeDown;
  1079. CTimePicker.prototype.keyPress = CTimePicker_keyPress;
  1080. CTimePicker.prototype.bCheckHour = CTimePicker_bCheckHour;
  1081. CTimePicker.prototype.bCheckMinute = CTimePicker_bCheckMinute;
  1082. CTimePicker.prototype.bCheckSecond = CTimePicker_bCheckSecond;
  1083. CTimePicker.prototype.bCheckMillisecond = CTimePicker_bCheckMillisecond;
  1084. CTimePicker.prototype.bCheckAMPM = CTimePicker_bCheckAMPM;
  1085. CTimePicker.prototype.checkTimePass = CTimePicker_checkTimePass;
  1086. CTimePicker.prototype.checkTimeFail = CTimePicker_checkTimeFail;
  1087. CTimePicker.prototype.sGetFormatTime = CTimePicker_sGetFormatTime;
  1088. CTimePicker.prototype.sGetSQLTime = CTimePicker_sGetSQLTime;
  1089. CTimePicker.prototype.checkData= CTimePicker_checkData;
  1090. CTimePicker.prototype.preProcess = CTimePicker_preProcess;
  1091. CTimePicker.prototype.enable = CTimePicker_enable;
  1092. CTimePicker.prototype.disable = CTimePicker_disable;
  1093. CTimePicker.prototype.toggleDisable = CTimePicker_toggleDisable;
  1094. CTimePicker.prototype.sGetFormatValue = CTimePicker_sGetFormatValue;
  1095. CTimePicker.prototype.sGetValue = CTimePicker_sGetValue;
  1096. CTimePicker.prototype.setValue = CTimePicker_setValue;
  1097. CTimePicker.prototype.resetTime = CTimePicker_resetTime;
  1098. CTimePicker.prototype.hasValue = CTimePicker_hasValue;
  1099. CTimePicker.prototype.checkFail = CTimePicker_checkFail;
  1100. /* utility functions */
  1101. //returns a date object for a given time
  1102. function dParseTime(sTime)
  1103. {
  1104. var dTime = new Date(1970,0,1,0,0,0,0);
  1105. //set a default time if a default has been specified
  1106. var sDefaultTime = (sTime) ? sTime : K_PRMT_sEMPTY;
  1107. //convert from a valid date time format (XSD format and SQL)
  1108. var arDateTime = sDefaultTime.split(/[T\s]/g);
  1109. if (arDateTime.length == 2)
  1110. {
  1111. sDefaultTime = arDateTime[1];
  1112. }
  1113. var arDefaultTime = sDefaultTime.split(/[:\.\,]/g);
  1114. //do we have a valid date?
  1115. if ((arDefaultTime.length == 4) || (arDefaultTime.length == 3))
  1116. {
  1117. var sHours = parseInt(arDefaultTime[0],10);
  1118. if (sHours != NaN && sHours <= 23 && sHours >= 0)
  1119. {
  1120. dTime.setHours(sHours);
  1121. }
  1122. else
  1123. {
  1124. // going to default to 12
  1125. dTime.setHours(0);
  1126. }
  1127. var sMinutes = parseInt(arDefaultTime[1],10);
  1128. if (sMinutes != NaN && sMinutes <= 59 && sMinutes >= 0)
  1129. {
  1130. dTime.setMinutes(sMinutes);
  1131. }
  1132. else
  1133. {
  1134. // going to default to 0 minutes
  1135. dTime.setMinutes(0);
  1136. }
  1137. var sSeconds = parseInt(arDefaultTime[2],10);
  1138. if (sSeconds != NaN && sSeconds <= 59 && sSeconds >= 0)
  1139. {
  1140. dTime.setSeconds(sSeconds);
  1141. }
  1142. else
  1143. {
  1144. // going to default to 0 seconds
  1145. dTime.setSeconds(0);
  1146. }
  1147. //milliseconds are optional
  1148. if (arDefaultTime.length == 4)
  1149. {
  1150. var sMilliseconds = parseInt(arDefaultTime[3],10);
  1151. if (sMilliseconds != NaN && sMilliseconds <= 999 && sMilliseconds >= 0)
  1152. {
  1153. dTime.setMilliseconds(sMilliseconds);
  1154. }
  1155. else
  1156. {
  1157. // going to default to 0 milliseconds
  1158. dTime.setMilliseconds(0);
  1159. }
  1160. }
  1161. }
  1162. return dTime;
  1163. }
  1164. //returns a locale formatted time for a given date
  1165. //
  1166. // iDisplay: determine the display
  1167. // 0 = h:m:s:ms
  1168. // 1 = h:m:s
  1169. // 2 = h:m
  1170. function getFormatTime(dTime, iDisplay)
  1171. {
  1172. var sValue = K_PRMT_sEMPTY;
  1173. //format hours
  1174. var iHours = dTime.getHours();
  1175. if (g_24HourClock == 'false')
  1176. {
  1177. if (iHours == 0)
  1178. {
  1179. iHours = 12;
  1180. }
  1181. else if (iHours > 12)
  1182. {
  1183. iHours = iHours - 12;
  1184. }
  1185. }
  1186. var sHours = iHours.toString();
  1187. if ((sHours.length == 1) && (g_hourFormatMedium == 'hh'))
  1188. {
  1189. sHours = '0' + sHours;
  1190. }
  1191. sValue += sHours;
  1192. //format minutes
  1193. var sMinutes = dTime.getMinutes().toString();
  1194. if ((sMinutes.length == 1) && (g_minuteFormatMedium == 'mm'))
  1195. {
  1196. sMinutes = '0' + sMinutes;
  1197. }
  1198. sValue += g_timeSeparator + sMinutes;
  1199. //format seconds
  1200. if (iDisplay <= 1)
  1201. {
  1202. var sSeconds = dTime.getSeconds().toString();
  1203. if ((sSeconds.length == 1) && (g_secondFormatMedium == 'ss'))
  1204. {
  1205. sSeconds = '0' + sSeconds;
  1206. }
  1207. sValue += g_timeSeparator + sSeconds;
  1208. }
  1209. //format milliseconds
  1210. if (iDisplay == 0)
  1211. {
  1212. var sMilliseconds = dTime.getMilliseconds().toString();
  1213. if (sMilliseconds.length == 2)
  1214. {
  1215. sMilliseconds = '0' + sMilliseconds;
  1216. }
  1217. else if (sMilliseconds.length == 1)
  1218. {
  1219. sMilliseconds = '00' + sMilliseconds;
  1220. }
  1221. sValue += K_PRMT_sDOT + sMilliseconds;
  1222. }
  1223. if ((g_24HourClock == 'false') && (g_AMPMLocation == 'right'))
  1224. {
  1225. if (dTime.getHours() >= 12)
  1226. {
  1227. sValue = sValue + K_PRMT_sSP + g_pmString;
  1228. }
  1229. else
  1230. {
  1231. sValue = sValue + K_PRMT_sSP + g_amString;
  1232. }
  1233. }
  1234. else if ((g_24HourClock == "false") && (g_AMPMLocation == "left"))
  1235. {
  1236. if (dTime.getHours() >= 12)
  1237. {
  1238. sValue = g_pmString + K_PRMT_sSP + sValue;
  1239. }
  1240. else
  1241. {
  1242. sValue = g_amString + K_PRMT_sSP + sValue;
  1243. }
  1244. }
  1245. return sValue;
  1246. }
  1247. /* Messages */
  1248. // declare message strings
  1249. var g_amString = "AM";
  1250. var g_pmString = "PM";
  1251. var g_mediumFormat = "MMM d, yyyy h:mm:ss a";
  1252. var g_shortFormat = "M/d/yy h:mm a";
  1253. var g_hourFormatMedium = "h";
  1254. var g_minuteFormatMedium = "mm";
  1255. var g_secondFormatMedium = "ss";
  1256. var g_hourFormatShort = "h";
  1257. var g_minuteFormatShort = "mm";
  1258. var g_secondFormatShort = K_PRMT_sEMPTY;
  1259. var g_timeSeparator = K_PRMT_sCOLON;
  1260. var g_AMPMLocation = "right";
  1261. var g_24HourClock = "false";
  1262. /* Constants */
  1263. var MAX_HOURS = 23;
  1264. var MAX_MINUTES = 59;
  1265. var MAX_SECONDS = 59;
  1266. var MAX_MILLISECONDS = 999;
  1267. var MIN_HOURS = 0;
  1268. var MIN_MINUTES = 0;
  1269. var MIN_SECONDS = 0;
  1270. var MIN_MILLISECONDS = 0;