Moved onKeyDown from window to document (ie8 support)
Using $.trim() to support ie 8