﻿// This function traps the use of the enter key and calls the DoTimkenSearch command

function CheckTimkenEnterKey(e) {
var keynum;

if(window.event) { // IE
	keynum = e.keyCode;
} else if(e.which) { // Netscape/Firefox/Opera
	keynum = e.which;
}

if(keynum == 13) {
	DoTimkenSearch();
	return false;
}

return true;
} 



// This function inspects the user's locale and forwards the search request as appropriate
function DoTimkenSearch() {
	var textbox = document.getElementById("search");
	var userLocale = "";
	var variationPath = "";
	
	// TODO: Do region detection and forward to the correct variation
	//userLocale = window.navigator.userLanguage;
	
	// Get the user's location from the relative path
	var relativePath = document.location.href.substring( document.location.href.indexOf("/", 8) );
	userLocale = relativePath.substring(0,6);
	
	if(!(userLocale.substring(3,4) == "-")) {
		variationPath = "";
	} else {
		variationPath = userLocale;
	}
	
	var URL = window.document.location.toString();
	var start = URL.indexOf('/',8)+1
	var scope = URL.substring(start, start+5);

	// Forward the user to the correct search page.  Note that we must escape the search string
	//	to make it URL-safe.
	document.location.href= variationPath + "/Pages/Search.Aspx?k=" + escape(textbox.value) + "&s=" + scope;
}