// initialize array for use with multiple selections
// leave this value empty, it's only used for keeping track of active selections
var MA = [];

var today = new Date();

// calculate the date in seven days
var todayPlusSeven = new Date();
todayPlusSeven.setDate(todayPlusSeven.getDate() + 7);

// calculate the date in the next amount of months
var monthsFuture = new Date();
monthsFuture.setDate(monthsFuture.getDate() + (30 * monthsAhead));

function dateIsSpecial(year, month, day) {

	// loop through each calendar date (this month's view)
	// and see if this date needs to be disabled

	// alert(month); // January = 0, February = 1

	// try the current year first
	var y = disabledDates[year];

	if (!y) {
		return false;
	}

	for (var i in y) {
		// run through each month in this year
		var m = disabledDates[year][month];

		if (!m) {
			return false;
		}

		for (var j in m) {
			if (m[j] == day) {
				return true;
			}
		}
	}

	return false;
}

function ourDateStatusFunc(date, y, m, d) {

  if (date < today) {
    return true;
  }

  if (date < todayPlusSeven) {
    return true;
  }

  if (date == today) {
    return false;
  }

  // disable if more than certain amount of months in the future
  if (date > monthsFuture) {
    return true;
  }

  if (dateIsSpecial(y, m, d)) {
    // return "special";
    return true;
  } else {
    return false; // other dates are enabled
    // return true if you want to disable other dates
  }

}

function updateDateList(cal) {

  // here we'll write the output; this is only for example.  You
  // will normally fill an input field or something with the dates.
  var el = document.getElementById("date-list");
  var note = document.getElementById("date-note");
  // var wrap = document.getElementById("date-wrap");
  var input = document.getElementById("ReservationReservationDates");  // LBW added 01/16/09 to add selected dates to the hidden input
  var input_string = document.getElementById("ReservationReservationDatesString");  // LBW added 01/16/09 to add selected dates to the hidden input

  // show selected dates area
  // wrap.setAttribute("style", "display: block;");
  note.setAttribute("style", "display: none;");

  // reset initial content.
  el.innerHTML = "";
  input.value = "";  // LBW added 01/16/09 to add selected dates to the hidden input
  input_string.value = "";  // LBW added 01/16/09 to add selected dates to the hidden input

  // Reset the "MA", in case one triggers the calendar again.
  // CAREFUL!  You don't want to do "MA = [];".  We need to modify
  // the value of the current array, instead of creating a new one.
  // Calendar.setup is called only once! :-)  So be careful.
  MA.length = 0;

  // walk the calendar's multiple dates selection hash
  for (var i in cal.multiple) {
    var d = cal.multiple[i];
    // sometimes the date is not actually selected, that's why we need to check.
    if (d) {
      // OK, selected.  Fill an input field.  Or something.  Just for example,
      // we will display all selected dates in the element having the id "output".
      el.innerHTML += '<li>' + d.print("%A, %B %d, %Y") + '</li>';
      input.value += d.print("%Y-%m-%d") + ","; // LBW added 01/16/09 to add selected dates to the hidden input
      input_string.value += d.print("%A, %B %d, %Y") + ";"; // LBW added 01/16/09 to add selected dates to the hidden input

      // and push it in the "MA", in case one triggers the calendar again.
      MA[MA.length] = d;
    }
  }
  return true;
}