rewrote chat.js in jquery