var range
var srch = "sample";
function unhighlight()
{
  range = document.body.createTextRange()
  range.expand("textedit"); /* try commenting this out */
  range.select();           /* try commenting this out */
  document.execCommand("BackColor","false","white");
  document.execCommand("ForeColor","false","black");
  range.collapse(true);
}

function findandhighlight()
{
    if ( (navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4) )
    {
  srch = prompt("Enter a word or phrase to search for: ", srch)
  unhighlight();
  range = document.body.createTextRange()
  if (srch && range.findText(srch))
    {
      var count = 0;
      for (var i = 0; range.findText(srch) != false; i++)
        {
          count ++;
          range.select();
          if (i == 0) { range.scrollIntoView(); }
          document.execCommand("BackColor","false","red");
          document.execCommand("ForeColor","false","white");
          document.execCommand("Bold","false");
          range.collapse(false);
          range.select();
        }
      if (count > 0)
        {  range = document.body.createTextRange(); range.findText(srch); range.scrollIntoView();}
      else
        {  range = document.body.createTextRange(); range.scrollIntoView();}
      alert(srch+" was found "+count+" times on this page. Found text is highlighted in red.");
    }
   else
     {
       alert(srch+" was not found on this page.");
//       unhighlight();
     }
  }
 else
   {
     if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
      { window.find(); }
     else
      {  alert("A version 4 or newer Internet Explorer or version 4 Netscape browser is required for searching."); }
   }
}