<!-- copyright (c) 1998 Thomas Koehler. All rights reserved.
/**
* JN2(j,m+1) nicht fuer m=12
* Feb 4099 Mond
* Volkstrauertag 14.11.99
* 8.12.99 Mari„ Empf„ngnis
* 5.5. Europatag
*/


function div(a,b){
   var q=a/b;
   if (q<0)
      return Math.ceil(q); else
      return Math.floor(q);
   }


function ymdDate(y,m,d){   //  replaces the Date()-Obj 4 old Browsers
   this.y=y;
   this.m=m;
   this.d=d;
   var evt="";
   var hilite=-1;
   var start=-1;
   var explain="";
   this.DoM=Math.floor(d);
   this.hour=Math.floor( (d-this.DoM)*24 );
   this.min=Math.round( (d-this.DoM)*24*60-this.hour*60 );
   if (this.min==60){
      this.min=0; this.hour++;
      }  // don't care 4 midnite
   }


function sj(y){
var x=0;
   if ( (y<1583)&&(y%4==0) ) x=1;
   if ( (y>1582)&&(y%4==0)&&( (y%100!=0)||(y%400==0) ) ) x=1;
   return x;
   }


function wt(y,m,d){
/* 1986-1999 by Thomas K&ouml;hler. All rights reserved. */
   var w = y%28;
   w += Math.ceil(w/4);
   if ( (m==2)||(m==3)||(m==11) ) w+=3;
   if ( (m==4)||(m==7) ) w+=6;
   if ( m==5 ) w+=1;
   if ( m==6 ) w+=4;
   if ( m==8 ) w+=2;
   if ( (m==9)||(m==12) ) w+=5;
   if (m>2) w+=sj(y);
   if (y>1582){
      var y1=Math.floor((y-1)/100);  // ??
      w+=Math.floor(y1/4)+15-y1;
      }
   else w+=3;
/* julianisch */
   if ( (y<1582) || ((y==1582)&&(m<10)) ) w+=3;
   if ( (y==1582)&&(m==10)&&(d<15) ) w+=3;
/* \julianisch */
   w=(w+d+7004)%7; // 1 -> Mo, auch grosse Zahlen
   if (w==0) w=7;
   return(w);
   }  // wt


function maxTag(y,m){
   var mt=0;
   if (m<8){
      if (m%2==1) mt=31; else mt=30;
      }
   if (m>7){
      if (m%2==0) mt=31; else mt=30;
      }
   if (m==2) mt=28+sj(y);
   return(mt);
   }


function getJD(Y,M,D){
   var B=0;
   if (M<3) {Y--; M+=12;}
   if ( (Y>1582)||( (Y==1582)&&(M>10) )||( (Y==1582)&&(M==10)&&(D>14) ) ){
      var A=Math.floor(Y/100);
      B=2-A+Math.floor(A/4);
      }
   return(Math.floor(365.25*(Y+4716))+Math.floor(30.6001*(M+1))+D+B-1524.5);
   }


function parseDate(JD){
   var A,a;
   JD+=0.5;
   var Z=Math.floor(JD);
   var F=JD-Z;
   if (Z<2299161)
      A=Z;
   else{
      a=div( (Z-1867216.25),36524.25 );
      A=Z+1+a-div(a,4);
      }
   var B=A+1524;
   var C=div((B-122.1),365.25);
   var D=Math.floor(365.25*C);
   var E=Math.floor((B-D)/30.6001);
   var J_DoM=B-D-Math.floor(30.6001*E)+F;  //  real
   var J_Month=(E<14)? E-1 : E-13;
   var J_Year=(J_Month>2)? C-4716 : C-4715;
   return new ymdDate(J_Year,J_Month,J_DoM);
   } // parseDate


function relatDate(oldDate,diff){
   var x=getJD(oldDate.y,oldDate.m,oldDate.d);
   return parseDate(x+diff);
   }


function getDoWName(n){
   if (n==1) return "Mo"; else
   if (n==2) return "Di"; else
   if (n==3) return "Mi"; else
   if (n==4) return "Do"; else
   if (n==5) return "Fr"; else
   if (n==6) return "Sa"; else
   return "So";
   }


function getEasterDate(y,method){
// This algorithm is an arithmetic interpretation
// of the 3 step Easter Dating Method developed
// by Ron Mallen 1985, as a vast improvement on
// the method described in the Common Prayer Book
// Published Australian Almanac 1988
// Refer to this publication, or the Canberra Library
// for a clear understanding of the method used
// Because this algorithm is a direct translation of the
// official tables, it can be easily proved to be 100% correct
// It's free!  Please do not modify code or comments!
// Jan 3, 1999 converted in2 JavaScript by Thomas Koehler, www.thkoehler.de
var jh=Math.floor(y/100);  // first 2 digits of the year
var r19=y%19;       // remainder of the year/19
var m=3,d,ta,tb,tc,td,te,temp;  // ta..te = table A to E results
   if ( (method==1)||(method==2) ){
   /* calculate PFM date */
      ta=((225-11*r19)%30)+21;
   /* find the next Sunday */
      tb=(ta-19)%7;
      tc=(40-jh)%7;
      temp=y%100;
      td=(temp+Math.floor(temp/4))%7;
      te=((20-tb-tc-td)%7)+1;
      d=ta+te;
      if (method==2){ //convert Julian 2 Gregorian date
         temp=10;  //10 days were skipped in the Greg. calendar: oct 5..14, 1582
            // only 1 in every 4 century years R leap years in the Greg. calendar
            // every century is a leap year in the Jul. calendar
         if (y>1600) temp+=jh-16-Math.floor( (jh-16)/4 );
         d+=temp;
         }
      }
   else{
   /* calculate PFM date */
      temp=Math.floor( (jh-15)/2)+202-11*r19;
      if (jh>26) temp--;
      if (jh>38) temp--;
      if ((jh==21)||(jh==24)||(jh==25)||(jh==33)||(jh==36)||(jh==37)) temp--;
      temp%=30;
      ta=temp+21;
      if (temp==29) ta--;
      if ((temp==28)&&(r19>10)) ta--;
 /* find the next Sunday */
      tb=(ta-19)%7
      temp=(40-jh)%4;
      tc=temp;
      if (temp>1) tc++;
      if (temp==3) tc++;
      temp=y%100;
      td= ( temp+Math.floor(temp/4) )%7;
      te=( (20-tb-tc-td)%7 )+1;
      d=ta+te;
      }
 /* return the date */
   if (d>61) {d-=61; m=5;}    // when the original calc is converted in2 the
   if (d>31) {d-=31; m=4;}    // Greg. calendar, Easter sunday can occur in May
   return new ymdDate(y,m,d);
   }


