title: jquery UI datepicker - disabling date ranges
body: <p>I'm struggling to get something working - I'm getting a 'Uncaught TypeError: Cannot read property '0' of undefined' error with the below and I can't figure out why!</p>
  
  <p>I'm trying to use the jQuery UI datepicker on a site for a holiday cottage to indicate availability and season (low, high etc). I have a function as a datePicker event to check if there's a booking for a date, and if not, I then go out to check which season we're in (In non-peak season bookings can be made on a Monday or Friday. In Peak season, it's Fridays only. )</p>
  
  <p>I'm using a cms to generate some date arrays (via loops) that I can then iterate through when building the calendar, so the javascript is a little verbose.</p>
  
  <p>The arrays look like this:</p>
  
  <pre><code>&lt;script&gt; 
  //Peak Season 1 2011
  var ps1 = new Date('June 17, 2011');
  var pe1 = new Date('September 2, 2011');
  //Peak Season 2 2011
  var ps2 = new Date('December 19, 2011');
  var pe2 = new Date('January 6, 2012');
  // season start and end date arrays
  var peakStart = new Array(ps1,ps2);
  var peakEnd = new Array(pe1,pe2);
  
  // Bookings
  //Mr &amp;amp; Mrs Smith 
  var cbs1 = new Date('May 27, 2011');
  var cbe1 = new Date('June 5, 2011');
  //Mr &amp;amp; Mrs Jones 
  var cbs2 = new Date('September 1, 2011');
  var cbe2 = new Date('September 18, 2011');
  var cottageStart = new Array(cbs1,cbs2);
  var cottageEnd = new Array(cbe1,cbe2);
  
  // last date of season - don't book past here
  var lastDate = '01/06/2012';
  &lt;/script&gt;
  </code></pre>
  
  <p>I have the following function that I call from the beforeShowDate event to check the calendar date against the booking array:</p>
  
  <pre><code>$('#cottageCal').datepicker({
      minDate: '0d',
      maxDate: lastDate,
      beforeShowDay: function(date) {
          $.each(cottageStart, function(key, value) { 
            //alert (((date &gt;= value) &amp;&amp; (date &lt;= value)) ? 'booked' : 'notbooked');
              if ((date &gt;= value) &amp;&amp; (date &lt;= value)) {
                  return [false, 'booked'];
              } else {
                  return checkPeak(date);
              }
          });
      }
  });
  </code></pre>
  
  <p>Finally, the checkPeak function that is called from here looks like this:</p>
  
  <pre><code>var checkPeak = function(date) {
      var day = date.getDay();
      var month = date.getMonth();
      $.each(peakStart, function(key, value) { 
          if ((date &gt; value) &amp;&amp; (date &lt; value)) {
          /* december peak bookings on monday*/
              if (month != 11) {
                  return [(day == 5), ''];
              } else {
                  return [(day == 1), ''];
              }
          }
          if (month == 0) {
              return false;
          } else {
              // it's not during a peak period
              return [(day == 1 || day == 5), ''];
          }
      });
  }
  </code></pre>
  
  <p>I must be doing something fundamentally wrong here but I can't see what!</p>