
// JavaScript Document

function getElementsByClass( classID, parentNode )
{
	if ( !parentNode )
		parentNode = document.getElementByTagName( "body" )[0];
		
	var resultSet = new Array();
	var expression = new RegExp( '\\b' + classID + '\\b' );
	var source =  parentNode.getElementsByTagName( "*" );
	
	for ( var i=0, maximum=source.length; i < maximum; i++ )
		if ( expression.test( source[i].className ) )
			resultSet.push( source[i] );
			
	return resultSet;
}


function setButtonGroupWidth( targetID, vertical_flag )
{
	var target = document.getElementById( targetID );
	if ( !target )		return -1;
	
	var long_button_amount = getElementsByClass( "long_button", target ).length;
	var short_button_amount = getElementsByClass( "short_button", target ).length;

	if ( long_button_amount == 0 )
		long_button_amount = getElementsByClass( "green_long_button", target ).length;
	
	if ( vertical_flag )
		target.style.width = ( long_button_amount ? 128 : 92 )+"px";	
	else	// +3 ==> use for IE display problem	
		target.style.width = ( long_button_amount*128 + short_button_amount*92 + 3 )+"px";
}


function adjustButtonGroupVertical( parentID, targetID, top_region_percent )
{
	var parent = document.getElementById( parentID );
	var target = document.getElementById( targetID );	
	if ( !parent || !target )		return -1;
	if ( !top_region_percent )		top_region_percent = 50;

	var long_button_amount = getElementsByClass( "long_button", target ).length;
	var short_button_amount = getElementsByClass( "short_button", target ).length;
	var total = long_button_amount + short_button_amount;
	if ( total == 0 )	return -2;
	
	var button_group_height = total*38 + (total-1)*10;	// br width is 10px (it is between two buttons)	
	var viewport_height = parent.clientHeight ? parent.clientHeight : document.documentElement.clientHeight;
	if ( button_group_height > document.documentElement.clientHeight ) return -3;
	if ( viewport_height >= document.body.clientHeight )	
			viewport_height = document.body.clientHeight; 
		
	var center_percent = button_group_height/viewport_height*100;
	var top_percent = (100 - center_percent)*top_region_percent/100;

	target.style.position = "relative";
	target.style.top = top_percent+"%";		
	target.style.height = center_percent+"%";
}

