// --------------------------------------
// KNOWLEDGE MAP SEARCH SUPPORT FUNCTIONS
// --------------------------------------
// Copyright (c) 2003-2004 The Salamander Organization Ltd.  All Rights Reserved.
//
// THIS WORK IS SUBJECT TO U.K. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
//
// DISCLAIMER:
//
// The Salamander Organization Ltd. (hereto referred as "Salamander") makes no representations or warranties
// with respect to the contents or use of this code, and specifically disclaims any express or implied
// warranties of merchantability or fitness for any particular purpose.  Further, Salamander reserves the right
// to revise this publication and to make changes to its content, at any time, without obligation to notify any
// person or entity of such revisions or changes.
//
// Further, Salamander makes no representations or warranties with respect to any software, and specifically
// disclaims any express or implied warranties of merchantability or fitness for any particular purpose.  Salamander
// reserves the right to make changes to any and all parts of the software, at any time, without obligation to notify
// any person or entity of such changes.
//
// Inclusion of the above notice does not necessarily imply publication.


// ##############################
// For the Search Page

// initialise the search on this page
function InitSearchParams()
{
	var params = GetQueryString();
	
	if (params)
	{
		SetSearchParameters(params);
		
		// fire the search (contained in Indexes/Search/search.js)
		button1_onclick();
	}
}

// preload the search input box with the params provided
function SetSearchParameters(params)
{
	txtSearchTerms.value = params;
}

// read the GET query string from the current address bar location
function GetQueryString()
{
	var queryString = window.location.search.substring(1);
	
	var queryParts = queryString.split("&");
	
	var queryValues = "";
	
	if (queryString)
	{
		for (var i = 0; i < queryParts.length; i++)
		{
			var keyValuePair = queryParts[i].split("=");

			var currValue = keyValuePair[1];

			if (queryValues == "")
			{
				queryValues = currValue;
			}
			else
			{
				queryValues = queryValues + " " + currValue;
			}
		}
	}
	
	return queryValues;
}

// ##############################
// For the "local" search dialogues

// do the simple web search from a "local" simple search dialogue
function DoClientSearch(urlPath)
{
	var queryString = BuildQueryString();
	
	if (queryString)
	{
		window.location = urlPath + "Indexes/Search/websearch" + outputExtension + "?" + queryString;
	}
}

// build the query string from the contents of the simple search dialogue
function BuildQueryString()
{
	var searchText = document.getElementById("txtSimpleSearchTerms").value;
	
	var searchParts = searchText.split(" ");
	
	var queryString = "";
	
	for (var i = 0; i < searchParts.length; i++)
	{
		currPart = searchParts[i];
		
		queryPair = "val" + i + "=" + currPart;
		
		if (queryString == "")
		{
			queryString = queryPair;
		}
		else
		{
			queryString = queryString + "&" + queryPair;
		}
	}
	
	return queryString;
}