var extra_highlight = null;


function imgreplace( parent, name )
{

	var c;

	c = parent.firstChild;
	while ( c )
	{

		if ( imgreplace( c, name ) )
			return true;

		if ( c.src )
		{
			c.src = 'http://harms-spinesurgery.com/src/image.php?n=' + name + '&d=inline';
			return true;
		}

		c = c.nextSibling;

	}


	return false;

}



/*
 * Adjusts class of provided node's container by adding suffix '-rollover'.
 */

function c_rok( node, keepid )
{

	if ( !keepid || ( extra_highlight && ( extra_highlight.id != keepid ) ) )
		if ( extra_highlight )
		{
			t_noro( extra_highlight );
			extra_highlight = null;
		}

	if ( keepid && !extra_highlight )
	{
		extra_highlight = document.getElementById( keepid );
		if ( extra_highlight )
			c_rok( extra_highlight.firstChild, keepid );
	}

	if ( node )
	{

		var p = node.parentNode;
		if ( p )
		{

			var cln = p.getAttributeNode( 'class' );
			if ( cln )
				if ( cln.nodeValue )
					if ( cln.nodeValue.indexOf( 'rollover' ) < 0 )
						cln.nodeValue += '-rollover';

		}
	}
}

function c_ro( node )
{
	return c_rok( node, null );
}

function t_rok( node, keepid )
{
	return c_rok( node.firstChild, keepid );
}

function t_ro( node )
{
	return t_rok( node, null );
}




/*
 * Adjusts class of provided node's container by removing suffix '-rollover'.
 */

function c_norok( node, keepid )
{

	if ( !keepid || ( extra_highlight && ( extra_highlight.id != keepid ) ) )
		if ( extra_highlight )
		{
			temp = extra_highlight;
			extra_highlight = null;
			c_norok( temp.firstChild, keepid );
		}

	if ( node )
	{

		var p = node.parentNode;
		if ( p )
		{

			var cln = p.getAttributeNode( 'class' );
			if ( cln )
				if ( cln.nodeValue )
				{

					var pos = cln.nodeValue.indexOf( '-rollover' );
					if ( pos > 0 )
						cln.nodeValue = cln.nodeValue.substring( 0, pos );

				}

		}
	}
}

function c_noro( node )
{
	return c_norok( node, null );
}

function t_norok( node, keepid )
{
	return c_norok( node.firstChild, keepid );
}

function t_noro( node )
{
	return t_norok( node, null );
}




/*
 * Adjusts ID of provided node's container by adding suffix '-rollover'.
 */

function c_iro( node )
{

	if ( node )
	{

		var p = node.parentNode;
		if ( p )
		{

			var idn = p.getAttributeNode( 'id' );
			if ( idn )
				if ( idn.nodeValue )
					if ( idn.nodeValue.indexOf( 'rollover' ) < 0 )
						idn.nodeValue += '-rollover';

		}
	}
}

function t_iro( node )
{
	return c_iro( node.firstChild );
}



/*
 * Adjusts ID of provided node's container by removing suffix '-rollover'.
 */

function c_inoro( node )
{

	if ( node )
	{

		var p = node.parentNode;
		if ( p )
		{

			var idn = p.getAttributeNode( 'id' );
			if ( idn )
				if ( idn.nodeValue )
				{

					var pos = idn.nodeValue.indexOf( '-rollover' );
					if ( pos > 0 )
						idn.nodeValue = idn.nodeValue.substring( 0, pos );

				}

		}
	}
}

function t_inoro( node )
{
	return c_inoro( node.firstChild );
}



/*
 * Traverses all descendants of provided node looking for an anchor tag (A)
 * with a set reference (attribute HREF) and redirecting to that reference.
 */

function c_click( node )
{

	if ( node )
	{

		var c = node.firstChild;

		while ( c )
		{
			if ( c.nodeName == 'A' )
			{

				var ref = c.getAttribute( 'href' );
				if ( ref )
					location.href = ref;

				return true;

			}

			if ( c.firstChild )
				if ( c_click( c ) )
					return true;


			c = c.nextSibling;

		}
	}


	return false;

}


var last_layer = false;

function show_layer( id )
{
	hide_layer();

	var layer = document.getElementById( id );
	if ( layer )
		if ( layer.style )
		{
			layer.style.visibility = 'visible';
			last_layer = layer;
		}
}

function hide_layer()
{
	if ( last_layer )
	{
		last_layer.style.visibility = 'hidden';
		last_layer = false;
	}
}



function getpdf( ref )
{

	w = 500;
	h = 300;

	x = ( screen.width  - w ) / 2;
	y = ( screen.height - h ) / 2;

	window.open( ref, 'harmspdfprompt', 'location=no,status=no,toolbar=no,menubar=no,' +
				'dependent=yes,width=' + w + ',height=' + h + ',left=' + x + ',top=' + y );

}


function MSIE_toAnchor( name )
{

	if ( document.all )
	{

		var y    = 0;
		var node = document.getElementById( name );

		while ( node )
		{
			y   += node.offsetTop;
			node = node.offsetParent;
		}


		window.scrollTo( 0, y );

		return false;

	}
}


function MSIE_anchorOnLoadWrapper()
{

	if ( document.all )
	{

		if ( location.hash.length > 0 )
			MSIE_toAnchor( location.hash.substring( 1, location.hash.length ) );

	}
}
