/**
 * returnTab.js
 * Author: Kent Seaton
 * Version: 1.1
 *
 * This method requires the initial work to be done inside the page rather
 * than calling by a function.  Perhaps an onload function would work
 * with this.  The functionality does not work in Opera... yet, still
 * testing.  The nextfield box must start with the requestFocus.js
 * field and changed using this simple template:
 *
 *       <body onLoad="nextfield ='<elementname>'">
 *       onFocus="nextfield ='<elementname>';"
 *
 * Once complete on the page the return key should act as the tab key
 * normally works.
 *
 * Currently this script fails with Opera 6.  Working to build any additional
 * component work to ensure it will work with Opera.  It may be the Opera
 * cannot trap key events properly and thus a script like this wouldn't work.
 *
 * Application: This script was developed for KCBig.net
 */

var ua        = navigator.userAgent.toLowerCase();
var is_ie     = (ua.indexOf("ie") != -1);
var is_moz    = (ua.indexOf("mozilla") != -1);

function keyDown(DnEvents) {
  k = (is_moz && !is_ie) ? DnEvents.which : window.event.keyCode;
  if (k == 13) {
    if (nextfield == 'submit') {
      return true;
    } else {
      var elementName = nextfield;
      eval('document.form.' + elementName + '.focus()');
      eval('document.form.' + elementName + '.select()');
      return false;
    }
  }
}

document.onkeydown = keyDown;
if (is_moz && !is_ie) {
  document.captureEvents(Event.KEYDOWN|Event.KEYUP);
}
