/**
 * Called when the page DOM is done loading.
 */
$(document).ready( function () {
		// init the travel calendar
		initTravelCalendar();
		$("#p_altdate").datepicker({
			 onSelect: function(dateText, inst) { initTravelCalendar(); }
		});
});


/**
 * Breaks down the date of the calendar into it's pieces and populates required hidden input values.
 */
function initTravelCalendar() {
	debug.group('initTravelCalendar says hi!!!');
	// Code takes the "p_altdate" and "n_nights" and does the math 
	// to get a checkin and checkout date
	var iNight = $('#n_nights').val();
	var dt = new Date($("#p_altdate").val());
	var day = dt.getDate();
	var day2 = 1+ parseInt(day) + parseInt(iNight); // +1?
	var month = dt.getMonth();
	$('#dd').val(day2);
	$('#dm').val(month);
	$('#ad').val(day);
	$('#am').val(month);
	
	debug.log($('#dd').val(),'dd');
	debug.log($('#dm').val(),'dm');
	debug.log($('#ad').val(),'ad');
	debug.log($('#am').val(),'am');
	
	debug.groupEnd();
}
