
	var currentTripPlannerDrag = '';

	function loadCalendar(year, month){

		dojo.xhrGet( {
			url: "http://www.visitithaca.com/my-ithaca-experience/ajax/calendar.php?y="+year+"&m="+month, 
			handleAs: "text",
			timeout: 5000,
			load: function(response, ioArgs) { // The LOAD function will be called on a successful response.
				dojo.byId("calendarContent").innerHTML = response;
				fadeIn('calendarContent', 500);
			},
			error: function(response, ioArgs) { // The ERROR function will be called in an error case.
				alert('There was an error.\n'+response);
				return response;
			}
		});
		return true;
	}
	

	function calendarDayClick(year, month, day, itineraryID){
			// set by onmousedown event on draggable button
		if(currentTripPlannerDrag!='') currentTripPlannerDrag = '&new='+currentTripPlannerDrag;
		else currentTripPlannerDrag = '';
	
		dojo.xhrGet( {
			url: "http://www.visitithaca.com/my-ithaca-experience/ajax/calendarDay.php?year="+year+"&month="+month+"&day="+day+"&itineraryID="+itineraryID+""+currentTripPlannerDrag, 
			handleAs: "text",
			timeout: 5000,
			load: function(response, ioArgs) { // The LOAD function will be called on a successful response.
				dojo.byId("calendarAdd").innerHTML = response;
			},
			error: function(response, ioArgs) { // The ERROR function will be called in an error case.
				alert('There was an error.\n'+response);
				return response;
			}
		});

		window.location = '#'; // jump to top
		currentTripPlannerDrag = '';
		fadeIn('calendarAdd', 500);
		return true;
	}

	function closeCalendarDay(){
		fadeOut('calendarAdd', 500); 
		return true;
	}
	
	function saveCalendarItem(year, month, day, name, startTime, notes, itineraryID){
		//closeCalendarDay();
		dojo.xhrGet( {
			url: "http://www.visitithaca.com/my-ithaca-experience/ajax/calendarDay.php?year="+year+"&month="+month+"&day="+day+"&name="+name+"&startTime="+startTime+"&notes="+notes+"&itineraryID="+itineraryID, 
			handleAs: "text",
			timeout: 5000,
			load: function(response, ioArgs) { // The LOAD function will be called on a successful response.
				dojo.byId("calendarAdd").innerHTML = response;
			},
			error: function(response, ioArgs) { // The ERROR function will be called in an error case.
				alert('There was an error.\n'+response);
				return response;
			}
		});
		window.location = '#'; // jump to top
		currentTripPlannerDrag = '';
		//fadeIn('calendarAdd', 500);

		return true;
	}
	
	function processAddItemForm(year, month, day, itineraryID){
		name = document.getElementById('newName').value;
		startTime = document.getElementById('newTime').value;
		notes = document.getElementById('newNotes').value;
		if(name=='' || startTime==''){
			alert('You need to enter a name and a start time.');
			return false;
		}
		saveCalendarItem(year, month, day, name, startTime, notes, itineraryID);
		return true;
	}
