Running an agent with onfocus on the web

Can someone please help me with this.

I have a webpage displaying a frame set. The frameset has two frames, one called Side and one called Main. When using the database I use several forms in new windows. When a document is opened in a new window a field called flag is set to “1”. When the document is closed through the close button next to the minimise and maximise buttons on the IE window I wish to run an agent.

The only way I can think of doing this is by the window with the frameset getting focus. I have a page in the side frame and a view or a form in the Main frame. How do I call the agent with the onfocus handler and can I do it in the page that is displayed in the Side frame? If so how do I code an onfocus handler event? Thanks for any help.

Subject: Running an agent with onfocus on the web

If you want the agent to run when a document is closed, why not run it in the WebQuerySave?