function HelpPopUp(help_file)
{
  DoPopUp("Help", help_file);
}

function DocPopUp(bio_file)
{
  DoPopUp("FLP2", bio_file);
}

function PrintPopUp(html_file)
{
  DoPopUp("Printable", html_file);
}

function DoPopUp(win_title, uri)
{
  var opt, win;
  opt = "toolbar,scrollbars,resizable,";
  opt += "top=25,left=25,height=500,width=500";
  win = window.open(uri, win_title, opt);
  win.focus();
}

function DoHighlight(body_text, search_terms) 
{
  var script_rex = new RegExp(".");
  var tag_rex = new RegExp(".");
  var text_rex = new RegExp(".");

  script_rex.compile("^<script\\b.*?</script>", "i");
  tag_rex.compile("^<.*?>");
  text_rex.compile("^[^<]+");
  
  var replace_string = "<span style='color: #000000; background-color: #FFFF00;'>$&</span>";
    
  var i = -1;
  var new_text = "";
  
  while (body_text.length > 0) 
  {
    var m_script = body_text.match(script_rex);
    if (m_script)
    {
      new_text += m_script[0];
      body_text = body_text.substr(m_script[0].length);
    }
  
    var m_tag = body_text.match(tag_rex);
    if (m_tag)
    {
      new_text += m_tag[0];
      body_text = body_text.substr(m_tag[0].length);
    }
  
    var m_text = body_text.match(/^[^<]+/);
    if (m_text)
    {
      var s = m_text[0];
      
      if (s.length > 2)
      {
        for (var i = 0; i < search_terms.length; i++)
        {
          try
          {
            var r = new RegExp("\\b" + search_terms[i] + "\\b", "i");
            s = s.replace(r, replace_string);
          }
          catch(e)
          {
          }
        }
      }
      
      new_text += s;
      body_text = body_text.substr(m_text[0].length);
    }
  }
  
  return new_text;
}


function HighlightText()
{
  if (!document.body || typeof(document.body.innerHTML) == "undefined") 
    return false;

  var uri_search = decodeURI(window.location.search);
  
  if (uri_search)
  {
    var m = uri_search.match(/hi=([^&]+)/)
    if (m)
    {
      var search_terms = m[1].split("|");
      document.body.innerHTML = DoHighlight(document.body.innerHTML, search_terms);
    }
    if (uri_search.indexOf("mode=print") > -1)
    {
      var s = document.body.innerHTML;
      s = s.replace(/<a\b.*?>/ig, "");
      s = s.replace("</a>", "");
      document.body.innerHTML = s;
    }
  }
  
  return true;
}


