/**********************************************************************
* Calendar JavaScript [DOM] v3.11 by Michael Loesler *
************************************************************************
* Copyright (C) 2005-09 by Michael Loesler, http//derletztekick.com *
* *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see *
* or write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
**********************************************************************/
/*
function logout()
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', "calendar.php?logout=1", true);
xmlHttp.onload = function ()
{
if (xmlHttp.status!=200)
{
alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
return;
}
alert("Logout successful!");
};
xmlHttp.send();
}
*/
function resize()
{
var table = document.getElementById("table");
var W = window.innerWidth;
var H = window.innerHeight;
table.style.width =W+"px";
table.style.height=H+"px";
}
var institutes= ["Shift", "Debug", "moon", "ETHZ", "ISDC", "TUDO", "UNIWUE" ];
function CalendarJS()
{
this.now = new Date();
this.dayname = ["Mo","Tu","We","Th","Fr","Sa","So"];
this.monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"];
this.tooltip = ["previous month","next month","current date","last year","next year"];
this.monthCell = document.createElement("th");
this.tableHead = null;
this.tableFoot = null;
this.parEl = null;
this.init = function( id, initDate )
{
this.now = initDate ? initDate : new Date();
this.date = this.now.getDate();
this.month = this.mm = this.now.getMonth();
this.year = this.yy = this.now.getFullYear();
this.monthCell.appendChild(document.createTextNode( this.monthname[this.mm]+"\u00a0"+this.yy ));
this.tableHead = this.createTableHead();
this.tableFoot = this.createTableFoot();
this.parEl = document.getElementById( id );
this.show();
if (!initDate)
this.checkDate();
};
this.checkDate = function()
{
var self = this;
var today = new Date();
if (this.date != today.getDate())
{
this.tableHead = this.createTableHead();
this.tableFoot = this.createTableFoot();
this.date = today.getDate();
if (this.mm == this.month && this.yy == this.year)
this.switchMonth("current");
this.month = today.getMonth();
if (this.mm == this.month && this.yy == this.year)
this.switchMonth("current");
this.year = today.getFullYear();
if (this.mm == this.month && this.yy == this.year)
this.switchMonth("current");
}
window.setTimeout(function() { self.checkDate(); }, Math.abs(new Date(this.year, this.month, this.date, 24, 0, 0)-this.now));
},
this.removeElements = function( Obj )
{
while( Obj.childNodes.length > 0)
Obj.removeChild(Obj.lastChild);
return Obj;
};
this.show = function()
{
this.parEl = this.removeElements( this.parEl );
this.monthCell.firstChild.replaceData(0, this.monthCell.firstChild.nodeValue.length, this.monthname[this.mm]+"\u00a0"+this.yy);
var table = document.createElement("table");
table.id = "table";
this.parEl.appendChild( table );
table.appendChild( this.tableHead );
table.appendChild( this.tableFoot );
table.appendChild( this.createTableBody(window.innerHeight-table.offsetHeight) );
resize();
};
this.createTableFoot = function()
{
var tfoot = document.createElement("tfoot");
var tr = document.createElement("tr");
var td = document.createElement("td");
td.height = "1%";
td.colSpan = 7;
td.style.padding="3px 3px";
tfoot.appendChild(tr);
tr.appendChild(td);
var table = document.createElement("table");
table.width="100%";
td.appendChild(table);
tr = document.createElement("tr");
table.appendChild(tr);
for (var i=0; i50)
td0.style.color = "gray";
if (phase<3.4)
{
txt = "o";
td0.style.textWeight = "bolder";
td0.style.fontSize = "0.7em";
td0.style.color = "darkgreen";
}
if (phase>96.6)
{
txt = "•";
td0.style.textWeight = "bolder";
td0.style.fontSize = "0.8em";
td0.style.color = "darkred";
}
tab.title = str;
td0.innerHTML = txt;
var sp = document.createElement("span");
sp.appendChild(document.createTextNode("*"));
sp.style.color="darkred";
sp.style.display="none";
td1.appendChild(sp);
tr.appendChild( td );
}
var daysNextMonth = 1;
for (var i=sevendaysaweek; i1)
td.removeChild(td.lastChild);
for (var i=0; i1)
td.className += " enabled";
else
td.className = td.className.replace(/enabled/g, "");
};
xmlHttp.send();
}
function logout()
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', "calendar.php?logout", true);
xmlHttp.onload = function ()
{
if (xmlHttp.status!=401)
{
alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
return;
}
alert(xmlHttp.statusText);
};
xmlHttp.send();
}
function pushComment()
{
var c = document.getElementById("comment");
var y = c.getAttribute("data-y");
var m = c.getAttribute("data-m");
var d = c.getAttribute("data-d");
var v = c.value;
var uri = "calendar.php?y="+y+"&m="+m+"&d="+d+"&c="+encodeURIComponent(v);
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', uri, true);
xmlHttp.onload = function()
{
if (xmlHttp.status!=200)
{
alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
return;
}
alert("Comment inserted successfully.");
var td = document.getElementById(m+"-"+d);
var sp = td.firstChild.firstChild.lastChild.lastChild;
if (v=="")
{
sp.style.display="none";
td.title="Click to select this date.";
}
else
{
sp.style.display="";
td.title=v;
}
};
xmlHttp.send();
}
function requestComment(yy, mm, dd)
{
var c = document.getElementById("comment");
var y = c.getAttribute("data-y");
var m = c.getAttribute("data-m");
var d = c.getAttribute("data-d");
if (y==yy && m==mm && d==dd)
return;
var uri = "calendar.php?comment&y="+yy+"&m="+mm+"&d="+dd;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', uri, true);
xmlHttp.onload = function ()
{
if (xmlHttp.status!=200)
{
alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
return;
}
var td = document.getElementById(mm+"-"+dd);
var sp = td.firstChild.firstChild.lastChild.lastChild;
if (sp!=undefined)
{
c.color="#888";
if (xmlHttp.responseText=="")
{
c.value="enter comment here";
sp.style.display="none";
td.title="";
}
else
{
c.value = xmlHttp.responseText;
sp.style.display="";
td.title=xmlHttp.responseText;
}
}
c.setAttribute("data-y", yy);
c.setAttribute("data-m", mm);
c.setAttribute("data-d", dd);
};
xmlHttp.send();
}
var xmlReqAll = null;
function requestAll(yy, mm)
{
if (xmlReqAll)
xmlReqAll.abort();
var uri = "calendar.php?y="+yy+"&m="+mm;
xmlReqAll = new XMLHttpRequest();
xmlReqAll.open('POST', uri, true);
xmlReqAll.onload = function ()
{
if (xmlReqAll.status!=200)
{
alert("ERROR - HTTP request: "+xmlReqAll.statusText+" ["+xmlReqAll.status+"]");
return;
}
var lines = xmlReqAll.responseText.split('\n');
if (lines.length==0)
return;
for (var i=0; i 1..12
M += 1;
// calculate the Julian date at 12h UT
var YY = Y - Math.floor( ( 12 - M ) / 10 );
var MM = ( M + 9 ) % 12;
var K1 = Math.floor( 365.25 * ( YY + 4712 ) );
var K2 = Math.floor( 30.6 * MM + 0.5 );
var K3 = Math.floor( Math.floor( ( YY / 100 ) + 49 ) * 0.75 ) - 38;
var JD = K1 + K2 + D + 59; // for dates in Julian calendar
if ( JD > 2299160 ) // for Gregorian calendar
JD = JD - K3;
// calculate moon's age in days
var IP = ( ( JD - 2451550.1 ) / 29.530588853 ) % 1;
return IP;
// Moon's age
//var AG = IP*29.53;
}
this.getMoonPhaseStr = function(IP)
{
var phase = " ("+(100-Math.abs(IP-0.5)*200).toPrecision(2)+"%)";
if (IP*16 < 1) return "New moon" + phase;
if (IP*16 < 3) return "Evening crescent" + phase;
if (IP*16 < 5) return "First quarter" + phase;
if (IP*16 < 7) return "Waxing gibbous" + phase;
if (IP*16 < 9) return "Full moon" + phase;
if (IP*16 <11) return "Waning gibbous" + phase;
if (IP*16 <13) return "Last quarter" + phase;
if (IP*16 <15) return "Morning crescent" + phase;
return "New moon"+phase;
}
}
var DOMContentLoaded = false;
function addContentLoadListener (func)
{
if (document.addEventListener)
{
var DOMContentLoadFunction = function ()
{
window.DOMContentLoaded = true;
func();
};
document.addEventListener("DOMContentLoaded", DOMContentLoadFunction, false);
}
var oldfunc = (window.onload || new Function());
window.onload = function ()
{
if (!window.DOMContentLoaded)
{
oldfunc();
func();
}
};
}
addContentLoadListener( function() {
new CalendarJS().init("calendar");
//new CalendarJS().init("calendar", new Date(2009, 1, 15));
} );