
function fillform() {
  /* (c)2000 www.diaware.de */
  /* Fülle Form mit Defaultwerten */
 var Dat = new Date();
 var Day = Dat.getDate();
 var Month = Dat.getMonth() + 1;
 var Year = Dat.getYear();
 if(Year > 99 && Year < 1600) Year += 1900;
 document.datum.jahr.value = Year;
 document.datum.monat.value = Month;
 document.datum.tag.value = Day;
}

function checkform() {
  /* (c)2000 www.diaware.de */
  /* Teste Form auf Plausibilität */
   var Check;

   Check = 1;
   for(i=0;i<document.datum.jahr.value.length;++i)
     if(document.datum.jahr.value.charAt(i) < "0"
     || document.datum.jahr.value.charAt(i) > "9")
     Check = -1;
   if (document.datum.jahr.value < 1600 && document.datum.jahr.value > 99) Check=-1;
   if (document.datum.jahr.value < 0) Check=-1;
   if (document.datum.jahr.value < 100 && document.datum.jahr.value >= 50) document.datum.jahr.value = Number(document.datum.jahr.value) + 1900;
   if (document.datum.jahr.value < 50 && document.datum.jahr.value >= 0) document.datum.jahr.value = Number(document.datum.jahr.value) + 2000;
   if(Check == -1) {
            //document.datum.jahr.value = "";
            document.datum.jahr.focus();
            return Check;
   }

   Check = 1;
   for(i=0;i<document.datum.monat.value.length;++i)
     if(document.datum.monat.value.charAt(i) < "0"
     || document.datum.monat.value.charAt(i) > "9")
     Check = -1;
   if (document.datum.monat.value > 12 || document.datum.monat.value < 1) Check=-1;
   if(Check == -1) {
            //document.datum.monat.value = "";
            document.datum.monat.focus();
            return Check;
   }
   Check = 1;
   if (document.datum.tag.value < 1 || document.datum.tag.value > daysofmonth(Number(document.datum.jahr.value),Number(document.datum.monat.value)) ) Check=-1;
   for(i=0;i<document.datum.tag.value.length;++i)
     if(document.datum.tag.value.charAt(i) < "0"
     || document.datum.tag.value.charAt(i) > "9")
     Check = -1;
   if(Check == -1) {
            //document.datum.tag.value = "";
            document.datum.tag.focus();
            return Check;
   }

}

