/*
 Text markup script by Patrik Lundin
 plundin@javathings.com
 http://www.javathings.com

 Designed to work with the Site Search Applet 1.3+
 will mark all occurencies of the word sent in through 
 the query string on the page.

 Put this script within the header of the page and then
 place OnLoad="markUp()" inside the opening body tag:

 <html>
 <head>
 <script src="markup.js"></script>
 </head>
 </html>
 
 <BODY ONLOAD="markUp()">
 ..
 </body>

 </html>

*/

// #####################################################
// CONFIGURATION VARIABLES

// Only search and mark the first 100 matches found
// change if you want more searches = slower.
var loops = 100;

// Opening and closing html, determines the way to markup matches.
var openingHtml = "<u><span style=\"background-color: #FFFF00;\">";
var closingHtml = "</span></u>"

// ######################################################
// DON'T CHANGE ANYTHING BELOW THIS LINE

function storage(){}

var querystring = null;

function requestQueryString( name )
{
	var pairs, values, search;
	if( querystring == null )
	{
		search = location.search;
		if( search == null || search == "" ) return;
		querystring = new storage();
		search = search.substring( 1 );
		search = search.split( "+" ).join( " " );
		pairs = search.split( "&" );
		for( i = 0; i < pairs.length; i++ )
		{
			values = pairs[ i ].split( "=" );
			querystring[ values[ 0 ] ] = unescape( values[ 1 ] );
		}
	}
	return( querystring[ name ] );
}

function markUp() 
{
  if( document.body.createTextRange )
  {
	  var range, search, mode, words;

	  search = requestQueryString( "ssrchstr" );
	  mode = requestQueryString( "ssrchmode" );

	  if( search == null || search == "" ) return;

	  if( mode == 0 || mode == 1 )
	  {
		words = search.split( " " );
	  }
	  else
	  {
		words = new Array( search );
	  }
	  
	  for( i = 0; i < words.length; i++ )
	  {
		  range = document.body.createTextRange();
		  range.collapse(true);
		  while( range.findText( words[ i ], loops ) )
		  {
			range.pasteHTML( openingHtml + range.text + closingHtml );
			range.collapse(false);
		  }
	  }
  }
}