/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */

var found = false;


function highlightWord(node, word, classname) {
	// Iterate into this nodes childNodes
	
	var spanstyle = classname;
	
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word, classname);
		}
	}
	

	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != spanstyle) {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
								
				hiword = document.createElement("span");				
				hiword.className = spanstyle; //"concordia";				
				hiword.appendChild(hiwordtext);
				
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				
				pn.removeChild(node);
				
				found = true;
				//ShowNote(spanstyle);
				
			}
		}
	}
}


function ShowNote(spanstyle)
{
	var start = 150;
	var end;
	
	switch(spanstyle) {
		case "wholesalequote":
			end = 365;
			break;
			
		case "concordiaquote":
			end = 405;
			break;
			
		case "ccraquote":
			end = 395;
			break;
			
		case "nobuyback":
			end = 300;
			break;
			
		default:
			end = 390;
	}
	
	//document.getElementById(spanstyle).style.top = start + "px"
	//document.getElementById(spanstyle).style.visibility = 'visible';
	//SlideNote(start,end);
	setTimeout("SlideNote(" + start + "," + end +",'" + spanstyle + "')",500);

}


function SlideNote(start, end, spanstyle)
{
	if(spanstyle != "") {
		if(document.getElementById(spanstyle).style.visibility != 'visible' && (start < end-10)) {
			document.getElementById(spanstyle).style.visibility = 'visible';
		}	

		if(start <= end) {


			start += Math.round((end - start)/2)
			document.getElementById(spanstyle).style.top = start + "px"
			setTimeout("SlideNote(" + start + "," + end +",'" + spanstyle + "')",200);
		}
	}
}


function HidePromo(id)
{
	document.getElementById(id).style.visibility = 'hidden';
}


function icbbSearchHighlight() {

	//words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	
	var words = "";
	var spanstyle = "";
	var foundclass = "";
	
	words = "(Based on wholesale prices)";
	spanstyle = "wholesalequote";
	highlightWord( document.getElementsByTagName("body")[0], words, spanstyle);
	if(found==true) {
		foundclass = spanstyle;
		found = false;
	}

	words = "(Represents approximately 30% of the new book price)";
	spanstyle = "ccraquote";
	highlightWord( document.getElementsByTagName("body")[0], words, spanstyle);
	if(found==true) {
		foundclass = spanstyle;
		found = false;
	}
	
	words = "(Represents approximately 50% of the new book price)";
	spanstyle = "concordiaquote";
	highlightWord( document.getElementsByTagName("body")[0], words, spanstyle);
	if(found==true) {
		foundclass = spanstyle;
		found = false;
	}
	
	
	words = "Sorry, we were unable to offer a price for this ISBN.  Demand for this book is too low at this time.";
	spanstyle = "nobuyback";
	highlightWord( document.getElementsByTagName("body")[0], words, spanstyle);
	if(found==true) {
		foundclass = spanstyle;
		found = false;
	}
	
	ShowNote(foundclass);
}