function getCalendarText(Art) {

  /* (c)2000 www.diaware.de */
  /* Anzeige des Kalenders */
  /* Art...wie darstellen? 0=Nur Tag; 1=Monatskalender; 2=Jahreskalender */

  /* Nur Internet Explorer oder Netscape Navigator */
  //if(!document.all && !document.layers) return;

  /* Year...gesuchte Jahr */
  /* Month...gesuchter Monat */
  /* Day...gesuchter Tag */
  var Year=parseInt(document.datum.jahr.value);
  var Month=parseInt(document.datum.monat.value);
  var Day=parseInt(document.datum.tag.value);
  var Text;
  var TitelText = getCalendarTitelText(Art);

  switch(Art) {
  case 1:
       Text = "<b>" + TitelText + "</b></p>";
       Text += caltable(Year, Month);
       Text+="<i>Angaben ohne Gewähr</i>"
       break;
  case 2:
       Text= "<b>" + TitelText + "</b><table border=0 cellspacing=1 cellpading=0><tr>"
       Text+= "<td valign=top align=center><b>" + monthtotext(1) + "</b><br>" + caltable(Year, 1) + "</td>"
       Text+= "<td valign=top align=center><b>" + monthtotext(2) + "</b><br>" + caltable(Year, 2) + "</td>"
       Text+= "<td valign=top align=center><b>" + monthtotext(3) + "</b><br>" + caltable(Year, 3) + "</td></tr><tr>"
       Text+= "<td valign=top align=center><b>" + monthtotext(4) + "</b><br>" + caltable(Year, 4) + "</td>"
       Text+= "<td valign=top align=center><b>" + monthtotext(5) + "</b><br>" + caltable(Year, 5) + "</td>"
       Text+= "<td valign=top align=center><b>" + monthtotext(6) + "</b><br>" + caltable(Year, 6) + "</td></tr><tr>"
       Text+= "<td valign=top align=center><b>" + monthtotext(7) + "</b><br>" + caltable(Year, 7) + "</td>"
       Text+= "<td valign=top align=center><b>" + monthtotext(8) + "</b><br>" + caltable(Year, 8) + "</td>"
       Text+= "<td valign=top align=center><b>" + monthtotext(9) + "</b><br>" + caltable(Year, 9) + "</td></tr><tr>"
       Text+= "<td valign=top align=center><b>" + monthtotext(10) + "</b><br>" + caltable(Year, 10) + "</td>"
       Text+= "<td valign=top align=center><b>" + monthtotext(11) + "</b><br>" + caltable(Year, 11) + "</td>"
       Text+= "<td valign=top align=center><b>" + monthtotext(12) + "</b><br>" + caltable(Year, 12) + "</td>"
       Text+= "</tr></table>"
       Text+="<i>Angaben ohne Gewähr</i>"

       break;
  case 3:
       /* Berechnung des Osterfestes */
       /* Formel nach Oudin */
       C = Math.floor(Year / 100)
       N = Year - 19 * Math.floor(Year / 19)
       K = Math.floor((C - 17) / 25)
      I1 = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15
      I2 = I1 - 30 * Math.floor(I1 / 30)
      I3 = I2 - Math.floor(I2 / 28) * (1 - Math.floor(I2 / 28) * Math.floor(29 / (I2 + 1)) * Math.floor((21 - N) / 11))
      A1 = Year + Math.floor(Year / 4) + I3 + 2 - C + Math.floor(C/4)
      A2 = A1 - 7 * Math.floor(A1 / 7)
       L = I3 - A2
       M = 3 + Math.floor((L + 40) / 44)
       D = L + 28 - 31 * Math.floor(M / 4)

       Text ="<b>" + TitelText + "</b><br><br><table border=1 cellspacing=1 class=visible><tr>"
       Text+="<td class=head>Neujahr</td><td class=body>" +
             weekdaytotext(weekday(Year, 1, 1)) + "</td><td class='body'>" +
             1 + ". " + monthtotext(1) + "</td></tr><tr>";
       Text+="<td class=head>Heiligen 3 K&ouml;nige</td><td class=body>" +
             weekdaytotext(weekday(Year, 1, 6)) + "</td><td class='body'>" +
             6 + ". " + monthtotext(1) + "</td></tr><tr>";
       Dat = decdate(Year, M, D, 48);
       Text+="<td class=head>Rosenmontag</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = decdate(Year, M, D, 46);
       Text+="<td class=head>Aschermittwoch</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = decdate(Year, M, D, 3);
       Text+="<td class=head>Gründonnerstag</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = decdate(Year, M, D, 2);
       Text+="<td class=head>Karfreitag</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Text+="<td class=head><b>Ostersonntag</b></td><td class=body>" +
             weekdaytotext(weekday(Year, M, D)) + "</td><td class='body'>" +
             D + ". " + monthtotext(M) + "</td></tr><tr>";
       Dat = incdate(Year, M, D, 39);
       Text+="<td class=head>Christi Himmelfahrt</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = incdate(Year, M, D, 49);
       Text+="<td class=head>Pfingstsonntag</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = incdate(Year, M, D, 50);
       Text+="<td class=head>Pfingstmontag</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = incdate(Year, M, D, 60);
       Text+="<td class=head>Fronleichnam</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Text+="<td class=head>Maria Himmelfahrt</td><td class=body>" +
             weekdaytotext(weekday(Year, 8, 15)) + "</td><td class='body'>" +
             15 + ". " + monthtotext(8) + "</td></tr><tr>";
       Text+="<td class=head>Reformationstag</td><td class=body>" +
             weekdaytotext(weekday(Year, 10, 31)) + "</td><td class='body'>" +
             31 + ". " + monthtotext(10) + "</td></tr><tr>";
       Text+="<td class=head>Allerheiligen</td><td class=body>" +
             weekdaytotext(weekday(Year, 11, 1)) + "</td><td class='body'>" +
             1 + ". " + monthtotext(11) + "</td></tr><tr>";
       /* Berechnung des 4. Adventes */
       /* zunächst Differenz zum Heilig Abend */
       diffHA = ((weekday(Year,12,24)+1)%7)
       /* Nun Advent und Buß und Bettag bestimmen */
       Dat = decdate(Year, 12, 24, diffHA+(3*7)+11);
       Text+="<td class=head>Bu&szlig;- und Bettag</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       /* Nun Advent und Buß und Bettag bestimmen */
       Dat = decdate(Year, 12, 24, diffHA+(3*7));
       Text+="<td class=head>1. Advent</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       /* Nun Advent und Buß und Bettag bestimmen */
       Dat = decdate(Year, 12, 24, diffHA+(2*7));
       Text+="<td class=head>2. Advent</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       /* Nun Advent und Buß und Bettag bestimmen */
       Dat = decdate(Year, 12, 24, diffHA+7);
       Text+="<td class=head>3. Advent</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       /* Nun Advent und Buß und Bettag bestimmen */
       Dat = decdate(Year, 12, 24, diffHA);
       Text+="<td class=head>4. Advent</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = decdate(Year, 12, 24, 0);
       Text+="<td class=head>Heilig Abend</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = incdate(Year, 12, 24, 1);
       Text+="<td class=head>1. Weihnachtsfeiertag</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = incdate(Year, 12, 24, 2);
       Text+="<td class=head>2. Weihnachtsfeiertag</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td></tr><tr>";
       Dat = incdate(Year, 12, 31, 0);
       Text+="<td class=head>Silvester</td><td class=body>" +
             weekdaytotext(weekday(Year, Dat[1], Dat[2])) + "</td><td class='body'>" +
             Dat[2] + ". " + monthtotext(Dat[1]) + "</td>";
       Text+="</tr></table>"
       Text+="<i>Angaben ohne Gewähr</i>"
       break;
  default:
       Text="<p>Der <b>" + Day + ".</b> <b>" + monthtotext(Month) + "</b> des Jahres <b>" + Year + "</b> war/ist ein <b>" + weekdaytotext(weekday(Year,Month,Day)) + "</b>.</p>";
}
       return Text
}

