JavaScript functions to calculate calendars