Thanks for your quick reply, Adam.
I tried to remove either this line or remove the window.attach.. lines, or even just put the code in <body onunload="window_onunload()">. In these case, the code will only triggered once (one alert shows), but looks like the chat window is not close properly: The person's record still in CuteChatClient table; And if I tried to open another chat window, that will freeze all my application running, I have kill it from windows task manager .
Any advise is very welcome, thanks very much.