function getCalendarTitelText(Art) {

  /* (c)2000 www.diaware.de */
  /* Anzeige des Kalenders */
  /* Art...wie darstellen? 0=Nur Tag; 1=Monatskalender; 2=Jahreskalender */

  /* Year...gesuchte Jahr */
  /* Month...gesuchter Monat */
  /* Day...gesuchter Tag */
  var Year=parseInt(document.datum.jahr.value);
  var Month=parseInt(document.datum.monat.value);
  var Day=parseInt(document.datum.tag.value);
  var TitelText;

  switch(Art) {
  case 1:
       TitelText = "Kalender vom " + monthtotext(Month) + " im Jahre " + Year
       break;
  case 2:
       TitelText = "Kalender des Jahres " + Year
       break;
  case 3:
       TitelText = "(Bewegliche) Feiertage des Jahres " + Year
       break;
  default:
       TitelText = "Informationen zum "+ Day + ". " + monthtotext(Month) + " " + Year;
       break
  }

  return TitelText;
}


function showcalendar(Art) {

  /* (c)2000 www.diaware.de */
  /* Anzeige des Kalenders */
  /* Art...wie darstellen? 0=Nur Tag; 1=Monatskalender; 2=Jahreskalender */

  /* Nur Internet Explorer oder Netscape Navigator */
  //if(!document.all && !document.layers) return;

  /* Eingaben prüfen */
  if( checkform() == -1 ) return;

  var Text, TitelText;
  Text = getCalendarText(Art);
  TitelText = getCalendarTitelText(Art);

  showWindow(Text, TitelText);
}

function showWindow(text, titeltext) {
  showWin=open("","showWin","locationbar=no,menubar=no,status=no,width=550,height=610,dependent=no");
  showWin.document.close();
  showWin.document.writeln("<html><head><title>d i a w a r e - "+ titeltext +"</title>");
  showWin.document.writeln("" +
     "<style type='text/css'>" +
     "body { background-color:#E9E9E9; background-repeat: no-repeat; background-attachment:fixed;" +
     "margin:0px; text-align:justify; font-family:Verdana,Helvetica,Arial; font-size:8pt;}\n" +
     "h1,h2,h3,h4,h5,h6,p,div,li,ul,ol,dt,dd,dl,td,tr,table,a,span,input,textarea { " +
     "font-family:Verdana,Helvetica,Arial; font-size:8pt;}\n" +
     ".visible {background-color:#555555; }\n" +
     ".head { background-color:#986800; color:#FFFFFF; }\n" +
     ".body { background-color:#FFD098; }\n" +
     ".body2 { background-color:#CCCCCC; text-decoration:none; font-weight:bold; font-size:8pt;}\n" +
     ".empty { background-color:#FFFFFF; }\n" +
     "</style>");
  showWin.document.write("</head><body>");
  showWin.document.write("<table border=0 cellspacing=2 cellpadding=0 width=100%><tr><td>");
  showWin.document.write("<a href='javascript:this.print()'><b>Diese Seite drucken</b></a></td>");
  showWin.document.write("<td align=right><a href='javascript:this.close()'><b>Schließen</b></a></td></tr></table>");
  showWin.document.write("<table width=100% height=95% cellpadding=0 cellspacing=0>");
  showWin.document.write("<tr><td align=center valign=middle>");
  showWin.document.write(text);
  showWin.document.write("</td></tr></table>");
  showWin.document.write("</body></html>");
  showWin.document.close();
}