//------------------------------------------------------------
//-- JAVASCRIPT FOR LANGTREE WEB SITE
//------------------------------------------------------------
	
//------------------------------------------------------------
//-- Work out the dates of the Sundays in the month
//------------------------------------------------------------

	function DateOfSundays(n)
	{
	// Set the current date and also the date for the
	// start of this month
	CurDate = new Date();
	MonthStartDate = new Date();
	MonthStartDate.setDate(1);
	
	// Find the day of the week that the month started on,
	// if it started on a Sunday then we'll use 7 in our
	// calculation below
	MonthStartDayOfWeek = MonthStartDate.getDay();
	if (MonthStartDayOfWeek == 0) {
		MonthStartDayOfWeek = 7;
	}

	// Calculate the first Sunday in the month	
	SundayInMonth = new Date();
    SundayInMonth.setDate(8 - MonthStartDayOfWeek + ((n - 1) * 7));

    // Handle the case of no fifth Sunday in the month    
    if (SundayInMonth.getMonth() != CurDate.getMonth()) {
		return "No fifth Sunday";
    }
    else {
        DaysUntilSunday = (SundayInMonth.getDate() - CurDate.getDate());
			return FormatDateExDay(SundayInMonth);
    }
    
  }
    	
//------------------------------------------------------------
//-- Format a date including day of week
//------------------------------------------------------------

	function FormatDate(d)
	{

			dateText = "";
			dayValue = d.getDay();
			if (dayValue == 0)
			    dateText += "Sunday";
			else if (dayValue == 1)
			    dateText += "Monday";
			else if (dayValue == 2)
			    dateText += "Tuesday";
			else if (dayValue == 3)
			    dateText += "Wednesday";
			else if (dayValue == 4)
			    dateText += "Thursday";
			else if (dayValue == 5)
			    dateText += "Friday";
			else if (dayValue == 6)
			    dateText += "Saturday";

			monthValue = d.getMonth();
			dateText += " "
			dateText += MonthText(monthValue);

			dateText += (" " + d.getDate() + ", " + d.getFullYear());

			return (dateText);
	}

//------------------------------------------------------------
//-- Format a date excluding day of week
//------------------------------------------------------------

	function FormatDateExDay(d)
	{

			dateText = "";

			monthValue = d.getMonth();
			dateText += MonthText(monthValue);

			dateText += (" " + d.getDate() + ", " + d.getFullYear());

			return (dateText);
	}

//------------------------------------------------------------
//-- Return the text equivalent of a month number
//------------------------------------------------------------

	function MonthText(monthValue)
	{
	
			if (monthValue == 0)
				return "January";
			if (monthValue == 1)
			    return "February";
			if (monthValue == 2)
			    return "March";
			if (monthValue == 3)
			    return "April";
			if (monthValue == 4)
			    return "May";
			if (monthValue == 5)
			    return "June";
			if (monthValue == 6)
			    return "July";
			if (monthValue == 7)
			    return "August";
			if (monthValue == 8)
			    return "September";
			if (monthValue == 9)
			    return "October";
			if (monthValue == 10)
			    return "November";
			if (monthValue == 11)
			    return "December";
			    
	}
			    
//------------------------------------------------------------
//-- Add a time-specific greeting to the current date & time
//------------------------------------------------------------

	function Greeting(d) {
		
			hourValue = d.getHours();
			if (hourValue < 12)
			    {
			    greeting = "Good morning";
			    }
			else if (hourValue == 12)
			    {
			    greeting = "Good afternoon";
			    }
			else if (hourValue < 17)
			    {
			    greeting = "Good afternoon";
			    }
			else
			    {
			    greeting = "Good evening";
			    }

			return (greeting + " on " + FormatDate(d));
	}
	
//------------------------------------------------------------
//-- Handle the selection made in the drop-down "find" list
//------------------------------------------------------------

	function HandleChoose() {
	
	  choosechoice = document.frmChoose.Choose.options[document.frmChoose.Choose.selectedIndex].value;
	  
	    if (choosechoice == "contact") {
			document.location = "contact.htm";
	    }
	    else if (choosechoice == "window") {
			document.location = "stokerow.htm#Rose";
	    }
	    else if (choosechoice == "game") {
			document.location = "slider.htm";
	    }
	    else if (choosechoice == "still") {
			document.location = "stokerow.htm#Still";
	    }
	    else if (choosechoice == "Oxford") {
			document.location = "http://www.oxford.anglican.org/";
	    }
	    else if (choosechoice == "services") {
			document.location = "notices.htm";
	    }
	    else if (choosechoice == "study") {
			document.location = "study.htm";
	    }
	    else if (choosechoice == "calendar") {
			document.location = "calendar.htm";
	    }
	    else {
	        alert("If you cannot find what you're looking for then please e-mail us using the link at the bottom of the page.");
	    }
	    
	}

//------------------------------------------------------------
//-- Fill the calendar with column headings
//------------------------------------------------------------

	function day_title(day_name){

		document.write("<TD ALIGN=center WIDTH=35>"+day_name+"</TD>");
	
	}

//------------------------------------------------------------
//-- Fill the calendar with numbers
//------------------------------------------------------------

	function fill_table(month,month_length,year) {

		// Specify the current date
		CurDate = new Date();
		CurDay = CurDate.getDate();
				
		// first day of the week of the new year
		StartYear = new Date(month + " 1, " + year)
		StartDay = StartYear.getDay() + 1;

		day=1;

		// begin the new month table
		document.write("<TABLE BORDER=1 CELLSPACING=5 CELLPADDING=5><TR>");
		document.write("<TD COLSPAN=7 ALIGN=center><B>"+month+"   "+CurYear+"</B><TR>");
		
		// column headings
		day_title("Sun");
		day_title("Mon");
		day_title("Tue");
		day_title("Wed");
		day_title("Thu");
		day_title("Fri");
		day_title("Sat");

		// pad cells before first day of month
		document.write("</TR><TR>");

		for (var i=1;i<StartDay;i++) {

			document.write("<TD></TD>");

		}

		// fill the first week of days
		for (var i=StartDay;i<8;i++) {

			if (i == 1) {
				if (day == CurDay) {
					document.write("<TD ALIGN=center BGCOLOR='yellow'><font color='red'>"+day+"&nbsp;</font></TD>");
				}
				else {
					document.write("<TD ALIGN=center><font color='red'>"+day+"&nbsp;</font></TD>");
				}
			}
			else
			{
				if (day == CurDay) {
					document.write("<TD ALIGN=center BGCOLOR='yellow'>"+day+"&nbsp;</TD>");
				}
				else {
					document.write("<TD ALIGN=center>"+day+"&nbsp;</TD>");
				}
			}
			
			day++;
			
		}

		document.write("<TR>");

		// fill the remaining weeks
		while (day <= month_length) {

			for (var i=1;i<=7 && day<=month_length;i++) {

				if (i == 1) {
					if (day == CurDay) {
						document.write("<TD ALIGN=center BGCOLOR='yellow'><font ='red'>"+day+"&nbsp;</font></TD>");
					}
					else {
						document.write("<TD ALIGN=center><font color='red'>"+day+"<font></TD>");
					}
				}
				else
				{
					if (day == CurDay) {
						document.write("<TD ALIGN=center BGCOLOR='yellow'>"+day+"&nbsp;</TD>");
					}
					else {
						document.write("<TD ALIGN=center>"+day+"</TD>");
					}
				}

				day++;

				}

			document.write("</TR><TR>");

			// the first day of the next month
			StartDay=i;

		}

		document.write("</TR></TABLE><BR>");

	}