function focalpoint()
{
	this.document.searchform.q.focus();
}

function addKeyword(kw)
{
	if (this.document.searchform.q.value == " ")
	{
		this.document.searchform.q.value = kw;
	}
	else
	{
		this.document.searchform.q.value += " " + kw;
	}
	return false;
}

function jumpToTopic(topic)
{
	this.location = "http://www.thrall.org/proteus2/" + topic;
}

function clearBox()
{
	this.document.searchform.q.value = "";
}

function search()
{
	var se = this.document.searchform.searchengine.value;
	var k  = this.document.searchform.q.value;

	if (se == "AltaVista")
	{
		this.location = "http://www.altavista.com/web/results?itag=ody&q=" + k + "&kgs=1&kls=0";
	}

	if (se == "Biography.com")
	{
		this.location = "http://www.biography.com/search/biography.do?keywords=" + k;
	}

	if (se == "Bing")
	{
		this.location = "http://www.bing.com/search?q=" + k + "&go=&form=QBLH&qs=n";
	}

	if (se == "Dogpile")
	{
		this.location = "http://www.dogpile.com/dogpile_other/ws/redir/_iceUrlFlag=11?rfcp=TopNavigation&rfcid=407&qcat=Web&qkw=" + k + "&newtxn=false&qcoll=Relevance&_IceUrl=true";
	}

	if (se == "Google")
	{
		this.location = "http://www.google.com/#hl=en&q=" + k;
	}

	if (se == "Google Blogs")
	{
		this.location = "http://blogsearch.google.com/blogsearch?hl=en&source=hp&q=" + k + "&um=1&ie=UTF-8&sa=N&tab=wb";
	}

	if (se == "Google Books")
	{
		this.location = "http://books.google.com/books?hl=en&source=hp&q=" + k + "&um=1&ie=UTF-8&sa=N&tab=bp";
	}

	if (se == "Google Images")
	{
		this.location = "http://images.google.com/images?hl=en&q=" + k + "&um=1&ie=UTF-8&sa=N&tab=wi";
	}

	if (se == "Google News")
	{
		this.location = "http://news.google.com/news/search?aq=f&pz=1&cf=all&ned=us&hl=en&q=" + k;
	}

	if (se == "Google Scholar")
	{
		this.location = "http://scholar.google.com/scholar?hl=en&source=hp&q=" + k + "&um=1&ie=UTF-8&sa=N&tab=ws";
	}

	if (se == "Internet Movie Database")
	{
		this.location = "http://www.imdb.com/find?s=all&q=" + k;
	}

	if (se == "Intute")
	{
		this.location = "http://www.intute.ac.uk/cgi-bin/search.pl?term1=" + k + "&submit=Search&limit=0&subject=All";
	}

	if (se == "Librarians Internet Index" || se == "ipl2")
	{
		this.location = "http://ipl2.org/IPL/Finding?Key=" + k;
	}

	if (se == "MedlinePlus.gov")
	{
		this.location = "http://vsearch.nlm.nih.gov/vivisimo/cgi-bin/query-meta?v%3Aproject=medlineplus&query=" + k + "&x=0&y=0";
	}

	if (se == "NASA.gov")
	{
		this.location = "http://search.nasa.gov/search/search.jsp?nasaInclude=" + k;
	}

	if (se == "Open Directory Project")
	{
		this.location = "http://search.dmoz.org/cgi-bin/search?search=" + k;
	}

	if (se == "RCLS Library Catalog")
	{
		this.location = "http://www.thrall.org/libcatsearchk.pl?k=" + k;
	}

	if (se == "Thrall Web Guides")
	{
		this.location = "http://www.thrall.org/guides/webguidesearch8.pl?query=" + k + "&g=";
	}

	if (se == "USA.gov")
	{
		this.location = "http://usasearch.gov/search?v%3Aproject=firstgov-web&query=" + k + "&USA.gov+Search=Search";
	}

	if (se == "Wikipedia")
	{
		this.location = "http://en.wikipedia.org/w/index.php?title=Special:Search&search=" + k;
	}

	if (se == "Yahoo")
	{
		this.location = "http://search.yahoo.com/search?p=" + k;
	}

	if (se == "Yahoo Espanol")
	{
		this.location = "http://espanol.search.yahoo.com/search?p=" + k;
	}

	if (se == "Yahoo Kids")
	{
		this.location = "http://kids.yahoo.com/search?p=" + k + "&x=0&y=0";
	}
}

function toggleToolView()
{
		if (document.getElementById('toolView').style.display == "none")
		{
			document.getElementById('toolView').style.display = "inline";
			document.getElementById('toolLink').style.display = "none";
		}
		else
		{
			document.getElementById('toolView').style.display = "none";
			document.getElementById('toolLink').style.display = "inline";
		}
}

