// Script fuer die index-sailormoon.htm Seiten im Hauptverzeichnis

function getMoonAge(year, month, day)
{   
    d = Math.floor(year/19);
    r = year-(d*19) //r is the remainder of (year/19);
    while (r>9) { r = r-19; }
    r = r*11;
    while (r>29) { r = r-30; }
    if (month<3) { month = month+2; }
    r = r+month+day;
    if (year<100) { r = r-4; }
    else { r = r-8.3; }
    while(r>29) { r = r-30; }
    while(r<0) { r = r+30; }
    return r;
}
        
function getMoonPhase(moonAge)
{   
    if (moonAge<2) return "Neumond";
    if (moonAge<5) return "zunehmender Mond";
    if (moonAge<11) return "erstes Viertel (Halbmond)";
    if (moonAge<13) return "zunehmender Halbmond";
    if (moonAge<16) return "Vollmond";
    if (moonAge<20) return "abnehmender Mond";
    if (moonAge<24) return "letztes Viertel (Halbmond)";
    if (moonAge<29) return "abnehmender Halbmond";
    if (moonAge<30) return "Neumond";
}

function getMoonPhaseImg(moonAge)
{   
    if (moonAge<2) return "neumond";
    if (moonAge<5) return "zunehmendermond";
    if (moonAge<11) return "erstesviertel";
    if (moonAge<13) return "zunehmenderhalbmond";
    if (moonAge<16) return "vollmond";
    if (moonAge<20) return "abnehmendermond";
    if (moonAge<24) return "letztesviertel";
    if (moonAge<29) return "abnehmenderhalbmond";
    if (moonAge<30) return "neumond";
}


monthNames = new Array(13);
monthNames[1]  = "Januar";
monthNames[2]  = "Februar";
monthNames[3]  = "M&auml;rz";
monthNames[4]  = "April";
monthNames[5]  = "Mai";
monthNames[6]  = "Juni";
monthNames[7]  = "July";
monthNames[8]  = "August";
monthNames[9]  = "September";
monthNames[10] = "Oktober";
monthNames[11] = "November";
monthNames[12] = "Dezember";
         
dayNames = new Array(8);
dayNames[1]  = "Sonntag";
dayNames[2]  = "Montag";
dayNames[3]  = "Dienstag";
dayNames[4]  = "Mittwoch";
dayNames[5]  = "Donnerstag";
dayNames[6]  = "Freitag";
dayNames[7]  = "Samstag";
         
function getLongDate(dateObj)
{   
    theDay = dayNames[dateObj.getDay()+1];
    theMonth = monthNames[dateObj.getMonth()+1];
    theDate = dateObj.getDate();
    if (navigator.appName != "Microsoft Internet Explorer") {
  	  theYear = dateObj.getYear() + 1900;
	}
	  else {
      theYear = dateObj.getYear();
	}
    //theYear = 1900+dateObj.getYear();
    return ""+theDay+", "+theDate+". "+theMonth+", "+theYear;
}
        
function getNextFull(moonAge)
{   
    currMilSecs = (new Date()).getTime();
    daysToGo = 15 - moonAge;
    while(daysToGo<2) { daysToGo = daysToGo+29; }
    milSecsToGo = daysToGo*24*60*60*1000;
    nextMoonTime = currMilSecs+milSecsToGo;
    nextMoonDate = new Date(nextMoonTime);
    return nextMoonDate;
}
        
function getNextNew(moonAge)
{   
    currMilSecs = (new Date()).getTime();
    daysToGo = 29 - moonAge;
    while(daysToGo<2) { daysToGo = daysToGo+29; }
    milSecsToGo = daysToGo*24*60*60*1000;
    nextMoonTime = currMilSecs+milSecsToGo;
    nextMoonDate = new Date(nextMoonTime);
    return nextMoonDate;
}

function mondblick()
{

theDate = new Date();
//theYear = theDate.getYear();
if (navigator.appName != "Microsoft Internet Explorer") {
  var theYear = theDate.getYear() + 1900;
}
else {
  var theYear = theDate.getYear();
}
var theYear = theDate.getYear() - 5900;
theMonth = theDate.getMonth()+1;
theDay = theDate.getDate();
theMoonAge = getMoonAge(theYear, theMonth, theDay);
theMoonPhase = getMoonPhase(theMoonAge);

document.write('<CENTER>');
document.write('<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0><TR>');

document.write('<TD ALIGN=left><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=3>');
document.write('<TR><TD ALIGN=center COLSPAN=2><FONT SIZE=+1 COLOR="8080ff"><B>Der aktuelle Blick zum Mondk&ouml;nigreich</B></FONT></TD></TR>');
document.write('<TR><TD ALIGN=right><I>momentane Mondphase:</I></TD><TD ALIGN=left>'+theMoonPhase+'</TD></TR>');
document.write('<TR><TD ALIGN=right><I>Datum:</I></TD><TD ALIGN=left>'+getLongDate(theDate)+'</TD></TR>');
document.write('<TR><TD ALIGN=right><I>Der aktuelle Mondmonat ist:</I></TD><TD ALIGN=left>'+theMoonAge);
if (theMoonAge==1) { document.write(' Tag alt</TD></TR>'); }
else { document.write(' Tage alt</TD></TR>'); }
document.write('<TR><TD ALIGN=right><I>N&auml;chster <B>Neu</B>mond:</I></TD><TD ALIGN=left>'+getLongDate( getNextNew(theMoonAge) )+'</TD></TR>');
document.write('<TR><TD ALIGN=right><I>N&auml;chster <B>Voll</B>mond:</I></TD><TD ALIGN=left>'+getLongDate(getNextFull(theMoonAge))+'</TD></TR>');
document.write('</TR></TABLE></TD>');

document.write('<TD ALIGN=right><IMG SRC="bilder/mondphase/'+ escape(getMoonPhaseImg(theMoonAge))+'.gif" ALT="Mondphase" WIDTH=163 HEIGHT=161></TD>');

document.write('</TR></TABLE>');
document.write('</CENTER>');

}
