// OTF Keyword Highlighting

function highlight(keyword)
{
   var body=document.getElementsByTagName("body")[0];
   
   var bodyContent=body.innerHTML;
   
   var newText = "";
   var i = -1;
   var lckeyword = keyword.toLowerCase();
   var lcbodyContent = bodyContent.toLowerCase();
   
   while (bodyContent.length > 0)
   {
      i = lcbodyContent.indexOf(lckeyword, i+1);
      if (i < 0)
      {
         newText += bodyContent;
         bodyContent = "";
      }
      else
      {
         // skip anything inside an HTML tag
         if (bodyContent.lastIndexOf(">", i) >= bodyContent.lastIndexOf("<", i))
         {
            // skip anything inside a <script> block
            if (lcbodyContent.lastIndexOf("/script>", i) >= lcbodyContent.lastIndexOf("<script", i))
            {
               newText += bodyContent.substring(0, i) + "<span class='highlight'>" + bodyContent.substr(i, keyword.length) + '</span>';
               bodyContent = bodyContent.substr(i + keyword.length);
               lcbodyContent = bodyContent.toLowerCase();
               i = -1;
            }
         }
      }
   }
   
   body.innerHTML=newText;
}