/* vim: set expandtab tabstop=4 shiftwidth=4: */

// +----------------------------------------------------------------------+
// | $Workfile: global.js $
// +----------------------------------------------------------------------+
// | Javascript 1.2                                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005 Bueche Studios                                    |
// +----------------------------------------------------------------------+
// | Author: Michael Bueche <mbueche@satx.rr.com>				          |
// +----------------------------------------------------------------------+

// $Header: /Consulting/Diamante Homes/www.diamantehomes.com/www/html/js/global.js 4     2/18/09 10:35p Engineer $

//-------------------------------------------------------------------------
/**
* Global JS file
*
* @version		$Revision: 4 $
* @author		Michael Bueche <michael.bueche@billingconcepts.com>
* @since		1.2
*/
//-------------------------------------------------------------------------

var $objPreload = document.createElement( 'img' );
$objPreload.src = '/images/navbar_background_over.gif';

/**
* Shows/Hides the Status Window for echoing window to users
*
* @param	string		Text
* @param	boolean		On/Off
* @return	void
* @access	public
* @author	Michael Bueche <mbueche@satx.rr.com>
*/
function fShowHideDiv( $strText, $bolOnOff )
{
	$strState = $bolOnOff ? 'visible' : 'hidden';
	SetStatusWindowPosition();
	document.getElementById('status').style.visibility = $strState;
	document.getElementById('statusText').innerHTML = $strText;
}


/**
* Hides/Shows a Div Block
*
* @access	public
* @author	Michael Bueche <michael.bueche@billingconcepts.com>
*
* @param	string $strId
* @return	void
*/
function fCollapseExpandDiv( $strDivName )
{
	$objDiv = document.getElementById( $strDivName );

	if( $objDiv )
	{
		if ( $objDiv.style.display == 'none' )
		{
			$objDiv.style.display = '';
		}
		else
		{
			$objDiv.style.display = 'none';
		}
	}
}

/**
* Does a Simple Image Swap
*
* @access	public
* @author	Michael Bueche <michael.bueche@billingconcepts.com>
*
* @param	string $strImageId
* @param	string $strImage1
* @param	string $strImage2
* @return	void
*/
function fFlipImage( $strImageId, $strImage1, $strImage2 )
{
	$objImage = document.getElementById( $strImageId );

	if ( $objImage )
	{
		if ( $objImage.src.match( $strImage1 ) )
		{
			$objImage.src = $strImage2;
		}
		else
		{
			$objImage.src = $strImage1;
		}
	}
}

/**
* Toggles the rollover effect on the navbar
*
* @access	public
* @author	Michael Bueche <mbueche@satx.rr.com>
*
* @param	object $objCell
* @param	string $strMode
* @return	void
*/
function fNavbarRollover( $objCell, $strMode )
{
	$strImage = $strMode == 'on' ? '_over' : '';
	$objCell.style.backgroundImage = 'url(images/navbar_background'+$strImage+'.gif)';
}

/**
* Finds the "X" position of an element by climbing
* the DOM tree and adding all the offsetLeft coordinates
*
* @access	public
* @author	Michael Bueche <mbueche@satx.rr.com>
*
* @param	object
* @return	integer
*/
function fGetXPosition( $objToGetX )
{
	var $intLeftTotal = 0;
	if ( $objToGetX.offsetParent )
	{
		while ( $objToGetX.offsetParent )
		{
			$intLeftTotal  += $objToGetX.offsetLeft
			$objToGetX		= $objToGetX.offsetParent;
		}
	}
	else if ( $objToGetX.x )
	{
		$intLeftTotal += $objToGetX.x;
	}

	return $intLeftTotal;
}


/**
* Finds the "Y" position of an element by climbing
* the DOM tree and adding all the offsetTop coordinates
*
* @access	public
* @author	Michael Bueche <mbueche@satx.rr.com>
*
* @param	object
* @return	integer
*/
function fGetYPosition( $objToGetY )
{
	var $intTopTotal = 0;
	if ( $objToGetY.offsetParent )
	{
		while ( $objToGetY.offsetParent )
		{
			$intTopTotal   += $objToGetY.offsetTop
			$objToGetY		= $objToGetY.offsetParent;
		}
	}
	else if ( $objToGetY.y )
	{
		$intTopTotal += $objToGetY.y;
	}

	return $intTopTotal;
}

/**
* Recursively walks the DOM tree until it finds a parent
* node with the tag type specified as the second parameter
*
* @param	object
* @param	string
* @return	object
*/
function fGetParent( $objChild, $strTagName )
{
	if ( $objChild == null )
	{
		return null;
	}

	else if (    $objChild.nodeType == 1
			  && $objChild.tagName.toLowerCase() == $strTagName.toLowerCase() )
	{
		return $objChild;
	}

	else
	{
		return fGetParent( $objChild.parentNode, $strTagName );
	}
}