/*=============================================================================
' Library Description:
'
' Contains JavaScript code to manipulate the calendar object, created by and 
' used in conjunction with libCalendarFunctions.asp.
' 
'============================================================================*/

/*=============================================================================
' Subroutine:	ToggleCalendarFrame
' Description:	Toggles the diplay of the Calendar Frame.
' Notes:		None.
' Assumptions:  None.
' Dependencies:	None.
' Usage:		ToggleCalendarFrame ("Calendar1");
' Input:		None.
' Return value: None.
'------------------------------------------------------------------------------
' 2002-04-29 JRM - Created.
'============================================================================*/

function ToggleCalendarFrame (strFrameID) {
	var objCalendar = document.getElementById(strFrameID);
		
	if (objCalendar) {
		if (objCalendar.style.display == "" || objCalendar.style.display == "block") {
			objCalendar.style.display = "none";
			//objCalendar.style.visibility = "hidden";
		} else {
			objCalendar.style.display = "block";
			//objCalendar.style.visibility = "";
		}
	}
}

/*=============================================================================
' Subroutine:	ChangeCalendarDate
' Description:	None.
' Notes:		None.
' Assumptions:  None.
' Dependencies:	None.
' Usage:		ChangeCalendarDate (document.frmCalendarObject, 12, 1990, '<% =Server.URLEncode(strScriptName) %>');
' Input:		None.
' Return value: None.
'------------------------------------------------------------------------------
' 2002-04-29 JRM - Created.
'============================================================================*/

function ChangeCalendarDate (objForm, intNewMonth, intNewYear, strScriptName) {
	try {
		if (objForm) {
			objForm.Month.value = intNewMonth; 
			objForm.Year.value = intNewYear; 
			objForm.action = strScriptName; 
			objForm.submit();
		}
	} catch (e) {
		alert ("Error! Could not page to the specified date for Month=" + intNewMonth + " and Year=" + intYear + ".\n\n" + e.number + "\n" + e.description);
	}
}
	
/*=============================================================================
' Subroutine:	SetCalendarDate
' Description:	None.
' Notes:		None.
' Assumptions:  None.
' Dependencies:	None.
' Usage:		SetCalendarDate(objCell, window.parent.document.frmMyForm.txtInputField, "", "", "");
' Input:		None.
' Return value: None.
'------------------------------------------------------------------------------
' 2002-04-29 JRM - Created.
' 2002-04-30 JRM - Modified logic to remember previously selected cells 
'				for better paging.
' 2002-11-29 JRM - Added code to allow form submitting.
'============================================================================*/

function SetCalendarDate (objForm, objNewCell, objInputForm, objInputField, strDate, strParentFrameName, strDateFormat, blnSubmitForm) {

	//-----------------------------------------------------------------------------
	// Perform GUI related tasks, such as highlighting the currently selected
	// date cell.
	//-----------------------------------------------------------------------------
	if (objNewCell && objInputField) {
		var objAttSelectedDay = objInputField.getAttribute("SelectedDay");
		var strTodayCellID = objInputField.getAttribute("TodayCellID");
			
		// Grab the default date that was loaded into the page.
		var strDefaultDate = objForm.DefaultDate.value;
		var objDefaultDate = document.getElementById(strDefaultDate);
			
		if (objDefaultDate) {
			// On page load, there is no previously selected cell.
			// Deselect the default date (if specified).
			objDefaultDate.className = "OtherDay";
		} else if (objAttSelectedDay) {
			// If exists, set the previously selected cell to a normal cell.
			objAttSelectedDay.className = "OtherDay";
		}
	
		// Remember the newly selected cell and set the new default date.
		objInputField.setAttribute("SelectedDay", objNewCell);
		objForm.DefaultDate.value = strDate;

		// Now, change its class to make it highlighted.
		if (objNewCell.className == "Today") {
			// Do nothing.
		} else if (objNewCell.className == "OtherDay") {
			objNewCell.className = "Today";
		} else if (objNewCell.className == "OtherDayOn") {
			objNewCell.className = "Today";
		}
	}

	//-----------------------------------------------------------------------------
	// First, set the INPUT field in the parent window to the selected date.
	//-----------------------------------------------------------------------------
	try {
		if (objInputField) {
			var objDate = new Date(strDate);

			//objInputField.value = WriteCustomDate(objDate, strDateFormat);
			objInputField.value = strDate;
		} else {
			alert ("Error! Could not find the INPUT field to populate");
		}
	} catch (e) {
		alert ("Error! Could not assign the selected date to the specified INPUT field.\n\n" + e.number + "\n" + e.description);
	}
		
	//-----------------------------------------------------------------------------
	// Next, close the Calendar Frame if a name is provided.
	//-----------------------------------------------------------------------------
	if (strParentFrameName) {
		try {
			var objParentFrame = window.parent.document.getElementById(strParentFrameName);
				
			if (objParentFrame) {
				objParentFrame.style.display = "none";
				//objParentFrame.style.visibility = "hidden";
			}
		} catch (e) {
			alert ("Error! Could not hide the parent frame: " + strParentFrameName + "\n\n" + e.number + "\n" + e.description);
		}
	}
	
	if (blnSubmitForm) {
		objInputForm.submit();
	}	
}

/*=============================================================================
' Subroutine:	SetLastSelectedDate
' Description:	None.
' Notes:		None.
' Assumptions:  None.
' Dependencies:	None.
' Usage:		SetLastSelectedDate(this.form);
' Input:		None.
' Return value: None.
'------------------------------------------------------------------------------
' 2002-04-30 JRM - Created.
'============================================================================*/

function SetLastSelectedDate (objForm, objDate) {
	if (objForm) {
		//objForm.DefaultDate.value = objDate;
	}
}

/*=============================================================================
' Subroutine:	MouseOverDateCell
' Description:	None.
' Notes:		None.
' Assumptions:  None.
' Dependencies:	None.
' Usage:		MouseOverDateCell(objCell, window.parent.document.frmMyForm.txtInputField);
' Input:		None.
' Return value: None.
'------------------------------------------------------------------------------
' 2002-04-29 JRM - Created.
'============================================================================*/

function MouseOverDateCell (objCellChild, objInputField) {

	//-----------------------------------------------------------------------------
	// Perform GUI related tasks, such as highlighting the currently selected
	// date cell.
	//-----------------------------------------------------------------------------
	if (objCellChild) {
		if (objCellChild.className == "Today") {
		} else if (objCellChild.className == "OtherDay") {
			objCellChild.className = "OtherDayOn";
		}
	}
}

/*=============================================================================
' Subroutine:	MouseOutDateCell
' Description:	None.
' Notes:		None.
' Assumptions:  None.
' Dependencies:	None.
' Usage:		MouseOutDateCell(objCell, window.parent.document.frmMyForm.txtInputField);
' Input:		None.
' Return value: None.
'------------------------------------------------------------------------------
' 2002-04-29 JRM - Created.
'============================================================================*/

function MouseOutDateCell (objCellChild, objInputField) {

	//-----------------------------------------------------------------------------
	// Perform GUI related tasks, such as highlighting the currently selected
	// date cell.
	//-----------------------------------------------------------------------------
	if (objCellChild) {
		if (objCellChild.className == "Today") {
		} else if (objCellChild.className == "OtherDay") {
			objCellChild.className = "";
		} else if (objCellChild.className == "OtherDayOn") {
			objCellChild.className = "OtherDay";
		}
	}
}
