function doHighlight(a,f,d,e){if(!d||!e){d="<font style='color:blue; background-color:yellow;'>";e="</font>"}var g="",b=-1,h=f.toLowerCase(),c=a.toLowerCase();while(a.length>0){b=c.indexOf(h,b+1);if(b<0){g+=a;a=""}else if(a.lastIndexOf(">",b)>=a.lastIndexOf("<",b))if(c.lastIndexOf("/script>",b)>=c.lastIndexOf("<script",b)){g+=a.substring(0,b)+d+a.substr(b,f.length)+e;a=a.substr(b+f.length);c=a.toLowerCase();b=-1}}return g}function highlightSearchTerms(c,f,g,d,e){if(f)searchArray=[c];else searchArray=c.split(" ");if(!document.body||typeof document.body.innerHTML=="undefined"){g&&alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");return false}for(var a=document.body.innerHTML,b=0;b<searchArray.length;b++)a=doHighlight(a,searchArray[b],d,e);document.body.innerHTML=a;return true}function searchPrompt(a,b,c,d){if(!a)a="";if(!c||!d){highlightStartTag="";highlightEndTag=""}else{highlightStartTag="<font style='color:"+c+"; background-color:"+d+";'>";highlightEndTag="</font>"}if(b)promptText="Please enter the phrase you'd like to search for:";else promptText="Please enter the words you'd like to search for, separated by spaces:";searchText=prompt(promptText,a);if(!searchText){alert("No search terms were entered. Exiting function.");return false}return highlightSearchTerms(searchText,b,true,highlightStartTag,highlightEndTag)}function highlightGoogleSearchTerms(b){if(!b)return false;var d="q=",c=b.toLowerCase().indexOf(d);if(c<0||c+d.length==b.length)return false;var e=b.indexOf("&",c);if(e<0)e=b.length;var a=b.substring(c+d.length,e);a=a.replace(/%20/gi," ");a=a.replace(/\+/gi," ");a=a.replace(/%22/gi,"");a=a.replace(/\"/gi,"");return highlightSearchTerms(a,false)}function testHighlightGoogleSearchTerms(){var a="http://www.google.com/search?q=javascript%20highlight&start=0";a=prompt("Test the following referrer string:",a);return highlightGoogleSearchTerms(a)};
