///////////////////////////////////

// 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 = 250;
	wHeight = 250;
	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("event.aspx?day=" + event_id,'newWindow',params);
	}
	else
	{
		newWindow = window.open("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";
}


///////////////////////////////////

// Load the calendar choices

function loadCalendars()
{
	// Get the li's with and id of "cat..."
	var tagLi = document.getElementsByTagName("li");
	var availCals = new Array();
	var j = -1;

	for(var i = tagLi.length; i --> 0;)
	{
		if(tagLi[i].id.toString().indexOf("cat") > -1)
		{
			j++;
			availCals[j] = tagLi[i].id.toString();
		}
	}

	// Get the div's with a class name of "cat..."
	var tagDiv = document.getElementsByTagName("div");
	var calEvents = new Array();
	var k = -1;

	for(var i = tagDiv.length; i --> 0;)
	{
		if(tagDiv[i].className.indexOf("cat") > -1)
		{
			k++;
			calEvents[k] = tagDiv[i].className;
		}
	}

	// while were here...
	// we're going to remove the style attribute from the calendar table and...
	// set the attribute "width" equal to "100%"
	// ie5 and ie5.5 only
	fixCalendar();

	// if there's no events, no reason to show just the heading for the submenu's
	// and then we should probably stop the function
	if(calEvents.length < 1)
	{
		var cMenu = document.getElementById("calendarMenu");
		cMenu.style.display = "none";
		return;
	}

	// find out which avalCals exist and show the options for only the ones that
	// are available to everyone
	for(var i = availCals.length; i --> 0;)
	{
		for(var h = calEvents.length; h --> 0;)
		{
			if(availCals[i] == calEvents[h])
			{
				var calendarOption = document.getElementById(availCals[i]);
				calendarOption.style.display = "block";
				var optionCheck = document.getElementById(availCals[i].replace("cat","check"));
				optionCheck.src = "/images/calendar/check.gif";
			}
		}
	}
}

function fixCalendar()
{
	//uaDetect();
/*
	if(screen.width)
	{
		cWidth = screen.width;
	
		if(cWidth < 801)
		{
			var right = document.getElementById("right");
			var middle = document.getElementById("middle");

			right.style.display = "none";
			middle.style.marginRight = "20px";
		}
	}
*/

	if(this.ie5)
	{
		var calendarTable = document.getElementsByTagName("table");
		var middleArea = document.getElementById("middle");

		for(var i = calendarTable.length; i --> 0;)
		{
			if(calendarTable[i].id == "CalendarControl")
			{
				calendarTable[i].removeAttribute("style");
				calendarTable[i].setAttribute("style","");
				calendarTable[i].setAttribute("width",middleArea.offsetWidth);
			}
			if(calendarTable[i].className == "month")
			{
				calendarTable[i].removeAttribute("style");
				calendarTable[i].setAttribute("style","");
				calendarTable[i].setAttribute("width","100%");
			}
		}
	}
}

///////////////////////////////////

// For multiple onload events

var onloadEvents = new Array();

function setOnload(f)
{
	var i = onloadEvents.length;
	onloadEvents[i] = f;
}

function doOnload()
{
	if(onloadEvents.length == 0) return;

	for(var i = onloadEvents.length;i-->0;)
	{
		eval(onloadEvents[i] + "()");
	}
}

onload=doOnload;

setOnload("getTd");
setOnload("loadCalendars");