// calendar.js - calendar-related utility functions and data

var cal_util = {

days_in_month: [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ],

// (Is there no way to get this from the Date object, or some other way in
// Javascript?  I can't believe I have to hard-code these.)
month_name: [
  'January',
  'February',
  'March',
  'April',
  'May',
  'June',
  'July',
  'August',
  'September',
  'October',
  'November',
  'December'
],

// Naive -- doesn't handle 100-, 400-year exceptions.  Those won't happen
// until 2100 anyway.  If this code is still running as-is by then, I will
// consider myself to have been immortalized.
isLeapYear: function(y) { return y%4 == 0; },

// m is 1-based.
daysInMonth: function(y, m) {
  if (m == 2 && this.isLeapYear(y)) return 29;
  return this.days_in_month[m-1];
},

// m is 1-based.
isValidDate: function(y, m, d) {
  if (m < 1 || m > 12) return false;
  return d >= 1 && d <= this.daysInMonth(y, m);
}

// NOTE: the last entry must not have a trailing comma because IE treats this
// as a syntax error.  The other alternative is to declare an empty object for
// the namespace and then define each field using an explicit reference to the
// namespace.  That's annoying though.

};  // namespace cal_util

