I would recommend not using "real" (popup) windows but using CSS-Layers.
So if a new chat message from someone different comes in, e.g. a div container with the ID "chatSessionXXX" is being created in which the dialog happens. You can then always use this ID as your current chat session ID when saving or displaying messages via AJAX.
When a new message comes in, you could also move the layer on top by adjusting the z-index or simply add a CSS class that adds some "flashy" effect to that container.
But if you want to rely on real popup windows you could use focus() to get the window to the foreground.
/* Inside your chat popup */
if(newMessage)
window.focus();
You may also encounter a problem when you want to terminate a chat session when a popup is closed by a user - the unload and beforeunload event is not reliable and may not work correctly in some browsers (at least as far as my experience goes on this one).