/**
* Setup the floors array for manipulation
*/
var floors 		= new Array(3);
floors[10001] 	= make_date();
floors[1007] 	= make_date();
floors[1008] 	= make_date();

/**
* Next/Previous functions
* Note: End date is just the start date with a further "end day" 1st/28(<-- end day.)th etc.
*/
function switch_dates(propertyId, go) {
	/**
	* javascript starts "january" as 0 therefor december is 11
	*/
	var maxMonth = 11;
	var minMonth = 0;

	/**
	* AJAX throbber
	*/
	document.getElementById('floor-' + propertyId).innerHTML = '<br /><br /><div style="width: 185px;"><img src="/images/throbber.gif" /></div>';
	var cloneObj		= floors[propertyId];
	var currentDay		= cloneObj.getDate();
	var currentYear 	= cloneObj.getFullYear();
	var currentMonth	= cloneObj.getMonth();

	/**
	* Change dates accordingly
	*/
	switch (go) {
		case 'next':
		if (currentMonth == maxMonth) {
			currentMonth = minMonth; currentYear++;
		} else {
			currentMonth++;
		}
		break;

		/**
		* Previous month
		*/
		case 'previous':
		if (currentMonth == minMonth) {
			currentMonth = maxMonth; currentYear--;
		} else {
			currentMonth--;
		}
		break;
	}

	// override old values
	cloneObj.setMonth(currentMonth);
	cloneObj.setFullYear(currentYear);
	cloneObj.setDate(cloneObj.getDate());

	var daysToAdd 		= daysInMonth(currentMonth, currentYear);

	var endDate 		= new Date();
	endDate.setDate(28);
	endDate.setMonth(currentMonth);
	endDate.setFullYear(currentYear);
	endDate.setDate(endDate.getDate());

	$.get('/content/en/booking-calendar/ajax.table.php', { "propertyId" : propertyId, "startDate" : cloneObj, "endDate" : endDate, "go" : go }, function (data) {
		/** REMOVE ACTIVITY INDICATOR **/
		document.getElementById('floor-' + propertyId).innerHTML = data;
	});
}

function daysInMonth(month,year) {
	var m = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (month != 2) return m[month - 1];
	if (year%4 != 0) return m[1];
	if (year%100 == 0 && year%400 != 0) return m[1];
	return m[1] + 1;
}