function whichEaster(y){
   if (y>1582) return getEasterDate(y,3);
   else return getEasterDate(y,1);
   }


function twoDigs(x){
   x=Math.floor(x);
   if (x<10) return ("0"+x); else return x;
   }  // just positive


function getMonthName(mon){
   if (mon==1) return('Januar'); else
   if (mon==2) return('Februar'); else
   if (mon==3) return('M&auml;rz'); else
   if (mon==4) return('April'); else
   if (mon==5) return('Mai'); else
   if (mon==6) return('Juni'); else
   if (mon==7) return('Juli'); else
   if (mon==8) return('August'); else
   if (mon==9) return('September'); else
   if (mon==10) return('Oktober'); else
   if (mon==11) return('November'); else
   return('Dezember');
   }


function getJMoon(y,m,full){
   if (full==0) y+=(m-0.5)/12;  // NM
   if (full==2) y+=(m-1)/12;    // VM
   var k=0;
   if (full==0)  // NM
      k=Math.floor((y-2000)*12.3685);
   else if (full==2)  // VM
      k=Math.floor((y-2000)*12.3685)+0.5;
   var T=k/1236.85;
   var T2=T*T,T3=T2*T,T4=T2*T2;
   var JD=2451550.09765+29.530588853*k
       +0.0001337*T2
       -0.00000015*T3
       +0.00000000073*T4;
   var E=1-0.002516*T-0.0000074*T2;
   var M=(2.5534+29.10535669*k-0.0000218*T2-0.00000011*T3)%360;
   var M1=(201.5643+385.81693528*k+0.1017438*T2+0.00001239*T3-0.000000058*T4)%360;
   var F=(160.7108+390.67050274*k-0.0016341*T2-0.00000227*T3+0.000000011*T4)%360;
   var Z=(124.7746-1.5637558*k+0.0020691*T2+0.00000215*T3)%360;
   if (M<0) M+=360; if (M1<0) M1+=360; if (F<0) F+=360; if (Z<0) Z+=360;
   M=M/180*Math.PI; M1=M1/180*Math.PI; F=F/180*Math.PI; Z=Z/180*Math.PI;
   var korr=0;
   if (full==0){
      korr+= -0.4072*Math.sin(M1)
             +0.17241*E*Math.sin(M)
             +0.01608*Math.sin(2*M1)
             +0.01039*Math.sin(2*F)
             +0.00739*E*Math.sin(M1-M)
             -0.00514*E*Math.sin(M1+M)
             +0.00208*E*E*Math.sin(2*M)
             -0.00111*Math.sin(M1-2*F)
             -0.00057*Math.sin(M1+2*F);
             }
   if (full==2){
      korr+= -0.40614*Math.sin(M1)
             +0.17302*E*Math.sin(M)
             +0.01614*Math.sin(2*M1)
             +0.01043*Math.sin(2*F)
             +0.00734*E*Math.sin(M1-M)
             -0.00515*E*Math.sin(M1+M)
             +0.00209*E*E*Math.sin(2*M)
             -0.00111*Math.sin(M1-2*F)
             -0.00057*Math.sin(M1+2*F);
             }
   JD+=korr;
   var dT=0;
   if ( (y<1667)||(y>1950) ) dT=60/86400;
   JD-=dT;
   return (JD);
   }   // getJMoon


function cod(d){
   d%=360;
   if (d<0) d+=360;
   var g=d/180*Math.PI;
   return Math.cos(g);
   }


