'User is typing a message' function...?
Use a timer to send an AJAX request onkeyup
that tells the database the user is typing, on the other side when your pulling down chat messages you can then notify the other person that they are typing.
Take a look at doTimeOut which has a great example of debouncing in javascript...
http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/