ManoUtilities.KeyStroke = {

  // ------------------------------------------------------------------------------
  // ------------------------------------------------------------------------------
  // ------------------------------------------------------------------------------
  //  PROPERTIES - Representations of keystrokes

   KEY_ENTER : "ENTER"
  ,KEY_BACKSPACE : "BACKSPACE"
  ,KEY_TAB : "TAB"
  ,KEY_ESCAPE : "ESCAPE"
  ,KEY_F1 : "F1"
  ,KEY_F2 : "F2"
  ,KEY_F3 : "F3"
  ,KEY_F4 : "F4"
  ,KEY_F5 : "F5"
  ,KEY_F6 : "F6"
  ,KEY_F7 : "F7"
  ,KEY_F8 : "F8"
  ,KEY_F9 : "F9"
  ,KEY_a  : "a"
  ,KEY_A  : "A"
  ,KEY_b  : "b"
  ,KEY_B  : "B"

  // ------------------------------------------------------------------------------
  // ------------------------------------------------------------------------------
  // ------------------------------------------------------------------------------
  //  FUNCTIONS

  // Gets the key code for the event, browser-specifically
  ,getKeyCode : function(event) 
  {
    event = event || {};
  
    // SEE http://unixpapa.com/js/key.html for information on browser handling of keystrokes!!
    //  THE ORDER OF THE IF-BRANCHES BELOW MAKES A DIFFERENCE!!
    if ((event.keyCode != null) && (event.keyCode > 0))
      return event.keyCode;
    // We must look in .charCode before .which so that in 'keypress' events we get the ASCII code in
    //  Mozilla browsers instead of the Mozilla keycode that's in .which
    else if ((event.charCode != null) && (event.charCode > 0))
      return event.charCode;
    else if ((event.which != null) && (event.which > 0))
      return event.which;
    else
      return 0;
  }

  // Gets a one of the keystroke definitions above - or, if we haven't specified
  //  a keystroke property above for whatever it is, then returns the key code
  ,getKey : function(event) {
    var code = ManoUtilities.KeyStroke.getKeyCode(event);
    
    if (code == Event.KEY_ESC)
      return ManoUtilities.KeyStroke.KEY_ESCAPE;
    else if (code == Event.KEY_TAB)
      return ManoUtilities.KeyStroke.KEY_TAB;
    else if (code == Event.KEY_BACKSPACE)
      return ManoUtilities.KeyStroke.KEY_BACKSPACE;
    // KEY_RETURN, KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_DELETE, KEY_HOME, KEY_END, KEY_PAGEUP, KEY_PAGEDOWN  
      
      
    else if (code == 13)
      return ManoUtilities.KeyStroke.KEY_ENTER;
    else if (code == 112)
      return ManoUtilities.KeyStroke.KEY_F1;
    else if (code == 113)
      return ManoUtilities.KeyStroke.KEY_F2;
  	else if (code == 114)
      return ManoUtilities.KeyStroke.KEY_F3;
    else if (code == 115)
      return ManoUtilities.KeyStroke.KEY_F4;
    else if (code == 116)
      return ManoUtilities.KeyStroke.KEY_F5;
    else if (code == 117)
      return ManoUtilities.KeyStroke.KEY_F6;
    else if (code == 118)
      return ManoUtilities.KeyStroke.KEY_F7;
    else if (code == 119)
      return ManoUtilities.KeyStroke.KEY_F8;
    else if (code == 120)
      return ManoUtilities.KeyStroke.KEY_F9;
    else if (code == 97)
      return ManoUtilities.KeyStroke.KEY_a;
    else if (code == 65)
      return ManoUtilities.KeyStroke.KEY_A;
    else if (code == 98)
      return ManoUtilities.KeyStroke.KEY_b;
    else if (code == 66)
      return ManoUtilities.KeyStroke.KEY_B;
    else
      return code;
  }
  
  // Disables the continuation of the specified event, cross-browser style (should be a keydown event)
  ,stopKeyStrokeEvent : function(event) {
    Event.stop(event);
    
    // Setting event.keyCode in Mozilla is not allowed, it is read-only
    try { event.keyCode = 0; }
    catch (ex) {}
    
    event.cancelBubble = true;
    event.returnValue = false;
  }

} // ManoUtilities.KeyStroke