function wordhighlight(aSourceObject, aWords){
	regexp=/<[^<>]*>/ig;
	vHTMLArray = aSourceObject.innerHTML.match(regexp);
	vStrippedHTML = aSourceObject.innerHTML.replace(regexp,"$!$");
	rexp= new RegExp ("\\b(" + aWords + ")\\b", "gi");
	vTemp = vStrippedHTML.replace(rexp,'<span class="highlight">$1</span>');
	for(i=0;vTemp.indexOf("$!$") > -1;i++){
		vTemp = vTemp.replace("$!$", vHTMLArray[i]);
	}
	aSourceObject.innerHTML = vTemp;
}

function removehighlight(aSourceObject){
	aSourceObject.innerHTML = aSourceObject.innerHTML.replace(/(<span class=["]*highlight["]*>)([^<>]*)(<\/span>)/gi,'$2');
}

function highlightwords(aSourceObject, aWords){
	wTemp = unescape(aWords.replace(/\+/g,' '));
	wTemp = wTemp.replace(/(site:\s*www.smallcanonsearch.com|site:\s*smallcanonsearch.com)/i,' ');
	document.f.q.value = wTemp.replace(/^\s+/,'');
	wTemp = wTemp.replace(/\W/g,' ');
	lWords = wTemp.split(/\s+/g);
	for (w=0;w<lWords.length;w++) {
		if((lWords[w]!=' ')&&(lWords[w]!='')){
			wordhighlight(aSourceObject,lWords[w]);
		}
    }
}

function highlightsearch(){
	if (!document.getElementById || !document.createElement) return;
	if(document.getElementById("textContent")){
		highlightwords(document.getElementById("textContent"), document.f.q.value);
	}
}

function removesearchhighlight(){
	if (!document.getElementById || !document.createElement) return;
	if(document.getElementById("textContent")){
		removehighlight(document.getElementById("textContent"));
	}
}

function loadHighlight(){
	document.f.q.focus();
	if (!document.getElementById || !document.createElement) return;
	if(document.getElementById("textContent")){
		ref = document.referrer;
		if (ref.indexOf('?') == -1) return;
		qs = ref.substr(ref.indexOf('?')+1);
		qsa = qs.split('&');
		for (i=0;i<qsa.length;i++) {
			qsip = qsa[i].split('=');
		        if (qsip.length == 1) continue;
   		     	if (qsip[0] == 'q' || qsip[0] == 'p' || qsip[0] == 'va') { // q= for Google, Ask, MSN, and AltaVisa p= for Yahoo, va= for Yahoo SiteSearch
					highlightwords(document.getElementById("textContent"), qsip[1]);
	   	    	}
		}
	}
}