promptengine_calendar.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. /* Copyright (c) Business Objects 2006. All rights reserved. */
  2. // BEGIN USER-EDITABLE SECTION -----------------------------------------------------
  3. // CALENDAR COLORS
  4. topBackground = "black"; // BG COLOR OF THE TOP FRAME
  5. bottomBackground = "white"; // BG COLOR OF THE BOTTOM FRAME
  6. tableBGColor = "black"; // BG COLOR OF THE BOTTOM FRAME'S TABLE
  7. cellColor = "lightgrey"; // TABLE CELL BG COLOR OF THE DATE CELLS IN THE BOTTOM FRAME
  8. headingCellColor = "white"; // TABLE CELL BG COLOR OF THE WEEKDAY ABBREVIATIONS
  9. headingTextColor = "black"; // TEXT COLOR OF THE WEEKDAY ABBREVIATIONS
  10. //dateColor = "blue"; // TEXT COLOR OF THE LISTED DATES (1-28+)
  11. //focusColor = "#ff0000"; // TEXT COLOR OF THE SELECTED DATE (OR CURRENT DATE)
  12. //hoverColor = "darkred"; // TEXT COLOR OF A LINK WHEN YOU HOVER OVER IT
  13. //fontStyle = "12pt arial, helvetica"; // TEXT STYLE FOR DATES
  14. //they are in CSS file
  15. headingFontStyle = "bold 12pt arial, helvetica"; // TEXT STYLE FOR WEEKDAY ABBREVIATIONS
  16. // FORMATTING PREFERENCES
  17. bottomBorder = false; // TRUE/FALSE (WHETHER TO DISPLAY BOTTOM CALENDAR BORDER)
  18. tableBorder = 0; // SIZE OF CALENDAR TABLE BORDER (BOTTOM FRAME) 0=none
  19. //Offset of calander popup from calendar image
  20. calendarTopOffsetFromImage = 15;
  21. calendarLeftOffsetFromImage = 15;
  22. var DateTimeFormat = true; //"DateTime" if true, else a "Date"
  23. // END USER-EDITABLE SECTION -------------------------------------------------------
  24. // DETERMINE BROWSER BRAND
  25. var isNav = false;
  26. var isIE = false;
  27. // ASSUME IT'S EITHER NETSCAPE OR MSIE
  28. if (navigator.appName == "Netscape") {
  29. isNav = true;
  30. }
  31. else {
  32. isIE = true;
  33. }
  34. // global variable for top frame and bottom frame
  35. var calDocTop;
  36. var calDocBottom;
  37. var promptEngineOrigOnMouseDown;
  38. // PRE-BUILD PORTIONS OF THE CALENDAR WHEN THIS JS LIBRARY LOADS INTO THE BROWSER
  39. buildCalParts();
  40. // CALENDAR FUNCTIONS BEGIN HERE ---------------------------------------------------
  41. // SET THE INITIAL VALUE OF THE GLOBAL DATE FIELD
  42. function setDateField(formName, dateField) {
  43. // ASSIGN THE INCOMING FIELD OBJECT TO A GLOBAL VARIABLE
  44. thisform = document.forms[formName];
  45. calDateField = thisform[dateField];
  46. // GET THE VALUE OF THE INCOMING FIELD
  47. inDate = thisform[dateField].value;
  48. // SET calDate TO THE DATE IN THE INCOMING FIELD OR DEFAULT TO TODAY'S DATE
  49. setInitialDate();
  50. // THE CALENDAR FRAMESET DOCUMENTS ARE CREATED BY JAVASCRIPT FUNCTIONS
  51. calDocTop = buildTopCalFrame();
  52. calDocBottom = buildBottomCalFrame();
  53. if(document.onmousedown)
  54. promptEngineOrigOnMouseDown = document.onmousedown;
  55. document.onmousedown= clickit;
  56. }
  57. // SET THE INITIAL CALENDAR DATE TO TODAY OR TO THE EXISTING VALUE IN dateField
  58. function setInitialDate() {
  59. calDate = ParseDate(inDate, DateTimeFormat);
  60. // IF THE INCOMING DATE IS INVALID, USE THE CURRENT DATE
  61. if (isNaN(calDate)) {
  62. // ADD CUSTOM DATE PARSING HERE
  63. // IF IT FAILS, SIMPLY CREATE A NEW DATE OBJECT WHICH DEFAULTS TO THE CURRENT DATE
  64. calDate = new Date();
  65. }
  66. // KEEP TRACK OF THE CURRENT DAY VALUE
  67. calDay = calDate.getDate();
  68. // SET DAY VALUE TO 1... TO AVOID JAVASCRIPT DATE CALCULATION ANOMALIES
  69. // (IF THE MONTH CHANGES TO FEB AND THE DAY IS 30, THE MONTH WOULD CHANGE TO MARCH
  70. // AND THE DAY WOULD CHANGE TO 2. SETTING THE DAY TO 1 WILL PREVENT THAT)
  71. calDate.setDate(1);
  72. }
  73. // CREATE THE TOP CALENDAR FRAME
  74. function buildTopCalFrame() {
  75. // CREATE THE TOP FRAME OF THE CALENDAR
  76. var calDoc =
  77. "<div style=\"background:" + topBackground + "\" >" +
  78. "<div id='IDcalControl'>" +
  79. "<CENTER>" +
  80. "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0 WIDTH=100%>" +
  81. "<TR><TD COLSPAN=7>" +
  82. "<CENTER>" +
  83. getMonthSelect() +
  84. "<INPUT id='INtopYear' VALUE='" + calDate.getFullYear() + "'TYPE=TEXT SIZE=4 MAXLENGTH=4 onChange='setYear()' onfocus='INopenDocumentKey()' onblur='INopenDocumentKey()' onkeyup='INopenDocumentKey()' onKeyDown='if (window.event != null && window.event.keyCode == 13) setYear()'>" +
  85. "</CENTER>" +
  86. "</TD>" +
  87. "</TR>" +
  88. "<TR>" +
  89. "<TD COLSPAN=7>" +
  90. "<CENTER>" +
  91. "<INPUT " +
  92. "TYPE=BUTTON id='INtopPreviousYear' VALUE='<<' onClick='setPreviousYear()'><INPUT " +
  93. "TYPE=BUTTON id='INtopPreviousMonth' VALUE=' < ' onClick='setPreviousMonth()'><INPUT " +
  94. "TYPE=BUTTON id='INtopToday' VALUE='" + L_Today + "' onClick='setToday()'><INPUT " +
  95. "TYPE=BUTTON id='INtopNextMonth' VALUE=' > ' onClick='setNextMonth()'><INPUT " +
  96. "TYPE=BUTTON id='INtopNextYear' VALUE='>>' onClick='setNextYear()'>" +
  97. "</CENTER>" +
  98. "</TD>" +
  99. "</TR>" +
  100. "</TABLE>" +
  101. "</CENTER>" +
  102. "</div>" +
  103. "</div>";
  104. return calDoc;
  105. }
  106. // CREATE THE BOTTOM CALENDAR FRAME
  107. // (THE MONTHLY CALENDAR)
  108. function buildBottomCalFrame() {
  109. // START CALENDAR DOCUMENT
  110. var calDoc = calendarBegin;
  111. // GET MONTH, AND YEAR FROM GLOBAL CALENDAR DATE
  112. month = calDate.getMonth();
  113. year = calDate.getFullYear();
  114. // GET GLOBALLY-TRACKED DAY VALUE (PREVENTS JAVASCRIPT DATE ANOMALIES)
  115. day = calDay;
  116. var i = 0;
  117. // DETERMINE THE NUMBER OF DAYS IN THE CURRENT MONTH
  118. var days = getDaysInMonth();
  119. // IF GLOBAL DAY VALUE IS > THAN DAYS IN MONTH, HIGHLIGHT LAST DAY IN MONTH
  120. if (day > days) {
  121. day = days;
  122. }
  123. // DETERMINE WHAT DAY OF THE WEEK THE CALENDAR STARTS ON
  124. var firstOfMonth = new Date (year, month, 1);
  125. // GET THE DAY OF THE WEEK THE FIRST DAY OF THE MONTH FALLS ON
  126. var startingPos = firstOfMonth.getDay();
  127. days += startingPos;
  128. // KEEP TRACK OF THE COLUMNS, START A NEW ROW AFTER EVERY 7 COLUMNS
  129. var columnCount = 0;
  130. // MAKE BEGINNING NON-DATE CELLS BLANK
  131. for (i = 0; i < startingPos; i++) {
  132. calDoc += blankCell;
  133. columnCount++;
  134. }
  135. // SET VALUES FOR DAYS OF THE MONTH
  136. var currentDay = 0;
  137. var dayType = "weekday";
  138. // DATE CELLS CONTAIN A NUMBER
  139. for (i = startingPos; i < days; i++) {
  140. var paddingChar = "&nbsp;";
  141. // ADJUST SPACING SO THAT ALL LINKS HAVE RELATIVELY EQUAL WIDTHS
  142. if (i-startingPos+1 < 10) {
  143. padding = "&nbsp;&nbsp;";
  144. }
  145. else {
  146. padding = "&nbsp;";
  147. }
  148. // GET THE DAY CURRENTLY BEING WRITTEN
  149. currentDay = i-startingPos+1;
  150. // SET THE TYPE OF DAY, THE focusDay GENERALLY APPEARS AS A DIFFERENT COLOR
  151. if (currentDay == day) {
  152. dayType = "focusDay";
  153. }
  154. else {
  155. dayType = "weekDay";
  156. }
  157. // ADD THE DAY TO THE CALENDAR STRING
  158. calDoc += "<TD align=center style=\"background:" + cellColor + "\" >" +
  159. "<a class='" + dayType + "' href='javascript:returnDate(" +
  160. currentDay + ")'>" + padding + currentDay + paddingChar + "</a></TD>";
  161. columnCount++;
  162. // START A NEW ROW WHEN NECESSARY
  163. if (columnCount % 7 == 0) {
  164. calDoc += "</TR><TR>";
  165. }
  166. }
  167. // MAKE REMAINING NON-DATE CELLS BLANK
  168. for (i=days; i<42; i++) {
  169. calDoc += blankCell;
  170. columnCount++;
  171. // START A NEW ROW WHEN NECESSARY
  172. if (columnCount % 7 == 0) {
  173. calDoc += "</TR>";
  174. if (i<41) {
  175. calDoc += "<TR>";
  176. }
  177. }
  178. }
  179. // FINISH THE NEW CALENDAR PAGE
  180. calDoc += calendarEnd;
  181. // RETURN THE COMPLETED CALENDAR PAGE
  182. return calDoc;
  183. }
  184. // WRITE THE MONTHLY CALENDAR TO THE BOTTOM CALENDAR FRAME
  185. function writeCalendar() {
  186. // CREATE THE NEW CALENDAR FOR THE SELECTED MONTH & YEAR
  187. calDocBottom = buildBottomCalFrame();
  188. //it support ie5 and FF
  189. if (document.getElementById) { // ns6 & ie
  190. document.getElementById("bottomDiv").innerHTML = calDocBottom;
  191. }
  192. }
  193. // SET THE CALENDAR TO TODAY'S DATE AND DISPLAY THE NEW CALENDAR
  194. function setToday() {
  195. // SET GLOBAL DATE TO TODAY'S DATE
  196. calDate = new Date();
  197. // SET DAY MONTH AND YEAR TO TODAY'S DATE
  198. var month = calDate.getMonth();
  199. var year = calDate.getFullYear();
  200. // SET MONTH IN DROP-DOWN LIST
  201. document.getElementById("INtopMonth").selectedIndex = month;
  202. // SET YEAR VALUE
  203. document.getElementById("INtopYear").value = year;
  204. // SET THE DAY VALUE
  205. calDay = calDate.getDate();
  206. // DISPLAY THE NEW CALENDAR
  207. writeCalendar();
  208. }
  209. // SET THE GLOBAL DATE TO THE NEWLY ENTERED YEAR AND REDRAW THE CALENDAR
  210. function setYear() {
  211. // GET THE NEW YEAR VALUE
  212. var year = document.getElementById("INtopYear").value;
  213. // IF IT'S A FOUR-DIGIT YEAR THEN CHANGE THE CALENDAR
  214. if (isFourDigitYear(year)) {
  215. calDate.setFullYear(year);
  216. writeCalendar();
  217. //document.getElementById("INtopYear").blur(); it is possiable that user press enter many times
  218. }
  219. else {
  220. // HIGHLIGHT THE YEAR IF THE YEAR IS NOT FOUR DIGITS IN LENGTH
  221. document.getElementById("INtopYear").focus();
  222. document.getElementById("INtopYear").select();
  223. }
  224. document.onkeydown = function(){return false;}//( if calendar year is onKey, the keypress functions should not be used in the document)
  225. }
  226. // SET THE GLOBAL DATE TO THE SELECTED MONTH AND REDRAW THE CALENDAR
  227. function setCurrentMonth() {
  228. // GET THE NEWLY SELECTED MONTH AND CHANGE THE CALENDAR ACCORDINGLY
  229. var month = document.getElementById("INtopMonth").selectedIndex;
  230. calDate.setMonth(month);
  231. writeCalendar();
  232. }
  233. // SET THE GLOBAL DATE TO THE PREVIOUS YEAR AND REDRAW THE CALENDAR
  234. function setPreviousYear() {
  235. var year = document.getElementById("INtopYear").value;
  236. if (isFourDigitYear(year) && year > 1000) {
  237. year--;
  238. calDate.setFullYear(year);
  239. document.getElementById("INtopYear").value = year;
  240. writeCalendar();
  241. }
  242. }
  243. // SET THE GLOBAL DATE TO THE PREVIOUS MONTH AND REDRAW THE CALENDAR
  244. function setPreviousMonth() {
  245. var year = document.getElementById("INtopYear").value;
  246. if (isFourDigitYear(year)) {
  247. var month = document.getElementById("INtopMonth").selectedIndex;
  248. // IF MONTH IS JANUARY, SET MONTH TO DECEMBER AND DECREMENT THE YEAR
  249. if (month == 0) {
  250. month = 11;
  251. if (year > 1000) {
  252. year--;
  253. calDate.setFullYear(year);
  254. document.getElementById("INtopYear").value = year;
  255. }
  256. }
  257. else {
  258. month--;
  259. }
  260. calDate.setMonth(month);
  261. document.getElementById("INtopMonth").selectedIndex = month;
  262. writeCalendar();
  263. }
  264. }
  265. // SET THE GLOBAL DATE TO THE NEXT MONTH AND REDRAW THE CALENDAR
  266. function setNextMonth() {
  267. var year = document.getElementById("INtopYear").value;
  268. if (isFourDigitYear(year)) {
  269. var month = document.getElementById("INtopMonth").selectedIndex;
  270. // IF MONTH IS DECEMBER, SET MONTH TO JANUARY AND INCREMENT THE YEAR
  271. if (month == 11) {
  272. month = 0;
  273. year++;
  274. calDate.setFullYear(year);
  275. document.getElementById("INtopYear").value = year;
  276. }
  277. else {
  278. month++;
  279. }
  280. calDate.setMonth(month);
  281. document.getElementById("INtopMonth").selectedIndex = month;
  282. writeCalendar();
  283. }
  284. }
  285. // SET THE GLOBAL DATE TO THE NEXT YEAR AND REDRAW THE CALENDAR
  286. function setNextYear() {
  287. var year = document.getElementById("INtopYear").value;
  288. if (isFourDigitYear(year)) {
  289. year++;
  290. calDate.setFullYear(year);
  291. document.getElementById("INtopYear").value = year;
  292. writeCalendar();
  293. }
  294. }
  295. // GET NUMBER OF DAYS IN MONTH
  296. function getDaysInMonth() {
  297. var days;
  298. var month = calDate.getMonth()+1;
  299. var year = calDate.getFullYear();
  300. // RETURN 31 DAYS
  301. if (month==1 || month==3 || month==5 || month==7 || month==8 ||
  302. month==10 || month==12) {
  303. days=31;
  304. }
  305. // RETURN 30 DAYS
  306. else if (month==4 || month==6 || month==9 || month==11) {
  307. days=30;
  308. }
  309. // RETURN 29 DAYS
  310. else if (month==2) {
  311. if (isLeapYear(year)) {
  312. days=29;
  313. }
  314. // RETURN 28 DAYS
  315. else {
  316. days=28;
  317. }
  318. }
  319. return (days);
  320. }
  321. // CHECK TO SEE IF YEAR IS A LEAP YEAR
  322. function isLeapYear (Year) {
  323. if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
  324. return (true);
  325. }
  326. else {
  327. return (false);
  328. }
  329. }
  330. // ENSURE THAT THE YEAR IS FOUR DIGITS IN LENGTH
  331. function isFourDigitYear(year) {
  332. if (year == null || year.match(/^[0-9]{4}$/) == null){
  333. document.getElementById("INtopYear").value = calDate.getFullYear();
  334. document.getElementById("INtopYear").select();
  335. document.getElementById("INtopYear").focus();
  336. }
  337. else {
  338. return true;
  339. }
  340. }
  341. // BUILD THE MONTH SELECT LIST
  342. function getMonthSelect() {
  343. monthArray = new Array(L_January, L_February, L_March, L_April, L_May, L_June,
  344. L_July, L_August, L_September, L_October, L_November, L_December);
  345. // DETERMINE MONTH TO SET AS DEFAULT
  346. var activeMonth = calDate.getMonth();
  347. // START HTML SELECT LIST ELEMENT
  348. monthSelect = "<SELECT id='INtopMonth' onChange='setCurrentMonth()'>";
  349. // LOOP THROUGH MONTH ARRAY
  350. for (i in monthArray) {
  351. // SHOW THE CORRECT MONTH IN THE SELECT LIST
  352. if (i == activeMonth) {
  353. monthSelect += "<OPTION SELECTED>" + monthArray[i] + "\n";
  354. }
  355. else {
  356. monthSelect += "<OPTION>" + monthArray[i] + "\n";
  357. }
  358. }
  359. monthSelect += "</SELECT>";
  360. // RETURN A STRING VALUE WHICH CONTAINS A SELECT LIST OF ALL 12 MONTHS
  361. return monthSelect;
  362. }
  363. // SET DAYS OF THE WEEK DEPENDING ON LANGUAGE
  364. function createWeekdayList() {
  365. weekdayArray = new Array(L_Su,L_Mo,L_Tu,L_We,L_Th,L_Fr,L_Sa);
  366. // START HTML TO HOLD WEEKDAY NAMES IN TABLE FORMAT
  367. var weekdays = "<TR BGCOLOR='" + headingCellColor + "'>";
  368. // LOOP THROUGH WEEKDAY ARRAY
  369. for (i in weekdayArray) {
  370. weekdays += "<TD style='text-decoration: none; color:" + headingTextColor + "; font: " + headingFontStyle + "' align=center>" + weekdayArray[i] + "</TD>";
  371. }
  372. weekdays += "</TR>";
  373. // RETURN TABLE ROW OF WEEKDAY ABBREVIATIONS TO DISPLAY ABOVE THE CALENDAR
  374. return weekdays;
  375. }
  376. // PRE-BUILD PORTIONS OF THE CALENDAR (FOR PERFORMANCE REASONS)
  377. function buildCalParts() {
  378. // GENERATE WEEKDAY HEADERS FOR THE CALENDAR
  379. weekdays = createWeekdayList();
  380. // BUILD THE BLANK CELL ROWS
  381. blankCell = "<TD align=center style=\"vertical-align:middle; background:" + cellColor + "\" >&nbsp;&nbsp;&nbsp;</TD>";
  382. // BUILD THE TOP PORTION OF THE CALENDAR PAGE USING CSS TO CONTROL SOME DISPLAY ELEMENTS
  383. calendarBegin = "";
  384. // STYLESHEET DEFINES APPEARANCE OF CALENDAR
  385. // "<STYLE type='text/css'>" +
  386. // "<!--" +
  387. //\ "TD.heading { text-decoration: none; color:" + headingTextColor + "; font: " + headingFontStyle + "; }" +
  388. // This style must in CSS file
  389. // "A.focusDay:link { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
  390. // "A.focusDay:hover { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
  391. // "A.focusDay:visited { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
  392. // "A.weekday:link { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
  393. // "A.weekday:hover { color: " + hoverColor + "; font: " + fontStyle + "; }" +
  394. // "A.weekday:visited { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
  395. // "-->" +
  396. // "</STYLE>" +
  397. //the A link style must in CSS file.
  398. "<div style=\"background:" + bottomBackground + "\" onload='javascript:self.focus()'>";
  399. if (document.getElementById) { // ns6 & ie
  400. calendarBegin +=
  401. "<DIV ID='bottomDiv'>";
  402. }
  403. calendarBegin +=
  404. "<CENTER>";
  405. // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE TABLE OUTLINES PROPERLY
  406. if (isNav) {
  407. calendarBegin +=
  408. "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'><TR><TD>";
  409. }
  410. // BUILD WEEKDAY HEADINGS
  411. calendarBegin +=
  412. "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'>" +
  413. weekdays +
  414. "<TR>";
  415. // BUILD THE BOTTOM PORTION OF THE CALENDAR PAGE
  416. calendarEnd = "";
  417. // WHETHER OR NOT TO DISPLAY A THICK LINE BELOW THE CALENDAR
  418. if (bottomBorder) {
  419. calendarEnd += "<TR></TR>";
  420. }
  421. // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE BORDERS PROPERLY
  422. if (isNav) {
  423. calendarEnd += "</TD></TR></TABLE>";
  424. }
  425. // END THE TABLE AND HTML DOCUMENT
  426. calendarEnd +=
  427. "</TABLE>" +
  428. "</CENTER>";
  429. if (document.getElementById) { // ns6 & ie
  430. calendarEnd +=
  431. "</DIV>";
  432. }
  433. calendarEnd +=
  434. "</div>";
  435. }
  436. // REPLACE ALL INSTANCES OF find WITH replace
  437. // inString: the string you want to convert
  438. // find: the value to search for
  439. // replace: the value to substitute
  440. //
  441. // usage: jsReplace(inString, find, replace);
  442. // example: jsReplace("To be or not to be", "be", "ski");
  443. // result: "To ski or not to ski"
  444. //
  445. function jsReplace(inString, find, replace) {
  446. var outString = "";
  447. if (!inString) {
  448. return "";
  449. }
  450. // REPLACE ALL INSTANCES OF find WITH replace
  451. if (inString.indexOf(find) != -1) {
  452. // SEPARATE THE STRING INTO AN ARRAY OF STRINGS USING THE VALUE IN find
  453. t = inString.split(find);
  454. // JOIN ALL ELEMENTS OF THE ARRAY, SEPARATED BY THE VALUE IN replace
  455. return (t.join(replace));
  456. }
  457. else {
  458. return inString;
  459. }
  460. }
  461. // JAVASCRIPT FUNCTION -- DOES NOTHING (USED FOR THE HREF IN THE CALENDAR CALL)
  462. function doNothing() {
  463. }
  464. // ENSURE THAT VALUE IS TWO DIGITS IN LENGTH
  465. function makeTwoDigit(inValue) {
  466. var numVal = parseInt(inValue, 10);
  467. // VALUE IS LESS THAN TWO DIGITS IN LENGTH
  468. if (numVal < 10) {
  469. // ADD A LEADING ZERO TO THE VALUE AND RETURN IT
  470. return("0" + numVal);
  471. }
  472. else {
  473. return numVal;
  474. }
  475. }
  476. // SET FIELD VALUE TO THE DATE SELECTED AND CLOSE THE CALENDAR WINDOW
  477. function returnDate(inDay)
  478. {
  479. // inDay = THE DAY THE USER CLICKED ON
  480. calDate.setDate(inDay);
  481. // SET THE DATE RETURNED TO THE USER
  482. var day = calDate.getDate();
  483. var month = calDate.getMonth()+1;
  484. var year = calDate.getFullYear();
  485. if(promptengine_getIsTwoDigitMonth()) {
  486. month = makeTwoDigit(month);
  487. }
  488. if(promptengine_getIsTwoDigitDay()) {
  489. day = makeTwoDigit(day);
  490. }
  491. var outDate = promptengine_getDatePattern();
  492. outDate = jsReplace(outDate, "Y", year);
  493. outDate = jsReplace(outDate, "M", month);
  494. outDate = jsReplace(outDate, "D", day);
  495. if ( DateTimeFormat == true ) {
  496. outDate += " ";
  497. outDate += gHour + ":"; gHour = "00";
  498. outDate += gMin + ":"; gMin = "00";
  499. outDate += gSec; gSec = "00";
  500. }
  501. // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR
  502. if (calDateField != null && !calDateField.disabled) {
  503. calDateField.value = outDate;
  504. // GIVE FOCUS BACK TO THE DATE FIELD
  505. calDateField.focus();
  506. }
  507. // CLOSE THE CALENDAR "WINDOW"
  508. document.getElementById("INIDcalendarWindow").style.display="none";
  509. }
  510. var gHour = "00";
  511. var gMin = "00";
  512. var gSec = "00";
  513. var regDateTimePrompt = /^(D|d)(A|a)(T|t)(E|e)(T|t)(I|i)(M|m)(E|e) *\( *\d{4} *, *(0?[1-9]|1[0-2]) *, *((0?[1-9]|[1-2]\d)|3(0|1)) *, *([0-1]?\d|2[0-3]) *, *[0-5]?\d *, *[0-5]?\d *\)$/
  514. var regDateTimePromptHTML = /^ *\d{4} *- *(0?[1-9]|1[0-2]) *- *((0?[1-9]|[1-2]\d)|3(0|1)) * *([0-1]?\d|2[0-3]) *: *[0-5]?\d *: *[0-5]?\d *$/
  515. function ParseDateTimePrompt(inDate)
  516. {
  517. if ( regDateTimePrompt.test ( inDate ) )
  518. {
  519. var sDate = inDate.substr ( inDate.indexOf("(")+1 ); //move past "DateTime ("
  520. sDate = sDate.substr ( 0, sDate.lastIndexOf(")") ); //remove trailing ")"
  521. var dateArray = sDate.split (',');
  522. var _date = new Date ( dateArray[0], Number(dateArray[1]) - 1, dateArray[2] );
  523. gHour = dateArray[3]; gMin = dateArray[4]; gSec = dateArray[5];
  524. return _date;
  525. }
  526. if ( regDateTimePromptHTML.test ( inDate ) )
  527. {
  528. var pos = inDate.indexOf("-");
  529. var sYear = inDate.substr(0, pos);
  530. var sMonth = inDate.substr(pos + 1);
  531. pos = sMonth.indexOf("-");
  532. var sDay = sMonth.substr(pos + 1);
  533. sMonth = sMonth.substr(0, pos);
  534. pos = sDay.indexOf(" ");
  535. var sHour = sDay.substr(pos + 1);
  536. sDay = sDay.substr(0, pos);
  537. pos = sHour.indexOf(":");
  538. var sMinute = sHour.substr(pos + 1);
  539. sHour = sHour.substr(0, pos);
  540. pos = sMinute.indexOf(":");
  541. var sSecond = sMinute.substr(pos + 1);
  542. sMinute = sMinute.substr(0, pos);
  543. gHour = sHour; gMin = sMinute; gSec = sSecond;
  544. return new Date ( sYear, Number(sMonth) - 1, sDay );
  545. }
  546. return new Date ();
  547. }
  548. var regDatePrompt = /^(D|d)(A|a)(T|t)(E|e) *\( *\d{4} *, *(0?[1-9]|1[0-2]) *, *((0?[1-9]|[1-2]\d)|3(0|1)) *\)$/
  549. var regDatePromptHTML = /^ *\d{4} *- *(0?[1-9]|1[0-2]) *- *((0?[1-9]|[1-2]\d)|3(0|1)) *$/
  550. function ParseDatePrompt(inDate)
  551. {
  552. if ( regDatePrompt.test ( inDate ) )
  553. {
  554. var sDate = inDate.substr ( inDate.indexOf("(")+1 ); //move past "Date ("
  555. sDate = sDate.substr ( 0, sDate.lastIndexOf(")") ); //remove trailing ")"
  556. var dateArray = sDate.split (',');
  557. return new Date ( dateArray[0], Number(dateArray[1]) - 1, dateArray[2] );
  558. }
  559. if ( regDatePromptHTML.test ( inDate ) )
  560. {
  561. var pos = inDate.indexOf("-");
  562. var sYear = inDate.substr(0, pos);
  563. var sMonth = inDate.substr(pos + 1);
  564. pos = sMonth.indexOf("-");
  565. var sDay = sMonth.substr(pos + 1);
  566. sMonth = sMonth.substr(0, pos);
  567. return new Date ( sYear, Number(sMonth) - 1, sDay );
  568. }
  569. return new Date();
  570. }
  571. function ParseDate(inDate, bDateTimeFormat)
  572. {
  573. var result;
  574. if (bDateTimeFormat == true) {
  575. result = ParseDateTimePrompt(inDate);
  576. } else {
  577. result = ParseDatePrompt(inDate);
  578. }
  579. return result;
  580. }
  581. //---------------------------------------------------------------
  582. //for write the calendar in page.
  583. var INwidth = 230;
  584. var INheight = 250;//the size(default value)
  585. var INscreenX =0;
  586. var INscreenY =0;//the positon
  587. function INCreateCalendar(titleImagePath, closeImagePath)
  588. {
  589. if(document.getElementById("INIDcalendarWindow") == null)
  590. {
  591. var inlineCalendarWindow =
  592. "<div class=\"INcalendarWindow\" id=\"INIDcalendarWindow\" onmousedown=\"INnoClose()\"> " +
  593. "<iframe src=\"\" scroll=none frameborder=0 style=\"width:100%;height:100%;position:absolute;z-index:-9999\"></iframe> " +
  594. "<div class=\"INcalendarTitle\" onmousedown=\"dragStart(event,'INIDcalendarWindow')\"> " +
  595. "<table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" style=\"background:url(\'" + titleImagePath + "button_middle_normal.gif\');\"> " +
  596. "<tr> " +
  597. "<td class=\"INtitleText\">&nbsp;Business Objects</td> " +
  598. "<td class=\"INclose\" onclick=\"INcloseWin()\"><img alt=\"Close\" src=\"" + closeImagePath + "errormsg.gif\" height=\"12\" width=\"12\"/></td> " +
  599. "</tr> " +
  600. "</table> " +
  601. "</div> " +
  602. "<div class=\"INcalendarTop\" id=\"INIDcalendarTop\">&nbsp;</div> " +
  603. "<div class=\"INcalendarBottom\" id=\"INIDcalendarBottom\">&nbsp;</div> " +
  604. "</div>";
  605. if(document.body.insertAdjacentHTML)
  606. {
  607. document.body.insertAdjacentHTML("afterBegin", inlineCalendarWindow);
  608. }
  609. else
  610. {
  611. var calendarWindow = document.createElement("div");
  612. calendarWindow.innerHTML = inlineCalendarWindow;
  613. document.body.appendChild(calendarWindow);
  614. }
  615. }
  616. }
  617. function INwriteCalendar(event,Iwidth, Iheight,IscreenX,IscreenY)
  618. {
  619. INwidth = Iwidth;
  620. INheight = Iheight;
  621. //location and size
  622. document.getElementById("INIDcalendarWindow").style.width= INwidth;
  623. document.getElementById("INIDcalendarWindow").style.height= INheight;
  624. document.getElementById("INIDcalendarTop").innerHTML = calDocTop;
  625. document.getElementById("INIDcalendarBottom").innerHTML = calDocBottom;
  626. setPosition(event);
  627. document.getElementById("INIDcalendarWindow").style.display="block";
  628. }
  629. function INcloseWin()
  630. {
  631. var l=document.getElementById("INIDcalendarWindow")
  632. if (l) l.style.display="none";
  633. if(promptEngineOrigOnMouseDown) document.onmousedown = promptEngineOrigOnMouseDown;
  634. }
  635. function setPosition(e)
  636. {
  637. var calImage;
  638. if(e.target) {
  639. calImage = e.target;
  640. }
  641. else {
  642. calImage = e.srcElement;
  643. }
  644. var calImagePos = findPos(calImage);
  645. var windowX, windowY;
  646. var calendarWidth;
  647. var calendarHeight;
  648. if (isIE)
  649. {
  650. windowX = document.body.clientWidth + document.documentElement.scrollLeft
  651. + document.body.scrollLeft;
  652. windowY = document.body.clientHeight + document.documentElement.scrollTop
  653. + document.body.scrollTop;
  654. calendarWidth = 230;
  655. calendarHeight = 250;
  656. }
  657. if (isNav)
  658. {
  659. windowX = window.innerWidth + window.scrollX -15;//for firefox scroll bar
  660. windowY = window.innerHeight + window.scrollY;//left-right scroll bar usually do not has
  661. calendarWidth = 230 + 8;//for firefox.
  662. calendarHeight = 250 + 8;
  663. }
  664. var posX = calendarLeftOffsetFromImage + calImagePos.x;
  665. var posY = calendarTopOffsetFromImage + calImagePos.y;
  666. //location of the window
  667. //first, check the right bottom
  668. if( windowX-posX >= calendarWidth && windowY-posY >= calendarHeight)//right bottom
  669. {
  670. document.getElementById("INIDcalendarWindow").style.left= posX;
  671. document.getElementById("INIDcalendarWindow").style.top= posY;
  672. }
  673. else if(windowX-posX >= calendarWidth && windowY-posY < calendarHeight)//right bottom, move up
  674. {
  675. document.getElementById("INIDcalendarWindow").style.left= posX;
  676. document.getElementById("INIDcalendarWindow").style.top= windowY - calendarHeight;
  677. }
  678. else if(windowX-posX < calendarWidth && windowY-posY >= calendarHeight)//right bottom, move left
  679. {
  680. document.getElementById("INIDcalendarWindow").style.left= windowX - calendarWidth;
  681. document.getElementById("INIDcalendarWindow").style.top= posY;
  682. }
  683. //right bottom has no enough space. try to show it left bottom (right, bottom is not enough)
  684. else if(windowY > calendarHeight && posX - calendarLeftOffsetFromImage > calendarWidth)//left bottom(left enough)
  685. {
  686. document.getElementById("INIDcalendarWindow").style.left= posX - calendarLeftOffsetFromImage - calendarWidth;
  687. document.getElementById("INIDcalendarWindow").style.top= windowY - calendarHeight;
  688. }
  689. //left bottom has no enough space. try to show it top (left, right, bottom is not enough)
  690. else if(windowX > calendarWidth && posY - calendarTopOffsetFromImage >= calendarHeight)//right top
  691. {
  692. document.getElementById("INIDcalendarWindow").style.left= windowX - calendarWidth;
  693. document.getElementById("INIDcalendarWindow").style.top= posY - calendarTopOffsetFromImage - calendarHeight;
  694. }
  695. else//right bottom has no enough space. show it anyway
  696. {
  697. document.getElementById("INIDcalendarWindow").style.left= windowX - calendarWidth;//move left
  698. document.getElementById("INIDcalendarWindow").style.top= windowY - calendarHeight;//move up.
  699. }
  700. }
  701. function findPos(obj) {
  702. var offsetLeft = obj.offsetLeft;
  703. var offsetTop = obj.offsetTop;
  704. while(obj.offsetParent && (obj.offsetParent.style.position == '' || obj.offsetParent.style.position == 'fixed'))
  705. {
  706. obj = obj.offsetParent;
  707. offsetLeft += obj.offsetLeft;
  708. offsetTop += obj.offsetTop;
  709. }
  710. return { x : offsetLeft , y : offsetTop};
  711. }
  712. //--------------------------drag-functions--------------------------------
  713. var dragObject = new Object();
  714. dragObject.zIndex = 0;
  715. function dragStart(event, id)
  716. {
  717. var el;
  718. var x, y;
  719. if (id)//notice: the id must be set!!
  720. {
  721. dragObject.elNode = document.getElementById(id);
  722. }
  723. if (isIE) {
  724. x = window.event.clientX + document.documentElement.scrollLeft
  725. + document.body.scrollLeft;
  726. y = window.event.clientY + document.documentElement.scrollTop
  727. + document.body.scrollTop;
  728. }
  729. if (isNav) {
  730. x = event.clientX + window.scrollX;
  731. y = event.clientY + window.scrollY;
  732. }
  733. dragObject.cursorStartX = x;
  734. dragObject.cursorStartY = y;
  735. dragObject.elStartLeft = parseInt(dragObject.elNode.style.left, 10);
  736. dragObject.elStartTop = parseInt(dragObject.elNode.style.top, 10);
  737. if(isIE)
  738. {
  739. if (isNaN(dragObject.elStartLeft)) dragObject.elStartLeft = INscreenX + INwidth/2 + 20;//original position
  740. if (isNaN(dragObject.elStartTop)) dragObject.elStartTop = INscreenY - INheight + 20;//+20 make it look better
  741. }
  742. else
  743. {
  744. if (isNaN(dragObject.elStartLeft)) dragObject.elStartLeft = INscreenX;//original position
  745. if (isNaN(dragObject.elStartTop)) dragObject.elStartTop = INscreenY;// make it look better
  746. }
  747. dragObject.elNode.style.zIndex = ++dragObject.zIndex;
  748. if (isIE) {
  749. document.attachEvent("onmousemove", dragBegin);
  750. document.attachEvent("onmouseup", dragEnd);
  751. window.event.cancelBubble = true;
  752. window.event.returnValue = false;
  753. }
  754. if (isNav) {
  755. document.addEventListener("mousemove", dragBegin, true);
  756. document.addEventListener("mouseup", dragEnd, true);
  757. event.preventDefault();
  758. }
  759. }
  760. function dragBegin(event)//mouse move
  761. {
  762. var x, y;
  763. if (isIE) {
  764. x = window.event.clientX + document.documentElement.scrollLeft
  765. + document.body.scrollLeft;
  766. y = window.event.clientY + document.documentElement.scrollTop
  767. + document.body.scrollTop;
  768. }
  769. if (isNav) {
  770. x = event.clientX + window.scrollX;
  771. y = event.clientY + window.scrollY;
  772. }
  773. dragObject.elNode.style.left = (dragObject.elStartLeft + x - dragObject.cursorStartX) + "px";
  774. dragObject.elNode.style.top = (dragObject.elStartTop + y - dragObject.cursorStartY) + "px";//set the position
  775. if (isIE) {
  776. window.event.cancelBubble = true;
  777. window.event.returnValue = false;
  778. }
  779. if (isNav)
  780. event.preventDefault();
  781. }
  782. function dragEnd(event)//mouse stop
  783. {
  784. dragObject.elNode = null;
  785. if (isIE)
  786. {
  787. document.detachEvent("onmousemove", dragBegin);
  788. document.detachEvent("onmouseup", dragEnd);
  789. }
  790. if (isNav)
  791. {
  792. document.removeEventListener("mousemove", dragBegin, true);
  793. document.removeEventListener("mouseup", dragEnd, true);
  794. }
  795. }
  796. //----------for click close calendar---------------------------------------------------------------
  797. var CloseIt = true;
  798. function clickit()
  799. {
  800. if(CloseIt)
  801. {
  802. if(document.getElementById("INIDcalendarWindow")!= null)//should have the calendar div
  803. {
  804. INcloseWin();
  805. }
  806. }
  807. else
  808. {
  809. CloseIt = true;
  810. }
  811. }
  812. function INnoClose()
  813. {
  814. CloseIt = false;
  815. }
  816. //---for calendar onKey functions( if calendar year is onKey, the keypress functions should not be used in the document)----
  817. function INopenDocumentKey()
  818. {
  819. document.onkeydown = function(){return true;}
  820. }
  821. /* Crystal Decisions Confidential Proprietary Information */