﻿//
//
// Created by: David Yutzler
// For: Specialized Technology Resources
// Purpose: Implement Google Custom Search in our site with click enter in the box bringing to search results.
//
//

	var defaultHost = "www.strholdings.com";

	var host = window.location.host;
	if (host.indexOf('phx.corporate-ir.net') >= 0)
		host = defaultHost;
	if (host.indexOf('ir.strholdings.com') >= 0)
		host = defaultHost;

	function searchOnKeyUp(e)
	{
		//alert('Keycode press ==' + e.keyCode);
		var objContainer = new Object;
		objContainer = document;
		var isForm = IsForm(objContainer);
		
		if (e.keyCode == 13)
		{
			if (isForm)
				objContainer.forms[0].elements['hiddenButton'].click();
			else
			{
				//objContainer.getElementById('hiddenButton').click();
				searchResultsUrl();
			}
		}
	} 
	
	function searchOnFocus(obj)
	{
		
		if(obj.value=='Search')
		{
			obj.value='';
			obj.style.textAlign='left';
			obj.style.color='black';
			obj.style.fontWeight='normal';
		}
	}
	
	function IsForm(obj)
	{
		var _isForm = false;
		/*if (obj.forms != null)
			_isForm = true;
			*/
		return _isForm;
	}
	
	function searchResultsUrl()
	{
		var isForm = IsForm(document);
		var redirectUrl;
		if (isForm)
		{
			var objContainer = document.forms[0];
			redirectUrl = '/en-us/Pages/SearchResults.aspx?cx=014390298048723027850:-uhbqyggdbg'
										+'&cof='+ objContainer.elements['cof'].value
										+'&ie='+ objContainer.elements['ie'].value
										+'&q='+ escape(objContainer.elements['q'].value);

		}
		else
		{
			redirectUrl = '/en-us/Pages/SearchResults.aspx?cx=014390298048723027850:-uhbqyggdbg'
											+'&cof='+ document.getElementById('cof').value
											+'&ie='+ document.getElementById('ie').value
											+'&q='+ escape(document.getElementById('q').value);
		}
		if (isForm)
		{
			STSNavigate(redirectUrl);
		}
		else
			window.location.href = "http://" + host + redirectUrl;
	}