/**
 * Opens a destination URL (destURL) in a popUp window of the given width and height
 *
 * @param string destURL
 * @param string windowName
 * @param integer width
 * @param integer height
 */
function popupWindow(destURL, windowName, width, height, options)
{
  var winWidth = parseInt(width);
  var winHeight = parseInt(height);
  var posX = (screen.width - winWidth) / 2;
  var posY = (screen.height - winHeight) / 2;
  
  var window_options = 'resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,status=no';
  if( options.length > 0 )
  {
  	window_options = options;
  }
	
  window.open(destURL,windowName,'left=' + posX + ',top=5,width=' + winWidth + ',height=' + winHeight + ',' + window_options);
}


/**
 * Closes the window it is called from
 *
 */
function closeWindow()
{
	self.close();
}


/**
 * Modifies the CSS display attribute of a row identified by table_row_id to either be visible ('shown') or invisible ('hidden')
 *
 * @param string table_row_id
 * @param string visibility
 * @return boolean
 */
function setTableRowVisibility(table_row_id, visibility)
{
	// Validate the input data
	if( table_row_id.length == 0 )
	{
		alert('Ivalid table row specified to modify the visibility of');
		return false;
	}
	
	if( visibility != 'hidden' && visibility != 'shown' )
	{
		alert('Invalid visibility setting specified');
		return false;
	}	
	
	// First ensure that one of the object we're modifying actually exists on the page
	if( document.getElementById(table_row_id) == undefined )
	{
		// Item doesn't exist on page so get out of here
		return false;
	}			

	// Set the visibility 'shown' value for the table row 
	var css_display_value_visible = "block";

	// Since Firefox (Netscape) doesn't render the table row correctly when the CSS display attribute is 'block',
	// we should use the value 'table-row' instead which is only currently supported by Firefox but renders correctly on screen.
	if( navigator.appName == "Netscape" && parseInt(navigator.appVersion) > 4 )
	{
		css_display_value_visible = "table-row"; 
	}

	// Are we requesting the table row to be shown?
	if( visibility == 'shown' )
	{
		// Yes. So show the row
		document.getElementById(table_row_id).style.display = css_display_value_visible;
	}
	else
	{
		document.getElementById(table_row_id).style.display = 'none';
	}
	
	// All successful
	return true;
}
