﻿///////////////////////////////////////////////////////////////////////////////////////////////////
// The page utility "namespace"
///////////////////////////////////////////////////////////////////////////////////////////////////
TTDNPage = {
		
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Make an element fill the space between two elements
	///////////////////////////////////////////////////////////////////////////////////////////////
	MakeElemFillVertNoClip:function( fillElem, contentElemID, footerElemID )
	{
		// Get the top of the control that will be expanded
		var topPos = YAHOO.util.Dom.getY( fillElem );
		
		// Get the height of the footer div
		var footerHeight = 0;
		var footerRgn = YAHOO.util.Dom.getRegion( footerElemID );
		if( footerRgn )
			footerHeight = footerRgn.bottom - footerRgn.top;

		// Get the height of the actual content
		var contentHeight = 0;
		var contentRgn = YAHOO.util.Dom.getRegion( contentElemID );
		if( contentRgn )
			contentHeight = contentRgn.bottom - contentRgn.top;

		// Calculate the height needed to fill the page, but make sure it doesn't clip any of
		// the content (Subtract 10 due to weird browser issues)
		var newHeight = YAHOO.util.Dom.getViewportHeight() - (footerHeight + topPos);
		newHeight -= 10;
		if( newHeight < contentHeight )
			newHeight = contentHeight;
			
		// If the height is valid then set it
		if( newHeight > 0 )
			YAHOO.util.Dom.setStyle( fillElem, 'height', newHeight + 'px' );
	},
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Make an element fill the vertical space between its top and the top of another element
	///////////////////////////////////////////////////////////////////////////////////////////////
	MakeElemFillVertAbove:function( fillElem, footerElemID )
	{
		// Get the top of the control that will be expanded
		var topPos = YAHOO.util.Dom.getY( fillElem );
		
		// Get the height of the footer div
		var footerHeight = 0;
		var footerRgn = YAHOO.util.Dom.getRegion( footerElemID );
		if( footerRgn )
			footerHeight = footerRgn.bottom - footerRgn.top;

		// Calculate the height needed to fill the page (Subtract 10 due to weird browser issues)
		var newHeight = YAHOO.util.Dom.getViewportHeight() - (footerHeight + topPos);
		newHeight -= 10;
		if( newHeight > 0 )
			YAHOO.util.Dom.setStyle( fillElem, 'height', newHeight + 'px' );
	},
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Make an element fill the vertical space between its left and the right of the browser
	///////////////////////////////////////////////////////////////////////////////////////////////
	MakeElemFillHorz:function( fillElem )
	{
		// Get the top of the control that will be expanded
		var leftPos = YAHOO.util.Dom.getX( fillElem );
		
		// Calculate the width needed to fill the page
		var newWidth = YAHOO.util.Dom.getViewportWidth() - leftPos;
		if( newWidth > 0 )
			YAHOO.util.Dom.setStyle( fillElem, 'width', newWidth + 'px' );
	}
}
	