You may notice in surfing through some of the older Companion Websites that the Net Search or Web Search module doesn't always work right. For example, choosing Excite as your search engine will often return a Webcrawler results page. And newer engines, like Google, were notably absent, while older, defunct engines, like Infoseek, were still listed. These an many other errors were the result of the script not being revised to keep up with mergers and acquisitions in the search engine marketplace. In developing the Web Publishing System, the time had come to address these issues. I wrote a wholly new JavaScript to fix the broken searches, remove defunct search engines, and add new search engines. Unlike the old netsearch module JavaScript, this new websearch JavaScript was written to allow faster updates to the code as the industry evolves. This page has a working example of the code, which is detailed below.

<script LANGUAGE="JavaScript">
<!--
// this function creates new array elements
// Christian: the url here should be the default url
// of a standard search up to, but not including the search term.
function engineElem(key, name, url)
{
	this.key = key;
	this.name = name;
	this.url = url;
}

// HotBot is the default?
var defaultEngine = 4;

// create standard array of search engines
var engineArray = new Array();
engineArray[0] = new engineElem('alltheweb', 'All the Web', 'http://www.alltheweb.com/cgi-bin/search?type=all&query=');
engineArray[1] = new engineElem('altavista', 'AltaVista', 'http://www.altavista.com/sites/search/web?q=');
engineArray[2] = new engineElem('ask', 'Ask Jeeves', 'http://www.askjeeves.com/main/askjeeves.asp?ask=');
engineArray[3] = new engineElem('dogpile', 'Dog Pile', 'http://search.dogpile.com/texis/search?q=');
engineArray[4] = new engineElem('excite', 'Excite', 'http://search.excite.com/search.gw?c=web&search=');
engineArray[5] = new engineElem('google', 'Google', 'http://www.google.com/search?q=');
engineArray[6] = new engineElem('goto', 'GoTo', 'http://www.goto.com/d/search/;$sessionid$55OE4ZYAAILD1QFIEPFAPUQ?type=home&tm=1&Keywords=');
engineArray[7] = new engineElem('hotbot', 'HotBot', 'http://hotbot.lycos.com/?MT=');
engineArray[8] = new engineElem('looksmart', 'LookSmart', 'http://www.looksmart.com/r_search?look=&pin=010607x55ade7fb2aee33abb41&key=');
engineArray[9] = new engineElem('lycos', 'Lycos', 'http://search.lycos.com/main/?query=');
engineArray[10] = new engineElem('northernlight', 'Northern Light', 'http://www.northernlight.com/nlquery.fcg?cb=0&qr=');
engineArray[11] = new engineElem('webcrawler', 'Webcrawler', 'http://search.excite.com/search.gw?lk=webcrawler&s=');
engineArray[12] = new engineElem('yahoo', 'Yahoo', 'http://search.yahoo.com/bin/search?p=');

function setCookie(name, value, expires, path, domain, secure)
{
	var new_cookie = name + '=' + escape(value) +
		((expires) ? '; expires=' + expires.toGMTString() : '') +
		((path) ? '; path=' + path : '') +
		((domain) ? '; domain=' + domain : '') +
		((secure) ? '; secure' : '');
	document.cookie = new_cookie;
}

function getCookie(name)
{
	if(document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(name + '=');

		if(offset == -1)
		{
			return '';
		}

		// if cookie exists
		offset += name.length + 1;
		end = document.cookie.indexOf(';', offset);

		if(end == -1)
		{
			end = document.cookie.length;
		}

		return unescape(document.cookie.substring(offset, end));
	}

	return '';
}

function showEngines()
{
	var key = getCookie('ph-websearch');
	var def = defaultEngine;

	for(var i = 0; i < engineArray.length; ++i)
	{
		if(key == engineArray[i].key)
		{
			def = i;
			break;
		}
	}

	var string = '';

	for(i = 0; i < engineArray.length; ++i)
	{
		var engine = engineArray[i];
		string += '<option VALUE="' + engine.key + '"';
		if(i == def)
		{
			string += ' SELECTED';
		}
		string += '>' + engine.name + '\n';
	}

	return string;
}

//copy the clicked term into the text field
function wordToSearch(word)
{
	var f = document.searchform;
	f.display.value += word + ' '';
}

//clear the text field
function clearAll()
{
	var f = document.searchform;
	f.display.value = '';
}

//launch a new window with the selected search engine and search term
function searchIt()
{
	var f = document.searchform;

	// save in cookie for reuse
	var i = f.engine.selectedIndex;
	var key = engineArray[i].key;
	var url = engineArray[i].url;

	// cookie lasts for one year
	var now = new Date();
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie('ph-websearch', key, now, '/', '/','.pearsoncmg.com');

	');//replace any spaces in the search term with +,
	//and remove any space at the end of the string.
	searchTerm = '';
	startTerm = f.display.value;
	x = startTerm.length - 1;
	last_char = startTerm.charAt(x);
	if(last_char == ' '')
	{
		//x = x - 1;
		startTerm = startTerm.substring(0,x);
	}
	for(c = 0; c < startTerm.length; ++c)
	{
		tempChar = startTerm.charAt(c);
		if(tempChar == ' ')
		{
			tempChar = '+';
		}
		searchTerm = searchTerm + tempChar;
	}
	
	//add search term to url of chosen search engine
	var searchUrl = url + searchTerm;
	
	//launch window with the full url + search term
	srchWindow = window.open(searchUrl, 'WebSearch',
		'toolbar=yes,location=yes,scrollbars=yes,resizable=yes,width=630,height=400');

	if(srchWindow.opener == null) srchWindow.opener = window;
	srchWindow.focus();
}
// -->
</script>