MyWindow=null; //esta variável armazena o nome da última janela aberta por
function OpenWindow(mypage, myname, w, h, scroll) {
  if(MyWindow != null)//Se já foi aberta uma janela anteriormente.
 {
  if(!MyWindow.closed) //se a janela aberta anteriormente ainda não foi fechada.
  {
  	// se a jenela que está sendo aberta é diferente da anterior
   if(MyWindow.name != winName) 
   {
    MyWindow.close();     //fecha a janela anterior
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
    win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus();}
   } else //caso as janelas tenham o mesmo nome
   {
    MyWindow.focus(); //muda o foco para a janela aberta tanteriormente.
   }
  } else // caso já tenha sido fechada uma janela anteriormente
  {   // abre a nova janela.
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
   win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus();}
  }
 }
 else  //caso nenhuma janela tenha sido aberta anteriormente, i.e.,  MyWindow == null
 { //abre uma nova janela.
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
   win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus();}
 }
}
