function externalLink() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
      anchor.target = "_blank";
    }
  }
}

function showAddForm(id, trigger){
  if(trigger.className == "btn-addbsh on"){
    trigger.className = "btn-addbsh";
    new Effect.toggle(id, 'slide', {duration: 0.6, transition: Effect.Transitions.sinoidal, from: 0.0, to: 1.0});
  }else{
    trigger.className = "btn-addbsh on";
    new Effect.toggle(id, 'slide', {duration: 0.6, transition: Effect.Transitions.sinoidal, from: 0.0, to: 1.0});
  }
}

function ratingFade(trigger){
  if(trigger.className == "rating"){
    trigger.className = "rating refresh";
  }else{
    trigger.className = "rating";
  }
}

function materialize_post() {
  if($('ajax-entry')) new Effect.Appear('ajax-entry');
  $('add-btn').className = "btn-addbsh";
  new Effect.BlindUp('add-bsh-content');
}

function switch_category(category) {
  var data = 'category='+category;
  new Ajax.Updater('response', '/switchcategory', {asynchronous:true, evalScripts:true, parameters: data});
}

function delete_complaint(complaintid, category, pager_current) {
  if($('entry-'+complaintid)) new Effect.Fade('entry-'+complaintid);
  var data = 'complaintid='+complaintid+'&category='+category+'&pager_current='+pager_current;;
  new Ajax.Updater('response', '/deletecomplaint', {asynchronous:true, evalScripts:true, parameters: data});
}

function page(category, pager_current) {
  var data = 'category='+category+'&pager_current='+pager_current;
  new Ajax.Updater('response', '/page', {asynchronous:true, evalScripts:true, parameters: data});
}

function vote(complaintid, score, category, pager_current) {
  var data = 'complaintid='+complaintid+'&score='+score+'&category='+category+'&pager_current='+pager_current;
  new Ajax.Updater('response', '/vote', {asynchronous:true, evalScripts:true, parameters: data});
}

function restart(form_object) {
  Form.reset(form_object);
}

function windowOnload() {
  externalLink();
}

if ((document.getElementById || document.all) && document.images) {
  window.onload = windowOnload;
}


