/*
Find In Page Script- 
By Mike Hall (MHall75819@aol.com)
Permission granted to Dynamicdrive.com to feature script in archive
For full source code, visit http://dynamicdrive.com
*/

function loadHelps(str1) {
  var text = "Locate the next occurrence of \""+str1+"\"?"
  if (confirm(text)) {
    findInPage(str1)
  }
}

var NS4=document.layers?1:0
var IE4=document.all?1:0
var win=window;    // window to search.
var n=0;

function findInPage(str) {
  var txt, i, found;

  if (str == "" || str == null) {return false}
//  if (str == "") {return false}

  // Find next occurrence of the given string on the page; wrap around
  // to the start of the page if necessary.
  if (NS4) {

    // Look for match starting at the current point. If not found, rewind
    // back to the first match.
    if (!win.find(str)) {
      while(win.find(str, false, true))
        n++;
    } else {loadHelps(str)}
  }

  if (IE4) {
    txt = win.document.body.createTextRange();
    // Find the nth match from the top of the page.
    for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
      txt.moveStart("character", 1);
      txt.moveEnd("textedit");
    }
    // If found, mark it and scroll it into view.
    if (found) {
      txt.moveStart("character", -1);
      txt.findText(str);
      txt.select();
      txt.scrollIntoView();
      n++;
      loadHelps(str);
    }
    // Otherwise, start over at the top of the page and find first match.
    else {
      if (n > 0) {
        n = 0;
        findInPage(str);
      }
      // Not found anywhere, give message.
//      else
//        alert("\"" + str + "\"" + " not found.");
    }
  }
  return false;
}

//function resetKeyword() {str = null;}
function resetKeyword() {parent.topw="";}

//var loadNotice;
function startSrch() {
//  if (top.find[0]) {
    self.location.href="srch.html";
//  } else {
//    var text = 'Activating the Search function requires accessing a search file.\n';
//    text += 'Do you want to activate Search?';
//    if (confirm(text)) {
//      var lntext='';
//      lntext+='<HTML>\n<HEAD>\n';
//      lntext+='<TITLE>Loading file<\/TITLE>\n<\/HEAD>\n';
//      lntext+='<BODY style="background-color:#fffafa;color:#000080">\n';
//      lntext+='<P style="margin-top:1em;text-align:center;font-family:Times, Times New Roman, serif">';
//      lntext+='The search file is loading ...<\/P>\n<\/BODY>\n<\/HTML>';
//      loadNotice=window.open("","load_notice","width=300,height=10,left=5,top=5,dependent");
//      loadNotice.focus();
//      loadNotice.document.write(lntext);
//      loadNotice.document.close();
//      top.holdNotice(loadNotice);
//
//      loadFile=window.open("loadsrch.html","load_file","width=300,height=10,left=5,top=5,dependent");
//      loadFile.blur();
//    }
//  }
}

