/**
*
* POPUP functions 
* 
* (C) ScolaVisa VOF
* 
* http://www.scolavisa.com
*
*/

/** 
* Fix position of the popup 
*/
var popupLeft = 100;
var popupTop  = 100;

/**
* show the popup
*/
function showPopup(){
  // hide select-boxes, z-index problem
  hideElms("SELECT");
  // if the screen hasn't scrolled yet, recalculatePopupPosition wasn't executed yet.
  // we must however make sure the fix position is determined
  // this overrules a setting in the CSS
  recalculatePopupPosition();
  document.getElementById("popup").style.visibility = 'visible';
}
/**
* close the popup
*/
function hideEditItemCancel(){
  document.getElementById("popup").style.visibility = 'hidden';
  // show the select-boxes
  showElms("SELECT");
}
// helper function part one: hide the select-boxes when a popup is showing
// thus tackeling the z-index problem of select-boxes
// @see: http://support.microsoft.com/support/kb/articles/Q177/3/78.ASP
// modified for compatibillity with Mozilla by ScolaVisa
function hideElms(elmTag) {
  var targetElems = document.getElementsByTagName(elmTag);
  for (i=0; i<targetElems.length; i++){
    obj = targetElems[i];
    if (!obj || !obj.offsetParent) continue;
    obj.style.visibility = "hidden";
  }
}
// part two: showing it again
function showElms(elmTag) {
  var targetElems = document.getElementsByTagName(elmTag);
  for (i=0; i<targetElems.length; i++){
    obj = targetElems[i];
    if (!obj || !obj.offsetParent) continue;
    obj.style.visibility = "visible";
  }
}
/*
* This functions makes the popup shift to a position relative to the scolbar-positions.
*/
function recalculatePopupPosition(){
  // get the position of the scroll-bars and adjust the position of the popup-DIV accordingly
  if(document.getElementById("popup")){
    document.getElementById("popup").style.left = popupLeft + document.body.scrollLeft + "px";
    document.getElementById("popup").style.top = popupTop + document.body.scrollTop + "px";
  }
}