If you do stuff like
code:
for (i=0;i<list.length;i++)
with arrays, replace it with
code:
for (i in list)
no need for length checks i increments and what not (This works for objects too to cycle thru all their properties; it will not work for enumerations).
Second, instead of
code:
ChatWnd.SendMessage("/close")
Use the sendmessage api to close the window. This is better because you don't need to send a message to the conversation in that way (for various reasons you wont always be able to send a message to the conversation).