function get_href()
{
  return (document.location.href.substring(0, document.location.href.length - document.location.hash.length));
}
function post_feature_setup(self, id, date, type)
{
  var container = $('container.' + type + '.' + id);
  if (container == null)
  {
    container = new Element('div', { id: 'container.' + type + '.' + id, className: 'container' });
    container.style['display'] = 'none';
    ac(document.body, ac(container, new Element('div', { id: 'calendar.' + type + '.' + id, className: 'calendar' })));
  }
  var featured = $(type + '.' + id);
  var calendar = new YAHOO.widget.Calendar('calendar.' + type + '.' + id, { iframe: false });
  calendar.cfg.setProperty('START_WEEKDAY', 1);
  if (date)
  {
    calendar.select(date);
    calendar.cfg.setProperty('pagedate', new Date(calendar.getSelectedDates()[0].getUTCFullYear(), calendar.getSelectedDates()[0].getMonth(), 1));
  }
  var dialog = new YAHOO.widget.Dialog('container.' + type + '.' + id, {
      context: [self, 'tl', 'bl'],
      buttons: [ {text: 'Update', isDefault: true, handler: post_feature_select(featured, id, calendar, type)}, { text: 'Cancel', handler: post_feature_select(featured, id, null, type) } ],
      draggable: false,
      close: false
    });
  calendar.render();
  dialog.render();
  dialog.hide();
  container.style['display'] = '';
  calendar.renderEvent.subscribe(function() { dialog.fireEvent("changeContent"); });
  self.onclick = function() { dialog.show(); return (false); };
  dialog.show();
}
function post_feature_select(self, id, calendar, type)
{
  return function()
  {
    var req = (window.XMLHttpRequest) ? new XMLHttpRequest() : ((ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : null);
    var date = '';
    if (calendar != null)
    {
      if (calendar.getSelectedDates().length > 0)
      {
        var date = calendar.getSelectedDates()[0];
        var wStr = calendar.cfg.getProperty("WEEKDAYS_LONG")[date.getDay()];
        var dStr = date.getDate();
        var mStr = calendar.cfg.getProperty("MONTHS_LONG")[date.getMonth()];
        var yStr = date.getFullYear();
        self.innerHTML = wStr + ", " + dStr + " " + mStr + " " + yStr;
        date = formatDate(date, 'yyyy-MM-dd');
      }
      else self.innerHTML = '';
    }
    else self.innerHTML = '';
    req.open('GET', '?id=' + id + '&' + type + '=' + encodeURIComponent(date), true);
    req.setRequestHeader('output', 'null');
    req.send(null);
    this.hide();
  }
}
function post_rate(self, url, rate)
{
  self.onclick = function() { return (false); };
  if (self.parentNode.parentNode.className.indexOf('post_unrated') == -1) return (false);
  var rating = parseFloat(self.nextSibling.innerHTML); if (isNaN(rating)) rating = 0;
  self.nextSibling.innerHTML = rating + Math.abs(rate);
  self.parentNode.parentNode.className = self.parentNode.parentNode.className.replace('post_unrated', 'post_rated');
  var req = (window.XMLHttpRequest) ? new XMLHttpRequest() : ((ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : null);
  req.open('GET', url + '&rate=' + encodeURIComponent(rate), true);
  req.setRequestHeader('output', 'null');
  req.send(null);
  return (false);
}
function post_report(self, id)
{
  document.location.href = '/post/report?id=' + encodeURIComponent(id) + '&r=' + encodeURIComponent(document.location.href);
  //self.parentNode.innerHTML = '<span style="color: #808080;">report sent</span>';
}
function post_reply(self, id)
{
  document.location.href = '?reply&id=' + encodeURIComponent(id) + '#reply';
}
function post_vote(self, url, vote)
{
  if (vote == 0) vote = 'a'; else if (vote == 1) vote = 'b'; else if (vote == 2) vote = 'c'; else if (vote == 3) vote = 'd';
  document.location.href = url + '&vote=' + encodeURIComponent(vote);
}
function post_delete(self, id)
{
  if (!confirm('Are you sure that you want to delete this post?')) return;
  var div = self.parentNode.parentNode.parentNode;
  div.innerHTML = '<div class="post_deleted">post deleted</div>';
  var req = (window.XMLHttpRequest) ? new XMLHttpRequest() : ((ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : null);
  req.open('GET', '?delete&id=' + encodeURIComponent(id), true);
  req.setRequestHeader('output', 'null');
  req.send(null);
  return (false);
  //div = div.parentNode.removeChild(div);
}
function post_flip(prefix, id)
{
  var post = $(prefix + id);
  if (post == null) return;
  var children = post.parentNode.parentNode.childNodes[0].childNodes[0].childNodes;
  for (var i = 0; i < children.length; i++) children[i].className = (children[i].id == prefix + 'flip_' + id) ? 'selected' : '';
  children = post.parentNode.childNodes;
  for (var i = 0; i < children.length; i++) $(children[i]).show(children[i].id == post.id);
}