// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Removes leading whitespaces
function LTrim( value ) {
  var re = /\s*((\S+\s*)*)/;
  return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
  var re = /((\s*\S+)*)\s*/;
  return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
  return LTrim(RTrim(value));
}

var FlashEffect = Class.create();
FlashEffect.prototype = {
  initialize: function() {
    $A(document.getElementsByClassName('flash-notice')).each(function(o){
        o.opacity = 100.0; Effect.Fade(o, {duration: 8.0})
      })
  }
}

var MyAjaxHandlers = {
  onCreate: function(e) {
    Element.show("ajax-status");
  },

  onComplete: function(e) {
    Element.hide("ajax-status");
  }
}

// Ajax.Responders.register(MyAjaxHandlers);

function loadPaginator() {
  if ($("paginator-next-page") || $("paginator-prev-page")) {
    Event.observe(document, "keydown", handlePaginator, false)
  }
}

function handlePaginator(e) {
  ev = e || window.event;
  kcode = ev.keyCode || ev.which;
  if ($("paginator-next-page") && ev.ctrlKey  && kcode == 37) {
    location.href = $("paginator-next-page").href;
  }
  else if ($("paginator-prev-page") && ev.ctrlKey  && kcode == 39) {
    location.href = $("paginator-prev-page").href;
  }
}

Event.observe(window, "load", function(e){new FlashEffect()}, false);
Event.observe(window, "load", loadPaginator, false)
