///////////////////////////////////

// Get and set the td for the day rollovers

function getTd()
{
	var td = document.getElementsByTagName("td");
	for(i=td.length;i-->0;)
	{
		if(td[i].className.indexOf("date") >-1)
		{
			td[i].onmouseover = tdOn;
			td[i].onmouseout = tdOff;
		}
	}
}

function tdOn()
{
	this.style.backgroundColor = "#ffffde";
}

function tdOff()
{
	this.style.backgroundColor = "#ffffff";
}

///////////////////////////////////

// Open the window for the event

function eventDetails(event_id)
{
	var wWidth,wHeight,wScrollbars,wToolbars,wMenuBar,wStatus,wLocation,wResizable;

	wWidth = 300;
	wHeight = 300;
	wScrollbars = "yes";
	wToolbar = "no";
	wMenubar = "no";
	wStatus = "no";
	wLocation = "no";
	wResizable = "yes";	

	var params ="width=" + wWidth + ",height=" + wHeight + ",scrollbars=" + wScrollbars + ",toolbar=" + wToolbar + ",menubar=" + wMenubar + ",status=" + wStatus + ",location=" + wLocation + ",resizable=" + wResizable + "";
	var newWindow;
	
	if(event_id.indexOf(".") > 0)
	{
		newWindow = window.open("calendar-event.aspx?day=" + event_id,'newWindow',params);
	}
	else
	{
		newWindow = window.open("calendar-event.aspx?event=" + event_id,'newWindow',params);
	}
	
	// bring it to the front:
	newWindow.focus();
}

///////////////////////////////////

// Hide, show the calendar event types

function toggleEvents(eClass)
{
	var tagDiv = document.getElementsByTagName("div");

	for(var i = tagDiv.length; i --> 0;)
	{
		if(tagDiv[i].className == eClass)
		{
			var toggle = (tagDiv[i].style.display=="" || tagDiv[i].style.display=="block") ? "none" : "block";
			tagDiv[i].style.display = (toggle == "none") ? "none" : "block";
		}
	}

	var strImg = eClass.toString().replace("cat","check");
	var objImg = document.getElementById(strImg);
	objImg.src = (toggle == "none") ? "/images/calendar/checkblank.gif" : "/images/calendar/check.gif";
}


/////////////// Calendar Sub Menu Choices

function load_calendar_choices()
{
	// Get all the div's
	var c_div = document.getElementsByTagName("div");
	var cal_events = new Array();

	for(var i=0; i<c_div.length; i++)
	{
		// If the div's have a class that starts with "cat" then there's calendar events on the page
		if(c_div[i].className.indexOf("cat") == 0)
		{
			cal_events[cal_events.length] = c_div[i].className.toString();
		}
	}

	// If there are no events, no need to continue
	if(cal_events.length < 1)
	{
		return;
	}
	else
	{
		// Show the calendar sub menu
		var calendar_menu = document.getElementById("calendarMenu");
		calendar_menu.style.display = "block";

		// Get all the list items on the page
		var c_li = document.getElementsByTagName("li");
		var cal_choices = new Array();

		for(var i=0; i<c_li.length; i++)
		{
			if(c_li[i].id &&  c_li[i].id.toString().indexOf("cat")==0)
			{
				c_li[i].style.display = "none"; // Hide em' all (we'll show them below if an event matches the category)
				cal_choices[cal_choices.length] = c_li[i].id.toString();
			}
		}

		// Ok, match up the menu choices to the events
		// If an event matches a menu choice, show that choice
		for(var i=0; i<cal_choices.length; i++) // Loop through all of the menu choices
		{
			for(var j=0; j<cal_events.length; j++) // For each choice, loop through all the events
			{
				if(cal_choices[i] == cal_events[j]) // If an event matches a choice...
				{
					// Get the calendar choice (li)
					var c_show_choice = document.getElementById(cal_choices[i]);
					// Get the calendar choice image (icon)
					var c_show_choice_img = document.getElementById(cal_choices[i].replace("cat","check"));
					c_show_choice_img.src = "/images/calendar/check.gif";
					c_show_choice.style.display = "block";
				}
			}
		}
	}
}

set_onload("getTd");
set_onload("load_calendar_choices");