String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
function doSearch( arg_q )
{
	var PROD_MAIN = 4;
	var PROD_SUPPORT = 6;
	var url = "";
	var q = "";
	var coll;
	if( location.href.match( /\/support\//i ) )
	{
		url += "/Support";
		coll = PROD_SUPPORT;
	}
	else
		coll = PROD_MAIN;
	if( arg_q != null && arg_q.length > 0 )
		q = escape( unescape ( arg_q ).trim() );
	else
		q = escape( ( document.getElementById("ts_q").value ).trim() );
	if( !( q.length > 0 ) )
		return false;	
	url += "/Search/Results.aspx?search=" + q + "&coll=" + coll;
	window.location.href = url;
}
function KeyDownHandler(e, btn)
{
	e = (e) ? e : (window.event) ? event : null;
	key = (e.keyCode) ? e.keyCode : ((e.which) ? e.which : null);
	// process only the Enter key
	if (key == 13)
	{
		// cancel the default submit
		if( e.preventDefault) 
			e.preventDefault();
		e.returnValue=false;
		e.cancel = true;
		// submit the form by programmatically clicking the specified button
		btn.click();
	}
}
function getSearchTerm()
{
	// if not in search results page, return false
	if( !location.href.match( /\/search\/results\.aspx/i ) )
		return "Search...";
	var searchTerm = "";
	var qs = window.location.search.substring(1);
	var vars = qs.split("&");
	var i;
	for( i = 0; i < vars.length; i++  )
	{
		var pair = vars[i].split("=");
		if( pair[0] == "search" && pair.length == 2 )
			return unescape( pair[1] );
		if( pair[0] == "q" && pair.length == 2 )
			return unescape( pair[1] );
			
	}
	return "";
}
function searchWithin()
{
	var searchTerm = getSearchTerm();
	var q = getQ();
	if( searchTerm == q )
		doSearch( q );
	else
		doSearch( searchTerm + " " + q );
}
function getQ()
{
	var q = document.getElementsByName("q")[0];
	if( q )
		return q.value;
	return "";
}
var tsq = document.getElementById("ts_q");
tsq.value = getSearchTerm();
