Javascript popup and form remote tag


I have a javascript popup window, in that i have a form_remote_tag call.
On the completion of this call, i want some server side code to execute
and form to be submitted, after that is done i want the pop up window to
close and after that a DOM element to be updated in the main window.

Can someone help how shld the form_remote_tag be invoked to achieve all