calendar_tbl_change.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. var day;
  2. var month;
  3. var year;
  4. var hour;
  5. var minute;
  6. var second;
  7. var clock_set = 0;
  8. /**
  9. * Opens calendar window.
  10. *
  11. * @param string form name
  12. * @param string field name
  13. */
  14. function openCalendar(form, field) {
  15. window.open("./calendar_view.php", "calendar", "width=260,height=250,status=no");
  16. day = eval("document." + form + "." + field + "day.options["+ "document." + form + "." + field + "day.selectedIndex].value");
  17. month = eval("document." + form + "." + field + "month.options["+ "document." + form + "." + field + "month.selectedIndex].value");
  18. month = month-1;
  19. year = eval("document." + form + "." + field + "year.options["+ "document." + form + "." + field + "year.selectedIndex].value");
  20. formName = form;
  21. fieldName =field;
  22. }
  23. /**
  24. * Formats number to two digits.
  25. *
  26. * @param int number to format.
  27. */
  28. function formatNum2(i, valtype) {
  29. f = (i < 10 ? '0' : '') + i;
  30. if (valtype && valtype != '') {
  31. switch(valtype) {
  32. case 'month':
  33. f = (f > 12 ? 12 : f);
  34. break;
  35. case 'day':
  36. f = (f > 31 ? 31 : f);
  37. break;
  38. }
  39. }
  40. return f;
  41. }
  42. /**
  43. * Formats number to four digits.
  44. *
  45. * @param int number to format.
  46. */
  47. function formatNum4(i) {
  48. return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
  49. }
  50. /**
  51. * Initializes calendar window.
  52. */
  53. function initCalendar() {
  54. if (!year && !month && !day) {
  55. day = window.opener.day;
  56. month = window.opener.month;
  57. year = window.opener.year;
  58. if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
  59. dt = new Date();
  60. year = dt.getFullYear();
  61. month = dt.getMonth();
  62. day = dt.getDate();
  63. }
  64. } else {
  65. /* Moving in calendar */
  66. if (month > 11) {
  67. month = 0;
  68. year++;
  69. }
  70. if (month < 0) {
  71. month = 11;
  72. year--;
  73. }
  74. }
  75. if (document.getElementById) {
  76. cnt = document.getElementById("calendar_data");
  77. } else if (document.all) {
  78. cnt = document.all["calendar_data"];
  79. }
  80. cnt.innerHTML = "";
  81. str = ""
  82. //heading table
  83. str += '<table class="data_table"><tr><th class="monthyear" width="50%">';
  84. str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
  85. str += month_names[month];
  86. str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
  87. str += '</th><th class="monthyear" width="50%">';
  88. str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
  89. str += year;
  90. str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
  91. str += '</th></tr></table>';
  92. str += '<table class="data_table"><tr>';
  93. for (i = 0; i < 7; i++) {
  94. str += "<td class='weekdays'>" + day_names[i] + "</td>";
  95. }
  96. str += "</tr>";
  97. var firstDay = new Date(year, month, 1).getDay();
  98. var lastDay = new Date(year, month + 1, 0).getDate();
  99. str += "<tr>";
  100. dayInWeek = 0;
  101. for (i = 0; i < firstDay; i++) {
  102. str += "<td>&nbsp;</td>";
  103. dayInWeek++;
  104. }
  105. for (i = 1; i <= lastDay; i++) {
  106. if (dayInWeek == 7) {
  107. str += "</tr><tr>";
  108. dayInWeek = 0;
  109. }
  110. dispmonth = 1 + month;
  111. actVal = formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
  112. if (i == day) {
  113. style = ' class="selected"';
  114. } else {
  115. style = '';
  116. }
  117. str += "<td" + style + "><a href=\"javascript:returnDate(" + i +","+month+","+year + ");\">" + i + "</a></td>"
  118. dayInWeek++;
  119. }
  120. for (i = dayInWeek; i < 7; i++) {
  121. str += "<td>&nbsp;</td>";
  122. }
  123. str += "</tr></table>";
  124. cnt.innerHTML = str;
  125. }
  126. /**
  127. * Returns date from calendar.
  128. *
  129. * @param string date text
  130. */
  131. function returnDate(d,m,y) {
  132. cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"day.selectedIndex = "+(d-1);
  133. eval(cmd);
  134. cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"month.selectedIndex = "+m;
  135. eval(cmd);
  136. date = new Date();
  137. year = date.getFullYear()-1;
  138. cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"year.selectedIndex = "+(y-year);
  139. eval(cmd);
  140. window.close();
  141. }