var disableAllId = "disableAll";
var gDialogId = null;
//<!--[if lt IE 7]>
var imgLoaded_cart = false;
var imgLoaded_zlec = false;
//<![endif]-->

function adjustModalDialog() {
  if (!gDialogId) return;
  var mask = document.getElementById(disableAllId);
  var scTop = parseInt(getScrollTop(),10);
  var scLeft = parseInt(getScrollLeft(),10);
  mask.style.top = scTop + "px";
  mask.style.left =  scLeft + "px";

  var dialog = document.getElementById(gDialogId);
  var fullHeight = getViewportHeight();
  var fullWidth = getViewportWidth();
  var height = parseInt(dialog.offsetHeight,10);
  var width = parseInt(dialog.offsetWidth,10);
  if (!isNaN(fullHeight) && !isNaN(width)) {
    dialog.style.top = (scTop + ((fullHeight - height) / 2)) + "px";
    dialog.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
	mask.style.width = fullWidth;
	mask.style.height = fullHeight;
  }
}

function cartAddOpen(dialogId) {
  var mask = document.getElementById(disableAllId);
  mask.style.display='block';
  var dialog = document.getElementById(dialogId);
  dialog.style.display='block';
  gDialogId = dialogId;
  adjustModalDialog();

  if (typeof(correctOnePng) != 'undefined' && !imgLoaded_cart) {
	imgLoaded_cart = true;
    var img = document.getElementById('cart_dlg_img_zamknij');
    if (img) correctOnePng(img);
    var img = document.getElementById('cart_dlg_img_dodaj');
    if (img) correctOnePng(img);
    var img = document.getElementById('cart_dlg_img_usun');
    if (img) correctOnePng(img);
    var img = document.getElementById('cart_dlg_img_koszyk');
    if (img) correctOnePng(img);
  }
}

function cartAddClose(dialogId) {
  var mask = document.getElementById(disableAllId);
  mask.style.display='none';
  var dialog = document.getElementById(dialogId);
  dialog.style.display='none';
  gDialogId = null;
}

addEvent(window, "resize", adjustModalDialog);
addEvent(window, "scroll", adjustModalDialog);
window.onscroll = adjustModalDialog;

function ustawObrazek(id, src) {
	document.getElementById(id).src = src;
};
