/*
 * Set up popup window object to hold references to all
 * popup windows.
 */
if (null == versionID) var versionID = new Array();
versionID[versionID.length] = ("Popup Script: v1.3\n");

function NL_popupWindow(bgcolor)
{
this.win = null;
this.color = bgcolor;
}

var nl_popup = new Array();
nl_popup["text"]     = new NL_popupWindow("#CCFFCC");
nl_popup["answer"]   = new NL_popupWindow("#FFFFFF");
nl_popup["grammar"]  = new NL_popupWindow("#FFFFFF");
nl_popup["wordlist"] = new NL_popupWindow("#FFFFCC");
nl_popup["tape"]     = new NL_popupWindow("#FFCC99");

function openPopupWindowSpecURL(winArray,linkHref,linkTarget,settings)
{
  if (navigator.appVersion.indexOf("MSIE 3") >= 0) return;

  var theURL = linkHref;
  var theTarget = linkTarget;
  if (null == settings)
    settings = 'scrollbars=yes,width=300,height=200,menubar=yes,resizable=yes';

  if (null == winArray[theTarget].win) {//    alert("New window or was closed programmatically");
    winArray[theTarget].win = window.open(theURL,theTarget,settings)
  }
  else if (!winArray[theTarget].win.closed) {//    alert("Already open, load new document");
    winArray[theTarget].win.location.assign(theURL)
    winArray[theTarget].win.focus();
  }
  else {//    alert("Closed manually");
    winArray[theTarget].win = window.open(theURL,theTarget,settings)
  }
}

function openPopupWindowURL(winArray,theLink,settings)
{
  if (navigator.appVersion.indexOf("MSIE 3") >= 0) return;

  var theURL = theLink.href;
  var theTarget = theLink.target;

  openPopupWindowSpecURL(winArray,theURL,theTarget,settings);
}

function openPopupWindowSameDir(winArray,theLink,settings)
{
  if (navigator.appVersion.indexOf("MSIE 3") >= 0) return;

  var theURL = theLink.href;
  var theFile = theURL.substring(theURL.lastIndexOf("/"),theURL.length);
  var theDocument = document.location.href.toString();
  var theDirectory = theDocument.substring(0,theDocument.lastIndexOf("/"));
  theURL = theDirectory + theFile;
  var theTarget = theLink.target;

  openPopupWindowSpecURL(winArray,theURL,theTarget,settings);
}

function openPopupWindowHTML(winArray,winName,title,content,settings)
{
  var tophtml = "<html><head><title>";
  var midhtml = "</title></head><body background=\"../../images/backie.jpg\" bgcolor="+winArray[winName].color+" text=#000000>";
  var bothtml = "<form onsubmit='return false'><center><input type=button onclick='window.close()' value='OK'></center></form></body></html>";

  if (null == settings) settings = 'scrollbars=yes,width=300,height=400,menubar=yes,resizable=yes';

  if (navigator.appVersion.indexOf("MSIE 3") >= 0)
  {
    var win = window.open("",winName,settings);
    win.document.open();
    win.document.write(tophtml + title + midhtml + content + bothtml);
    win.document.close();
    return;
  }

  if (winArray[winName].win == null) {//    alert("New window or was closed programmatically");
    winArray[winName].win = window.open("",winName,settings)
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + title + midhtml + content + bothtml);
    winArray[winName].win.document.close();
  }
  else if (!winArray[winName].win.closed) {//    alert("Already open, write new document");
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + title + midhtml + content + bothtml);
    winArray[winName].win.document.close();
    if (navigator.appVersion.indexOf("MSIE 3") < 0) winArray[winName].win.focus();
  }
  else {//    alert("Closed manually");
    winArray[winName].win = window.open("",winName,settings)
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + title + midhtml + content + bothtml);
    winArray[winName].win.document.close();
  }
}

function openPopupWindowFrames(winArray,leftContent,rightContent,winName,title,settings)
{
  if (null == settings) settings = 'scrollbars=yes,width=500,height=250,menubar=yes,resizable=yes';
  if (null == title) title = 'its-english FAQ';
  if (null == winName) winName = 'grammar';

  var tophtml = "<html><head><title>"+title+"</title></head>\n" +
    "<frameset cols=\"156,*\" bordercolor=\"#000000\" border=\"0\">\n<frame src=\"";
  var midhtml = "\" scrolling=\"YES\" bordercolor=\"#FFFFFF\" frameborder=\"NO\" name=\"left\">\n" +
    "<frame src=\"";
  var bothtml = "\" scrolling=\"AUTO\" frameborder=\"NO\" bordercolor=\"#FFFFFF\" name=\"right\">"+
    "</frameset></html>";

  if (navigator.appVersion.indexOf("MSIE 3") >= 0)
  {
    var win = window.open("",winName,settings);
    win.document.open();
    win.document.write(tophtml + leftContent + midhtml + rightContent + bothtml);
    win.document.close();
    return;
  }

  if (winArray[winName].win == null) {//    alert("New window or was closed programmatically");
    winArray[winName].win = window.open("",winName,settings)
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + leftContent + midhtml + rightContent + bothtml);
    winArray[winName].win.document.close();
  }
  else if (!winArray[winName].win.closed) {//    alert("Already open, write new document");
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + leftContent + midhtml + rightContent + bothtml);
    winArray[winName].win.document.close();
    if (navigator.appVersion.indexOf("MSIE 3") < 0) winArray[winName].win.focus();
  }
  else {//    alert("Closed manually");
    winArray[winName].win = window.open("",winName,settings)
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + leftContent + midhtml + rightContent + bothtml);
    winArray[winName].win.document.close();
  }
}

function closePopupWindows(popupArray)
{
if (navigator.appVersion.indexOf("MSIE 3") >= 0) return;

if (popupArray["text"].win != null)
  if (!popupArray["text"].win.closed)
    popupArray["text"].win.close();
popupArray["text"].win = null;

if (popupArray["answer"].win != null)
  if (!popupArray["answer"].win.closed)
    popupArray["answer"].win.close();
popupArray["answer"].win = null;

if (popupArray["grammar"].win != null)
  if (!popupArray["grammar"].win.closed)
    popupArray["grammar"].win.close();
popupArray["grammar"].win = null;

if (popupArray["wordlist"].win != null)
  if (!popupArray["wordlist"].win.closed)
    popupArray["wordlist"].win.close();
popupArray["wordlist"].win = null;

if (popupArray["tape"].win != null)
  if (!popupArray["tape"].win.closed)
    popupArray["tape"].win.close();
popupArray["tape"].win = null;
}

document.nl_config.add("onunload","closePopupWindows(nl_popup);");

