calendar_js.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. + Calendar JS v2.0 +
  3. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. + Copyright (C) 2005 by Michael Loesler, http://www.derletztekick.de +
  5. + +
  6. + +
  7. + This program is free software; you can redistribute it and/or modify +
  8. + it under the terms of the GNU General Public License as published by +
  9. + the Free Software Foundation; either version 2 of the License, or +
  10. + (at your option) any later version. +
  11. + +
  12. + This program is distributed in the hope that it will be useful, +
  13. + but WITHOUT ANY WARRANTY; without even the implied warranty of +
  14. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
  15. + GNU General Public License for more details. +
  16. + +
  17. + You should have received a copy of the GNU General Public License +
  18. + along with this program; if not, write to the +
  19. + Free Software Foundation, Inc., +
  20. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +
  21. + +
  22. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  23. var now = new Date();
  24. var date = now.getDate();
  25. var month = now.getMonth();
  26. var year = now.getFullYear();
  27. function prevMonth(pd, pm, py, formelement){
  28. if (pm == 0){
  29. pm = 11;
  30. py -= 1;
  31. }
  32. else{
  33. pm -= 1;
  34. }
  35. getCalendar(pd, pm, py, formelement);
  36. }
  37. function nextMonth(nd, nm, ny, formelement){
  38. if (nm == 11){
  39. nm = 0;
  40. ny += 1;
  41. }
  42. else{
  43. nm += 1;
  44. }
  45. getCalendar(nd, nm, ny, formelement);
  46. }
  47. function CalOut(dd, mm, yy, formelement){
  48. if(dd < 10) dd = 0+""+dd;
  49. document.getElementsByName(formelement)[0].value = (dd) + "." + (mm+1) + "." + yy;
  50. document.getElementById("calendar").innerHTML = "";
  51. document.getElementById("calendar").style.display = "none";
  52. }
  53. function getCalendar(dd, mm, yy, formelement){
  54. var sevendaysaweek = 0;
  55. var begin = new Date(yy,mm,1);
  56. var firstday = begin.getDay()-1;
  57. if (firstday < 0){
  58. firstday = 6;
  59. }
  60. dayname = new Array("Mo","Di","Mi","Do","Fr","Sa","So");
  61. monthname = new Array("Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
  62. dayspermonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  63. if ((yy%4==0) && ((yy%100!=0) || (yy%400==0))){
  64. dayspermonth[1] = 29;
  65. }
  66. if ((mm != month) || (yy != year)){
  67. var today = '';
  68. }
  69. else {
  70. var today = date+'.';
  71. }
  72. var showcalendar = document.getElementById("calendar");
  73. for (var i=0; i<showcalendar.childNodes.length; i++){
  74. showcalendar.removeChild(showcalendar.childNodes[i]);
  75. }
  76. var newCalTable = document.createElement('table');
  77. newCalTable.setAttribute('id','caltable');
  78. var newCalTHead = document.createElement('thead');
  79. var newCalTBody = document.createElement('tbody');
  80. var newCalRow = document.createElement('tr');
  81. var newCalHead = document.createElement('th');
  82. newCalHead.setAttribute('class','select');
  83. newCalHead.setAttribute('title','vorheriger');
  84. newCalHead.appendChild(document.createTextNode("«"));
  85. newCalHead.style.cursor= ("hand"||"pointer")?"hand":"pointer";
  86. newCalHead.onclick=function () { prevMonth(dd, mm, yy, formelement); };
  87. newCalRow.appendChild(newCalHead);
  88. var newCalHead = document.createElement('th');
  89. newCalHead.setAttribute('colspan','5');
  90. newCalHead.colSpan = 5;
  91. newCalHead.appendChild(document.createTextNode(today+" "+monthname[mm]+" "+yy));
  92. newCalRow.appendChild(newCalHead);
  93. var newCalHead = document.createElement('th');
  94. newCalHead.setAttribute('class','select');
  95. newCalHead.setAttribute('title','nächster');
  96. newCalHead.appendChild(document.createTextNode("»"));
  97. newCalHead.style.cursor= ("hand"||"pointer")?"hand":"pointer";
  98. newCalHead.onclick=function () { nextMonth(dd, mm, yy, formelement); };
  99. newCalRow.appendChild(newCalHead);
  100. newCalTHead.appendChild(newCalRow);
  101. var newCalRow = document.createElement('tr');
  102. for (var i=0; i<dayname.length; i++){
  103. var newCalDayname = document.createElement('td');
  104. newCalDayname.setAttribute('class','days');
  105. newCalDayname.appendChild(document.createTextNode(dayname[i]));
  106. newCalRow.appendChild(newCalDayname);
  107. }
  108. newCalTBody.appendChild(newCalRow);
  109. var newCalRow = document.createElement('tr');
  110. for (var i=0; i<firstday; i++){
  111. var newCalDays = document.createElement('td');
  112. newCalDays.appendChild(document.createTextNode(String.fromCharCode(160)));
  113. newCalRow.appendChild(newCalDays);
  114. sevendaysaweek++;
  115. }
  116. var j=1;
  117. for (var i=1; i<=dayspermonth[mm]; i++){
  118. if (dayname.length == sevendaysaweek){
  119. newCalTBody.appendChild(newCalRow);
  120. var newCalRow = document.createElement('tr');
  121. var newCalDays = document.createElement('td');
  122. newCalDays.appendChild(document.createTextNode(i));
  123. newCalDays.onmouseout = function () {this.style.backgroundColor = "#FFFFFF";};
  124. newCalDays.onclick = function () { CalOut(this.innerHTML, mm, yy, formelement); };
  125. newCalDays.onmouseover = function () {this.style.backgroundColor = "#E8EEFF";};
  126. newCalDays.style.cursor= ("hand"||"pointer")?"hand":"pointer";
  127. newCalRow.appendChild(newCalDays);
  128. sevendaysaweek = 0;
  129. }
  130. else {
  131. var newCalDays = document.createElement('td');
  132. newCalDays.appendChild(document.createTextNode(i));
  133. newCalDays.onmouseout = function () {this.style.backgroundColor = "#FFFFFF";};
  134. newCalDays.onclick = function () { CalOut(this.innerHTML, mm, yy, formelement); };
  135. newCalDays.onmouseover = function () {this.style.backgroundColor = "#E8EEFF";};
  136. newCalDays.style.cursor= ("hand"||"pointer")?"hand":"pointer";
  137. newCalRow.appendChild(newCalDays);
  138. }
  139. sevendaysaweek++;
  140. j++;
  141. }
  142. for (var i=sevendaysaweek; i<dayname.length; i++){
  143. var newCalDays = document.createElement('td');
  144. newCalDays.appendChild(document.createTextNode(String.fromCharCode(160)));
  145. newCalRow.appendChild(newCalDays);
  146. }
  147. newCalTBody.appendChild(newCalRow);
  148. newCalTable.appendChild(newCalTHead);
  149. newCalTable.appendChild(newCalTBody);
  150. showcalendar.appendChild(newCalTable);
  151. }
  152. function startCalendar(obj, formelement, direction){
  153. document.getElementById("calendar").innerHTML = "";
  154. document.getElementById("calendar").style.display = "inline";
  155. var left = 0;
  156. var top = 0;
  157. var temp_obj = obj;
  158. while(temp_obj.tagName != "BODY"){
  159. if(temp_obj.tagName != ("TBODY" && "TR")){
  160. left = left + temp_obj.offsetLeft;
  161. top = top + temp_obj.offsetTop;
  162. }
  163. temp_obj = temp_obj.parentNode;
  164. }
  165. document.getElementById("calendar").style.left = left;
  166. document.getElementById("calendar").style.top = top;
  167. getCalendar(date, month, year, formelement);
  168. if(direction == 'up') document.getElementById("calendar").style.top = document.getElementById("calendar").offsetTop - document.getElementById("calendar").offsetHeight;
  169. if(direction == 'down') document.getElementById("calendar").style.top = document.getElementById("calendar").offsetTop + obj.offsetHeight;
  170. document.getElementById("calendar").style.left = document.getElementById("calendar").offsetLeft - document.getElementById("calendar").offsetWidth + obj.offsetWidth;
  171. //document.onclick = calendarStatus;
  172. calendarStatus;
  173. }
  174. function calendarStatus(){
  175. obj = event.srcElement;
  176. var ret = false;
  177. var temp_obj = obj;
  178. while(temp_obj.tagName != "BODY"){
  179. if(temp_obj.id == 'calendar' || temp_obj.name == 'calendar'){
  180. ret = true;
  181. break;
  182. }
  183. temp_obj = temp_obj.parentNode;
  184. }
  185. if(ret === false){
  186. document.getElementById("calendar").innerHTML = "";
  187. document.getElementById("calendar").style.display = "none";
  188. document.onclick = null;
  189. }
  190. return ret;
  191. }
  192. //window.onload=startCalendar;