dojo.provide('smart.calendar');

smart.calendar.showMonth = function(i, month, section, venue, category){
    if(dojo.byId('month_' + i)){

        dojo.query('.calendar_month').forEach(function(e){
            e.style.display = 'none';
        });
        
        dojo.byId('month_' + i).style.display = 'block';

    }

    smart.calendar.getEvents(month, section, venue, category);
}

smart.calendar.getEvents = function(date, section, venue, category){
    dojo.byId('calendar_events_inner').innerHTML = 'Loading...';

    var url = '/events/getevents';
    if(date != ''){
        url = '/events/getevents/date/' + date;
    }

    if(section != ''){
        url += '/section/' + section;
    }

    if(venue != ''){
        url += '/venue/' + venue;
    }

    if(category != ''){
        url += '/category/' + category;
    }

    dojo.xhrGet({
       url: url,
       load: function(response){
           dojo.byId('calendar_events_inner').innerHTML = response;
       },
       error: function(e, io){
          if(io.xhr.status != 0){
              alert('Sorry, an error occurred. Please reload the page and try again.');
          }
       }
    });
}
