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

function doHighlight_mlist(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 > 10000 && 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 > 5000)
		  {
	  
	   if(found == 0)
	   {
 	      var whitepaper = new Array(); 
	      whitepaper[0] = "<br/><div style='background-color:#fcfcfc; width:600px; height:80px;  padding:10px; font-family:Arial, Helvetica, sans-serif; border:solid 1px #f0f0f0; margin-bottom:15px;'><span style='float:left; width: 450px; border:none'><h3 style='font-size:17px; color:#990000; margin:0; margin-bottom:10px; magin-top:-80px'>Download Free Whitepaper</h3><a href='http://castoroil.in/downloads/download.php?name=CastorOil_Diverse_Business_Potential.pdf' style='text-decoration:none; border:none'><p style='color:#19426a; font-size:13px; margin:0; font-weight:bold;'>Diverse Business Potential for Castor Oil Chemicals and Leveraging India's Advantage in Castor Oil Products</p></a></span><span style='float:right'><a href='http://castoroil.in/downloads/download.php?name=CastorOil_Diverse_Business_Potential.pdf' style='text-decoration:none; border:none'><img src='http://www.castoroil.in/images/download_wp.png' style='padding-top:10px'></a></span></div>";
		  
		  whitepaper[1] = "<br/><div style='background-color:#fcfcfc; width:600px; height:80px;  padding:10px; font-family:Arial, Helvetica, sans-serif; border:solid 1px #f0f0f0; margin-bottom:15px;'><span style='float:left; width: 450px; border:none'><h3 style='font-size:17px; color:#990000; margin:0; margin-bottom:10px; magin-top:-80px'>Download Free Whitepaper</h3><a href='http://castoroil.in/downloads/download.php?name=Production_and_Uses_of_Key_Castor_Oil_Oleochemicals.pdf' style='text-decoration:none; border:none'><p style='color:#19426a; font-size:13px; margin:0; font-weight:bold;'>Production and Uses of Key Castor Oil Oleochemicals</p></a></span><span style='float:right'><a href='http://castoroil.in/downloads/download.php?name=Production_and_Uses_of_Key_Castor_Oil_Oleochemicals.pdf' style='text-decoration:none; border:none'><img src='http://www.castoroil.in/images/download_wp.png' style='padding-top:10px'></a></span></div>";
		  
		  var display_wp = Math.floor((Math.random()*2));
		  highlightStartTag = whitepaper[display_wp];
		  
		 
		 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_mlist(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('content').innerHTML;
 
  for (var i = 1; i < mlist_ad.length; i++) {
    bodyText = doHighlight_mlist(bodyText, mlist_ad[i], highlightStartTag, highlightEndTag,i);
  }
  document.getElementById('content').innerHTML = bodyText;
  return true;
}
highlightSearchTerms_mlist(false);
