calendar_xs.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Title: Tigra Calendar
  2. // URL: http://www.softcomplex.com/products/tigra_calendar/
  3. // Version: 3.2 (American date format)
  4. // Date: 10/14/2002 (mm/dd/yyyy)
  5. // Feedback: feedback@softcomplex.com (specify product title in the subject)
  6. // Note: Permission given to use this script in ANY kind of applications if
  7. // header lines are left unchanged.
  8. // Note: Script consists of two files: calendar?.js and calendar.html
  9. // About us: Our company provides offshore IT consulting services.
  10. // Contact us at sales@softcomplex.com if you have any programming task you
  11. // want to be handled by professionals. Our typical hourly rate is $20.
  12. // if two digit year input dates after this year considered 20 century.
  13. var NUM_CENTYEAR = 30;
  14. // is time input control required by default
  15. var BUL_TIMECOMPONENT = false;
  16. // are year scrolling buttons required by default
  17. var BUL_YEARSCROLL = true;
  18. var calendars = [];
  19. var RE_NUM = /^\-?\d+$/;
  20. function calendarXS(obj_target) {
  21. // assing methods
  22. this.gen_date = cal_gen_dateXS;
  23. this.gen_time = cal_gen_timeXS;
  24. this.gen_tsmp = cal_gen_tsmpXS;
  25. this.prs_date = cal_prs_dateXS;
  26. this.prs_time = cal_prs_timeXS;
  27. this.prs_tsmp = cal_prs_tsmpXS;
  28. this.popup = cal_popupXS;
  29. // validate input parameters
  30. if (!obj_target)
  31. return cal_error("Error calling the calendar: no target control specified");
  32. if (obj_target.value == null)
  33. return cal_error("Error calling the calendar: parameter specified is not valid tardet control");
  34. this.target = obj_target;
  35. this.time_comp = BUL_TIMECOMPONENT;
  36. this.year_scroll = BUL_YEARSCROLL;
  37. // register in global collections
  38. this.id = calendars.length;
  39. calendars[this.id] = this;
  40. }
  41. function cal_popupXS (str_datetime) {
  42. this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
  43. if (!this.dt_current) return;
  44. var obj_calwindow = window.open(
  45. '/esp/files_/calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
  46. 'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
  47. ',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
  48. );
  49. obj_calwindow.opener = window;
  50. obj_calwindow.focus();
  51. }
  52. // timestamp generating function
  53. function cal_gen_tsmpXS (dt_datetime) {
  54. return(this.gen_date(dt_datetime) + 'T' + this.gen_time(dt_datetime));
  55. }
  56. // date generating function
  57. function cal_gen_dateXS (dt_datetime) {
  58. return ( dt_datetime.getFullYear() + "-" + ( dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
  59. + (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate()
  60. );
  61. }
  62. // time generating function
  63. function cal_gen_timeXS (dt_datetime) {
  64. return (
  65. (dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
  66. + (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
  67. + (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
  68. );
  69. }
  70. // timestamp parsing function
  71. function cal_prs_tsmpXS (str_datetime) {
  72. // if no parameter specified return current timestamp
  73. if (!str_datetime)
  74. return (new Date());
  75. // if positive integer treat as milliseconds from epoch
  76. if (RE_NUM.exec(str_datetime))
  77. return new Date(str_datetime);
  78. // else treat as date in string format
  79. var arr_datetime = str_datetime.split(' ');
  80. return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
  81. }
  82. // date parsing function
  83. function cal_prs_dateXS (str_date) {
  84. var arr_date = str_date.split('-');
  85. if (arr_date.length != 3) return alert ("Invalid date format: '" + str_date + "'.\nFormat accepted is yyyy-mm-dd.");
  86. if (!arr_date[2]) return alert ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
  87. if (!RE_NUM.exec(arr_date[2])) return alert ("Invalid day of month value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");
  88. if (!arr_date[1]) return alert ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
  89. if (!RE_NUM.exec(arr_date[1])) return alert ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
  90. if (!arr_date[0]) return alert ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
  91. if (!RE_NUM.exec(arr_date[0])) return alert ("Invalid year value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
  92. var dt_date = new Date();
  93. dt_date.setDate(1);
  94. if (arr_date[1] < 1 || arr_date[1] > 12) return alert ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
  95. dt_date.setMonth(arr_date[1]-1);
  96. if (arr_date[0] < 100) arr_date[0] = Number(arr_date[0]) + (arr_date[0] < NUM_CENTYEAR ? 2000 : 1900);
  97. dt_date.setFullYear(arr_date[0]);
  98. var dt_numdays = new Date(arr_date[0], arr_date[1], 0);
  99. dt_date.setDate(arr_date[2]);
  100. if (dt_date.getMonth() != (arr_date[1]-1)) return alert ("Invalid day of month value: '" + arr_date[2] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");
  101. return (dt_date)
  102. }
  103. // time parsing function
  104. function cal_prs_timeXS (str_time, dt_date) {
  105. if (!dt_date) return null;
  106. var arr_time = String(str_time ? str_time : '').split(':');
  107. if (!arr_time[0]) dt_date.setHours(0);
  108. else if (RE_NUM.exec(arr_time[0]))
  109. if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
  110. else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
  111. else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
  112. if (!arr_time[1]) dt_date.setMinutes(0);
  113. else if (RE_NUM.exec(arr_time[1]))
  114. if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
  115. else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
  116. else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");
  117. if (!arr_time[2]) dt_date.setSeconds(0);
  118. else if (RE_NUM.exec(arr_time[2]))
  119. if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
  120. else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
  121. else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");
  122. dt_date.setMilliseconds(0);
  123. return dt_date;
  124. }
  125. function cal_error (str_message) {
  126. alert (str_message);
  127. return null;
  128. }
  129. function show_calendar(control_name)
  130. {
  131. var calx = new calendarXS(document.all.namedItem(control_name));
  132. calx.popup()
  133. }