function as(y,t){
   var x= (y-2000)/1000;
   var JD0=0;
   if (t==1)
      JD0=2451623.80984+x*(365242.37404+x*(0.05169+x*(-0.00411-x*0.00057))); else
      if (t==2)
      JD0=2451716.56767+x*(365241.62603+x*(0.00325+x*(0.00888-x*0.0003))); else
      if (t==3)
      JD0=2451810.21715+x*(365242.01767+x*(-0.11575+x*(0.00337+x*0.00078))); else
      JD0=2451900.05952+x*(365242.74049+x*(-0.06223+x*(-0.00823+x*0.00032)));
   var T=(JD0-2451545)/36525;
   var W=35999.373*T-2.47;
   var dl=1+0.0334*cod(W)+0.0007*cod(2*W);
   var S=485*cod(324.96+1934.467*T); S+=203*cod(337.23+32964.467*T);
       S+=199*cod(342.08+20186*T);    S+=182*cod(27.85+445267.112*T);
       S+=156*cod(73.14+45036.886*T); S+=136*cod(171.52+22518.443*T);
       S+=77*cod(222.54+65928.934*T); S+=74*cod(296.72+3034.906*T);
       S+=70*cod(243.58+90037.513*T); S+=58*cod(119.81+33718.147*T);
       S+=52*cod(297.17+150.678*T);   S+=50*cod(21.02+2281.226*T);
       S+=45*cod(247.54+29929.562*T); S+=44*cod(325.15+31555.956*T);
       S+=29*cod(60.93+4443.417*T);   S+=18*cod(155.12+67555.328*T);
       S+=17*cod(288.79+4562.452*T);  S+=16*cod(198.04+62894.029*T);
       S+=14*cod(199.76+31436.921*T);
      JD0+=0.00001*S/dl;
   var dT=0;
   if ( (y<1667)||(y>1950) ) dT=60/86400;
   JD0-=dT;
   JD0+=2/1440;  // ??
   return parseDate(JD0);
   }

function moonDate(y,m,full,which){
   var N1Date=parseDate(getJMoon(y,m,full));
   if (N1Date.m!=m)
      N1Date=parseDate(getJMoon(y,m+0.5,full));
   var N2Date=parseDate(getJMoon(y,m+1,full));
   var V1Date=parseDate(getJMoon(y,m,2));
   if (V1Date.m!=m)
      V1Date=parseDate(getJMoon(y,m+0.5,2));
   var V2Date=parseDate(getJMoon(y, m+1,2));

   if (full==0){ // Neumond
      if ( (N1Date.m==m)&&(which==1) )
         return N1Date; else
         if ( (N2Date.m==m)&&(which==2)&&(N2Date.d!=N1Date.d) )
            return N2Date; else
            return new ymdDate(0,0,-99);
      }
   if (full==2){ // Vollmond
      if ( (V1Date.m==m)&&(which==1) )
         return V1Date; else
         if ( (V2Date.m==m)&&(which==2)&&(V2Date.d!=V1Date.d) )
            return V2Date; else
            return new ymdDate(0,0,-99);
      }
   }  // moonDate


function Fastnacht(y){return relatDate(whichEaster(y),-47);}
function Hifa(y){return relatDate(whichEaster(y),39);}
function Pfingsten(y){return relatDate(whichEaster(y),49);}
function FronLN(y){return relatDate(whichEaster(y),60);}
function MuTag(y){return new ymdDate(y,5,(15-wt(y,5,1)));}
function ErnteDF(y){return new ymdDate(y,10,(8-wt(y,10,1)));}
//function Adv1(y){return relatDate( new ymdDate(y,12,24),(-21-(wt(y,12,24)%7)) );}
function Adv1(y){return relatDate( new ymdDate(y,11,26),(7-(wt(y,11,26)%7)) );}
function ToSo(y){return relatDate(Adv1(y),-7);}
function BBTag(y){return relatDate(Adv1(y),-11);}
function SoZeit(y){return new ymdDate(y,3,31-(wt(y,3,31)%7));}
function WiZeitMon(y){return (y<1996)? 9 : 10;}
function WiZeit(y){
   var t=WiZeizMon(y);
   return new ymdDate(y,t,maxTag(y,t)-(wt(y,t,maxTag(y,t))%7));
   }


function today(){
   y=aky; anzYear=y;
   m=akm; anzMonth=m;
   d=akd; anzday=d;
   document.f.y.value=aky;
   document.f.m.value=akm;
   document.f.d.value=akd;
   }


function change(what,how){
   y=parseInt(document.f.y.value);
   m=parseInt(document.f.m.value);
   if (what==2){
      if (how==1){
         m++;
         if (m>12){y++; anzYear=y; m=1;}
         }
      if (how==-1){
         m--;
         if (m<1){y--; anzYear=y; m=12;}
         }
      anzMonth=m;
      }
   if (what==1){
      if (how==1) y++;
      if (y>4099) {y=4099; document.f.y.value=4099}
      if (how==-1) y--;
      anzYear=y;
      }
   document.f.y.value=y;
   document.f.m.value=m;
   }


var dat=new Date();
var aky = dat.getYear()%100;
aky += (aky>97? 1900 : 2000);
var akm = parseInt(dat.getMonth()+1);
var akd = dat.getDate();
var y=parseInt(window.prompt("Welches Jahr anzeigen?",aky));
var m=parseInt(window.prompt("Welchen Monat anzeigen?",akm));
var temp0=1;
if (akm==m) temp0=akd;
var d=parseInt(window.prompt("und der Tag?",temp0));
if (m>12) m=12;
if (m<1) m=1;
if (y>4099) y=4099;
temp0=maxTag(y,m); if (d>temp0) d=temp0;

if (m>12) {m=12; document.f.m.value=12;}
if (m<1) {m=1; document.f.m.value=1;}
if (y>4099) {y=4099; document.f.y.value=4099;}
if (d<1) {d=1; document.f.d.value=1;}

var temp0=maxTag(y,m);
if (d>temp0) {d=temp0; document.f.d.value=temp0;}

var anzYear=y,anzMonth=m,anzDay=d;

