var divMainBody = null;
var divBackground = null;
var divImgCadre = null;
var imgPopup = null;

function getById(id) {
  var obj = null;
  if (document.getElementById(id)) obj = document.getElementById(id);
  return obj;
}

function getDivMainBody() {
  if (divMainBody == null) divMainBody = getById("divMainBody");
  return divMainBody;
}

function getDivBackground() {
  if (divBackground == null) divBackground = getById("divBackground");
  return divBackground;
}

function getDivImgCadre() {
  if (divImgCadre == null) divImgCadre = getById("divImgCadre");
  return divImgCadre;
}

function getImgPopup() {
  if (imgPopup == null) imgPopup = getById("imgPopup");
  return imgPopup;
}

function getAllPopup() {
  divMainBody = getDivMainBody();
  divBackground = getDivBackground();
  divImgCadre = getDivImgCadre();
  imgPopup = getImgPopup();
}

function getClientHeight() {
  return document.body.clientHeight;
}

function getClientTop() {
  return document.documentElement.scrollTop;
}

function showPopup(src) {
  getAllPopup();

  var currentHeight = getClientHeight();
  var currentTop = getClientTop();

  divBackground.style.visibility = "visible";
  divImgCadre.style.visibility = "visible";
  imgPopup.style.visibility = "visible";
  divBackground.style.backgroundColor = "#CC3333";
  divBackground.style.zIndex = 98;
  divImgCadre.style.zIndex = 99;
  divMainBody.style.zIndex = -99;

  divBackground.style.height = getClientHeight() + "px";
  divImgCadre.style.top = (getClientTop() + 30) + "px";

  imgPopup.src = src;
}

function hidePopup() {
  getAllPopup();

  divBackground.style.visibility = "hidden";
  divImgCadre.style.visibility = "hidden";
  imgPopup.style.visibility = "hidden";
  divBackground.style.backgroundColor = "#FFFFFF";
  divBackground.style.zIndex = -99;
  divImgCadre.style.zIndex = -98;
  divMainBody.style.zIndex = 1;

  imgPopup.src = "/images/animations/wait100X100.gif";
}
