﻿function SearchKeyDown(event, strUrl)
{
	if (IsKeyDownSubmit(event))
	{
		SubmitSearchRedirect(strUrl);
		return false;
	}
	return true;
}
function IsKeyDownSubmit(event)
{
	if (event !=null)
	{
		var charCode;
		var bKeyModifiers;
		if (browseris.ie)
		{
			charCode=event.keyCode;
			bKeyModifiers=event.altKey || event.ctrlKey;
		}
		else
		{
			charCode=event.which;
			bKeyModifiers=event.modifers &
						   (event.ALT_MASK | event.CONTROL_MASK);
		}
		if ((charCode==13) && !bKeyModifiers)
			return true;
	}
	return false;
}
function SubmitSearchRedirect(strUrl)
{
	var frm=document.forms["frmSiteSearch"];
	if (frm==null)
	{
		if (typeof(MSOWebPartPageFormName) !="undefined")
			frm=document.forms[MSOWebPartPageFormName];
	}
	if (frm !=null)
	{
		var searchText=frm.elements["SearchString"].value;
		strUrl=strUrl+"?k="+escapeProperly(searchText);
		var searchScope=frm.elements["SearchScope"];
		if (searchScope !=null)
		{
			var searchScopeUrl=searchScope.value;
			if (searchScopeUrl)
			{
				strUrl=strUrl+"&u="+escapeProperly(searchScopeUrl);
			}
		}
		frm.action=strUrl;
		frm.submit();
	}
}
function TopHelpButtonClick(strParam)
{
	if(typeof(navBarHelpOverrideKey) !="undefined")
	   return HelpWindowKey(navBarHelpOverrideKey);
	if (strParam !=null)
		HelpWindowKey(strParam);
	else
		HelpWindowKey('NavBarHelpHome');
}
function HelpWindowHelper(strParam)
{
	var strHelpUrl;
	if (typeof(strParam)=="undefined")
		{strHelpUrl="/_layouts/help.aspx?Lcid="+L_Language_Text;}
	else
		{strHelpUrl="/_layouts/help.aspx?Lcid="+L_Language_Text+strParam;}
	var wndHelp=window.open(strHelpUrl, "STSHELP",
		"height=500,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=475"
		);
	wndHelp.focus();
}
function HelpWindowKey(strKey)
{
	HelpWindowHelper("&Key="+strKey);
}
function HelpWindowUrl(strUrl)
{
	HelpWindowHelper("&Url="+strUrl);
}
function HelpWindow()
{
	HelpWindowKey("helphome");
}
function HelpBack()
{
	history.back();
}
function HelpForward()
{
	history.forward();
}
function HelpPrint()
{
	window.print();
}
function HelpSearch(strStringToSearchFor)
{
	var nMaxLengthSearchString=256;
	var strLocationHref="";
	if (typeof(glob_strLocaleNumId)=="undefined")
	{
		return true;
	}
	if (typeof(glob_strCollectionIds)=="undefined")
	{
		return true;
	}
	if (glob_strCollectionIds.length <=0)
	{
		return true;
	}
	if (typeof(strStringToSearchFor)=="undefined")
	{
		return true;
	}
	if (strStringToSearchFor.length <=0)
	{
		return true;
	}
	strStringToSearchFor=TrimWhiteSpaces(strStringToSearchFor);
	if (strStringToSearchFor.length==0)
	{
		return true;
	}
	strStringToSearchFor=strStringToSearchFor.substr(0,nMaxLengthSearchString);
	strStringToSearchFor=encodeURIComponent(strStringToSearchFor);
	strLocationHref="/_layouts/HelpSearch.aspx?lcid="
+escapeProperlyCore(glob_strLocaleNumId, true);
	for (var i=0; i < glob_strCollectionIds.length ;i++)
		{
		strLocationHref=strLocationHref
+"&cid"
+i
+"="
+escapeProperlyCore(glob_strCollectionIds[i], true);
		}
	strLocationHref=strLocationHref
+"&sq="
+strStringToSearchFor
		;
	window.location.href=strLocationHref;
}
