var year;
var month;
var datum;
var mar = new Array(35);
var apr = new Array(35);

function currentYear() {

 var dat = new Date();
 year = dat.getYear();
 if (year<1900) year=year+1900;
 document.form.jahr.value=year;
 getEasterDate();
}


function getEasterYears() {

 x=document.form.resultYear.value;
 if (x=="") year1=document.form.startYear.value; else year1=Number(x)+1;
 if (isNaN(year1)) {alert("Falsche Eingabe");document.form.startYear.select();return}
 if (year1<1583) {
 alert("Valid from the year 1583 on.");
 document.form.startYear.value=1583;
 year1=1583;
 }
 year2 = document.form.stopYear.value;
 if (isNaN(year2)) {alert("Falsche Eingabe");document.form.stopYear.select();return}
 if (year2<year1) {
 alert("Second year input year must be greater.");
 year2 = year1+100
 document.form.stopYear.value=year2;
 }
 
 theMonth = document.form.monat.selectedIndex+3;
 theDay = document.form.tag.selectedIndex+1;
 var theMonth, theYear;

 for (var y=year1; y<=year2; y++) {

 var a = y % 19;
 var b = Math.floor(y/100);
 var c = y % 100;
 var d = Math.floor(b/4);
 var e = b % 4;
 var f = Math.floor((b+8)/25);
 var g = Math.floor((b-f+1)/3);
 var h = (19*a+b-d-g+15) % 30;
 var i = Math.floor(c/4);
 var k = c % 4;
 var l = (32+2*e+2*i-h-k) % 7;
 var m = Math.floor((a+11*h+22*l)/451);
 var n = Math.floor((h+l-7*m+114)/31);
 var p = (h+l-7*m+114) % 31;
 p = Math.round(p+1);
 
 if ((theMonth==n) && (theDay==p)) {document.form.resultYear.value=y;return}

}

}


function getEasterDate() {

 y = Number(document.form.jahr.value);
 if (isNaN(y)) {alert("Falsche Eingabe");document.form.jahr.select();return}
 if (y<1583) {
 alert("Valid from the year 1583 on!");
 document.form.result.value="?";return;
 }

/*
 var a = y % 19;
 var b = Math.floor(y/100);
 var c = y % 100;
 var d = Math.floor(b/4);
 var e = b % 4;
 var f = Math.floor((b+8)/25);
 var g = Math.floor((b-f+1)/3);
 var h = (19*a+b-d-g+15) % 30;
 var i = Math.floor(c/4);
 var k = c % 4;
 var l = (32+2*e+2*i-h-k) % 7;
 var m = Math.floor((a+11*h+22*l)/451);
 var n = Math.floor((h+l-7*m+114)/31);
 var p = (h+l-7*m+114) % 31;
 p = Math.round(p+1);

 if (n==3) document.form.result.value = " March " + p;
 if (n==4) document.form.result.value = " April " + p;
*/

 var K = Math.floor(y/100);
 var M = 15 + Math.floor((3*K+3)/4) - Math.floor((8*K+13)/25);
 var S = 2 - Math.floor((3*K+3)/4);
 var A = y % 19;
 var D = (19*A+M) % 30;
 var R = Math.floor(D/29) + (Math.floor(D/28) - Math.floor(D/29))*Math.floor(A/11);
 var	OG = 21 + D - R; // Märzdatum des Ostervollmonds
 var	SZ = 7 - (y + Math.floor(y/4)+S) % 7; // Datum des 1. Sonntags im März
 var OE = 7 - (OG-SZ) % 7;
 var OS = OG + OE;

 if (OS<=31) str=" Mar " + OS;
 else str=" Apr " + (OS-31);
 document.form.result.value = str;
 if (OG<=31) str=" Mar " + OG;
 else str=" Apr " + (OG-31);
 document.form.moon.value = str;

}


function getEasterTable() {

 document.form.areaMarchApril.value=" ";

 for (var i=1; i<=32; i++) {mar[i]=0;apr[i]=0;}

 var y1 = document.form.startYear.value;
 if (isNaN(y1)) {alert("Falsche Eingabe");document.form.startYear.select();return}
 var y2 = document.form.stopYear.value;
 if (isNaN(y2)) {alert("Falsche Eingabe");document.form.stopYear.select();return}
 if (y1<1583) {
 alert("Valid from the year 1583 on");
 y1=1583;
 document.form.startYear.value=y1;
 }

 if (y2<y1) {
 alert("Second year input must be greater.");
 y2=y1+100;
 document.form.stopYear.value=y2;
 }

 for (var y=y1; y<=y2; y++) {

 var a = y % 19;
 var b = Math.floor(y/100);
 var c = y % 100;
 var d = Math.floor(b/4);
 var e = b % 4;
 var f = Math.floor((b+8)/25);
 var g = Math.floor((b-f+1)/3);
 var h = (19*a+b-d-g+15) % 30;
 var i = Math.floor(c/4);
 var k = c % 4;
 var l = (32+2*e+2*i-h-k) % 7;
 var m = Math.floor((a+11*h+22*l)/451);
 var n = Math.floor((h+l-7*m+114)/31);
 var p = (h+l-7*m+114) % 31;
 p = Math.round(p+1);
 if (n==3) mar[p]+=1;
 if (n==4) apr[p]+=1;
}

var z=0, n, sm, sa;

for (var i=22; i<=31; i++) {
n = mar[i];
sm = n;
if (n<10) sm="0"+sm; 
document.form.areaMarchApril.value +="3/"+i+" ("+sm+") ";
if (document.form.draw.checked) {
for (var j=1; j<=n; j++) 
{document.form.areaMarchApril.value +="*";z+=1;}
}
document.form.areaMarchApril.value+="\n";
}


for (var i=1; i<=25; i++) {
if (i<10) s="0"+i; else s=i;
n = apr[i];
sa = n;
if (n<10) sa="0"+sa; 
document.form.areaMarchApril.value+="4/"+s+" ("+sa+") ";
if (document.form.draw.checked) {
for (var j=1; j<=n; j++) 
{document.form.areaMarchApril.value+="*";z+=1;}
}
document.form.areaMarchApril.value+="\n";
}


}