var StrN1="x";StrN2="x";StrV1="x";StrV2="x";

   var N1Date= moonDate(y,m,0,1);
   if (N1Date.m==m)
      StrN1=""+twoDigs(N1Date.DoM)+". "+getMonthName(m)+" "+y+"&nbsp;&nbsp;"+twoDigs(N1Date.hour)+":"+twoDigs(N1Date.min)+" UT";
   var N2Date= moonDate(y,m,0,2);
   if (N2Date.m==m)
      StrN2=""+twoDigs(N2Date.DoM)+". "+getMonthName(m)+" "+y+"&nbsp;&nbsp;"+twoDigs(N2Date.hour)+":"+twoDigs(N2Date.min)+" UT";
   var V1Date= moonDate(y,m,2,1);
   if (V1Date.m==m)
      StrV1=""+twoDigs(V1Date.DoM)+". "+getMonthName(m)+" "+y+"&nbsp;&nbsp;"+twoDigs(V1Date.hour)+":"+twoDigs(V1Date.min)+" UT";
   var V2Date= moonDate(y,m,2,2);
   if (V2Date.m==m)
      StrV2=""+twoDigs(V2Date.DoM)+". "+getMonthName(m)+" "+y+"&nbsp;&nbsp;"+twoDigs(V2Date.hour)+":"+twoDigs(V2Date.min)+" UT";

var anzOst=whichEaster(y);
var anzAdv=Adv1(y);

var hiDate=new Array();  // all years hilites

hiDate[1] =new ymdDate(y,1,1); hiDate[1].evt="Neujahr";
   hiDate[1].start=1;
hiDate[2] =new ymdDate(y,1,6);  hiDate[2].evt="Heilige Drei K&ouml;nige";
   hiDate[2].hilite=1; // print just bold
   hiDate[2].explain="Feiertag in Baden-W., Bayern, Sachsen-Anhalt";
hiDate[3] =new ymdDate(y,2,14); hiDate[3].evt="Valentinstag";
   hiDate[3].hilite=0; // hilite off
hiDate[4] =relatDate(anzOst,-48);hiDate[4].evt="Rosenmontag";
   hiDate[4].hilite=0;
hiDate[5] =relatDate(anzOst,-47);hiDate[5].evt="Fastnacht";
   hiDate[5].hilite=0;
hiDate[6] =relatDate(anzOst,-46);hiDate[6].evt="Aschermittwoch";
   hiDate[6].hilite=0;
hiDate[7] =new ymdDate(y,3,31-(wt(y,3,31)%7)); hiDate[7].evt="Sommerzeitumstellung";
   hiDate[7].start=1985; //??
hiDate[8] =relatDate(anzOst,-2); hiDate[8].evt="Karfreitag";
hiDate[9] =anzOst; hiDate[9].evt="Ostersonntag";
hiDate[10] =relatDate(anzOst,1); hiDate[10].evt="Ostermontag";
hiDate[11] =new ymdDate(y,5,1); hiDate[11].evt="Maifeiertag";
hiDate[12] =relatDate(new ymdDate(y,5,1),(14-wt(y,5,1))); hiDate[12].evt="Muttertag";
   hiDate[12].start=1914;
hiDate[13] =relatDate(anzOst,39); hiDate[13].evt="Christi Himmelfahrt";
hiDate[14] =relatDate(anzOst,49); hiDate[14].evt="Pfingstsonntag";
hiDate[15] =relatDate(anzOst,50); hiDate[15].evt="Pfingstmontag";
hiDate[16] =relatDate(anzOst,60); hiDate[16].evt="Fronleichnam";
   hiDate[16].hilite=1; hiDate[16].start=1246;
   hiDate[16].explain="Feiertag in Baden-W., Bayern, Hessen, Nordrhein-W. "
   +"Rheinland-Pf.; in Sachsen, Th&uuml;ringen in kathol. Regionen";
hiDate[17]=new ymdDate(y,8,15); hiDate[17].evt="Mari&auml; Himmelfahrt";
   hiDate[17].hilite=1;
   hiDate[17].explain="Feiertag in Bayern (kathol. Regionen), Saarland";
hiDate[18]=new ymdDate(y,10,3); hiDate[18].evt="Nationalfeiertag";
   hiDate[18].start=1990;
hiDate[19]= new ymdDate(y,10,(8-wt(y,10,1))); hiDate[19].evt="Erntedankfest";
   hiDate[19].start=1770;
hiDate[20]=new ymdDate(y,WiZeitMon(y),maxTag(y,WiZeitMon(y))-(wt(y,WiZeitMon(y),maxTag(y,WiZeitMon(y)))%7));  hiDate[20].evt="Winterzeitumstellung";
   hiDate[20].start=1985;  //  ??
hiDate[21]=new ymdDate(y,10,31); hiDate[21].evt="Reformationstag";
   hiDate[21].hilite=1; hiDate[21].start=1517;
   hiDate[21].explain="Feiertag in Brandenburg, Mecklenburg-V., Sachsen, Sachsen-A., Th&uuml;ringen";
hiDate[22]=new ymdDate(y,11,1);  hiDate[22].evt="Allerheiligen";
   hiDate[22].hilite=1;
   hiDate[22].explain="Feiertag in Baden-W., Bayern, Nordrhein-W., Rheinland-Pf., Saarland";
hiDate[23] =relatDate(anzAdv,-11);  hiDate[23].evt="Bu&szlig;- und Bettag";
   hiDate[23].hilite=1; hiDate[23].start=1853;
   hiDate[23].explain="Feiertag in Sachsen";
hiDate[24] =relatDate(anzAdv,-14); hiDate[24].evt="Volkstrauertag";
   hiDate[24].start=1990; //??
hiDate[25] =relatDate(anzAdv,-7); hiDate[25].evt="Totensonntag";
hiDate[26]= anzAdv; hiDate[26].evt="Erster Advent";
   hiDate[26].start=826;
