// Inserts the progress bar for the buttons on the page
function ReplaceButtons()
{
  // Get the buttons element
  var element = ElementById('buttons');
  if(!buttons) return;
  // Replace it with the loading image
  buttons.innerHTML = '<img src="images/loading.gif" />';
}

// Bookmark the given site with the given title and url
function BookmarkSite( title, url )
{
  // Firefox
  if(window.sidebar) window.sidebar.addPanel(title, url, "");
  // Opera
  else if(window.opera && window.print)
  {
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
  }
  // IE
  else if(document.all) window.external.AddFavorite(url, title);
}

// Simple function to get an element by id
function ElementById( id )
{
  // DOM3 = IE5, NS6
  if(document.getElementById) return document.getElementById(id);
  // Netscape 4
  else if(document.layers) return document[id];
  // IE 4
  return document.all[id];
}

// Function that assumes the given element is a select element,
// returns an array of all of the currently selected options.
function SelectedOptions( selectElement )
{
  var selected = new Array();
  for(var i = 0; i < selectElement.options.length; i++)
    if(selectElement.options[i].selected)
      selected.push(selectElement.options[i]);
  return selected;
}

// Selects all of the options in the given multiple select form element
function SelectAllOptions( selectElement )
{
  for(var i = 0; i < selectElement.options.length; i++)
    if(!selectElement.options[i].disabled)
      selectElement.options[i].selected = true;
  return;
}

// Clears all options in the given select element
function ClearOptions( selectElement )
{
  while(selectElement.options.length > 0) selectElement.remove(0);
}

var popupWindow;

function Popup( text, title, width, height, autoPrint )
{
  if(typeof width == 'undefined') width = 500;
  if(typeof height == 'undefined') height = 500;
  if( !popupWindow || popupWindow.closed )
    popupWindow = window.open('popup.php', '', 'height='+height+',width='+width+',scrollbars=yes,resizable=yes,menubar=yes');
  else 
    popupWindow.location = 'popup.php';
  
  popupWindow.document.write('<html><title>' + title + '</title>' +
   '<link rel=stylesheet type=\"text/css\" href=\"css/vngsa.css\">' + 
   '<body' + (autoPrint ? ' onload=\"window.print();\">' : '>') );
  popupWindow.document.write(text + '</body></html>');
  popupWindow.document.close();
  popupWindow.resizeTo(width, height);
  popupWindow.focus();
}

function PopupPage( page, width, height )
{
  if(typeof width == 'undefined') width = 500;
  if(typeof height == 'undefined') height = 500;
  if(!popupWindow || popupWindow.closed)
    popupWindow = window.open( page,'', 'height='+height+',width='+width+',scrollbars=yes,resizable=yes,menubar=yes' );
  else
    popupWindow.location = page;
  popupWindow.resizeTo(width, height);
  popupWindow.focus();
}

function PopupElement( bodyId, pageTitle, printTitle, width, height, autoPrint )
{
  var text = (printTitle != "" ? "<center><h1>" + printTitle + "</h1></center>" : "");
  var element = ElementById(bodyId);
  if(element) text += element.innerHTML;
  
  Popup(text, pageTitle, width, height, autoPrint);
}


