﻿function calendar_display(a)
{
  if (a.blur) a.blur();
  var href = (a.href) ? a.href : a;
  var el = $('<div />').addClass('dialog hidden').css({ height: '600px', width: '800px' });
  el.append($('<iframe frameborder="0" scrolling="no" />').css({ height: '600px', width: '100%' }).attr({ id: 'iframe_' + new Date().getTime().toString(), src: href + ((href.indexOf('?') == -1) ? '?' : '&') + 'output=iframe' }));
  dialog(el, { cancel: false });
  return (false);
}
function calendar_show(id)
{
  if (typeof (id) == 'undefined') id = null;
  var calendars = $('.calendar_show');
  if (id == null) $('.event,.event_color').hide();
  var update = '';
  for (var i = 0; i < calendars.length; i++)
  {
    var num = calendars[i].id.substring('calendar_show_'.length), selected = $('#calendar_id_' + num).val();
    if (id == null) { if (calendars[i].checked) $('.calendar_' + selected + ',.calendar_color_' + selected).show(); }
    else if (id == selected) $('.calendar_color_' + id).css('backgroundColor', $('#calendar_color_' + num).val());
    update += ((update == '') ? '' : '&') + 'calendar_id_' + num + '=' + selected + ((calendars[i].checked) ? '&calendar_show_' + num + '=1' : '') + '&calendar_color_' + num + '=' + encodeURIComponent($('#calendar_color_' + num).val());
  }
  $.ajax({ url: document.location.href, data: update, type: 'POST', beforeSend: function(req) { req.setRequestHeader('output', 'null'); }, error: function(req) { if (req.status == 403) document.location.href = el.attr('href'); } });
}
function event_respond(el, id, status)
{
  var el2 = el.parents('tr').eq(0);
  el.parents('ul').eq(0).find('a').removeClass('selected');
  el.addClass('selected');
  if (status == 'ACCEPTED')
  {
    el2.removeClass('event_attendee_declined');
    el2.removeClass('event_attendee_needs-action');
    el2.addClass('event_attendee_accepted');
  }
  else if (status == 'NEEDS-ACTION')
  {
    el2.removeClass('event_attendee_accepted');
    el2.removeClass('event_attendee_declined');
    el2.addClass('event_attendee_needs-action');
  }
  else if (status == 'DECLINED')
  {
    el2.removeClass('event_attendee_accepted');
    el2.removeClass('event_attendee_needs-action');
    el2.addClass('event_attendee_declined');
  }
  $.ajax({ url: 'event?id=' + id + '&a=' + encodeURIComponent(status), beforeSend: function(req) { req.setRequestHeader('output', 'null'); }, error: function(req) { if (req.status == 403) document.location.href = el.attr('href'); } });
  if (window.event) window.event.cancelBubble = true;
  return (false);
}
function flyer_hover(el)
{
  var offset = el.offset();
  var src = el.attr('src'); var src2 = src.substring(0, src.indexOf('&w=')) + '&w=200&h=200';
  var el2 = $('<img />').attr({ src: src2 }).css({ cursor: 'pointer', overflow: 'hidden', position: 'absolute', left: (offset.left - 200) + 'px', top: (offset.top - 50) + 'px' });
  el.unbind('mouseout');
  el.bind('mouseout', function() { el2.remove(); });
  var img = new Image(); img.src = src2;
  $(document.body).append(el2);
  return (false);
}