/* script.js 

copyright 2008 Future Medium Pty Ltd

*/


/**
 * Attaches an onclick event to each link with rel="external" that opens the
 * link in a new window.
 */
function initExternalLinks() {
  var as = document.getElementsByTagName("a");
  for (var i = 0; i < as.length; i++) {
    if (as[i].getAttribute("rel") == "external") {
      as[i].onclick = openNewWindow;
    }
  }

  function openNewWindow() {
    window.open(this.href);
    return false;
  }
}


/**
 * Attaches submit handlers to text inputs of the given form, to compensate for
 * pretent submit buttons (i.e. <a> elements).
 *
 * @param form form to attach submit handlers to
 */
function attachSubmitHandlers(form) {
  // find all text-like inputs
  var inputs = form.getElementsByTagName("input");
  for (var i = 0; i < inputs.length; i++) {
    var inputType = inputs[i].getAttribute("type").toLowerCase();
    if (!(inputType == "text" || inputType == "password")) {
      continue;
    }

    attachHandler(inputs[i], form);
  }

  /**
   * Attaches the enter key handler (that submits the given form) to the
   * given input. Uses mootools Event class.
   */
  function attachHandler(i, f) {
    i.onkeypress = function(e) {
      var event = new Event(e);
      if (event.key == "enter") {
        ajaxFunction();
        //return f.submit();
      }
    }
  }
}