//
// Caps Lock detector from:
//
// http://www.howtocreate.co.uk/jslibs/otherdemo.html#cld
// Usage:
// <input type="text" ... onkeypress="capsDetect(arguments[0]);">
//
//
function capsDetect( e ) {
  //
  //if the browser did not pass event information to the handler,
  //check in window.event
  //
  if( !e ) { e = window.event; } if( !e ) { return; }
    //what (case sensitive in good browsers) key was pressed
    //this uses all three techniques for checking, just in case
  var theKey = 0;
  if( e.which ) { theKey = e.which; } //Netscape 4+, etc.
  else if( e.keyCode ) { theKey = e.keyCode; } //Internet Explorer, etc.
  else if( e.charCode ) { theKey = e.charCode } //Gecko - probably not needed
    //was the shift key was pressed
  var theShift = false;
  if( e.shiftKey ) { theShift = e.shiftKey; } //Internet Explorer, etc.
  else if( e.modifiers ) { //Netscape 4
    //check the third bit of the modifiers value (says if SHIFT is pressed)
    if( e.modifiers & 4 ) { //bitwise AND
      theShift = true;
    }
  }
  //
  //if upper case, check if shift is not pressed
  //
  if( theKey > 64 && theKey < 91 && !theShift ) {
    alert( 'The Caps Lock is engaged' );
    }
    //
    //if lower case, check if shift is pressed
    //
  else if( theKey > 96 && theKey < 123 && theShift ) {
    alert( 'The Caps Lock is engaged' );
    }
}
