
this.name = "MainFrame";
var mainFrame = this; 

var litElement = null;
var unlitColor = null;
var litColor   = "YELLOW";

/****************************************************/
/* The following code is executed before onload()   */
/* and it is used to permit the URL that opens the  */
/* index page to detect a request to simultaneously */
/* open a sideWindow.  The syntax is to append      */ 
/* "#keyWord" to the url.                           */
/* Note: this.
/****************************************************/
var frameURL = this.location.href;//temporary variable 
indx = this.location.href.indexOf("?");
//this array sets up the key values the program will recognize 
var queryString = "";
var key = "";
var value = "";
var keyValuePairs = {"Bedrock":"/jsp-pages/lvl-2/pages/americas-bedrock-principles.jsp"};
if (indx > 0) {
  this.queryString = this.location.href.substring (indx + 1);
  jndx = this.queryString.indexOf("=");
  if (jndx < 0) {
    alert ("ERROR: script-main-frame.js queryString has no \'=\'");
  } else {
    this.key = this.queryString.substring(jndx + 1);    
  }
}

this.onload=(
    function() {
      try {
        if (this.key.length < 1) {
          return;
        } else {
          if(this.keyValuePairs[this.key]) {
            this.value = this.keyValuePairs[this.key];
          } else {
            alert("ERROR: onload() no value for key: " +  this.key);
            return;
          }
          this.openSideWindow(this.value);
        }
      } catch(err) { 
        alert("Frame onload(): Unrecognized URL: " + this.location.href);
      }
    }
  );

function closeFrame () {
  this.opener.focus();
  this.close();
}

function clearHighlight() {
  if (this.litElement !== null) {
    this.litElement.style.background = this.unlitColor;
    this.litElement = null;
    this.unlitColor = null;
  }
}

function hltDelay (tagId) {
  try {
    var myElement = this.mainindex.document.getElementById(tagId);
    if (myElement === null) {
      alert ("Error: script-main-frame.jsp - tagId [" + "\'" + tagId + "\'] not found.");
      return;
    }
    if (myElement.style) {
      if (this.litElement) {
        this.litElement.style.background = this.unlitColor;
      }
      this.litElement = myElement;
      this.unlitColor = myElement.style.background;
      myElement.style.background = this.litColor;
    } else {
       alert ("Error: script-main-frame.jsp - tagId [" + "\'" + tagId + "\'] found but style is null.");
    }
  } catch (error) {
    alert ("Error: script-main-frame.hltDelay");
  }
}

function highlightText (theURL, tagId, anchor) {
  this.mainindex.focus();
  this.mainindex.location =theURL + "#" + anchor;
  window.setTimeout ('hltDelay(\"' + tagId +  '\")', 1000);
}

function setMainMenu (theURL) {
  this.mainindex.location = theURL;
  this.focus();
}

