var activeDate; // holds currently selected date for Month and Week views
var classList; // holds the list of Event Classes to show 

// constants used to make modification easier
var Cal_Monthview = "/calendar/monthview.aspx";
var Cal_Weekview = "/calendar/weekview.aspx";
var Cal_Dayview = "/calendar/dayview.aspx";
var Cal_AddEvent = "/calendar/editevent.aspx";
var Cal_EditEvent = "/calendar/editevent.aspx";
var Cal_DelEvent = "/calendar/delevent.aspx";
var Cal_Filter = "/calendar/filter.aspx";
var Cal_Popup = "/calendar/popup.aspx";

var url = new String();

url = location.href;

if(url.indexOf("?class") > 0)
{
	classList = "&" + url.substr(url.indexOf("?class") + 1);
	
} // if

else
	if(url.indexOf("&class") > 0)
	{
		classList = url.substr(url.indexOf("&class"));
	
	} // if
	
	else
		classList = "";

function viewMonth()
{
	location.href = Cal_Monthview + "?date=" + activeDate + classList;
} // viewMonth

function viewWeek()
{
	location.href = Cal_Weekview + "?date=" + activeDate + classList;
	
} // viewWeek

function viewDay()
{
	location.href = Cal_Dayview + "?date=" + activeDate + classList;
	
} // viewDate

function addEvent()
{	
	window.open(Cal_AddEvent + "?action=add&date=" + activeDate, "addevent", "width=500,height=550,location=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes");
	
} // addEvent

function editEvent(id)
{
	window.open(Cal_EditEvent + "?action=edit&id=" + id, "editevent", "width=500,height=550,location=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes");
	
} // editEvent

function delEvent(id)
{
	window.open(Cal_DelEvent + "?id=" + id, "delevent", "width=500,height=400,location=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes");
	
} // deleEvent

function filterClasses()
{
	window.open(Cal_Filter, "filterclasses", "width=400,height=200,location=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes");
		
} // filterClasses

function changeMonth()
{
	var selMonth;
	var txtYear;
	selMonth = document.getElementById("selmonth");
	txtYear = document.getElementById("txtyear");
	location.href = Cal_Monthview + "?date=" + selMonth.value + "-1-" + txtYear.value;
	
} // changeMonth

function setActiveDate(control)
{
	var i, divs;
		
	divs = document.getElementsByTagName("div");
	
	for(i = 0; i < divs.length; i++)
	{
		if((divs[i].className == "event") || (divs[i].className == "otherevent"))
			divs[i].style.backgroundColor = "";
		
	} // for
	
	activeDate = control.id.substr(1); // trim the "d" off of the control id to get a plain date
	
	control.style.backgroundColor = "#0080ff"; // highlight background color. Doesn't work with Opera, things stay highlighted.
	
} // setActiveDate

function printCalendar()
{
	var i, divs, control;
		
	divs = document.getElementsByTagName("div");
	
	for(i = 0; i < divs.length; i++)
	{
		if((divs[i].className == "event") || (divs[i].className == "otherevent"))
			divs[i].style.backgroundColor = "";
		
	} // for
	
	window.print();
	
	control = document.getElementById("d" + activeDate);
	
	control.style.backgroundColor = "#0080ff";
	
} // printCalendar

function popupDetail(id)
{
	window.open(Cal_Popup + "?id=" + id, "detail", "width=620,height=400,location=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes");
	
} // popupDetail