var lexiconWindow;

var lexWidth       =  600;
var lexFmTop       =  20;
var lexFmBottom    =  60;
var lexHeight      =  screen.height - (lexFmTop + lexFmBottom);

var lexFmRightEdge =  40;
var lexHorizPosition = screen.width - (lexWidth + lexFmRightEdge);
var lexVertPosition  = lexFmTop;
var lexiconWindowName    = "Lexicon";
var lexStyleStr              = "toolbar=no, scrollbars=yes, resizable=yes, fullscreen=no, location=no";
    lexStyleStr = lexStyleStr + ", width=" + lexWidth  + ", height=" + lexHeight;
    lexStyleStr = lexStyleStr + ", top="   + lexVertPosition + ", left="   + lexHorizPosition;
    
/*  -----------------------------openLexicon(link)----------------------------  *
 * The function is used to open a supplemental window in which the user can        * 
 * display the Lexicon for reference to defined terms used by the site.            *
 *                                                                                 *
 *  Note:  When a window is closed, it still exists, but when typeof is applied    *
 *  to it, typeof returns 'undefined' which typeof is not supposed to ever retun.  *
 *  So I have some code to check that.                                             *
 *                                                                                 *
 *  openLexicion() calling openLex1() calling openLex2() was necessary because  *
 *  when frames are used, there can be a thread problem.  In this case, the        *
 *  openLexicon () function was looking for this.lexiconWindow.bottomlexframe,  *
 *  before it was instantiated.                                                    *
/*  ------------------------------------------------------------------------------ */
function openLex1 () {
  try {
    if (this.lexiconWindow) {
      var ok = openLex2(this.link);
      if (!ok) {
        throw "Err2";
      }
    } else {
      throw "Err1";
    }
  } catch (err) {
    if (err=="Err1") {
      alert ("Error! script-lexicon.openLex1()\nthis.lexiconWindow didn\'t instantiate")
    } else if (err=="Err2") {
      alert ("Error! script-lexicon.openLex1()\nCall to openLex2() returned false.")
    } else {
      alert ("Error! script-lexicon.openLex1()\nunidentifified error.")
    }
  }
}

function openLex2 (link) {
  try {
    var myHref = lexiconWindow.bottomlexframe.location.toString();
    myHref += link;
    lexiconWindow.bottomlexframe.location = myHref;
    window.setTimeout ('lexiconWindow.focus()', 500);
    return true;
  } catch (err) {
    alert("ERROR: script-lexicon.openLex2()\nunrecognized error.");
    return false;
  }
}

function openLexicon(link) {
  var theURL = "/jsp-pages/lexicon/lex-window.jsp";
  this.link = "#" + link;
  try {
    if (lexiconWindow === null ||
        'undefined' == typeof lexiconWindow ||
        ((typeof lexiconWindow) == 'object' && lexiconWindow.closed)) {
      this.lexiconWindow = open (theURL, this.lexiconWindowName, this.lexStyleStr);
      window.setTimeout ('openLex1()', 500);
    } else if ((typeof lexiconWindow) == 'object') {
      var myHref = lexiconWindow.bottomlexframe.location.toString();
      var index = myHref.indexOf ('#');
      if (index >= 0) {
        myHref = myHref.substring(0, index);
      }
      myHref += this.link;
      lexiconWindow.bottomlexframe.location = myHref;
      lexiconWindow.focus();
    } else {
      alert("ERROR IN openLexicon() -- uncovered type");      
    }
  } catch (err) {
    alert("ERROR IN openLexicon()");
  }
}

/*    
    alert("CRAP");
    if (typeof toplexframe != 'object') {
      m += "\ntoplexframe is not an object."
      err.name = "Error 3";
      err.message = m;
      throw(err);
    }
    if (typeof bottomlexframe != 'object') {
      m += "\nbottomlexframe is not an object."
      err.name = "Error 4";
      err.message = m;
      throw(err);
    }
    
    // Assign focus to lexiconWindow
    var myHref = bottomlexframe.location.toString();
    var index = myHref.indexOf("#");
    if (index >= 0) {
      myHref = myHref.substring(0, index)
    }
    myHref += link;
    m += "\nadjusted href is: " + myHref;
    bottomlexframe.location = myHref;
    lexiconWindow.focus();
 else if (lexiconWindow.closed) {
      lexiconWindow = open (theURL, lexiconWindowName, lexStyleStr);  
      alert("closed: " + (typeof lexiconWindow.bottomlexframe));
    } else if ((typeof lexiconWindow) == 'object') {
      alert("OK: " + (typeof lexiconWindow.bottomlexframe));
    } else {
      m += "\nError: lexiconWindow is not an object";
      return;
      err.name = "Error 1";
      err.message = m;
      throw(err);
    }
    m += "\nlexiconWindow.bottomlexframe: " + typeof lexiconWindow.bottomlexframe;
*/


