// ----------------------------------------------------------------------------
// ReadSBS.aspx.js
// ----------------------------------------------------------------------------
// Contains JavaScript functions for use in ReadSBS.aspx
// ----------------------------------------------------------------------------
	
	// Initialises the page.
	function pageLoad()
	{
		resizeItemsDiv();
		restoreDivPosition();
		if (blnPrintPage)
		{
			reformatForPrint();
		}	
	}
	
	// Resizes divItems to fill the maximum available area.
	function resizeItemsDiv()
	{
		if(document.location.href.split("-")[1] == null)
		{
		document.getElementById("divItems").style.height = document.body.clientHeight - 91;	
		}
	}
	
	// Restores the divItems scroll position as it was before postback.
	function restoreDivPosition()
	{
		if(document.location.href.split("?")[1] != null)
		{
			divItems.scrollTop = document.location.href.split("?")[1].split("=")[1]
		}
	}
	
	// Formats the page as 'printer-friendly'. 
	function reformatForPrint()
	{
		document.body.innerHTML = document.getElementById("divItems").innerHTML;
		document.body.style.overflow = "scroll";
	}
	
	// Loads a printer-friendly version of this page in a popup window.
	function openPrintWindow()
	{
		
		var strUrl = document.location.href.split("?")[0].toLowerCase();
		if(strUrl.substring(strUrl.length,strUrl.length-1) == "/")
		{
			strUrl = strUrl + "Read-Print.html";
		}
		strUrl = strUrl.replace("index", "Read-Print");
		strUrl = strUrl.replace("docs", "Docs-Print");
		strUrl = strUrl.replace("cmte", "Cmte-Print");
		strUrl = strUrl.replace("bills", "Bills-Print")

		window.open(strUrl);
	}
	
	// Refreshes the page contents.
	function performRefresh()
	{
		// Attach the scroll location
		document.location.href = document.location.href.split("?")[0]+"?x="+divItems.scrollTop;
	}
	
	// Scrolls the current SBS item to the top of divItems. 
	function scrollToCurrentItem()
	{
		// Locate the row marked as the current item (contains a <marker> tag).
		var divItems = document.getElementById("divItems");
		var rows = divItems.getElementsByTagName("marker");
		
		// Scroll to row if it was found.
		if (rows.length > 0)	
		{
			rows[0].scrollIntoView(true);
			divItems.scrollTop -= 5;
		}		
	}
