// JavaScript Document
// easter calculator

/**
 * Calculates the day on which Easter Sunday falls for the current year using
 * Butcher's Method. Returns an integer between '1' and '31'
 *
 * @summary             easter day
 * @author              Stuart Wigley
 * @version             1.0, 12/01/03
 * @interface           <code>Date.getEasterDay()</code>
 * @return              the day on which Easter Sunday falls
 * @return              <code>null</code> if an exception is encountered
 * @throws              IllegalArgumentException
 */
Date.prototype.getEasterDay = function() {

    try {

        var vError = null;
        var iNumArguments = arguments.length;

        if (iNumArguments > 0) {
            throw vError = new IllegalArgumentException('Date.getEasterDate', 0, iNumArguments);
        }

		var iYear = this.getFullYear();
        var a = iYear % 19;
        var b = Math.floor(iYear / 100);
        var c = iYear % 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 p = (h + l - 7 * m + 114) % 31;
        var iEasterDay = p + 1;

    }
    catch (vError) {

        if (vError instanceof Error) {
            vError.handleError();
        }
    }
    finally {

        return vError ? null : iEasterDay;
    }
}


/**
 * Calculates the month in which Easter Sunday falls for the current year using
 * Butcher's Method. Returns '3' for March or '4' for April.
 *
 * @summary             easter month
 * @author              Stuart Wigley
 * @version             1.0, 12/01/03
 * @interface           <code>Date.getEasterMonth()</code>
 * @return              the month in which Easter Sunday falls
 * @return              <code>null</code> if an exception is encountered
 * @throws              IllegalArgumentException
 */
Date.prototype.getEasterMonth = function() {

    try {

        var vError = null;
        var iNumArguments = arguments.length;

        if (iNumArguments > 0) {
            throw vError = new IllegalArgumentException('Date.getEasterMonth', 0, iNumArguments);
        }

		var iYear = this.getFullYear();
        var a = iYear % 19;
        var b = Math.floor(iYear / 100);
        var c = iYear % 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 iEasterMonth = Math.floor((h + l - 7 * m + 114) / 31);

    }
    catch (vError) {

        if (vError instanceof Error) {
            vError.handleError();
        }
    }
    finally {

        return vError ? null : iEasterMonth;
    }
}

function calendarImage()
{
	var date = new Date();
	var month = date.getMonth();
	var day = date.getDate();
	var dayofweek = date.getDay();
	var hour = date.getHours();
	var sunday = "0";
	var november = "10";
	var december = "11";
	var xmasEve = "24";
	var xmasDay = "25";
	var easter = new Date();
	var easterDay = easter.getEasterDay();
	var easterMonth = easter.getEasterMonth();
	var goodFriday = (parseInt(easterDay) - 2);
	var holySaturday = (parseInt(easterDay) - 1);
	var maundyThursday = (parseInt(goodFriday) - 1);
	/*alert ("Maundy Thursday: " + easterMonth + "/" + maundyThursday + "/" + easter.getFullYear());
	alert("Good Friday: " + easterMonth + "/" + goodFriday + "/" + easter.getFullYear());
	alert("Easter: " + easterMonth + "/" + easterDay + "/" + easter.getFullYear()); */
	/* Check for Christmas */
	if (month == december)
	{
		if (day <= "7")
		{
			document.write("<img src=\"http://www.welcome2faith.com/images/bethstar.jpg\" align=\"top\" width=\"160\" height=\"233\" alt=\"Photograph of a bright star\" title=\"The Star of Bethlehem\"/>");
		}
		else if (day > "7" && day <= "14")
		{
			document.write("<img src=\"http://www.welcome2faith.com/images/magi-small.jpg\" align=\"top\" width=\"160\" height=\"218\" alt=\"An image of the magi following the Star of Bethlehem\" title=\"The Magi following the Star of Bethlehem\"/>");
		}
		else if (day > "14" && (day <= "24" && hour < "18"))
		{
		/* document.write("<img src=\"http://www.welcome2faith.com/images/magi-small.jpg\" align=\"top\" width=\"160\" height=\"239\" alt=\"A painting called The Star of Bethlehem\" title=\"The Star of Bethlehem\"/>"); */
			document.write("<img src=\"http://www.welcome2faith.com/images/mang-star.gif\" align=\"top\" width=\"160\" height=\"257\" alt=\"An image of the Star of Bethlehem over the Manger\" title=\"The Star over the Manger\"/>");
		}
		else if (day >= "25" || (day == "24" && hour >= "18"))
		{
			document.write("<img src=\"http://www.welcome2faith.com/images/nativity-small.jpg\" align=\"top\" width=\"160\" height=\"226\" alt=\"A painting of the Nativity\" title=\"The Nativity\"/>");
		}			
	}
	else if ((parseInt(month) + 1) == easterMonth)
	{
		switch(day)
		{
			case maundyThursday:
        		document.write("<img src=\"http://www.welcome2faith.com/images/gethsemane-small.jpg\" align=\"top\" width=\"160\" height=\"208\" alt=\"Painting of Jesus praying in the Garden of Gethsemane\" title=\"Gethsemane\" />");
				break;
				
			case goodFriday:
				if (hour < "21")
				{
					document.write("<img src=\"http://www.welcome2faith.com/images/cranach-crucifixion-small.png\" align=\"top\" width=\"160\" height=\"222\" alt=\"Painting of the Crucifixion by Lucas Cranach the Elder\" title=\"The Crucifixion by Lucas Cranach the Elder\"/>");
					break;
				}
				
			case holySaturday:
				document.write("<img src=\"http://www.welcome2faith.com/images/holysaturday.jpg\" align=\"top\" width=\"160\" height=\"225\" alt=\"A completely black canvas representing the grave\" title=\"The light shines in the darkness, and the darkness has not overcome it...\"/>");
				break;
				
			case easterDay:
				if (hour < "4")
				{
					document.write("<img src=\"http://www.welcome2faith.com/images/holysaturday.jpg\" align=\"top\" width=\"160\" height=\"225\" alt=\"A completely black canvas representing the grave\" title=\"The light shines in the darkness, and the darkness has not overcome it...\"/>");
					break;
				}
				else 
				{
					document.write("<img src=\"http://www.welcome2faith.com/images/resjesus.jpg\" align=\"top\" width=\"160\" height=\"227\" alt=\"Painting of the Risen Christ by Dewey\" title=\"Christ is risen! He is risen indeed!\"/>");
					break;
				}
				
			default:
				document.write("<img src=\"http://www.welcome2faith.com/images/cranach-crucifixion-small.png\" align=\"top\" width=\"160\" height=\"222\" alt=\"Painting of the Crucifixion by Lucas Cranach the Elder\" title=\"The Crucifixion by Lucas Cranach the Elder\"/>");
				break;
		}
	}
	else
	{
		document.write("<img src=\"http://www.welcome2faith.com/images/conversionofstpaul.jpg\" align=\"top\" width=\"160\" height=\"212\" alt=\"Painting of the Conversion of St. Paul by Carvaggio\" title=\"The Conversion of St. Paul\"/>");
	}
}