// --------------------------------------------------------------------------------------------------------------------
// 	
// 	The information contained in this file is the intellectual property of Useful Gizmos
//	and may not be used or reproduced unless under license from Useful Gizmos
//
//
//	Do not edit this file - it is automatically created by Useful Gizmos Site Search
//
//
//		(c) Copyright 2003 Useful Gizmos
//
// --------------------------------------------------------------------------------------------------------------------
var g_acD2H = "0123456789abcdef";
var g_acC2A = "abcdefghijklmnopqrstuvwxyz";
var g_asSL=["ying","ment","ing","ies","ed","es","ly","s","y","e"];
var g_asStop=["10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","1st","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","2nd","30th","31st","3rd","4th","5th","6th","7th","8th","9th","about","after","all","also","am","an","and","any","are","as","at","be","became","because","been","but","by","can","cannot","cant","could","couldn","couldnt","did","didn","didnt","do","does","doesn","doesnt","dont","each","every","for","from","get","gets","give","go","going","good","got","had","hadn","hadnt","has","have","havn","havnt","he","her","here","hers","herself","him","himself","his","how","i","if","in","include","including","into","is","isn","isnt","it","its","itself","many","may","me","more","most","my","no","not","now","of","on","only","or","other","our","out","said","say","says","she","should","shouldn","shouldnt","so","some","such","than","that","the","their","theirs","them","then","there","these","they","theyre","this","to","too","up","very","was","we","went","were","what","when","where","which","who","why","will","with","would","yes","you","your","youre"];



var g_astrSearchTerms=[""];
var g_astrStemmedSearchTerms=[""];
var g_asIndex=[""];


function fnIJ(a1,a2) { j=a1.length; for (i=0;i<a2.length;i++) { a1[j]=a2[i];j++; }}

function fnGK()
{
	var strKeyword=document.location.href;
	var SearchTerm=strKeyword.split("=");
	if (SearchTerm!=null&&SearchTerm[1]!=null)
	{
		SearchTerm=SearchTerm[1].split("&");
		g_astrSearchTerms=SearchTerm[0];
		
		// Lower case the term
		g_astrSearchTerms=g_astrSearchTerms.toLowerCase();
		
	
		g_astrSearchTerms=unescape(g_astrSearchTerms);
		g_astrSearchTerms=g_astrSearchTerms.split(/[,.\!:;£$%^\| \+]/);

		var nNewLength=0;
		asNewArray=new Array();
		for(i=0;i<g_astrSearchTerms.length;i++)
		{
				var bStop=false;
			for (j=0;j<g_asStop.length;j++)
			{
				if (g_astrSearchTerms[i]==g_asStop[j])
				{
					bStop=true;
				}
			}
			if (!bStop)
			{
				asNewArray[nNewLength]=g_astrSearchTerms[i];
				nNewLength++;
			}
		}
		g_astrSearchTerms=asNewArray;
		// now to stem the terms
		for(i=0;i<nNewLength;i++)
		{
			g_astrStemmedSearchTerms[i]=g_astrSearchTerms[i];
			bStemmed=false;
			for(j=0;j<g_asSL.length&&!bStemmed; j++)
			{
				n =g_astrSearchTerms[i].length-g_asSL[j].length; 

				if((g_astrSearchTerms[i].lastIndexOf(g_asSL[j])==n)&&(n>0))
				{
					bStemmed=true;
					g_astrStemmedSearchTerms[i]= g_astrSearchTerms[i].substring(0,n);

				}
			}
		}		
	}
	else
	{
		g_astrSearchTerms=null;
	}
	
}

function d2h( n ) // return hex string of decimal value in arg n
{ var s="";  while(n) { s=g_acD2H.charAt( n%16)+s; n=Math.floor(n/16); }	return s;}

function c2a( c ) 
{ return g_acC2A.indexOf( c )-g_acC2A.indexOf( 'a')+97;}