hiDate[27]=new ymdDate(y,12,6); hiDate[27].evt="Nikolaus";
   hiDate[27].hilite=0;
hiDate[28]=new ymdDate(y,12,25); hiDate[28].evt="Erster Weihnachtstag";
   hiDate[28].start=1;
hiDate[29]=new ymdDate(y,12,26); hiDate[29].evt="Zweiter Weihnachtstag";
   hiDate[29].start=1;
hiDate[30]=new ymdDate(y,12,31); hiDate[30].evt="Silvester";
     hiDate[30].hilite=0; hiDate[29].start=1;
hiDate[31]=as(y,1); hiDate[31].evt="Fr&uuml;hlingsanfang";
   hiDate[31].hilite=0; hiDate[31].start=1;
hiDate[32]=as(y,2); hiDate[32].evt="Sommeranfang";
   hiDate[32].hilite=0; hiDate[32].start=1;
hiDate[33]=as(y,3); hiDate[33].evt="Herbstanfang";
   hiDate[33].hilite=0; hiDate[33].start=1;
hiDate[34]=as(y,4); hiDate[34].evt="Winteranfang";
   hiDate[34].hilite=0; hiDate[34].start=1;
/*
hiDate[35] =new ymdDate(y,4,3);
hiDate[35].evt="<FONT size='-1'><A href='mailto:webmaster@thkoehler.de'>Geburtstag des Programmierers</A></FONT>";
   hiDate[35].hilite=0;
*/
var maxhiDate=hiDate.length-1;

for (i=1; i<=maxhiDate; i++){
   if (hiDate[i].start==null) hiDate[i].start=326; // the easter default
   if (hiDate[i].start<=y){
      if (hiDate[i].hilite==null)  hiDate[i].hilite=2;  // default
      }
   else hiDate[i].hilite=0;
   }

/** sorting the dates **/
   var temp;
   for (i=1; i<maxhiDate; i++)
   for (k=1; k<=maxhiDate-i; k++){
      if ( hiDate[k].m*100+hiDate[k].d > hiDate[k+1].m*100+hiDate[k+1].d ){
         temp=hiDate[k+1];
         hiDate[k+1]=hiDate[k];
         hiDate[k]=temp;
         }
      }

                 /******** --- now writing tables --- ********/


document.write("<CENTER>");

document.write("<table cellspacing=0 cellpadding=3 bgcolor='#C5D0C5'><tr><td valign='top'>");
document.write("<TABLE border cellspacing=1 cellpadding=3 bgcolor='#C0D0C0'>");
document.write("<TR bgcolor='#FFA050'><TD colspan=7><FONT size=2><I><B>",getMonthName(m)," ",(y<1)?(twoDigs(1-y)+" vor Chr."):(y<100)?("00"+twoDigs(y)):y,"</B></I></FONT></TD></TR>");
document.write("<TR bgcolor='#A0D050'><TH width='35'><I>Mo</TH><TH width='35'><I>Di</TH><TH width='35'><I>Mi</TH><TH width='35'><I>Do</TH><TH width='35'><I>Fr</TH><TH width='35'><I>Sa</TH><TH width='35'><font color='red'><I>So</TH></TR><TR>");

maxI=Math.ceil( (maxTag(y,m)+wt(y,m,1)-1)/7 )*7+1;

w1=2-wt(y,m,1); //   w1==1 on the i-th position

var VDay1=moonDate(y,m,2,1).DoM;
var VDay2=moonDate(y,m,2,2).DoM;
var NDay1=moonDate(y,m,0,1).DoM;
var NDay2=moonDate(y,m,0,2).DoM;

for (i=1; i<maxI; i++){
   if ( (y==1582)&&(m==10)&&( (w1>4)&&(w1<15) ) ) w1+=10;
   document.write("<TD align='right'",(w1==d)? "bgcolor='#D0D0FF'>" : ">");
   document.write("<FONT face='Trebuchet MS,Arial,Helvetica' size=-1>");
   if (i%7==0) document.write("<FONT color='#FF0000'>");
   for (j=1; j<=maxhiDate; j++)
      if ( (hiDate[j].m==m)&&(Math.floor(hiDate[j].d)==w1)&&(i%7!=0) ){
         if (hiDate[j].hilite==2) document.write("<FONT color='#FF0000'>"); else
         if (hiDate[j].hilite==1) document.write("<B>");
         }
   if ( (w1==VDay1)||(w1==VDay2) ) document.write("<IMG src='../img/vm.gif'>&nbsp;");
   if ( (w1==NDay1)||(w1==NDay2) ) document.write("<IMG src='../img/nm.gif'>&nbsp;");
   if ( (w1>0)&&(w1<=maxTag(y,m)) )
      document.write(w1);  else
      document.write("&nbsp;");
   document.write("</FONT></TD>");
   w1++;
   if (i%7==0) document.write("</TR><TR>");
   }

document.write("</TR></TABLE>");


                /** --- Folgemonat --- **/


document.write("</td><td valign='top'>");

m+=1; if (m>12){m=1; y++;}
w1=2-wt(y,m,1);

var fVDay1=moonDate(y,m,2,1).DoM;
var fVDay2=moonDate(y,m,2,2).DoM;
var fNDay1=moonDate(y,m,0,1).DoM;
var fNDay2=moonDate(y,m,0,2).DoM;

