$(function(){

	// master page language link
	$('#divLanguageAndPrint a').filter(function(){
		return $(this).text().indexOf("Version")==-1;	
	})
	.click(function(){

		// 0: English, 1: Spanish
		var id = $(this).text().indexOf("English")>-1 ? 0 : 1;

		// set the language at the server
		$.ajax({
			url: '/pages/AjaxHandler.ashx?action=setlanguage&id=' + id,
			async: false
			});
		
		// reload without reposting data
		location.href = location.href;
	});
		
	// create the search form if it doesn't exist
	if($('#divSearch>form').length==0)
	{
		$('<form id="searchForm" action="/pages/search.aspx" method="post"><input type="text" id="customSearchBox" name="customSearchBox" size="15"/><img alt="Search" id="customSearchGo" src="/SiteCollectionImages/searchicon.jpg"/></form>').prependTo('#divSearch');
	}
	
	// hook up search box
	$('#customSearchBox').bind("keyup", function(e){
		if(e.which&&e.which==13||e.keyCode&&e.keyCode==13)
		{   
			$('#customSearchGo').click();
		}
	});
	
	$('#customSearchGo').click(function(){
		// for some reason, the browser is resetting the action to the current page
		// so fix that before submitting
		$('#searchForm').attr({'action':'/pages/search.aspx'});
		$('#searchForm').submit();
	});

});

function ShowShortInsideTheLegMenu()
{
	// only show the first 4 entries in the menu
	$('div.navSectionContent').filter(function()
	{
		return $(this).prev().text().indexOf("Inside the Legislature")>-1;
	})
	.find('tr:gt(3)').hide();
}

String.prototype.trim = function()
{
	return this.replace(/(^\s*|\s*$)/g,'');
}