function fnGH(sW)
{ var nH=0; var nL=0; sW.toLowerCase(); for(nL=0;nL<sW.length;nL++){nH=((nH*131)+c2a(sW.charAt(nL)))%(1024*1024);} nH+=1;return  nH;}



if(g_astrSearchTerms!=null)
{
	strTerm="";
	fnGK();

	d=document;
	nKeywords=g_astrStemmedSearchTerms.length;
	for(i=0;i<nKeywords;i++)
	{
		strTerm=g_astrStemmedSearchTerms[i];
		nHash = fnGH(strTerm);
		nHash %= 256;
		
	
		strFile = g_sIndexPath+"/ssindex"+d2h(nHash)+".js";

		
		d.write("<SCRI");
		d.write("PT src=\"");
		d.write(strFile);
		d.write("\"></SCR");
		d.write("IPT>");
	}
	d.write("<SCRI");
	d.write("PT src=\""+g_sIndexPath);
	d.write("/sitemap.js");
	d.write("\"></SCR");
	d.write("IPT>");
	d.write("");

}
else
{
}

var g_nTotalWeight=0;
var	g_nResults=0;
var g_aResults = new Array();

function result(strTitle,strURL,strSummary,nWeight)
{
	this.strTitle	= strTitle;
    this.strURL		= strURL;
    this.strSummary	= strSummary;
	this.nWeight	= nWeight;
}

function fnSortByWeight(a, b)
{
    var x = a.nWeight;
    var y = b.nWeight;
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
}

	
function SSGetResults()
{
	bSearch=false;
	d=document;
	
	fnGK();
	
	if (g_astrSearchTerms!=null&&g_astrStemmedSearchTerms!=null&&g_astrStemmedSearchTerms[0]!=null)
	{
		bSearch=true;
		var asDuplicates= new Array();
		var anResultWeights= new Array();
		var aResultIDs=null;
		var bFound=false;
		var bFoundSomething=false;

		for(j=0;j<g_astrStemmedSearchTerms.length;j++)
		{
			g_nTotalWeight++;
			for(i=0;i<g_asIndex.length&&!bFound;i++)
			{
				if (g_asIndex[i]==g_astrStemmedSearchTerms[j])
				{
				
					bFound=true;
					bFoundSomething=true;
					
				}
			}
			if (bFound)
			{
				var nVal = parseInt(g_asIndex[i]);
				while(i<g_asIndex.length&&!isNaN(nVal))
				{
					nVal-=1;

					if (asDuplicates[g_asPages[nVal*3+1]])
					{
						nResult=asDuplicates[g_asPages[nVal*3+1]];
						g_aResults[nResult].nWeight++;
					}
					else if (g_asPages[nVal*3])
					{
						asDuplicates[g_asPages[nVal*3+1]]=g_nResults;
						
						g_aResults[g_nResults]=new result(g_asPages[nVal*3],g_asPages[nVal*3+1],g_asPages[nVal*3+2],1);
						g_nResults++;
						
					}
					i++;
					nVal = parseInt(g_asIndex[i]);
				}
				bFound=false;
				i=0;
			}
		}
		// sort the arrays by weight
		g_aResults.sort(fnSortByWeight);
				
	}

	
	return bSearch;
}



function SSWriteSearchString()
{
	// write the original query out
	for(j=0;j<g_astrSearchTerms.length;j++)
	{
		document.write(g_astrSearchTerms[j]+" ");
	}
}

function SSGetResultCount()
{
	return g_nResults;
}

function SSWriteResultTitle(nResult)
{
	document.write(g_aResults[nResult].strTitle);
}
function SSWriteResultURL(nResult)
{
	document.write(g_aResults[nResult].strURL);
}
function SSWriteResultSummary(nResult)
{
	document.write(g_aResults[nResult].strSummary);
}
function SSWriteResultWeight(nResult)
{
	document.write(Math.round(100*(g_aResults[nResult].nWeight/g_nTotalWeight)));
}