function nextmonth() {
  cmonth=Number(document.webervations_calendar.month_num.value);
  nmonth=cmonth+1;
  if (nmonth == 6) {
  	nmonth=1;
  }
  document.webervations_calendar.month_num.value = nmonth;
  document.dcalendar.src='https://reserve.webervations.com/bookings/calendars.asp?memberid=40118&m='+nmonth;
}

function lastmonth() {
  cmonth=Number(document.webervations_calendar.month_num.value);
  nmonth=cmonth-1;
  if (nmonth == 0) {
	nmonth=1;
  }
  document.webervations_calendar.month_num.value = nmonth;
  document.dcalendar.src='https://reserve.webervations.com/bookings/calendars.asp?memberid=40118&m='+nmonth+'';
}

var startDate;
var endDate;

function resetDates() {
	startDate = endDate = null;
}

function filterDates1(cal) {
	startDate = new Date(cal.date)
	startDate.setHours(0,0,0,0)	// used for compares without TIME
	/* If they haven't chosen an 
	end date before we'll set it to the same date as the start date This
	way if the user scrolls in the start date 5 months forward, they don't
	need to do it again for the end date.
	*/

	Zapatec.Calendar.setup({
		inputField     :    "edate",
		button         :    "button8b",  // What will trigger the popup of the calendar
		ifFormat       :    "%b %d, %Y",
		date           :     cal.date,
		showsTime      :     false,          //no time
		dateStatusFunc :    disallowDateBefore, //the function to call
 					weekNumbers    :    false,	  // no week numbers
		onUpdate       :    filterDates2
	});
	document.basicSearch.edate.value='';
}


function filterDates2(cal) {
	var date = cal.date;
	endDate = new Date(cal.date)
	endDate.setHours(0,0,0,0)	// used for compares without TIME
	resetDates();
}

/*
* This functions return true to disallow a date
* and false to allow it.
*/


/* 
* Check-Out calendar allowed dates
* Check-Out date can not be BEFORE Check-In date
* Check-Out date can not be before today
*/
function disallowDateBefore(dateCheckOut) {
	dateCheckOut.setHours(0,0,0,0)
	if ((startDate != null) && startDate > dateCheckOut)
		// startDate is defined, make sure cal date is NOT before start date
		return true; 
			
	var now = new Date()
	now.setHours(0,0,0,0)
	if (dateCheckOut < now) 
		// check out date can not be befor today if startDate NOT defined
		return true;

	return false;
}

/* 
* Check-In date checking
* Check-In date can not be AFTER Check-Out date
* Check-In date can not be before today
*/
function disallowDateAfter(dateCheckIn) {
	dateCheckIn.setHours(0,0,0,0)
	if ((endDate != null) && dateCheckIn > endDate)
		// endDate defined, calendar date can NOT be after endDate
		return true;

	var now = new Date()
	now.setHours(0,0,0,0)

	if (dateCheckIn < now)
		// endDate NOT defined, calendar date can not be before today
		return true;

	return false;
}

function init_avail() {
	Zapatec.Calendar.setup({		
		inputField     :    "bdate",   // id of the input field
		button         :    "button8a",  // What will trigger the popup of the calendar button8a/
		ifFormat       :    "%b %d, %Y",       // format of the input field: Mar 18, 2005
		showsTime      :     false,          //no time
		dateStatusFunc :     disallowDateAfter, //the function to call
		weekNumbers    :     false,	  // no week numbers
		onUpdate       :     filterDates1
	});
		
	Zapatec.Calendar.setup({
		inputField     :    "edate",
		button         :    "button8b",  // What will trigger the popup of the calendar
		ifFormat       :    "%b %d, %Y",       // format of the input field: Mar 18, 2005
		showsTime      :     false,          //no time
		dateStatusFunc :     disallowDateBefore, //the function to call
		weekNumbers    :     false,	  // no week numbers
		onUpdate       :     filterDates2
	});
}


