// jsCalendar handler.
// Allows specification of a template destination url to open in a new window
// when a date is clicked.
function cJsCalendar( strCalendarContainerID, strUrlTemplate, intPopupWidth, intPopupHeight )
{
	var parent = this;
	this.m_strCalendarContainerID = strCalendarContainerID;
	this.m_strUrlTemplate = strUrlTemplate;
	this.m_intPopupWidth = intPopupWidth;
	this.m_intPopupHeight = intPopupHeight;

	// Function that gets called when the date is changed (jsCalendar callback)
	//
	this.dateChanged = function(calendar) 
	{
		// Beware that this function is called even if the end-user only
		// changed the month/year.  In order to determine if a date was
		// clicked you can use the dateClicked property of the calendar:
		if (calendar.dateClicked) 
		{
			// OK, a date was clicked, open a window with the url
			var y = calendar.date.getFullYear();
			var m = calendar.date.getMonth();     // integer, 0..11
			var d = calendar.date.getDate();      // integer, 1..31

			var strUrl = parent.m_strUrlTemplate;

			// Un-encode the escaped values
			strUrl = strUrl.replace( /\%5b/gi, '[' );
			strUrl = strUrl.replace( /\%5d/gi, ']' );
			strUrl = strUrl.replace( /\%2f/gi, '\/' );

			strUrl = strUrl.replace( /\[y\]/gi, y );
			strUrl = strUrl.replace( /\[m\]/gi, m+1 );
			strUrl = strUrl.replace( /\[d\]/gi, d );

			var open_child_window = window.open(
				strUrl,
				'calendar',
				'scrollbars=yes,height=' + parent.m_intPopupHeight + ',width=' + parent.m_intPopupWidth )
		}
	};

	// Initialization of the calendar object.
	//	
	this.onLoad = function()
	{
		Calendar.setup(
			{
				flat         : this.m_strCalendarContainerID, // ID of the parent element
				flatCallback : this.dateChanged,           // our callback function
				weekNumbers  : false					// Show the week numbers?
			}
		);
	};

	return this;
}


