// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
Request.prototype._send = Request.prototype.send
Request.implement({

  auth_token: function(){
    return AUTH_TOKEN;
  },

  // This is more verbose than is ideal, but I don't see a better place
  // to hook this functionality in
  send: function(options){
    var type = $type(options);
    if (type == 'string' || type == 'element') options = {data: options};

    var old = this.options;
    options = $extend({data: old.data, url: old.url, method: old.method}, options);

    switch ($type(options.data)){
      case 'element': options.data = $(options.data).toQueryString(); break;
      case 'object': case 'hash': options.data = Hash.toQueryString(options.data);
    }

    // If this isn't a get request add the authenticity_token
    if (options.method != 'get' || options.method != 'GET')
      options.data = options.data+'&authenticity_token='+this.auth_token();

    // Call the original send
    this._send(options)
  }

});

function comment_approve(id,link) {
  var comment_approve = new Request.HTML ({
    url: link,
    update: 'comment_' + id,
    method: 'get'
  }).send();
}

function comment_unapprove(id,link) {
  var comment_unapprove = new Request.HTML ({
    url: link,
    update: 'comment_' + id,
    method: 'get'
  }).send();
}

window.addEvent('domready', function() {
  $$('input.focus_clear').each(function(el) {
    el.title = el.value;
    el.addEvent('focus', function() {
      if (el.value == el.title) el.value = "";
      el.removeClass('blur');
    });
    el.addEvent('blur', function() { if(el.value == "") el.value = el.title;});
  });
});
