// JavaScript Easter-related Functions
//
// Author:  Greg Coghlan
//
// adapted to work with calendar from code by Martin Webb (http://www.irt.org)
//
//



function Easter(Y) {
    var C = Math.floor(Y/100);
    var N = Y - 19*Math.floor(Y/19);
    var K = Math.floor((C - 17)/25);
    var I = C - Math.floor(C/4) - Math.floor((C - K)/3) + 19*N + 15;
    I = I - 30*Math.floor((I/30));
    I = I - Math.floor(I/28)*(1 - Math.floor(I/28)*Math.floor(29/(I + 1))*Math.floor((21 - N)/11));
    var J = Y + Math.floor(Y/4) + I + 2 - C + Math.floor(C/4);
    J = J - 7*Math.floor(J/7);
    var L = I - J;
    var M = 3 + Math.floor((L + 40)/44);
    var D = L + 28 - 31*Math.floor(M/4);

    return padout(M) + '.' + padout(D);
}

function padout(number) { return (number < 10) ? '0' + number : number; }

function getMM(string)  { return eval(string.substring(0,2)); }

function getDD(string)  { return eval(string.substring(3,5)); }

function makeArray()    {
    this[0] = makeArray.arguments.length;
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
}

var accumulate    = new makeArray(  0, 31, 59, 90,120,151,181,212,243,273,304,334);
var accumulateLY  = new makeArray(  0, 31, 60, 91,121,152,182,213,244,274,305,335);

//function LeapYear(year) {
//    if ((year/4)   != Math.floor(year/4))   return false;
//    if ((year/100) != Math.floor(year/100)) return true;
//    if ((year/400) != Math.floor(year/400)) return false;
//    return true;
//}

function daysinyear(year) { if (LeapYear(year)) return 366; else return 365; }

function addDays(day,month,year,addition) {
    if (LeapYear(year)) var number = day + accumulateLY[month] + addition;
    else                var number = day + accumulate[month]   + addition;

    var days = daysinyear(year);
   
    while (number > days) {
        number -= days;
        days = daysinyear(++year);
    }

    while (number < 1) {
        days = daysinyear(--year);
        number += days;
    }

    month = 1;

    if (LeapYear(year)) {
        while (number > accumulateLY[month]) { month++; }
        day = number - accumulateLY[--month];
    }
    else {
        while (number > accumulate[month]) { month++; }
        day = number - accumulate[--month];
    }

    return year + '.' + padout(month) + '.' + padout(day);
}

function getYYYY(string) {
    return eval(string.substring(0,string.indexOf('.')));
}

function getMMDD(string) {
    return string.substring(string.indexOf('.')+1,string.length);
}

function EasterDate(day,month,year,desc) {
    this.day = day;
    this.month = month;
    this.year = year;
    this.desc = desc;
}

//function setEasterDate(day,month,year,text) {
//    myEasterArray[EasterArrayIndex++] = new EasterDate(day,month,year,desc);
//}

var EasterArrayIndex = 0;
var myEasterArray = new Array();


function GetEasterDates(year1,year2) {

    for (var i=year1; i<=year2; i++) {
		//get date of Easter
		var easter = Easter(i);
		var easterDay = getDD(easter);
		var easterMonth = getMM(easter);

		//var when = addDays(easterDay,easterMonth,year,-46);
		//document.write('Ash Wednesday - ' + FullDate(getDD(getMMDD(when)),getMM(getMMDD(when)),getYYYY(when))+'<BR>');

		//var when = addDays(easterDay,easterMonth,year,-7);
		//document.write('Palm Sunday - ' + FullDate(getDD(getMMDD(when)),getMM(getMMDD(when)),getYYYY(when))+'<BR>');

		//var when = addDays(easterDay,easterMonth,year,-3);
		//document.write('Holy Thursday - ' + FullDate(getDD(getMMDD(when)),getMM(getMMDD(when)),getYYYY(when))+'<BR>');

		//var when = addDays(easterDay,easterMonth,year,-2);
		//document.write('Good Friday - ' + FullDate(getDD(getMMDD(when)),getMM(getMMDD(when)),getYYYY(when))+'<BR>');

		myEasterArray[EasterArrayIndex++] = new EasterDate(easterDay,easterMonth,i,"Easter");
		//document.write('Easter Sunday - ' + FullDate(easterDay,easterMonth,i)+'<BR>');

		//var when = addDays(easterDay,easterMonth,year,39);
		//document.write('Ascension Day - ' + FullDate(getDD(getMMDD(when)),getMM(getMMDD(when)),getYYYY(when))+'<BR>');

		//var when = addDays(easterDay,easterMonth,year,49);
		//document.write('Pentecost or Whitsunday - ' + FullDate(getDD(getMMDD(when)),getMM(getMMDD(when)),getYYYY(when))+'<BR>');

    }

}





