
	/*
	Creates a script element in the head to hold the json query,
	then it sets the element's src property to the Yahoo interface
	to retrieve the spelling suggestion
	*/
	function requestSpelling(query){
		var element = document.createElement('script');
		element.setAttribute("type", 'text/javascript');
		element.setAttribute("id", 'jsonContainer');
		document.getElementsByTagName("head").item(0).appendChild(element);
		document.getElementById('jsonContainer').src='http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=Dztf5DHV34FneEp6zf.Pz.G5KGHiCsH885tv4cpiIuxGeeltsAFIFqYdVp5P8L7AiiWVdgc-&query=' + query + '&output=json&callback=handleSpelling';
	}

	/*
	Fires when Yahoo has responeded to our initial request
	If we get a result back, it displays it in the "spellingSuggestion"
	div, else it clears the contents of said div.
	We then destroy the script element used to pull in the yahoo data.
	*/
	function handleSpelling(yahooResponse){
	  if (yahooResponse.ResultSet && yahooResponse.ResultSet.Result) {
		  yahooResponse = yahooResponse.ResultSet.Result;
		  document.getElementById('spellingSuggestion').style.display = 'block';
		  document.getElementById('spellingSuggestion').innerHTML = 'Did you mean: <a href="javascript:useSpelling(\'' + yahooResponse + '\')">' + yahooResponse +'</a><br/>&nbsp;';
	  }else{
	  	document.getElementById('spellingSuggestion').innerHTML = '';
	  	document.getElementById('spellingSuggestion').style.display = 'none';
	  }
	  document.getElementsByTagName("head").item(0).removeChild(document.getElementById('jsonContainer'));
	}


	/*
	Changes the value of the main search box, and then run s a new search. 
	This function is used by the links behind the suggested spelling.
	*/
	function useSpelling(suggestion){
		document.getElementById("query").value = suggestion;
		onFormSubmitEventHandler();
	}
