var inline_ad=new Array("&lt;br&gt;","</p>")
var tot, b, c;

function doHighlight_inline(bodyText, searchTerm, highlightStartTag, highlightEndTag,index)
{
  // the highlightStartTag and highlightEndTag parameters are optionalBiodiesel - Definition, Glossary, Details
  //alert(index);
  
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
  var alm, almm, leng, ll, lll;
  var found=0;
  var no_fd;
  //alert(bodyText.length);
		   if(bodyText.length < 5000)
				   {
					   no_fd = 1;
				   } else if(bodyText.length > 5000 && bodyText.length < 15000) {
					   no_fd = 2;
				   } else {
					   no_fd = 3;
				   }
  while (bodyText.length > 0) {
	//alert(i);
	i = lcBodyText.indexOf(lcSearchTerm, i+1);
	
	if (i < 0) {
	  newText += bodyText;
	  bodyText = "";
	} else {
		   if (bodyText.lastIndexOf("/a>", i) >= bodyText.lastIndexOf("<a", i)) {
			    //stip anything inside an table tag
			    if (lcBodyText.lastIndexOf("/table>", i) >= lcBodyText.lastIndexOf("<table", i)) {
		// skip anything inside a <script> block
		if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
				alm = bodyText.substr(i-1, searchTerm.length);
				almm = bodyText.substr(i+1, searchTerm.length);
				//var nmm = bodyText.substring(0, i);
				leng = alm.length;
				//alert(leng);
				ll = alm.charAt(0);
				lll = almm.charAt(leng-1);						   
		  //alert(lll);
		  var txt = bodyText.substring(0, i);
		  var tot_midl_worda = txt.length;
		 //alert(tot_midl_worda);
		  if((found < no_fd) && tot_midl_worda > 3500)
		  {
	  
	   if(found == 0)
	   {
			highlightStartTag = "";
			highlightEndTag = "";
	
	   } else if(found == 1) {
			highlightStartTag = "";
			highlightEndTag = "";
	   } else if(found == 2) {
			highlightStartTag = "";
			highlightEndTag = "";
	   }
		   
   //alert(found);
				newText += bodyText.substring(0, i) + bodyText.substr(i, searchTerm.length)+ highlightStartTag + highlightEndTag;  
				bodyText = bodyText.substr(i + searchTerm.length);
				lcBodyText = bodyText.toLowerCase();
				//alert(i);
				i = -1;
				found++;
				//alert(found);&& (found < 5) && (tot_link < 50)
		  }
		 
		}
		   }
	   }
	}
  }
  return newText;
}
function highlightSearchTerms_inline(warnOnFailure, highlightStartTag, highlightEndTag)
{
	//alert(warnOnFailure);
 if (!document.body || typeof(document.body.innerHTML) == "undefined") {
	  //alert(searchText);
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    //return false;
  }
 
  //var bodyText = document.body.innerHTML;
  var bodyText = document.getElementById('entry').innerHTML;
//alert(bodyText.length);
 
  for (var i = 1; i < inline_ad.length; i++) {
    bodyText = doHighlight_inline(bodyText, inline_ad[i], highlightStartTag, highlightEndTag,i);
  }
  document.getElementById('entry').innerHTML = bodyText;
  return true;
}
highlightSearchTerms_inline(false);