function toggleKeywords()
{
		if (document.getElementById('kwdView').style.display == "none")
		{
			document.getElementById('kwdView').style.display = "inline";
			document.getElementById('kwdLink').style.display = "none";
		}
		else
		{
			document.getElementById('kwdView').style.display = "none";
			document.getElementById('kwdLink').style.display = "inline";
		}
}

function toolPlusAll()
{
	var newstr = "";
	var inpstr = document.searchform.q.value;
	var c, c2;
	for (a=0; a < inpstr.length; a++)
	{
		c = inpstr.substring(a,a+1);
		c2 = inpstr.substring(a+1,a+2);
		if (a > 0)
		{
			if (c == " " && (c2 != " " && c2 != "+"))
			{
				newstr += " +";
			}
			else
			{
				if (c != "+")
				{
					newstr += c;
				}
			}
		}
		else
		{
			if (c != "+")
			{
				newstr += "+" + c;
			}
		}
	}
	document.searchform.q.value = newstr;
	focalpoint();
}

function toolDepunctuate()
{
	var oldquery = document.searchform.q.value;
	var newquery = "";
	for (a = 0; a < oldquery.length; a++)
	{
		c = oldquery.substring(a,a+1);
		if (c!="!" && c!="@" && c!="#" && c!="$" && c!="%" && c!="^" && c!="&" && c!="*" && c!="(" && c!=")" && c!="-" && c!="_" && c!="+" && c!="{" && c!="}" && c!="[" && c!="]" && c!=":" && c!=";" && c!="\"" && c!="'")
		{
			if (c!="<" && c!=">" && c!="," && c!="." && c!="?" && c!="/" && c!="~" && c!="`" && c!="\\" && c!="|")
			{
				newquery += c;
			}
		}
	}
	document.searchform.q.value = newquery;
	focalpoint();
}

function toolPhrase()
{
	var oldquery=document.searchform.q.value;
	if (oldquery[0]=='\"')
	{
		return;
	}
	document.searchform.q.value = "\"" + oldquery + "\"";
	focalpoint();
}

function toolLowercase()
{
	var words = document.searchform.q.value;
	words = words.toLowerCase();
	document.searchform.q.value = words;
	focalpoint();
}

