/* Javascript Library
 *
 * date: 3/16/00
 * author: Ryan Gay
 *
 * To use the functions in this library, insert the following lines into the page:
 *      <script language="Javascript" src="javascript_lib.js">
 *      </script>
 *
*/

// The following five functions are used to validate and then submit a form
// when the enter key is pressed in Netscape. IE should automatically submit a
// form when the enter key is pressed without use of these functions. To use,
// call captureNetscapeEnterKey() from somewhere in the page. If the capturing
// of the enter key needs to be disabled after captureEnterKey() is called, call
// captureOff(). Call captureOn() to re-enable the capturing. An example of when
// this is useful is when a page contains a textarea. While editing the textarea
// the enter key should add a new line, but when outside of the textarea the
// enter key should submit the form. This can be accomplished as follows:
//      <script language="Javascript>
//        captureNetscapeEnterKey();
//      </script>
//      <textarea onFocus="captureOff()" onBlur="captureOn()"></textarea>

var capture = true;
var formLoaded = false;
var formName = "mainForm";

function captureEnterKey()
{
  document.captureEvents(Event.KEYPRESS);
  document.onkeypress = checkKey;
}

function checkKey(e)
{
  if (capture)
  {
    var key = String.fromCharCode(e.which);
    if ((formLoaded) && (key == "\r"))
      document.forms[formName].submit();
  }
}

function captureNetscapeEnterKey()
{
  if (navigator.appName == "Netscape")
    captureEnterKey();
}

function captureNetscapeEnterKeyFormName(name)
{
  if (navigator.appName == "Netscape")
  {
    formName = name;
    formLoaded = true;
    captureEnterKey();
  }
}

function captureOn()
{
  capture = true;
}

function captureOff()
{
  capture = false;
}

