google.load('search', '1');

function getHost()
{
	var site = document.location.host;
	
	// Google can't see internal test servers,
	// so if testing use the public site instead
	return (site.indexOf('-dev.attache.com') === -1 ? site : 'AttacheSoftware.com');
}


function initSearch()
{
	var searchControl = new google.search.SearchControl();
	var siteSearch = new google.search.WebSearch();
	var searcherOptions = new google.search.SearcherOptions();
	var drawOptions = new google.search.DrawOptions();
	var thisSite = getHost();

	// Set the Search Control to get the most number of results
	searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);

	// Put results in tabs (just one, in this case)
	// to suppress expansion toolbar
	siteSearch.setUserDefinedLabel('Results');
	siteSearch.setUserDefinedClassSuffix('siteSearch');
	siteSearch.setSiteRestriction(thisSite);
	searchControl.addSearcher(siteSearch/*, searcherOptions*/);

	// Draw options:
	// 	Set location for search form
	// 	Draw results in a tab
	drawOptions.setSearchFormRoot(document.getElementById('googleSearchForm'));
	drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);

	// When clicked, search result links should open in the same window
	searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);

	searchControl.draw(document.getElementById('googleSearchResults'), drawOptions);
}

google.setOnLoadCallback(initSearch);
