
/**
 * displays the login box in parent frame
 * 
 * @author Christoph Hautzinger <ch@fuf.de>
 * 
 * @param destination_url the url to redirect to after successful login
 * @return void
 */
function showLogin(destination_url) {
  
  parent.$$('body')[0].insert($('login-lightbox').innerHTML);
  parent.$('lightbox').style.display = 'block';
  
  parent.$('redirect_to').value = destination_url;
}

/**
 * displays the configm box in parent frame
 * 
 * @author Christoph Hautzinger <ch@fuf.de>
 * 
 * @param destination_url the url to redirect to after successful login
 * @return void
 */
function showConfirm(destination_url, question) {
  
  parent.$$('body')[0].insert($('confirm-lightbox').innerHTML);
  parent.$('lightbox').style.display = 'block';
  parent.$('question').update(question);
  
  parent.$('redirect_to').value = destination_url;
}

/**
 * removes login from dom (method is called in context of parent frame)
 * and forwards to redirect page on success
 * 
 * @author Christoph Hautzinger <ch@fuf.de>
 * 
 * @return void
 */
function hideBox(perform_redirect) {
 
  if (perform_redirect || false) {

    frames['idframe'].location.href = $F('redirect_to');
  }
  $('lightbox', 'overlay').invoke('remove');
}

/**
 * looks for url-anchors (thisside.php#http://www.superweb.de/idcard.php/lalala)
 * and shows them in iframe
 */
document.observe('dom:loaded', function() {
  if (!window.frames['idframe']) return;
  
  var url = window.location.href;
  var sharp_pos = url.indexOf('#');
  // end processing when no '#' is found in url
  if (-1 == sharp_pos) return;
  // extract iframe url from main url
  var iframe_url = url.substr(sharp_pos + 1);
  // iframe url MUST call the idcard application for security reasons
  // this regxp only works for 
  if (!iframe_url.match(/^http:\/\/[^\/]+\.superweb\.de\/idcard/)) return;
  
  window.frames['idframe'].location.href = iframe_url;
});

