var calendarDivId;
function loadAvailabilityCalendar(journeyId, initCalendarDivId, isDisplayCalendar)
{	
	calendarDivId = initCalendarDivId;
	if ( isDisplayCalendar) {
		displayRelativeAjaxWarning(calendarDivId, "Loading Dates");

		new Ajax.Request(
			"ajaxGetJourneyTimesJSON.do", 
			{
		 		onSuccess  : loadJourneyTimesSuccessful,
		 		onFailure  : loadJourneyTimesFailed,
				parameters : "journeyId=" + journeyId
			}
		);
	}
}

function loadJourneyTimesSuccessful(xhrObject)
{
	if ( xhrObject.responseText.indexOf("fail") >= 0) {
		// Was really a failure on the server-side but HTTP request processed OK so this method was still called...
		loadJourneyTimesFailed(xhrObject);
	} else  {
       		var jsonData = eval('('+xhrObject.responseText+')');
			var recurringDates = jsonData.journeyTimes.recurringDates;
			var excludedDates = jsonData.journeyTimes.excludedDates;
			if ( excludedDates == "") 
				excludedDates = null;
			var calendar = new AvailabilityCalendar(recurringDates,excludedDates);
			calendar.showCalendar(calendarDivId);
	}
}
	
function loadJourneyTimesFailed(xhrObject)
{
	alert("An error occurred while loading the calendar of available time for this journey.\n\n"
		  + "Please refresh your page and contact us if the problem persists.");
	calendarDivId.innerHTML = "";
}

