function init() 
{
	if (document.getSelection || (document.selection && document.selection.createRange)) {
	

		if(navigator.userAgent.indexOf("Opera") >= 0) 
		{
			// we dont want OPERA to mark up the searchwords - it just fucks it up!
			// alert("OPERA DETECTED!");
		} 
		else
		{
			// initialize if browser is IE/WIN32 >= 4 OR MOZILLA >= 1.3
			funGetSearchWords();
		}
	}

}

function getArgs() {

	var args = new Object();
	// Get Query String
	var query = location.search.substring(1); 

	// Split query at the comma
	var pairs = query.split("&"); 
	
	// Begin loop through the querystring
	for(var i = 0; i < pairs.length; i++) {

		// Look for "name=value"
		var pos = pairs[i].indexOf('='); 
		// if not found, skip to next
		if (pos == -1) continue; 
		// Extract the name
		var argname = pairs[i].substring(0,pos); 
		
		// Extract the value
		var value = pairs[i].substring(pos+1); 
		// Store as a property
		args[argname] = unescape(value); 
	}
	return args; // Return the Object
}

function funGetSearchWords()
{
	var strSearchWord = "";

	// Get the values back
	var args = getArgs(); //Get the arguments
	if (args.searchword) strSearchWord = (args.searchword);

	// write the path for the style sheet now
	if (strSearchWord != "")
	{

		var arrWords = strSearchWord.split(" ");

		funMarkSearchWords(arrWords);
	}
}


function funMarkSearchWords(arrWords)
{

	
	if (document.getSelection) 
	{	
		// mozilla / netscape / (opera)
		var thistext = document.body.innerHTML;

	} 
	else if (document.selection && document.selection.createRange) 
	{
		// IE
		//		var bodytext = document.body.createTextRange();
		//		var thistext = bodytext.htmlText;

		var thistext = document.body.innerHTML;

	} 
	else 
	{
		// unsupported browser
	}

	// determine which words to mark
	var strFinalWords = ""
	for(var i = 0; i < arrWords.length; i++) {

		if (arrWords[i].charAt(0) == "-")
		{
			// exclude the word
			strFinalWords = strFinalWords + "|";
		} 
		else if (arrWords[i].charAt(0) == "+")
		{
			// multiple words
			strCleanedWord = arrWords[i].replace("+","");

			strFinalWords = strFinalWords + "|" + strCleanedWord + "|";  // .replace("+","")
		}
		else
		{
			// sentence
			strFinalWords = strFinalWords + arrWords[i] + " ";
		}

	}
	

	// create an array with the words to search for
	arrFinalWords = strFinalWords.split("|");
	
	// Begin loop through search words
	for(var i = 0; i < arrFinalWords.length; i++) {

		if (arrFinalWords[i] != "") {

			// remove trailing space
			thisword = arrFinalWords[i];
			while(''+thisword.charAt(thisword.length-1)==' ')thisword=thisword.substring(0,thisword.length-1);

			if (thisword.length > 2)
			{
				//mark it up

				// replacing alt texts	
				//						1				2						3		4
				var pat = new RegExp("<([^>]*)alt=\"([^\"]*)" + thisword + "([^\"]*)\"([^>]*)>", "gi");
				thistext = thistext.replace(pat,"<$1alt=''$4>");

				// replace <TAGS> with ¤¤¤
				// <(.|\n)+?>
				var pat = new RegExp("<([^>]*)" + thisword + "([^>]*)>", "gi");
				thistext = thistext.replace(pat,"<$1¤¤¤$2>");
				
				// search and replace
				var pat = new RegExp(thisword, "gi");
				thistext = thistext.replace(pat,"<span style='background-color: yellow; font-weight: bold;'>" + thisword + "</span>");

				// replace ¤¤¤ with <TAG> 
				var pat = new RegExp("<([^>]*)¤¤¤([^>]*)>", "gi");
				thistext = thistext.replace(pat,"<$1"+ thisword +"$2>");
			}

		}

	}

	document.body.innerHTML = thistext;
}

