1 | /**********************************************************************
|
---|
2 | * Calendar JavaScript [DOM] v3.11 by Michael Loesler *
|
---|
3 | ************************************************************************
|
---|
4 | * Copyright (C) 2005-09 by Michael Loesler, http//derletztekick.com *
|
---|
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 3 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, see <http://www.gnu.org/licenses/> *
|
---|
19 | * or write to the *
|
---|
20 | * Free Software Foundation, Inc., *
|
---|
21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
---|
22 | * *
|
---|
23 | **********************************************************************/
|
---|
24 | /*
|
---|
25 | function logout()
|
---|
26 | {
|
---|
27 | var xmlHttp = new XMLHttpRequest();
|
---|
28 | xmlHttp.open('POST', "calendar.php?logout=1", true);
|
---|
29 | xmlHttp.onload = function ()
|
---|
30 | {
|
---|
31 | if (xmlHttp.status!=200)
|
---|
32 | {
|
---|
33 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
34 | return;
|
---|
35 | }
|
---|
36 |
|
---|
37 | alert("Logout successful!");
|
---|
38 | };
|
---|
39 |
|
---|
40 | xmlHttp.send();
|
---|
41 | }
|
---|
42 | */
|
---|
43 | function resize()
|
---|
44 | {
|
---|
45 | var table = document.getElementById("table");
|
---|
46 |
|
---|
47 | var W = window.innerWidth;
|
---|
48 | var H = window.innerHeight;
|
---|
49 |
|
---|
50 | table.style.width =W+"px";
|
---|
51 | table.style.height=H+"px";
|
---|
52 | }
|
---|
53 |
|
---|
54 | var institutes= ["Shift", "Debug", "moon", "ETHZ", "ISDC", "TUDO", "UNIWUE" ];
|
---|
55 |
|
---|
56 | if (window.location.href.includes("ToO"))
|
---|
57 | {
|
---|
58 | // var institutes= [ "XMM-Mrk421", "INTEGRAL-Mrk421", "NuSTAR-Mrk421", "Swift-Mrk421", "XMM-Mrk501", "INTEGRAL-Mrk501", "NuSTAR-Mrk501", "Swift-Mrk501" ];
|
---|
59 | var institutes= [ "XMM", "INTEGRAL", "NuSTAR", "Swift", "ASTROSAT", "MAGIC" ];
|
---|
60 | document.title = "Visibilities for ToOs";
|
---|
61 | }
|
---|
62 |
|
---|
63 | function CalendarJS()
|
---|
64 | {
|
---|
65 | this.now = new Date();
|
---|
66 | this.dayname = ["Mo","Tu","We","Th","Fr","Sa","So"];
|
---|
67 | this.monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"];
|
---|
68 | this.tooltip = ["previous month","next month","current date","last year","next year"];
|
---|
69 | this.monthCell = document.createElement("th");
|
---|
70 | this.tableHead = null;
|
---|
71 | this.tableFoot = null;
|
---|
72 | this.parEl = null;
|
---|
73 |
|
---|
74 | this.init = function( id, initDate )
|
---|
75 | {
|
---|
76 | this.now = initDate ? initDate : new Date();
|
---|
77 | this.date = this.now.getDate();
|
---|
78 | this.month = this.mm = this.now.getMonth();
|
---|
79 | this.year = this.yy = this.now.getFullYear();
|
---|
80 | this.monthCell.appendChild(document.createTextNode( this.monthname[this.mm]+"\u00a0"+this.yy ));
|
---|
81 |
|
---|
82 | this.tableHead = this.createTableHead();
|
---|
83 | this.tableFoot = this.createTableFoot();
|
---|
84 |
|
---|
85 | this.parEl = document.getElementById( id );
|
---|
86 | this.show();
|
---|
87 |
|
---|
88 | if (!initDate)
|
---|
89 | this.checkDate();
|
---|
90 | };
|
---|
91 |
|
---|
92 | this.checkDate = function()
|
---|
93 | {
|
---|
94 | var self = this;
|
---|
95 | var today = new Date();
|
---|
96 |
|
---|
97 | if (this.date != today.getDate())
|
---|
98 | {
|
---|
99 | this.tableHead = this.createTableHead();
|
---|
100 | this.tableFoot = this.createTableFoot();
|
---|
101 |
|
---|
102 | this.date = today.getDate();
|
---|
103 | if (this.mm == this.month && this.yy == this.year)
|
---|
104 | this.switchMonth("current");
|
---|
105 |
|
---|
106 | this.month = today.getMonth();
|
---|
107 | if (this.mm == this.month && this.yy == this.year)
|
---|
108 | this.switchMonth("current");
|
---|
109 |
|
---|
110 | this.year = today.getFullYear();
|
---|
111 | if (this.mm == this.month && this.yy == this.year)
|
---|
112 | this.switchMonth("current");
|
---|
113 | }
|
---|
114 | window.setTimeout(function() { self.checkDate(); }, Math.abs(new Date(this.year, this.month, this.date, 24, 0, 0)-this.now));
|
---|
115 | },
|
---|
116 |
|
---|
117 | this.removeElements = function( Obj )
|
---|
118 | {
|
---|
119 | while( Obj.childNodes.length > 0)
|
---|
120 | Obj.removeChild(Obj.lastChild);
|
---|
121 |
|
---|
122 | return Obj;
|
---|
123 | };
|
---|
124 |
|
---|
125 | this.show = function()
|
---|
126 | {
|
---|
127 | this.parEl = this.removeElements( this.parEl );
|
---|
128 | this.monthCell.firstChild.replaceData(0, this.monthCell.firstChild.nodeValue.length, this.monthname[this.mm]+"\u00a0"+this.yy);
|
---|
129 |
|
---|
130 | var table = document.createElement("table");
|
---|
131 | table.id = "table";
|
---|
132 |
|
---|
133 | this.parEl.appendChild( table );
|
---|
134 |
|
---|
135 | table.appendChild( this.tableHead );
|
---|
136 | table.appendChild( this.tableFoot );
|
---|
137 |
|
---|
138 | table.appendChild( this.createTableBody(window.innerHeight-table.offsetHeight) );
|
---|
139 |
|
---|
140 | resize();
|
---|
141 | };
|
---|
142 |
|
---|
143 | this.createTableFoot = function()
|
---|
144 | {
|
---|
145 | var tfoot = document.createElement("tfoot");
|
---|
146 |
|
---|
147 | var tr = document.createElement("tr");
|
---|
148 | var td = document.createElement("td");
|
---|
149 | td.height = "1%";
|
---|
150 | td.colSpan = 7;
|
---|
151 | td.style.padding="3px 3px";
|
---|
152 | tfoot.appendChild(tr);
|
---|
153 | tr.appendChild(td);
|
---|
154 | var table = document.createElement("table");
|
---|
155 | table.width="100%";
|
---|
156 | td.appendChild(table);
|
---|
157 | tr = document.createElement("tr");
|
---|
158 | table.appendChild(tr);
|
---|
159 | for (var i=0; i<institutes.length; i++)
|
---|
160 | {
|
---|
161 | td = document.createElement("td");
|
---|
162 | td.width=100/institutes.length+"%";
|
---|
163 | td.setAttribute("style", "text-align:center;font-size:1em;border:solid #112A5D 2px;padding:3px 3px;");
|
---|
164 | td.changeUser = this.changeUser;
|
---|
165 | td.onclick = function(e) { this.changeUser(); }
|
---|
166 | td.appendChild(document.createTextNode(institutes[i]));
|
---|
167 | tr.appendChild(td);
|
---|
168 |
|
---|
169 | if (i==0)
|
---|
170 | td.style.backgroundColor = "yellow";
|
---|
171 | }
|
---|
172 | document.getElementById("body").setAttribute("data-user", institutes[0]);
|
---|
173 |
|
---|
174 |
|
---|
175 | tr = document.createElement("tr");
|
---|
176 | td = document.createElement("td");
|
---|
177 | td.colSpan = 7;
|
---|
178 | td.style.paddingLeft = "0px";
|
---|
179 | td.style.paddingTop = "0px";
|
---|
180 | td.height = "1%";
|
---|
181 | var form = document.createElement("form");
|
---|
182 | var input = document.createElement("textarea");
|
---|
183 | input.overflow = "auto";
|
---|
184 | input.wrap = "virtual";
|
---|
185 | input.id = "comment";
|
---|
186 | input.value = "enter comment here";
|
---|
187 | input.style.color = "#888";
|
---|
188 | input.style.width = "100%";
|
---|
189 | input.rows = 5;
|
---|
190 | input.title = "Enter a comment. Click somewhere in the calender to store the comment.";
|
---|
191 | input.onchange = function() { pushComment(); };
|
---|
192 | input.onfocus = function() { if (input.value=="enter comment here" && input.style.color!="black") input.value=""; input.style.color="black"; };
|
---|
193 | input.onblur = function() { input.style.color="#888"; if (input.value=="") input.value="enter comment here"; };
|
---|
194 | form.appendChild(input);
|
---|
195 | td.appendChild( form );
|
---|
196 | tr.appendChild( td );
|
---|
197 | tfoot.appendChild(tr);
|
---|
198 |
|
---|
199 | tr = document.createElement("tr");
|
---|
200 |
|
---|
201 | var td = document.createElement("td");
|
---|
202 | td.height="1%";
|
---|
203 | td.colSpan=7;
|
---|
204 | tr.appendChild(td);
|
---|
205 |
|
---|
206 | var tab = document.createElement("table");
|
---|
207 | var tr2 = document.createElement("tr");
|
---|
208 | tab.width="100%";
|
---|
209 | tab.cellSpacing=0;
|
---|
210 | tab.cellPadding=0;
|
---|
211 | tab.style.borderWidth = 0;
|
---|
212 | tab.style.fontSize = "1.5em";
|
---|
213 | tab.style.marginBottom = "2px";
|
---|
214 | td.appendChild(tab);
|
---|
215 | tab.appendChild(tr2);
|
---|
216 |
|
---|
217 | var tm = this.getCell( "td", this.timeTrigger(), "clock" );
|
---|
218 | tm.style.whiteSpace="nowrap";
|
---|
219 | tm.style.paddingLeft = "0px";
|
---|
220 | tm.style.width="33%";
|
---|
221 | tr2.appendChild( tm );
|
---|
222 |
|
---|
223 | var self = this;
|
---|
224 | window.setInterval(function() { tm.firstChild.nodeValue = self.timeTrigger(); }, 500);
|
---|
225 |
|
---|
226 | var td = document.createElement("td");
|
---|
227 | td.style.width="33%";
|
---|
228 | td.style.textAlign="center";
|
---|
229 | var a = document.createElement("a");
|
---|
230 | a.href = "overview.png";
|
---|
231 | a.style.whiteSpace="nowrap";
|
---|
232 | a.appendChild(document.createTextNode("click here for help"));
|
---|
233 | td.appendChild(a);
|
---|
234 | tr2.appendChild( td );
|
---|
235 |
|
---|
236 | td = this.getCell( "td", "logout", "logout");
|
---|
237 | td.style.width="33%";
|
---|
238 | td.onclick = function(e) { logout(); }
|
---|
239 | td.style.paddingRight = "0px";
|
---|
240 | tr2.appendChild( td );
|
---|
241 |
|
---|
242 | tfoot.appendChild( tr );
|
---|
243 |
|
---|
244 | return tfoot;
|
---|
245 | }
|
---|
246 |
|
---|
247 | this.createTableHead = function()
|
---|
248 | {
|
---|
249 | var thead = document.createElement("thead");
|
---|
250 | thead.style.height="1%";
|
---|
251 | var tr = document.createElement("tr");
|
---|
252 | var th = this.getCell( "th", "\u00AB", "prev_month" );
|
---|
253 |
|
---|
254 | th.rowSpan = 2;
|
---|
255 | th.Instanz = this;
|
---|
256 | th.onclick = function() { this.Instanz.switchMonth("prev"); };
|
---|
257 | th.title = this.tooltip[0];
|
---|
258 |
|
---|
259 | try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
|
---|
260 | tr.appendChild( th );
|
---|
261 |
|
---|
262 | this.monthCell.Instanz = this;
|
---|
263 | this.monthCell.rowSpan = 2;
|
---|
264 | this.monthCell.colSpan = 4;
|
---|
265 | this.monthCell.onclick = function() { this.Instanz.switchMonth("current"); };
|
---|
266 | this.monthCell.title = this.tooltip[2];
|
---|
267 |
|
---|
268 | try { this.monthCell.style.cursor = "pointer"; } catch(e){ this.monthCell.style.cursor = "hand"; }
|
---|
269 | tr.appendChild( this.monthCell );
|
---|
270 |
|
---|
271 | th = this.getCell( "th", "\u00BB", "next_month" );
|
---|
272 | th.rowSpan = 2;
|
---|
273 | th.Instanz = this;
|
---|
274 | th.onclick = function() { this.Instanz.switchMonth("next"); };
|
---|
275 | th.title = this.tooltip[1];
|
---|
276 |
|
---|
277 | try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
|
---|
278 | tr.appendChild( th );
|
---|
279 |
|
---|
280 | th = this.getCell( "th", "\u02c4", "prev_year" );
|
---|
281 | th.Instanz = this;
|
---|
282 | th.onclick = function() { this.Instanz.switchMonth("prev_year"); };
|
---|
283 | th.title = this.tooltip[3];
|
---|
284 |
|
---|
285 | try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
|
---|
286 | tr.appendChild( th );
|
---|
287 |
|
---|
288 | thead.appendChild( tr );
|
---|
289 |
|
---|
290 | tr = document.createElement("tr");
|
---|
291 | th = this.getCell( "th", "\u02c5", "next_year" );
|
---|
292 | th.Instanz = this;
|
---|
293 | th.onclick = function() { this.Instanz.switchMonth("next_year"); };
|
---|
294 | th.title = this.tooltip[4];
|
---|
295 |
|
---|
296 | try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
|
---|
297 | tr.appendChild( th );
|
---|
298 |
|
---|
299 | thead.appendChild( tr );
|
---|
300 |
|
---|
301 | tr = document.createElement('tr');
|
---|
302 | for (var i=0; i<this.dayname.length; i++)
|
---|
303 | {
|
---|
304 | var th = this.getCell("th", this.dayname[i], "weekday" );
|
---|
305 | th.width=100/7+"%";
|
---|
306 | tr.appendChild( th );
|
---|
307 | }
|
---|
308 |
|
---|
309 | thead.appendChild( tr );
|
---|
310 |
|
---|
311 | return thead;
|
---|
312 | },
|
---|
313 |
|
---|
314 | this.createTableBody = function(height)
|
---|
315 | {
|
---|
316 | var dayspermonth = [31,28,31,30,31,30,31,31,30,31,30,31];
|
---|
317 | var sevendaysaweek = 0;
|
---|
318 | var begin = new Date(this.yy, this.mm, 1);
|
---|
319 | var firstday = begin.getDay()-1;
|
---|
320 | if (firstday < 0)
|
---|
321 | firstday = 6;
|
---|
322 | if ((this.yy%4==0) && ((this.yy%100!=0) || (this.yy%400==0)))
|
---|
323 | dayspermonth[1] = 29;
|
---|
324 |
|
---|
325 | var tbody = document.createElement("tbody");
|
---|
326 | var tr = document.createElement('tr');
|
---|
327 |
|
---|
328 | tbody.height="100%";
|
---|
329 |
|
---|
330 | var height="";//"20%";//100/8+"%";
|
---|
331 |
|
---|
332 | if (firstday == 0)
|
---|
333 | {
|
---|
334 | for (var i=0; i<this.dayname.length; i++)
|
---|
335 | {
|
---|
336 | var prevMonth = (this.mm == 0)?11:this.mm-1;
|
---|
337 | var td = this.getCell( "td", dayspermonth[prevMonth]-6+i, "last_month" );
|
---|
338 | td.style.height=height;
|
---|
339 | tr.appendChild( td );
|
---|
340 | }
|
---|
341 | tbody.appendChild( tr );
|
---|
342 | tr = document.createElement('tr');
|
---|
343 | }
|
---|
344 |
|
---|
345 | for (var i=0; i<firstday; i++, sevendaysaweek++)
|
---|
346 | {
|
---|
347 | var prevMonth = (this.mm == 0)?11:this.mm-1;
|
---|
348 | var td = this.getCell( "td", dayspermonth[prevMonth]-firstday+i+1, "last_month" );
|
---|
349 | td.style.height=height;
|
---|
350 | tr.appendChild( td );
|
---|
351 | }
|
---|
352 |
|
---|
353 | for (var i=1; i<=dayspermonth[this.mm]; i++, sevendaysaweek++)
|
---|
354 | {
|
---|
355 | if (this.dayname.length == sevendaysaweek)
|
---|
356 | {
|
---|
357 | tbody.appendChild( tr );
|
---|
358 | tr = document.createElement('tr');
|
---|
359 | sevendaysaweek = 0;
|
---|
360 | }
|
---|
361 |
|
---|
362 | var td = null;
|
---|
363 | if (i==this.date && this.mm==this.month && this.yy==this.year && (sevendaysaweek == 5 || sevendaysaweek == 6))
|
---|
364 | td = this.getCell( "td", i, "today weekend" );
|
---|
365 | else
|
---|
366 | if (i==this.date && this.mm==this.month && this.yy==this.year)
|
---|
367 | td = this.getCell( "td", i, "today" );
|
---|
368 | else
|
---|
369 | if (sevendaysaweek == 5 || sevendaysaweek == 6)
|
---|
370 | td = this.getCell( "td", i, "weekend" );
|
---|
371 | else
|
---|
372 | td = this.getCell( "td", i, null);
|
---|
373 |
|
---|
374 | td.setDate = this.setDate;
|
---|
375 | td.chooseDate = this.chooseDate;
|
---|
376 | td.dd = i;
|
---|
377 | td.mm = this.mm;
|
---|
378 | td.yy = this.yy;
|
---|
379 | td.id = this.mm+"-"+i;
|
---|
380 | td.title = "Click to select this date.";
|
---|
381 |
|
---|
382 | td.style.height=height;
|
---|
383 |
|
---|
384 | td.onclick = function(e) {
|
---|
385 | this.chooseDate();
|
---|
386 | };
|
---|
387 |
|
---|
388 | var tab = document.createElement("table");
|
---|
389 | tab.width="100%";
|
---|
390 | tab.style.border = 0;
|
---|
391 | tab.style.padding = 0;
|
---|
392 | tab.style.margin = 0;
|
---|
393 | tab.style.fontSize = "1.5em";
|
---|
394 | tab.style.backgroundColor = "transparent";
|
---|
395 | var tr0 = document.createElement("tr");
|
---|
396 | var td0 = document.createElement("td");
|
---|
397 | var td1 = document.createElement("td");
|
---|
398 | td0.style.textAlign = "left";
|
---|
399 | td1.style.textAlign = "right";
|
---|
400 | td1.style.textWeight= "normal";
|
---|
401 | td0.style.color = "lightgray";
|
---|
402 | td0.style.border=0;
|
---|
403 | td1.style.border=0;
|
---|
404 | td0.style.padding=0;
|
---|
405 | td1.style.padding=0;
|
---|
406 | tab.appendChild(tr0);
|
---|
407 | tr0.appendChild(td0);
|
---|
408 | tr0.appendChild(td1);
|
---|
409 | //td0.appendChild(document.createTextNode(txt));
|
---|
410 |
|
---|
411 | td1.appendChild(td.firstChild);
|
---|
412 | td.appendChild(tab);
|
---|
413 |
|
---|
414 | var IP = this.getMoonPhase(this.yy, this.mm, i);
|
---|
415 | var str = this.getMoonPhaseStr(IP);
|
---|
416 | var phase = 100-Math.abs(IP-0.5)*200;
|
---|
417 | var txt = parseInt(phase+0.5,10)+"%";
|
---|
418 | if (phase>50)
|
---|
419 | td0.style.color = "gray";
|
---|
420 | if (phase<3.4)
|
---|
421 | {
|
---|
422 | txt = "o";
|
---|
423 | td0.style.textWeight = "bolder";
|
---|
424 | td0.style.fontSize = "0.7em";
|
---|
425 | td0.style.color = "darkgreen";
|
---|
426 | }
|
---|
427 | if (phase>96.6)
|
---|
428 | {
|
---|
429 | txt = "•";
|
---|
430 | td0.style.textWeight = "bolder";
|
---|
431 | td0.style.fontSize = "0.8em";
|
---|
432 | td0.style.color = "darkred";
|
---|
433 | }
|
---|
434 | tab.title = str;
|
---|
435 | td0.innerHTML = txt;
|
---|
436 |
|
---|
437 | var sp = document.createElement("span");
|
---|
438 | sp.appendChild(document.createTextNode("*"));
|
---|
439 | sp.style.color="darkred";
|
---|
440 | sp.style.display="none";
|
---|
441 | td1.appendChild(sp);
|
---|
442 |
|
---|
443 |
|
---|
444 | tr.appendChild( td );
|
---|
445 | }
|
---|
446 |
|
---|
447 | var daysNextMonth = 1;
|
---|
448 | for (var i=sevendaysaweek; i<this.dayname.length; i++)
|
---|
449 | tr.appendChild( this.getCell( "td", daysNextMonth++, "next_month" ) );
|
---|
450 |
|
---|
451 | tbody.appendChild( tr );
|
---|
452 |
|
---|
453 | while (tbody.getElementsByTagName("tr").length<6) {
|
---|
454 | tr = document.createElement('tr');
|
---|
455 | for (var i=0; i<this.dayname.length; i++)
|
---|
456 | {
|
---|
457 | var td = this.getCell( "td", daysNextMonth++, "next_month" );
|
---|
458 | td.style.height=height;
|
---|
459 | tr.appendChild( td );
|
---|
460 | }
|
---|
461 | tbody.appendChild( tr );
|
---|
462 | }
|
---|
463 |
|
---|
464 | requestAll(this.yy, this.mm);
|
---|
465 | requestAllComments(this.yy, this.mm);
|
---|
466 | if (this.year==this.yy && this.month==this.mm)
|
---|
467 | requestComment(this.year, this.month, this.date);
|
---|
468 | else
|
---|
469 | {
|
---|
470 | var c = document.getElementById("comment");
|
---|
471 | c.color="#888";
|
---|
472 | c.value="enter comment here";
|
---|
473 | }
|
---|
474 |
|
---|
475 | return tbody;
|
---|
476 | };
|
---|
477 |
|
---|
478 | this.getCalendarWeek = function(j,m,t)
|
---|
479 | {
|
---|
480 | var cwDate = this.now;
|
---|
481 | if (!t)
|
---|
482 | {
|
---|
483 | j = cwDate.getFullYear();
|
---|
484 | m = cwDate.getMonth();
|
---|
485 | t = cwDate.getDate();
|
---|
486 | }
|
---|
487 | cwDate = new Date(j,m,t);
|
---|
488 |
|
---|
489 | var doDat = new Date(cwDate.getTime() + (3-((cwDate.getDay()+6) % 7)) * 86400000);
|
---|
490 | cwYear = doDat.getFullYear();
|
---|
491 |
|
---|
492 | var doCW = new Date(new Date(cwYear,0,4).getTime() + (3-((new Date(cwYear,0,4).getDay()+6) % 7)) * 86400000);
|
---|
493 | cw = Math.floor(1.5+(doDat.getTime()-doCW.getTime())/86400000/7);
|
---|
494 | return cw;
|
---|
495 | };
|
---|
496 |
|
---|
497 | function request(td)
|
---|
498 | {
|
---|
499 | var user = document.getElementById("body").getAttribute("data-user");
|
---|
500 | var uri = "calendar.php?toggle&y="+td.yy+"&m="+td.mm+"&d="+td.dd;
|
---|
501 |
|
---|
502 | if (user!="Shift" && user!="Debug")
|
---|
503 | uri += "&u="+user;
|
---|
504 |
|
---|
505 | uri += "&x="+(user=="Debug"?1:0);
|
---|
506 |
|
---|
507 | var xmlHttp = new XMLHttpRequest();
|
---|
508 | xmlHttp.open('POST', uri, true);
|
---|
509 | xmlHttp.onload = function ()
|
---|
510 | {
|
---|
511 | if (xmlHttp.status!=200)
|
---|
512 | {
|
---|
513 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
514 | return;
|
---|
515 | }
|
---|
516 |
|
---|
517 | var lines = xmlHttp.responseText.split('\n');
|
---|
518 | if (lines.length==0)
|
---|
519 | return;
|
---|
520 |
|
---|
521 | while (td.childNodes.length>1)
|
---|
522 | td.removeChild(td.lastChild);
|
---|
523 |
|
---|
524 | for (var i=0; i<lines.length; i++)
|
---|
525 | {
|
---|
526 | var x = lines[i].split('\t');
|
---|
527 | if (x.length!=3)
|
---|
528 | continue;
|
---|
529 |
|
---|
530 | var div = document.createElement("div");
|
---|
531 | div.style.fontWeight="normal";
|
---|
532 | div.appendChild(document.createTextNode(x[2]=="1"?'('+x[1]+')':x[1]));
|
---|
533 | td.appendChild(div);
|
---|
534 |
|
---|
535 | for (var j=0; j<institutes.length; j++)
|
---|
536 | if (x[1]==institutes[j])
|
---|
537 | {
|
---|
538 | div.className += " institute";
|
---|
539 | break;
|
---|
540 | }
|
---|
541 | }
|
---|
542 |
|
---|
543 | if (td.childNodes.length>1)
|
---|
544 | td.className += " enabled";
|
---|
545 | else
|
---|
546 | td.className = td.className.replace(/enabled/g, "");
|
---|
547 | };
|
---|
548 |
|
---|
549 | xmlHttp.send();
|
---|
550 | }
|
---|
551 |
|
---|
552 | function logout()
|
---|
553 | {
|
---|
554 | var xmlHttp = new XMLHttpRequest();
|
---|
555 | xmlHttp.open('POST', "calendar.php?logout", true);
|
---|
556 | xmlHttp.onload = function ()
|
---|
557 | {
|
---|
558 | if (xmlHttp.status!=401)
|
---|
559 | {
|
---|
560 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
561 | return;
|
---|
562 | }
|
---|
563 |
|
---|
564 | alert(xmlHttp.statusText);
|
---|
565 | };
|
---|
566 |
|
---|
567 | xmlHttp.send();
|
---|
568 | }
|
---|
569 |
|
---|
570 | function pushComment()
|
---|
571 | {
|
---|
572 | var c = document.getElementById("comment");
|
---|
573 |
|
---|
574 | var y = c.getAttribute("data-y");
|
---|
575 | var m = c.getAttribute("data-m");
|
---|
576 | var d = c.getAttribute("data-d");
|
---|
577 | var v = c.value;
|
---|
578 |
|
---|
579 | var uri = "calendar.php?y="+y+"&m="+m+"&d="+d+"&c="+encodeURIComponent(v);
|
---|
580 |
|
---|
581 | var xmlHttp = new XMLHttpRequest();
|
---|
582 | xmlHttp.open('POST', uri, true);
|
---|
583 | xmlHttp.onload = function()
|
---|
584 | {
|
---|
585 | if (xmlHttp.status!=200)
|
---|
586 | {
|
---|
587 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
588 | return;
|
---|
589 | }
|
---|
590 |
|
---|
591 | alert("Comment inserted successfully.");
|
---|
592 |
|
---|
593 | var td = document.getElementById(m+"-"+d);
|
---|
594 | var sp = td.firstChild.firstChild.lastChild.lastChild;
|
---|
595 | if (v=="")
|
---|
596 | {
|
---|
597 | sp.style.display="none";
|
---|
598 | td.title="Click to select this date.";
|
---|
599 | }
|
---|
600 | else
|
---|
601 | {
|
---|
602 | sp.style.display="";
|
---|
603 | td.title=v;
|
---|
604 | }
|
---|
605 |
|
---|
606 | };
|
---|
607 |
|
---|
608 | xmlHttp.send();
|
---|
609 | }
|
---|
610 |
|
---|
611 | function requestComment(yy, mm, dd)
|
---|
612 | {
|
---|
613 | var c = document.getElementById("comment");
|
---|
614 |
|
---|
615 | var y = c.getAttribute("data-y");
|
---|
616 | var m = c.getAttribute("data-m");
|
---|
617 | var d = c.getAttribute("data-d");
|
---|
618 |
|
---|
619 | if (y==yy && m==mm && d==dd)
|
---|
620 | return;
|
---|
621 |
|
---|
622 | var uri = "calendar.php?comment&y="+yy+"&m="+mm+"&d="+dd;
|
---|
623 | var xmlHttp = new XMLHttpRequest();
|
---|
624 | xmlHttp.open('POST', uri, true);
|
---|
625 | xmlHttp.onload = function ()
|
---|
626 | {
|
---|
627 | if (xmlHttp.status!=200)
|
---|
628 | {
|
---|
629 | alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
|
---|
630 | return;
|
---|
631 | }
|
---|
632 |
|
---|
633 | var td = document.getElementById(mm+"-"+dd);
|
---|
634 | var sp = td.firstChild.firstChild.lastChild.lastChild;
|
---|
635 |
|
---|
636 | if (sp!=undefined)
|
---|
637 | {
|
---|
638 | c.color="#888";
|
---|
639 | if (xmlHttp.responseText=="")
|
---|
640 | {
|
---|
641 | c.value="enter comment here";
|
---|
642 | sp.style.display="none";
|
---|
643 | td.title="";
|
---|
644 | }
|
---|
645 | else
|
---|
646 | {
|
---|
647 | c.value = xmlHttp.responseText;
|
---|
648 | sp.style.display="";
|
---|
649 | td.title=xmlHttp.responseText;
|
---|
650 | }
|
---|
651 | }
|
---|
652 |
|
---|
653 | c.setAttribute("data-y", yy);
|
---|
654 | c.setAttribute("data-m", mm);
|
---|
655 | c.setAttribute("data-d", dd);
|
---|
656 | };
|
---|
657 |
|
---|
658 | xmlHttp.send();
|
---|
659 | }
|
---|
660 |
|
---|
661 | var xmlReqAll = null;
|
---|
662 | function requestAll(yy, mm)
|
---|
663 | {
|
---|
664 | if (xmlReqAll)
|
---|
665 | xmlReqAll.abort();
|
---|
666 |
|
---|
667 | var uri = "calendar.php?y="+yy+"&m="+mm;
|
---|
668 |
|
---|
669 | xmlReqAll = new XMLHttpRequest();
|
---|
670 | xmlReqAll.open('POST', uri, true);
|
---|
671 | xmlReqAll.onload = function ()
|
---|
672 | {
|
---|
673 | if (xmlReqAll.status!=200)
|
---|
674 | {
|
---|
675 | alert("ERROR - HTTP request: "+xmlReqAll.statusText+" ["+xmlReqAll.status+"]");
|
---|
676 | return;
|
---|
677 | }
|
---|
678 |
|
---|
679 | var lines = xmlReqAll.responseText.split('\n');
|
---|
680 | if (lines.length==0)
|
---|
681 | return;
|
---|
682 |
|
---|
683 | for (var i=0; i<lines.length; i++)
|
---|
684 | {
|
---|
685 | var x = lines[i].split('\t');
|
---|
686 | if (x.length!=3)
|
---|
687 | continue;
|
---|
688 |
|
---|
689 | var td = document.getElementById(mm+"-"+x[0]);
|
---|
690 |
|
---|
691 | var div = document.createElement("div");
|
---|
692 | div.style.fontWeight="normal";
|
---|
693 | div.appendChild(document.createTextNode(x[2]=="1"?'('+x[1]+')':x[1]));
|
---|
694 | td.appendChild(div);
|
---|
695 |
|
---|
696 | for (var j=0; j<institutes.length; j++)
|
---|
697 | if (x[1]==institutes[j])
|
---|
698 | {
|
---|
699 | div.className += " institute";
|
---|
700 | break;
|
---|
701 | }
|
---|
702 |
|
---|
703 | td.className += " enabled";
|
---|
704 | }
|
---|
705 | };
|
---|
706 |
|
---|
707 | xmlReqAll.send();
|
---|
708 | }
|
---|
709 |
|
---|
710 | var xmlReqCom = null;
|
---|
711 | function requestAllComments(yy, mm)
|
---|
712 | {
|
---|
713 | if (xmlReqCom)
|
---|
714 | xmlReqCom.abort();
|
---|
715 |
|
---|
716 | var uri = "calendar.php?comment&y="+yy+"&m="+mm;
|
---|
717 | xmlReqCom = new XMLHttpRequest();
|
---|
718 | xmlReqCom.open('POST', uri, true);
|
---|
719 | xmlReqCom.onload = function ()
|
---|
720 | {
|
---|
721 | if (xmlReqCom.status!=200)
|
---|
722 | {
|
---|
723 | alert("ERROR - HTTP request: "+xmlReqCom.statusText+" ["+xmlReqCom.status+"]");
|
---|
724 | return;
|
---|
725 | }
|
---|
726 |
|
---|
727 | if (xmlReqCom.responseText<4)
|
---|
728 | return;
|
---|
729 |
|
---|
730 | var pos = 6;
|
---|
731 |
|
---|
732 | while (pos<xmlReqCom.responseText.length)
|
---|
733 | {
|
---|
734 | var len = parseInt(xmlReqCom.responseText.substr(pos-6, 4), 10);
|
---|
735 | var dd = parseInt(xmlReqCom.responseText.substr(pos-2, 2), 10);
|
---|
736 | var com = xmlReqCom.responseText.substr(pos, len);
|
---|
737 | pos += len+6;
|
---|
738 |
|
---|
739 | if (com!="")
|
---|
740 | {
|
---|
741 | var td = document.getElementById(mm+"-"+dd);
|
---|
742 | var sp = td.firstChild.firstChild.lastChild.lastChild;
|
---|
743 | sp.style.display="";
|
---|
744 | td.title=com;
|
---|
745 | }
|
---|
746 | }
|
---|
747 | };
|
---|
748 |
|
---|
749 | xmlReqCom.send();
|
---|
750 | }
|
---|
751 |
|
---|
752 | this.setDate = function()
|
---|
753 | {
|
---|
754 | request(this);
|
---|
755 | };
|
---|
756 |
|
---|
757 | this.changeUser = function()
|
---|
758 | {
|
---|
759 | var sib = this.nextSibling;
|
---|
760 | while (sib)
|
---|
761 | {
|
---|
762 | sib.style.backgroundColor = "";
|
---|
763 | sib = sib.nextSibling;
|
---|
764 | }
|
---|
765 |
|
---|
766 | sib = this.previousSibling;
|
---|
767 | while (sib)
|
---|
768 | {
|
---|
769 | sib.style.backgroundColor = "";
|
---|
770 | sib = sib.previousSibling;
|
---|
771 | }
|
---|
772 |
|
---|
773 | this.style.backgroundColor = "yellow";
|
---|
774 |
|
---|
775 | document.getElementById("body").setAttribute("data-user", this.firstChild.textContent);
|
---|
776 | };
|
---|
777 |
|
---|
778 | this.chooseDate = function()
|
---|
779 | {
|
---|
780 | while (document.getElementsByClassName("choosen")[0])
|
---|
781 | {
|
---|
782 | var e = document.getElementsByClassName("choosen")[0];
|
---|
783 | e.title = "Click to select this date.";
|
---|
784 | e.className = e.className.replace(/choosen/g, "");
|
---|
785 | e.onclick = function() {
|
---|
786 | this.chooseDate();
|
---|
787 | };
|
---|
788 | }
|
---|
789 |
|
---|
790 | this.className += " choosen";
|
---|
791 | this.title = "Click again to add or remove your name.";
|
---|
792 |
|
---|
793 | requestComment(this.yy, this.mm, this.dd);
|
---|
794 |
|
---|
795 | this.onclick = function() {
|
---|
796 | this.setDate();
|
---|
797 | };
|
---|
798 | };
|
---|
799 |
|
---|
800 | this.timeTrigger = function()
|
---|
801 | {
|
---|
802 | var now = new Date();
|
---|
803 | var ss = (now.getSeconds()<10)?"0"+now.getSeconds():now.getSeconds();
|
---|
804 | var mm = (now.getMinutes()<10)?"0"+now.getMinutes():now.getMinutes();
|
---|
805 | var hh = (now.getHours() <10)?"0"+now.getHours() :now.getHours();
|
---|
806 |
|
---|
807 | var kw = "KW" + this.getCalendarWeek(this.year, this.month, this.date);
|
---|
808 | var str = hh+":"+mm+":"+ss+"\u00a0["+kw+"]";
|
---|
809 | return str;
|
---|
810 | };
|
---|
811 |
|
---|
812 | this.getCell = function(tag, str, cssClass)
|
---|
813 | {
|
---|
814 | var El = document.createElement( tag );
|
---|
815 | El.appendChild(document.createTextNode( str ));
|
---|
816 | if (cssClass != null)
|
---|
817 | El.className = cssClass;
|
---|
818 | return El;
|
---|
819 | },
|
---|
820 |
|
---|
821 | this.switchMonth = function( s )
|
---|
822 | {
|
---|
823 | switch (s)
|
---|
824 | {
|
---|
825 | case "prev":
|
---|
826 | this.yy = (this.mm == 0) ? this.yy-1 : this.yy;
|
---|
827 | this.mm = (this.mm == 0) ? 11 : this.mm-1;
|
---|
828 | break;
|
---|
829 |
|
---|
830 | case "next":
|
---|
831 | this.yy = (this.mm == 11) ? this.yy+1 : this.yy;
|
---|
832 | this.mm = (this.mm == 11) ? 0 : this.mm+1;
|
---|
833 | break;
|
---|
834 |
|
---|
835 | case "prev_year":
|
---|
836 | this.yy = this.yy-1;
|
---|
837 | break;
|
---|
838 |
|
---|
839 | case "next_year":
|
---|
840 | this.yy = this.yy+1;
|
---|
841 | break;
|
---|
842 |
|
---|
843 | case "current":
|
---|
844 | this.yy = this.year;
|
---|
845 | this.mm = this.month;
|
---|
846 | break;
|
---|
847 | }
|
---|
848 | this.show();
|
---|
849 | }
|
---|
850 |
|
---|
851 | this.getMoonPhase = function(Y, M, D)
|
---|
852 | {
|
---|
853 | // M=0..11 --> 1..12
|
---|
854 | M += 1;
|
---|
855 |
|
---|
856 | // calculate the Julian date at 12h UT
|
---|
857 | var YY = Y - Math.floor( ( 12 - M ) / 10 );
|
---|
858 | var MM = ( M + 9 ) % 12;
|
---|
859 |
|
---|
860 | var K1 = Math.floor( 365.25 * ( YY + 4712 ) );
|
---|
861 | var K2 = Math.floor( 30.6 * MM + 0.5 );
|
---|
862 | var K3 = Math.floor( Math.floor( ( YY / 100 ) + 49 ) * 0.75 ) - 38;
|
---|
863 |
|
---|
864 | var JD = K1 + K2 + D + 59; // for dates in Julian calendar
|
---|
865 | if ( JD > 2299160 ) // for Gregorian calendar
|
---|
866 | JD = JD - K3;
|
---|
867 |
|
---|
868 | // calculate moon's age in days
|
---|
869 | var IP = ( ( JD - 2451550.1 ) / 29.530588853 ) % 1;
|
---|
870 |
|
---|
871 | return IP;
|
---|
872 |
|
---|
873 | // Moon's age
|
---|
874 | //var AG = IP*29.53;
|
---|
875 | }
|
---|
876 |
|
---|
877 | this.getMoonPhaseStr = function(IP)
|
---|
878 | {
|
---|
879 | var phase = " ("+(100-Math.abs(IP-0.5)*200).toPrecision(2)+"%)";
|
---|
880 |
|
---|
881 | if (IP*16 < 1) return "New moon" + phase;
|
---|
882 | if (IP*16 < 3) return "Evening crescent" + phase;
|
---|
883 | if (IP*16 < 5) return "First quarter" + phase;
|
---|
884 | if (IP*16 < 7) return "Waxing gibbous" + phase;
|
---|
885 | if (IP*16 < 9) return "Full moon" + phase;
|
---|
886 | if (IP*16 <11) return "Waning gibbous" + phase;
|
---|
887 | if (IP*16 <13) return "Last quarter" + phase;
|
---|
888 | if (IP*16 <15) return "Morning crescent" + phase;
|
---|
889 |
|
---|
890 | return "New moon"+phase;
|
---|
891 | }
|
---|
892 | }
|
---|
893 |
|
---|
894 | var DOMContentLoaded = false;
|
---|
895 | function addContentLoadListener (func)
|
---|
896 | {
|
---|
897 | if (document.addEventListener)
|
---|
898 | {
|
---|
899 | var DOMContentLoadFunction = function ()
|
---|
900 | {
|
---|
901 | window.DOMContentLoaded = true;
|
---|
902 | func();
|
---|
903 | };
|
---|
904 |
|
---|
905 | document.addEventListener("DOMContentLoaded", DOMContentLoadFunction, false);
|
---|
906 | }
|
---|
907 |
|
---|
908 | var oldfunc = (window.onload || new Function());
|
---|
909 |
|
---|
910 | window.onload = function ()
|
---|
911 | {
|
---|
912 | if (!window.DOMContentLoaded)
|
---|
913 | {
|
---|
914 | oldfunc();
|
---|
915 | func();
|
---|
916 | }
|
---|
917 | };
|
---|
918 | }
|
---|
919 |
|
---|
920 | addContentLoadListener( function() {
|
---|
921 | new CalendarJS().init("calendar");
|
---|
922 | //new CalendarJS().init("calendar", new Date(2009, 1, 15));
|
---|
923 | } ); |
---|