function on_filter_by_date(year, month, day, is_images, is_shows, is_videos)
{
  is_filter_by_date = true;
  cur_year = year;
  cur_month = month;
  cur_day = day;

  if (is_images)
  {
      get('iloader').innerHTML = '';

      if (is_full_content('i', 1) && get('ifiltered').value == 'false')
      {
        show_date('i', year, month, day);
        initialize_pages('i', IMAGES);
        images_go_page(1);
      }
      else
      if (has_date('i', year, month, day))
      {
        show_date('i', year, month, day);
        initialize_pages('i', IMAGES);
        images_go_page(1);
      }
      else
      {
          get('inavinfo').style.display = 'none';
          get('inavbar').style.display = 'none';
          get('ihascontent').style.display = 'none';
          get('inocontent').style.display = 'none';

          set_loading('imageinfo_content_loading');
          var o = get('imageinfo_content_loading');
          if (o)
            o.style.display = '';

          var callback_url = '/homepage/images.php';
          img_counter++;
          abort_connection(img_loader);
          get('ifiltered').value = 'true';
          // TODO: One month fetch
          callback_url += '?ipage=1&id=' + get('id').value + '&from_y=' + year + '&from_m=' + (month + 1) + '&from_d=' + day + '&to_y=' + year + '&to_m=' + (month + 1) + '&to_d=' + day + '&rand=' + Math.random();

          callback =
          {
              success:  fetch_images_calendar_callback,
              failure:  fetch_images_calendar_callback,
              argument: [img_counter, year, month, day]
          };

          img_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
      }
  }

  if (is_shows)
  {
      get('sloader').innerHTML = '';

      if (is_full_content('s', 1) && get('sfiltered').value == 'false')
      {
        show_date('s', year, month, day);
        initialize_pages('s', SHOWS);
        slideshows_go_page(1);
      }
      else
      if (has_date('s', year, month, day))
      {
        show_date('s', year, month, day);
        initialize_pages('s', SHOWS);
        slideshows_go_page(1);
      }
      else
      {
          get('snavinfo').style.display = 'none';
          get('snavbar').style.display = 'none';
          get('shascontent').style.display = 'none';
          get('snocontent').style.display = 'none';

          set_loading('slideshowinfo_content_loading');
          var o = get('slideshowinfo_content_loading');
          if (o)
            o.style.display = '';

          var callback_url = '/homepage/slideshows.php';
          show_counter++;
          abort_connection(show_loader);
          get('sfiltered').value = 'true';
          // TODO: One month fetch
          callback_url += '?spage=1&id=' + get('id').value + '&from_y=' + year + '&from_m=' + (month + 1) + '&from_d=' + day + '&to_y=' + year + '&to_m=' + (month + 1) + '&to_d=' + day + '&rand=' + Math.random();

          callback =
          {
              success:  fetch_shows_calendar_callback,
              failure:  fetch_shows_calendar_callback,
              argument: [show_counter, year, month, day]
          };

          show_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
      }
  }

  if (is_videos)
  {
      if (!get('videoinfo_content'))
          return;
      get('vloader').innerHTML = '';

      if (is_full_content('v', 1) && get('vfiltered').value == 'false')
      {
        show_date('v', year, month, day);
        initialize_pages('v', VIDEOS);
        videos_go_page(1);
      }
      else
      if (has_date('v', year, month, day))
      {
        show_date('v', year, month, day);
        initialize_pages('v', VIDEOS);
        videos_go_page(1);
      }
      else
      {
          get('vnavinfo').style.display = 'none';
          get('vnavbar').style.display = 'none';
          get('vhascontent').style.display = 'none';
          get('vnocontent').style.display = 'none';

          set_loading('videoinfo_content_loading');
          var o = get('videoinfo_content_loading');
          if (o)
            o.style.display = '';

          var callback_url = '/homepage/videos.php';
          video_counter++;
          abort_connection(video_loader);
          get('vfiltered').value = 'true';
          // TODO: One month fetch
          callback_url += '?vpage=1&id=' + get('id').value + '&from_y=' + year + '&from_m=' + (month + 1) + '&from_d=' + day + '&to_y=' + year + '&to_m=' + (month + 1) + '&to_d=' + day + '&rand=' + Math.random();

          callback =
          {
              success:  fetch_videos_calendar_callback,
              failure:  fetch_videos_calendar_callback,
              argument: [video_counter, year, month, day]
          };

          video_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
      }
  }

}


function fetch_images_calendar_callback(rsp)
{
    if (rsp.argument[0] != img_counter)
    {
        return;
    }

    get('imageinfo_content_loading').style.display = 'none';

    var obj = get("icontentdata");
    if (obj)
    {
        obj.innerHTML = rsp.responseText;
        initialize_images('i');
        on_filter_by_date(rsp.argument[1], rsp.argument[2], rsp.argument[3], true, false, false);
    }
}

function fetch_shows_calendar_callback(rsp)
{
    if (rsp.argument[0] != show_counter)
    {
        return;
    }

    get('slideshowinfo_content_loading').style.display = 'none';

    var obj = get("scontentdata");
    if (obj)
    {
        obj.innerHTML = rsp.responseText;
        initialize_shows('s');
        on_filter_by_date(rsp.argument[1], rsp.argument[2], rsp.argument[3], false, true, false);
    }
}

function fetch_videos_calendar_callback(rsp)
{
    if (rsp.argument[0] != video_counter)
    {
        return;
    }

    get('videoinfo_content_loading').style.display = 'none';

    var obj = get("vcontentdata");
    if (obj)
    {
        obj.innerHTML = rsp.responseText;
        initialize_videos('v');
        on_filter_by_date(rsp.argument[1], rsp.argument[2], rsp.argument[3], false, false, true);
    }
}


function ons(day, month, year)
{
    toggle_tag(null);
    get('tagname').value = '';
    on_filter_by_date(year, month, day, true, true, true);
}


function onc(month, year)
{
    var y = year;
    var m = month;

    if (is_month_cached(y, m))
    {
        var days = get_clickable_days(y, m);
        render_calendar(y, m, days);
    }
    else
    {
        if (is_full_content('i', 1) && is_full_content('s', 1))
        {
            // all images and shows are in the cache
             var days = get_clickable_days_ex(y, m);
             render_calendar(y, m, days);
        }
        else
        {
            var o = get('calendar_content');
            o.style.display = 'none';
            set_loading('calendar_content_loading');
            get('calendar_content_loading').style.display = '';
            var callback_url = '/homepage/calendar.php';
            cal_counter++;
            abort_connection(cal_loader);
            var from_y = y;
            var from_m = m - 3;
            if (from_m < 0)
            {
                from_m = 11;
                from_y--;
            }
            from_m++;
            callback_url += '?id=' + get('id').value + '&to_y=' + y + '&to_m=' + (m + 1) + '&from_y=' + from_y + '&from_m=' + from_m;

            callback =
            {
                success:  fetch_calendar_callback,
                failure:  fetch_calendar_callback,
                argument: [cal_counter, y, m]
            };

            cal_loader = YAHOO.util.Connect.asyncRequest('GET', callback_url, callback, null, null);
        }
    }
}


