var mailAddress  = 'aaa@bbb.cc';
var property     = escape(document.getElementById('property-title').innerHTML);
var mailSubject  = escape('Booking enquiry for ') + property;
var nl           = escape('<br>\r\n');

var bookingDates = [];
var mailDetails  = "";



var handleDates = function(cal) {
  bookingDates.length = 0;     

  for (var i in cal.multiple) {
    var curDate = cal.multiple[i];

    if (curDate) {
      bookingDates[bookingDates.length] = curDate;
    }
  }

  return true;
};

var isBooked = function(oCurDate, sYear, sMonth, sDay) {
    var sCurDate = oCurDate.print("%Y-%m-%d");
    for (var i in bookedDates) {
        if (bookedDates[i] == sCurDate) {
            return true;
        }
    }

    return false;
};

var makeBooking = function() {   
    mailDetails = "<strong>Dates Requested: </strong>";
    
    for (var i in bookingDates) {
        var booking = bookingDates[i];
        
        if (booking) {
            mailDetails += nl + booking.print("%A,  %d %B %Y");
        }
    }
    
    window.location.href = 'mailto:' + mailAddress
                         + '?subject=' + mailSubject
                         + '&body='
                         + '<html><body>' + nl + nl
                         + escape('Please include the following information in your mail:') + nl
                         + '--------------------------------------------------------------'
                         + '--------------------------------------------------------------' + nl
                         + '<strong>Property:</strong> ' + property + nl
                         + mailDetails
                         + '</body></html>';

};

Calendar.setup({
    flat        : "calendar-container",
    align       : "BR",
    firstDay    : 1, // 1=monday, 0=sunday (default)
    range       : dateRange,
    multiple    : true,
    dateStatusFunc : isBooked,
    onUpdate    : handleDates
});