document.write("<TABLE border cellspacing=1 cellpadding=3 bgcolor='#C0D0C0'>");
document.write("<TR bgcolor='#A0A0A0'><TD colspan=7><FONT size=2><I><B>",getMonthName(m)," ",(y<1)?(twoDigs(1-y)+" vor Chr."):(y<100)?("00"+twoDigs(y)):y,"</B></I></FONT></TD></TR>");
document.write("<TR bgcolor='#A0D050'><TH width='35'><I>Mo</TH><TH width='35'><I>Di</TH><TH width='35'><I>Mi</TH><TH width='35'><I>Do</TH><TH width='35'><I>Fr</TH><TH width='35'><I>Sa</TH><TH width='35'><font color='red'><I>So</TH></TR><TR>");

maxI=Math.ceil( (maxTag(y,m)+wt(y,m,1)-1)/7 )*7+1;

for (i=1; i<maxI; i++){
   if ( (y==1582)&&(m==10)&&( (w1>4)&&(w1<15) ) ) w1+=10;
   document.write("<TD align='right'>");
   document.write("<FONT face='Trebuchet MS,Arial,Helvetica' size=-1>");
   if (i%7==0) document.write("<FONT color='#FF0000'>");
   for (j=1; j<=maxhiDate; j++)
      if ( (hiDate[j].m==m)&&(Math.floor(hiDate[j].d)==w1)&&(i%7!=0) ){
         if (hiDate[j].hilite==2) document.write("<FONT color='#FF0000'>"); else
         if (hiDate[j].hilite==1) document.write("<B>");
         }
   if ( (w1==fVDay1)||(w1==fVDay2) ) document.write("<IMG src='../img/vm.gif'>&nbsp;");
   if ( (w1==fNDay1)||(w1==fNDay2) ) document.write("<IMG src='../img/nm.gif'>&nbsp;");

   if ( (w1>0)&&(w1<=maxTag(y,m)) )
      document.write(w1);  else
      document.write("&nbsp;");
   document.write("</FONT></TD>");
   w1++;
   if (i%7==0) document.write("</TR><TR>");
   }

document.write("</TR></TABLE>");


                 /******** --- end of Mtables --- ********/


document.write("</td></tr><tr><td valign='top'>");

for (j=1;j<=maxhiDate;j++){
   var hr=hiDate[j].hour; var mn=hiDate[j].min;
   if ((hiDate[j].m==anzMonth)&&(y>=hiDate[j].start)){
      document.write(hiDate[j].DoM+"."+anzMonth+". "+hiDate[j].evt);
      if (hr+mn>0)
         document.write(" "+twoDigs(hr)+":"+twoDigs(mn)+" UT");
      document.write("<BR>");
      }
   }

document.write("<P><TABLE>");

if (VDay1<NDay1){
   if (StrV1!="x") document.write("<TR><TD><FONT size=-1><IMG src='../img/vm.gif'> Vollmond: </TD><TD><FONT size=-1>"+StrV1+"</TD></TR>");
   if (StrN1!="x") document.write("<TR><TD><FONT size=-1><IMG src='../img/nm.gif'> Neumond: </TD><TD><FONT size=-1>"+StrN1+"</TD></TR>");
   if (StrV2!="x") document.write("<TR><TD><FONT size=-1><IMG src='../img/vm.gif'> Vollmond: </TD><TD><FONT size=-1>"+StrV2+"</TD></TR>");
   if (StrN2!="x") document.write("<TR><TD><FONT size=-1><IMG src='../img/nm.gif'> Neumond: </TD><TD><FONT size=-1>"+StrN2+"</TD></TR>");
   } else{
   if (StrN1!="x") document.write("<TR><TD><FONT size=-1><IMG src='../img/nm.gif'> Neumond: </TD><TD><FONT size=-1>"+StrN1+"</TD></TR>");
   if (StrV1!="x") document.write("<TR><TD><FONT size=-1><IMG src='../img/vm.gif'> Vollmond: </TD><TD><FONT size=-1>"+StrV1+"</TD></TR>");
   if (StrN2!="x") document.write("<TR><TD><FONT size=-1><IMG src='../img/nm.gif'> Neumond: </TD><TD><FONT size=-1>"+StrN2+"</TD></TR>");
   if (StrV2!="x") document.write("<TR><TD><FONT size=-1><IMG src='../img/vm.gif'> Vollmond: </TD><TD><FONT size=-1>"+StrV2+"</TD></TR>");
   }

document.write("</TABLE></td><td valign='top'>");
for (j=1; j<=maxhiDate;j++){
   if ((hiDate[j].m==m)&&(y>=hiDate[j].start)){
      var hr=hiDate[j].hour; var mn=hiDate[j].min;
      document.write(hiDate[j].DoM+"."+m+". "+hiDate[j].evt);
      if (hr+mn>0) document.write(" "+twoDigs(hr)+":"+twoDigs(mn)+" UT");
         document.write("<BR>");
      }
   }
document.write("</td></tr></table></CENTER>");

for (i=1; i<maxhiDate; i++){
   var D=hiDate[i];
   if ( (D.m==anzMonth)&&(D.explain!=null)&&(D.y>1989) )
      document.write("<BR> Der <B>"+D.d+". "+getMonthName(D.m)+"</B> ist "+D.explain+".");
      }

y=anzYear; m=anzMonth;


                  /******** --- old moondates --- ********/

/* --- Mondberechnung ThK--- */

var phase=29.530588853;
var y0=2000;
var d0=19.123; // average value in compare, april 2000


