
// ------------------ Description ------------------
// The purpose of this script is to keep a pop-up window focused  
// when its content changes. onBlur() and onFocus() is dealt with   
// inconsistently by different browsers, causing unpredictable 
// results. By closing the pop-up window and then automatically 
// opening a new one with different content, the pop-up will 
// immediately (and predictably) appear on top of the other windows 
// when its content changes, fixing the cross-browser inconsistency. 

// This script modifies and expands upon an example found in 
// the following book: 
// Goodman, Danny. JavaScript Bible. 3rd ed. California: 
// IDG Books Worldwide, Inc, 1998. 177-79. 

// Created by: Stefan Langer, Copyright 2000
// -------------------------------------------------


   // initialize global variables so all functions can access them.
   var newWind; 
   var path; 
   var site; 
   var windowName; 
   var newWidth; 
   var newHeight; 
   var scrollBars; 
   var resizeWindow; 
   var showDirectories; 
   var showLocation; 
   var showMenubar; 
   var showStatus; 
   var showToolbar; 
   var launchWin; 

   // set a flag to determine whether the browser being used is IE3.
   var isIE3 = (navigator.appVersion.indexOf("MSIE 3") != -1) ? true : false;


   // create a new window (the URL path comes 
   // from a global variable set earlier). 
   function newWindow(width, height) { 

        newWind = window.open(site, windowName, "directories=" + showDirectories + 
                  ",location="   + showLocation + 
                  ",menubar="    + showMenubar  + 
                  ",resizable="  + resizeWindow + 
                  ",scrollbars=" + scrollBars   + 
                  ",status="     + showStatus   + 
                  ",toolbar="    + showToolbar  + 
                  ",width="      + width        + 
                  ",height="     + height       + ""); 

        // take care of Navigator 2's special needs.
        if (newWind.opener == null) {
            newWind.opener = window;
        } // end-if statement 

   } // end-function newWindow 


   // this function tests whether a child window is open or closed. 
   // if it's already open, close it. if it hasn't been spawned yet, 
   // create a new window. code includes an ugly workaround for IE3. 
   function popupUrl(path, name, width, height, scroll, resize, directories, location, menubar, status, toolbar) { 

        // update global variables. 
        site = path; 
        windowName      = name; 
        scrollBars      = scroll; 
        newWidth        = width; 
        newHeight       = height; 
        resizeWindow    = resize; 
        showDirectories = directories; 
        showLocation    = location; 
        showMenubar     = menubar;
        showStatus      = status;
        showToolbar     = toolbar; 

        // check if the current browser is IE3. 
        if (isIE3) { 
             // for IE3, check if the child window is already open. if 
             // it is, nothing will appear to happen. if the child window 
             // is closed, the main window may flash momentarily (yech!). 
             if (newWind.opener == null) { 
                 newWind.opener = window; 
             } // end-if statement 
        } // end-if statement 

        // if the child window already exists and 
        // it hasn't been closed yet, close it.
        if (newWind && !newWind.closed) { 
             // once closed, automatically spawn 
             // a new window with a different URL. 
             newWind.close(); 
             launchWin = setTimeout("newWindow(newWidth, newHeight)",200); 

        // otherwise, no child window has been spawned yet, 
        // so create one by executing the correct function. 
        } else { 
             newWindow(newWidth, newHeight); 
        } // end-if statement 

   } // end-function popupUrl  
