/* Dynamic menu for days of months */

/* Written by Stephen Shott <webmaster@stjohnthebaptist.org.au>, April 2005.
   Updated August 2006 to use AJAX instead of iframes.
   Updated December 2011 to use jQuery.
*/

var totalDays = new Array (30, 31, 30, 31, 31, 29, 31, 30, 31, 30 , 31, 31);	


function expand(monthNum) {
	$(".days").css("display", "none");
	$("#month" + monthNum).css("display", "block");
}

function display(month, day) {
	$("#daytext").load("day.php", "month=" + month + "&day=" + day + "&mode=xhtmlFragment");
	return false; // Don't follow any fall-back links
}

function displayFromForm() {
	return display($("#month").val(), $("#day").val());
}

function updatedays() {
	var monLen = totallDays[$("#month").val()];
	if ($("#day").va() > moLen)
		$("#day").val(monLen);
	//if (monLen == 31)	
	//alert("Update");
}

// Remove non-JavaScript navigation after the DOM is ready
$(function () {
	$("#container").removeClass("index-container-nojs");
	$("#container").addClass("index-container");
	$(".days").css("display", "none");

	// Remove links used for non-Javascript operation but leave an event for iOS
	$("a.day").attr("href", "javascript:void(0)");

	var totalDays = new Array (30, 31, 30, 31, 31, 29, 31, 30, 31, 30 , 31, 31);	
 	var today = new Date();
	var month = (today.getMonth() + 4 ) % 12 + 1; // Month, 1-up, Sep is 1
	var day = today.getDate() ;
	// Convert to Church calendar
	day -= 13;
	if (day < 1) {
		month--;
		if (month < 1)
			month = 12;
		day += totalDays[month-1];
	}
 	display(month,day);
 	$("#month").val(month);
 	$("#day").val(day);
 });


