1.put a time based function in your parent window using setInterval("some_function","time").This "setInterval" should be set only when you open the child window,
2. Pass a flag variable to your child window. for eg. flag=false;
3. use onbeforeunload in your child window and set the flag to true.
4. In the parent window check for this flag. If flag is false use "new.document.focus()" which will focus the document of the child window.