// JavaScript Document
/****
FormWalker - walk form fields using the enter key by just adding the css class "next"
to each field which should be "walkable".
Michal Gabrukiewicz (FFTUIL - feel free to use it License)
****/
function FormWalker() {}
FormWalker.jumpNext = function(e) {
  if (!this.nextElement) return false;
  if (((window.event) ? window.event.keyCode : e.keyCode) == Event.KEY_RETURN) {
	  this.nextElement.activate();
	  return false;
  }
  return true;
}
FormWalker.load = function() {
  nexts = document.getElementsByClassName('walk_next');
  var prev = null;
  for (i = 0; i <nexts.length; i++) {
	  it = nexts[i];
	  if (prev) prev.nextElement = it;
	  if (i == nexts.length - 1) it.nextElement = nexts[0];
	  it.onkeydown = FormWalker.jumpNext;
	  prev = it;
  }

  var bFound = false;
  // for each form
  for (f=0; f < document.forms.length; f++)
  {
    // for each element in each form
    for(i=0; i < document.forms[f].length; i++)
    {
      // if it's not a hidden element
      if ((document.forms[f][i].type != "hidden") && 
	  	 (document.forms[f][i].type != "button") &&
		 (document.forms[f][i].type != "submit"))
      {
        // and it's not disabled
        if (document.forms[f][i].disabled != true)
        {
          // set the focus to it
			try {
			//Run some code here
			  document.forms[f][i].focus();
			  document.forms[f][i].select();
	          var bFound = true;
			}
			catch(err) { //Handle errors here
 			  var bFound = false;
			}		  
        }
      }
      // if found in this element, stop looking
      if (bFound == true)
        break;
    }
    // if found in this form, stop looking
    if (bFound == true)
      break;
  }
}