// JavaScript Document

// Define array of SpecialDays
	var arrSpecialDays=new Array();
	// Define the Name of the months
	var arrMonths=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	
	/* 	Create the Key for the lookup of Special Days
		Convert this date string into Date object. Time is set to 0. Return Date object  */
	function setKey(strDateIn)
	{
		var strDate=strDateIn
			if (isNaN(Date.parse(strDate)))
			{
				// see if we can fix any invalid chars
				strDate=strDate.replace(/[^0-9A-Za-z ]/g, " ");
			}
			else if (Zapatec.is_opera)
			{
				if (typeof strDate == "string") strDate=strDate.replace(/[^0-9A-Za-z ]/g, " ");
			}
	
			if (isNaN(Date.parse(strDate)))
			{
				alert("ERR:"+strDate+" not a valid date")
				return false;
			}
		var d=new Date(strDate)
		// Make sure TIME is zero.  We just want the dates
		d.setHours(0,0,0,0)
		return d
	}

/*	strDate: Date for special day, DD-MMM-YY
	strDesc: Text for Special Day
	return string where each line is Date,Special Day Text	*/
function add_SpecialDay(strDate, strDesc)
{
	arrSpecialDays[setKey(strDate)]=strDesc
}

/* return a string of all special days */
function dump_SpecialDays()
{
	var strDump=""
	var i
	for (i in arrSpecialDays)
		strDump+= (strDump ? "\n" : "") + i + " is " + arrSpecialDays[i]
	return strDump
}

/* 
Function to check if this date is a Special Day 
return true special day date is defined via add_SpecialDays calls
*/
function isSpecialDay(strDate)
{
	return typeof(getSpecialDay(strDate)) != "undefined"
}

/* return string for the special day */
function getSpecialDay(strDate)
{
	return arrSpecialDays[setKey(strDate)]
}

/* 
The date has changed, show the date in the HTML tag whose ID is preview
Also, display the text in a window
*/
function dateChanged(calendar)
{
	var strDate=calendar.date.print('%a %b %d, %Y');
	var strSpecialDay=getSpecialDay(strDate)
	var div=document.getElementById("showSpecial")
	var tdDate=document.getElementById("tdDate")
	var tdEvent=document.getElementById("tdEvent")

	//if (!strSpecialDay)
	// this is NOT a special day
	//return;
	// added by jen to open new page for calendar click item
	var url = "http://www.cocastl.org/subpage.cfm?vSection=events&vPage=calendar&eventDate=" + cal.date.print("%Y-%m-%d");
	window.location = url;
}

/*
Option: dateText
Use this function to set the Text in the calendar.
This function is called for each DAY cell.
You need to define the 
-Use this function to display special day text.
NOTE:When you use this function you MUST define the contents of the cell for the day.  For example, if the day
is NOT a special day then you still need to return the day number
*/
function getDateText(date)
{
	var strInfo=getSpecialDay(date);
	if (!strInfo)
		// No special day, just return the Day of Month
		// return date.getDate() + "<div class='zpCal-no-DayInfo'><" + "/div>";
		return "<span class='zpCalDayInfo2'>" + date.getDate() + "<" + "/span>";

	var strText=new String(strInfo)
	// Use special class zpCalDayInfo to visually show special day in calendar using CSS

	/*
	// Use this code to display the SpecialDay text in calendar
		if (strText.length > 8)
	{
		strText=strText.substring(0, 8)
		strText+="+"
	}
	return date.getDate() + "<br/><div class='zpCalDayInfo'>" + strText + "<" + "/div>";
	//return date.getDate() + "<br/><pre style='width:8em;'>" + strText + "<" + "/pre>";
	*/

	// Just show day number with special CSS, NO TEXT
	return "<span class='zpCalDayInfo'>" + date.getDate() + "<" + "/span>";
}

/*
Option: dateStatusFunc
A function that receives a JS Date object and returns a boolean or a string. This function allows one to set a certain CSS 
class to some date, therefore making it look different. 
If it returns true then the date will be disabled. 
If it returns false nothing special happens with the given date. 
If it returns a string then that will be taken as a CSS class and appended to the date element. 
If this string contains disabled then the date is also disabled (therefore is like returning true) but with your own custom style.
*/
function check_special(strDate)
{
	if (isSpecialDay(strDate)) 
		return "zpCalSpecialDay";
	else
		return "zpCalSpecialDay2";

	return false; // ALL other dates are enabled
	// NOTE:return true to disable a specific date
}