var newWin1;

function checkWin() {
  if (!newWin1 || newWin1.closed) {
  newWin1=window.open("","","width=700,height=500");
  window.newWin1.moveTo(5,5);
  setTimeout("winContent()",100);
  }
  else {
    newWin1.focus();
  }
}

function winContent() {
   var content = "<font size='1'><h3>This is placed in a separate file or head section:</h3>";
   content += "var newWin;";
   content += "<br>";
   content += "function checkWin() {<br>";
   content += "&nbsp;&nbsp;if (!newWin || newWin.closed) {<br>";
   content += "&nbsp;&nbsp;newWin=window.open(\"\",\"\",\"width=300,height=250\");<br>";
   content += "&nbsp;&nbsp;setTimeout(\"winContent()\",100);<br>";
   content += "&nbsp;&nbsp;}<br>";
   content += "&nbsp;&nbsp;else {<br>";
   content += "&nbsp;&nbsp;&nbsp;&nbsp;newWin.focus();<br>";
   content += "&nbsp;&nbsp;}<br>";
   content += "}<br>";
   content += "<br>";
   content += "function winContent() {<br>";
   content += "&nbsp;&nbsp;var content = \"&lt;html>&lt;head>&lt;title>The Other Window&lt;\/title>&lt;\/head>&lt;body>\";<br>";
   content += "&nbsp;&nbsp;content += \"&lt;h2>It Worked!&lt;\/h2>\";<br>";
   content += "&nbsp;&nbsp;content += \"&lt;p>This window is a sub window of the main one that opened it.\";<br>";
   content += "&nbsp;&nbsp;content += \"&lt;form>&lt;input type=\'button\' value=\'Bring Main Window to Front\' onclick=\'self.opener.focus()\'>&lt;p>\";<br>";
   content += "&nbsp;&nbsp;content += \"&lt;input type=\'button\' value=\'Move This Window to Back\' onclick=\'self.blur()\'>&lt;p>\";<br>";
   content += "&nbsp;&nbsp;content += \"&lt;input type=\'button\' value=\'Close This Window\' onclick=\'self.close()\'>\";<br>";
   content += "&nbsp;&nbsp;content += \"&lt;\/form>&lt;\/body>&lt;\/html>\";<br>";
   content += "&nbsp;&nbsp;newWin.document.write(content);<br>";
   content += "&nbsp;&nbsp;newWin.document.close();<br>";
   content += "}<br>";
   content += "<h3>This is placed in the body section:</h3>";
   content += "&lt;form><br>";
   content += "&lt;input type=\"button\" name=\"win\" value=\"Open/Re-Focus Window\" onClick=\"checkWin()\">&lt;br><br>";
   content += "&lt;\/form>";
   content += "<br><br><br></font>";
   content += "<input type='button' value='Close This Window' onclick='self.close()'>";
   newWin1.document.write(content);
   newWin1.document.close();
}