function evaluateQuery()
{
	var stopstring  = "about an and are as at be by for ";
	stopstring += "from how in is it of on or that ";
	stopstring += "the this to was what when where ";
	stopstring += "which who why will with ";
	var stopwords = stopstring.split(" ");
	var query = document.searchform.q.value;
	var queryU = query.toUpperCase();
	var querywords = query.split(" ");
	var ql = querywords.length;

	for (a = 0; a < (querywords.length-1); a++)
	{
		for (b = 0; b < (stopwords.length-1); b++)
		{
			var qwtemp = querywords[a];
			var qw = qwtemp.toLowerCase();
			if (qw == stopwords[b])
			{
				whatToSay = "Stop Word Alert:  \n\n" + qw + " \n\nis a stop word - a word typically ignored by many search engines.\n\nYou can try including stop words in a search by placing a + (plus sign) before each word or by putting quotes around your keywords (to tell a search engine to look for a sequence of word instead of individual words).";
				if (qw == "and" || qw == "or" || qw =="not")
				{
					whatToSay += "\n\n" + qw + " is also recognized as a Boolean Operator by some search engines.\n\nWords such as AND, OR, or NOT are Boolean Operators can be used (in search engines that support them) to group ideas and specify what you want to find, as in this example:  animals AND (dogs NOT cats).\n\nParentheses ( ) are used to group concepts logically.  In this search, we are looking for information on animals - dogs specifically - but nothing about cats.\n\n";
				}
				alert(whatToSay);
			}
		}
	}

	if (ql > 1)
	{
		if (query.indexOf("+") < 0)
		{
			alert("No + (plus sign) was found in your search.\n\nMost search engines look for all the words you type and report any matching web pages if one or more terms you typed appear in those websites.\n\nTo instruct a search engine (if it supports the + sign) to look for every word you type, place a + sign before each word, as in this example:\n\n+middletown +thrall +library");
		}

		if (query.indexOf("-") < 0)
		{
			alert("No - (minus sign) was found in your search.\n\nSearch engines usually report web pages containing one or more of your search terms.\n\nTo instruct a search engine (if it supports the - sign) NOT to report matches for certain words, place a - sign before each word, as in this example:\n\n+mathematics -calculus");
		}

		if (query.indexOf("\"") < 0)
		{
			alert("No \" \" (quotation marks) were found around your search.\n\nIf you are simply looking for the words you typed in any particular order, then no action needs to be taken.\n\nIf you are searching for a phrase (words in a specific order), then you need to place quotation marks around your search terms, as in this example: \"Middletown Thrall Library\"\n\nPlease note:  Not every search engine supports phrase searching in this manner.  Some search engines have an Advanced Search mode which often contains a phrase search option.");
		}
	}

	if (queryU.indexOf("WEB") > -1 || queryU.indexOf("WWW") > -1 || queryU.indexOf("HTTP") > -1 || queryU.indexOf(".COM") > -1 || queryU.indexOf("WEBSITE") > -1 || queryU.indexOf("WEB PAGE") > -1 || queryU.indexOf("SITES") > -1 || queryU.indexOf("URL") > -1 )
	{
		alert("Are you looking for a website?  If so, and if you know the website's proper web address (its URL - Uniform Resource Locator), then you should type it into the web browser's Location box instead.\n\nIf you are unsure as to what the web address is, then you might need to use a search engine to attempt to locate the website.\n\n\You can also use Middletown Thrall Library's web directories (at www.thrall.org/guides) to locate websites on particular topics or online directory tools (such as Reference USA) to locate persons, organizations, or businesses.");
	}

	if (query.indexOf("@") > -1)
	{
		alert("Your keywords contain an @ (at) symbol.  If this is not a mistake, are you looking for an e-mail address, to log into your e-mail account, or are you trying to send e-mail to someone?\n\nIf you are looking for an e-mail address, you should consider using a reputable online directory such as Reference USA (if you are a member of Thrall) or try to locate an official business or organization website and go through their directory to locate an e-mail address.\n\nE-mail addresses, as they appear in web pages, can be outdated, inactive, or incorrect.\n\nIf you want to send someone a message, you will first need to log into your e-mail account and find the Compose New Message function.\n\nIf you do not have e-mail yet, there are free e-mail providers you might consider.  Thrall's Reference Department has a free flyer about this.  Please inquire our Reference desk.");
	}

	if (query.indexOf(".") > -1 || query.indexOf(",") > -1 || query.indexOf(":") > -1 || query.indexOf(";") > -1 || query.indexOf("!") > -1 || query.indexOf("#") > -1 || query.indexOf("$") > -1 || query.indexOf("%") > -1 || query.indexOf("^") > -1 || query.indexOf("&") > -1 || query.indexOf("*") > -1 || query.indexOf("(") > -1 || query.indexOf(")") > -1 || query.indexOf("_") > -1 || query.indexOf("-") > -1 || query.indexOf("+") > -1 || query.indexOf("=") > -1 || query.indexOf("[") > -1 || query.indexOf("]") > -1 || query.indexOf("<") > -1 || query.indexOf(">") > -1 || query.indexOf("\\") > -1 || query.indexOf("/") > -1)
	{
		alert("Your keywords contain one or more symbols (i.e. characters such as  ! # $ % ^ & * - ; : ?).\n\nIf such symbols are not really required, you should eliminate them so they do not negatively impact your search results due to the search engine trying to locate those symbols in addition to your keywords.\n\nFYI:  Some search engines use symbols like ? or * as \"truncation characters\":  this means to search for more than one word based on its spelling.  For example, if you were to type libr* in a search engine supporting truncated searches,  web pages containing words such as LIBRARIAN, LIBRARIAN, LIBRARY, and LIBRARIES would be reported.");
	}

	// Caps Check
	var capyes = 0;
	for (a=0; a < query.length; a++)
	{
		c = query.substring(a,a+1);
		if (c >= 'A' && c<= 'Z')
		{
			capyes = 1;
		}
	}
	if (capyes == 1)
	{
		alert("Your search terms appear to contain capital letters.\n\nSome search engines can be \"case sensitive,\" which means they might only look for uppercase keywords if you TYPE THEM LIKE THAT.\n\nUnless your are typing an abbreviation (such as PM) or an acronym (such as NASA), you should just type your search using lowercase letters.\n\nIf you want to type normally but everything is coming out CAPITALIZED, check to see if the CAPS LOCK key is on (see if the CAPS LOCK light is lit on your keyboard).  You can press the CAPS LOCK key once to deactivate it if necessary.");
	}

	if (querywords.length < 3)
	{
		alert("You typed less than three keywords.  Unless the keywords you typed are very specific, you stand a very good chance of receiving too many search results, and most of those results will likely be irrelevant to what you want to find.\n\nTo remedy this, reconsider what it is you are looking for and then type all the specific words used to describe it as accurately as possible.\n\nExplore LightSwitch's various subject searches and their keywords to see if they can help you improve your search.");
	}
}



