// JavaScript Document
<!--  to hide script contents from old browsers

/* Insert this javascript file in the body section where you want the calendar to appear.  You will need the additional supporting .css and .js files in the header */

// 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)
		window.status=strDate + " - " + strSpecialDay
	else
		window.status=strDate

	//div.innerHTML=""
	div.style.visibility="visible";
	tdDate.innerHTML="&nbsp;" + strDate;
	tdEvent.innerHTML="&nbsp;"

	if (!strSpecialDay)
		// this is NOT a special day
		return;
	
	tdDate.innerHTML="&nbsp;" + strDate
	tdEvent.innerHTML="&nbsp;" + strSpecialDay
}



/*
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";

	return false; // ALL other dates are enabled
	// NOTE:return true to disable a specific date
}

/*
Use this function to add the special days
Add the DD-MMM-YYYY, Text for the special day
*/
function load_SpecialDays() {
add_SpecialDay("15-Jan-2012", "not used")
add_SpecialDay("17-Jan-2012", "not used")
add_SpecialDay("23-Jan-2012", "not used")
add_SpecialDay("31-Jan-2012", "not used")
add_SpecialDay("10-Feb-2012", "not used")
add_SpecialDay("15-Feb-2012", "not used")
add_SpecialDay("23-Feb-2012", "not used")
add_SpecialDay("29-Feb-2012", "not used")
add_SpecialDay("01-Mar-2012", "not used")
add_SpecialDay("15-Mar-2012", "not used")
add_SpecialDay("23-Mar-2012","not used")
add_SpecialDay("15-Apr-2012", "not used")
add_SpecialDay("16-Apr-2012", "not used")
add_SpecialDay("23-Apr-2012", "not used")
add_SpecialDay("30-Apr-2012", "not used")
add_SpecialDay("10-May-2012", "not used")
add_SpecialDay("15-May-2012", "not used")
add_SpecialDay("23-May-2012", "not used")
add_SpecialDay("15-Jun-2012", "not used")
add_SpecialDay("25-Jun-2012", "not used")
add_SpecialDay("30-Jun-2012", "not used")
add_SpecialDay("15-Jul-2012", "not used")
add_SpecialDay("16-Jul-2012", "not used")
add_SpecialDay("23-Jul-2012", "not used")
add_SpecialDay("31-Jul-2012", "not used")
add_SpecialDay("10-Aug-2012", "not used")
add_SpecialDay("15-Aug-2012", "not used")
add_SpecialDay("23-Aug-2012", "not used")
add_SpecialDay("31-Aug-2012", "not used")
add_SpecialDay("17-Sep-2012", "not used")
add_SpecialDay("24-Sep-2012", "not used")
add_SpecialDay("30-Sep-2012", "not used")
add_SpecialDay("15-Oct-2012", "not used")
add_SpecialDay("23-Oct-2012", "not used")
add_SpecialDay("31-Oct-2012", "not used")
add_SpecialDay("10-Nov-2012", "not used")
add_SpecialDay("15-Nov-2012", "not used")
add_SpecialDay("23-Nov-2012", "not used")
add_SpecialDay("17-Dec-2012", "not used")
add_SpecialDay("24-Dec-2012", "not used")
add_SpecialDay("31-Dec-2012", "not used")
}

// Call function to load all the special days
load_SpecialDays()

/*The following JavaScript code defines a function that will
get called each time the user modifies the date inside the calendar.
To make sure that a date was actually clicked, we check the
cal.dateClicked variable.  If a date wasn't clicked this will be
“false” and it usually means that the date was modified using the
month or year navigation buttons, or that only the time got modified. */

    //<![CDATA[
      function flatCalendarCallback(cal) {
        if (cal.dateClicked) {
          var url = "http://www.bradstreetcpas.com/special-days.htm#" + cal.date.print("%Y%m%d");
          // alert("Jumping to: “" + url + "” (not really).");
          // uncomment the following line to actually jump:
          window.location = url;
        }
      };
    //]]>


 //<![CDATA[
      Zapatec.Calendar.setup({
        weekNumbers       : false,
        step              : 1,
        flat              : "calendar",
        flatCallback      : flatCalendarCallback,
				dateStatusFunc 		: check_special
      });
	 //]]>	

// end hiding contents from old browsers  -->
