/**
 * 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, left, top, options)
{
  var window_options = '';

  // Set the window distance from the top of screen
  if( top == 0 )
  {
  	var winHeight = parseInt(height);
  	var posY = (screen.height - winHeight) / 2;

  	window_options = window_options + 'top=' + posY +  ',';
  }
  else
  {
  	window_options = window_options + 'top=' + parseInt(top) + ',';
  }

  // Set the window distance from the left of screen
  if( left == 0 )
  {
	var winWidth = parseInt(width);
	var posX = (screen.width - winWidth) / 2;

	window_options = window_options + 'left=' + posX + ',';
  }
  else
  {
  	window_options = window_options + 'left=' + parseInt(left) + ',';
  }


  if( options.length > 0 )
  {
  	window_options = options;
  }
  else
  {
  	window_options = window_options + 'resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,status=no';
  }

  window.open(destURL,windowName,'width=' + width + ',height=' + height + ',' + 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;
}


function add_bookmark( title, url )
{
	if(window.sidebar) // Firefox
	{
		window.sidebar.addPanel(title, url,'');
	}
	else if(window.opera)//Opera
	{
		var a = document.createElement("A");
		a.rel = "sidebar";
		a.target = "_search";
		a.title = title;
		a.href = url;
		a.click();
	}
	else if(document.all) //IE
	{
		window.external.AddFavorite(url, title);
	}
}