function moonThK(y,m){

   var vm=(y0-y)*10.882933764+d0  // Jahr mit 365,25 d

   vm += (m>2)? (y%4)*0.25 : ((y-1)%4)*0.25;   // Schaltjahreskorr julianisch

   if (y>1582){
      var y1=Math.floor(y/100);
      vm-=Math.floor(y1/4)+15-y1;
      if ( (y%100==0)&&(y%400!=0)&&(m<3) ) vm--;
      }
   if (y<=1582)vm-=3;
   if (y<0) vm++;
   if ( (y<0)&&(y%4==0)&&(m>2) ) vm--;
   if ( (y==0)&&(m<3) ) vm++;
      
   if (m==1)  vm +=  1.525;
   if (m==2)  vm += 0.138;
   if (m==3)  vm +=  1.462;
   if (m==5)  vm += -0.51;
   if (m==6)  vm += -2.054;
   if (m==7)  vm += -2.607;
   if (m==8)  vm += -4.153;
   if (m==9)  vm += -5.675;
   if (m==10) vm += -6.152;
   if (m==11) vm += -7.586;
   if (m==12) vm += -7.98;

   var faktor=Math.floor(vm/phase);
   vm -= faktor*phase;  // add von phasen bis zum pos. Bereich

   if (y<1582) vm-=10; else
     if ((y==1582)&&(m<10)) vm-=10; 
     if (vm<1) vm += phase;
// Fehler vm 1582 Okt.

   return new ymdDate(y,m,vm);    
}  // Mond ThK

if (y<5000){
//if ((y<1500)||(y>2500)){

var thMoon=moonThK(y,m);
var VM1r=thMoon.d;
var VM2r=VM1r+phase;
var NM1r=VM1r-phase/2;
if (NM1r<1) NM1r+=phase;
var NM2r=NM1r+phase;
var VM1i=twoDigs(Math.floor(VM1r));
var VM2i=twoDigs(Math.floor(VM2r));
var NM1i=twoDigs(Math.floor(NM1r));
var NM2i=twoDigs(Math.floor(NM2r));
var hoursV1=twoDigs(Math.round((VM1r-VM1i)*24));
var hoursV2=twoDigs(Math.round((VM2r-VM2i)*24));
var hoursN1=twoDigs(Math.round((NM1r-NM1i)*24));
var hoursN2=twoDigs(Math.round((NM2r-NM2i)*24));

document.write("<P><TABLE><TR><TD valign='top' rowspan='3' width=40%>"+
"<FONT size='-1'>Mondberechnung nach konstanter Phase f&uuml;r extreme Zeitr&auml;ume"+
"&nbsp;(Abweichung bis&nbsp;zu&nbsp;1&nbsp;d)</FONT></TD><TD rowspan='3'>&nbsp;</TD>");

if (NM1i<VM1i){
   if (NM1i<=maxTag(anzYear,anzMonth))
      document.write("<TD><FONT size=-1><IMG src='../img/nm.gif'> Neumond: ",NM1i,".",getMonthName(m),".",anzYear,"&nbsp; ",hoursN1,"&nbsp;Uhr</FONT></TD></TR><TR>");
   if (VM1i<=maxTag(anzYear,anzMonth))
      document.write("<TD><FONT size=-1><IMG src='../img/vm.gif'> Vollmond: ",VM1i,".",getMonthName(m),".",anzYear,"&nbsp; ",hoursV1,"&nbsp;Uhr</FONT></TD></TR><TR>");
   if ( (NM2i>NM1i)&&(NM2i<=maxTag(anzYear,anzMonth)) )
      document.write("<TD><FONT size=-1><IMG src='../img/nm.gif'> Neumond: ",NM2i,".",getMonthName(m),".",anzYear,"&nbsp; ",hoursN2,"&nbsp;Uhr</FONT></TD></TR><TR>");
   if ( (VM2i>VM1i)&&(VM2i<=maxTag(anzYear,anzMonth)) )
      document.write("<TD><FONT size=-1><IMG src='../img/vm.gif'> Vollmond: ",VM2i,".",getMonthName(m),".",anzYear,"&nbsp; ",hoursV2,"&nbsp;Uhr</FONT></TD></TR><TR>");
   }else{
   if (VM1i<=maxTag(anzYear,anzMonth))
      document.write("<TD><FONT size=-1><IMG src='../img/vm.gif'> Vollmond: ",VM1i,".",getMonthName(m),".",anzYear,"&nbsp; ",hoursV1,"&nbsp;Uhr</FONT></TD></TR><TR>");
   if (NM1i<=maxTag(anzYear,anzMonth))
      document.write("<TD><FONT size=-1><IMG src='../img/nm.gif'> Neumond: ",NM1i,".",getMonthName(m),".",anzYear,"&nbsp; ",hoursN1,"&nbsp;Uhr</FONT></TD></TR><TR>");
   if ( (VM2i>VM1i)&&(VM2i<=maxTag(anzYear,anzMonth)) )
      document.write("<TD><FONT size=-1><IMG src='../img/vm.gif'> Vollmond: ",VM2i,".",getMonthName(m),".",anzYear,"&nbsp; ",hoursV2,"&nbsp;Uhr</FONT></TD></TR><TR>");
   if ( (NM2i>NM1i)&&(NM2i<=maxTag(anzYear,anzMonth)) )
      document.write("<TR><TD><FONT size=-1><IMG src='../img/nm.gif'> Neumond: ",NM2i,".",getMonthName(m),".",anzYear,"&nbsp; ",hoursN2,"&nbsp;Uhr</FONT></TD></TR><TR>");
   }

document.write("</TR></TABLE></P>");

}  // y<1500...


            /*****  ----- d & Y information -----  *****/

