var ele_ids_checked=new Array();

function highlighter(searchText){
	var element=new Array()
	for (var i=0;i<document.getElementsByTagName('*').length;i++){
		if(document.getElementsByTagName('*')[i].id){
			if(!ele_ids_checked[document.getElementsByTagName('*')[i].id]){
				element[document.getElementsByTagName('*')[i].id]=document.getElementsByTagName('*')[i]
			}
		}
	}

	searchArray = searchText.split(" ");

	for(var j in element){
		var ELEText=element[j].innerHTML;
		if(ELEText){
			ele_ids_checked[j]=1;
			for(var i=0;i<searchArray.length;i++){
				NEWELEText=apc_doHighlight(ELEText,searchArray[i]);
				if(NEWELEText){
					element[j].innerHTML=NEWELEText;
					ELEText=NEWELEText;
				}
			}
		}
	}
}


function apc_doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag){
	// the highlightStartTag and highlightEndTag parameters are optional
	if((!highlightStartTag) || (!highlightEndTag)){
		highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
		highlightEndTag = "</font>";
	}

	// find all occurences of the search term in the given text,
	// and add some "highlight" tags to them (we're not using a
	// regular expression search, because we want to filter out
	// matches that occur within HTML tags and script blocks, so
	// we have to do a little extra validation)
	var newText = "";
	var i = -1;
	var lcSearchTerm = searchTerm.toLowerCase();
	var lcBodyText = bodyText.toLowerCase();
	var found=0;
	var substrstart=0;
	var indexofcount=0;
	var substrstr="";

	while(bodyText.length > 0){
//		i=lcBodyText.indexOf(lcSearchTerm,i+1);
		substrstart=i+1;
		substrstr=lcBodyText.substr(substrstart);
		var rg = new RegExp("[^0-9a-z]"+lcSearchTerm+"[^0-9a-z]",'i');
		indexofcount=substrstr.search(rg);
//		indexofcount=substrstr.search('/(^|[^a-z0-9])'+lcSearchTerm+'($|[^a-z0-9])]/i');
		if(indexofcount!=-1){
	//		alert(indexofcount);
			i=(indexofcount+substrstart)+1;
		}else{
			i=-1;
		}


		if(i<0){
			newText += bodyText;
			bodyText="";
		}else{
			// skip anything inside an HTML tag
			if(bodyText.lastIndexOf(">",i)>=bodyText.lastIndexOf("<",i)){
				// skip anything inside a <script> block
				if(lcBodyText.lastIndexOf("/script>",i)>=lcBodyText.lastIndexOf("<script", i)){
					newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
					bodyText = bodyText.substr(i + searchTerm.length);
					lcBodyText = bodyText.toLowerCase();
					i = -1;
					found=1;
				}
			}
		}
	}

	//APC ADDED - so that if not found nothing will be done
	if(found!=1){
		return false;
	}
	//END APC ADDED

	return newText;
}

