function showPopupDialog(html, title, options) {
  if (typeof options == "undefined") options = {};

  if (options.style) {
    $$('#popup_box div.popup_window').first().setStyle(options.style);
  }
  if (title) {
    $('popup_title').innerHTML = title.escapeHTML();
    $('popup_title_bar').show();
  } else {
    $('popup_title_bar').hide();
  }

  $('popup_content').innerHTML = html;
  $$('#popup_box div.popup_overlay').first().show();
  $('popup_box').show();
}

function showPopupMessage(msg, level, timeout) {
  if (typeof(timeout) == "undefined") timeout = 2;
  
  var html = '<p style="text-align:center;height:60px;' + (level == 'error' ? 'color:red;' : 'color:#2A9FC9') + '">';
  html += msg.escapeHTML() + '</p>';
  showPopupDialog(html);
  new PeriodicalExecuter(function(pe) {
    pe.stop();
    closePopupDialog();
  }, timeout);
}

function showPopupProgress() {
  showPopupDialog('<p style="text-align:center;height:20px;"><img src="/image/ajax-loader-2.gif"/></p>');
}

function closePopupDialog() {
  $$('#popup_box div.popup_overlay').first().hide();
  $('popup_box').fade({duration: 0.5});
}

function showHoverPopup(element, text){
  hover_id = $(element).id
  // Set position of hover-over popup
  $("hoverpopup").clonePosition(hover_id, { setHeight: false, setWidth: false, offsetTop: 30, offsetLeft: false } );
  // Change popup text and display
  $("hoverpopup-text").update(text);
  $("hoverpopup").show();
}

function hideHoverPopup(){
  $("hoverpopup").hide();
}