y=anzYear; m=anzMonth; d=anzDay;

var bisHeiligAbend=getJD( ((m==12)&&(d>24))? y+1 : y,12,24)-getJD(y,m,d);
var DoYear=getJD(y,m,d+1)-getJD(y,1,1);
var vonHeute=getJD(y,m,d)-getJD(aky,akm,akd);
var insE=(Math.abs(vonHeute)==1)? "" :"e";
var vHString="<LI>";
if (vonHeute<0)
   vHString+=-vonHeute+" Tag"+insE+" vor dem "+akd+"."+akm+"."+aky; else
if (vonHeute==0)
   vHString+="anscheinend heute"; else
vHString+=vonHeute+" Tag"+insE+" nach dem "+akd+"."+akm+"."+aky;
var KWString="";
if (y>1975){
   var temp=wt(anzYear,1,1);
   var KW=div((DoYear+5+temp),7);
   if (temp>4) KW--;
   KWString=("<LI>in der "+KW+". Kalenderwoche");
   if ((KW==0)&&(anzYear>1976)){
      temp=wt(anzYear-1,1,1)
      KW=div( (370+sj(y-1)+temp),7 );
      if (temp>4) KW--;
      KWString=("<LI>in der "+KW+". Kalenderwoche "+(y-1));
      }
   if ( (m==12)&&(d>28)&&(wt(y,12,31)<4) ){
      KW=1;
      KWString=("<LI>in der "+KW+". Kalenderwoche "+(y+1));
      }
   }

document.write("<FONT face='Trebuchet MS,Arial,Helvetica'><H3>"
+getDoWName(wt(y,m,d))+", der "+d+". ",getMonthName(m)," ",( ((y>-1)&&(y<10))?("000"+y):((y>-1)&&(y<100))?("00"+y):y ),(y<1)?(" ("+(1-y)+" vor Christus)"):""," ist...</H3></FONT>",
"<UL><LI>Julianischer Tag ",getJD(y,m,d),
"<LI>der ",DoYear,". Tag des Jahres",
vHString,
KWString);
if (y>0)
   document.write("<LI>",bisHeiligAbend," Tag",(bisHeiligAbend==1)? "" : "e"," vor Heiligabend");

document.write("</UL>");

if (y>1){
var y2show=(y>4094)? (6-y+4094):(y>-1)?6:0;
var s;
document.write("<FONT face='Trebuchet MS,Arial,Helvetica'><H3>Bewegliche Anl&auml;sse einiger Jahre</H3></FONT>"
+"<TABLE border bgcolor='#C0D0C0' cellspacing=1 cellpadding=3><TR bgcolor='#FFA050'><TH><FONT face='Trebuchet MS,Arial,Helvetica'>Anlass </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   document.write("<TH><FONT face='Trebuchet MS,Arial,Helvetica'>"+( (y<10)?("000"+y):(y<100)?("00"+y):y )+"</TH>");
   }
document.write("</TR><TR><TD>Fastnacht: </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   s=Fastnacht(y);
   if (y>325)
      document.write("<TD nowrap>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
   else
      document.write("<TD nowrap><I>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+". ?</I></TD>");
   }
document.write("</TR><TR><TD>Ostern: </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   s=whichEaster(y);
   if (y>325)
      document.write("<TD nowrap>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
   else
      document.write("<TD nowrap><I>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+". ?</I></TD>");
   }
document.write("</TR><TR><TD>Chr.&nbsp;Himmelfahrt: </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   s=Hifa(y);
   if (y>325)
      document.write("<TD nowrap valign='bottom'>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
   else
      document.write("<TD nowrap><I>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+". ?</I></TD>");
   }
document.write("</TR><TR><TD>Pfingsten: </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   s=Pfingsten(y);
   if (y>325)
      document.write("<TD nowrap>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
   else
      document.write("<TD nowrap><I>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+". ?</I></TD>");
   }
document.write("</TR><TR><TD>Fronleichnam: </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   s=FronLN(y);
   if (y>1245)
      document.write("<TD nowrap>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
   else
      document.write("<TD nowrap align='center'>---</TD>");
   }
document.write("</TR><TR><TD>Erntedankfest: </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   s=ErnteDF(y);
   if (y>=1770)
      document.write("<TD nowrap>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
   else
      document.write("<TD nowrap align='center'>---</TD>");
   }
document.write("</TR><TR><TD>Bu&szlig- und Bettag: </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   s=BBTag(y);
   if (y>=1853)
      document.write("<TD nowrap>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
   else
      document.write("<TD  nowrap align='center'>---</TD>");
   }
document.write("</TR><TR><TD>Erster Advent: </TD>");
for (y=anzYear;y<anzYear+y2show;y++){
   s=Adv1(y);
   if (y>825)
      document.write("<TD nowrap>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
   else
      document.write("<TD nowrap align='center'>---</TD>");
   }
if (anzYear>1583-y2show){
   document.write("</TR><TR bgcolor='#A0B0A0'><TD>Ostern orthodox: </TD>");
   for (y=anzYear;y<anzYear+y2show;y++){
      s=(y>1582)?getEasterDate(y,2):getEasterDate(y,1);
      if (y>325)
         document.write("<TD nowrap>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+".</TD>");
      else
         document.write("<TD nowrap><I>"+getDoWName(wt(y,s.m,s.d))+"&nbsp;"+s.d+". "+s.m+". ?</I></TD>");
      }
   }
document.write("</TR></TABLE>");
} // y>-1

//-->

