/**
 * Obsluga wywolan ajaxowych na stronie
 */
function AjaxPage() {
  var pg = new Object();

  /**
   * Parametry strony
   */
  pg.parameters = new Object();

  /**
   * URL strony
   */
  pg.url = null;
  
  /**
   * ustawienia URLa strony
   */
  pg.setUrl = function(url) {
    pg.url = url;
  }
  
  /**
   * przypisanie parametru
   */
  pg.setParam = function(paramName, paramValue) {
    pg.parameters[paramName] = paramValue;
  }
  
  /**
   * skasowanie parametrow
   */
  pg.unsetParams = function() {
    pg.parameters = new Object();
  }

  /**
   * przeladowanie wybranego boxa
   */
  pg.reloadBox = function(boxId) {
    AjaxRequest.post(
      {
      "url":pg.url
      ,"parameters":pg.parameters
      ,"onSuccess":function(req){ document.getElementById(boxId).innerHTML=req.responseText; }
      ,"onError":function(req){ document.getElementById(boxId).innerHTML=""; }
      }
    );
  }

  return pg;
}
  
function ajaxGet(boxId, urlString) {
    AjaxRequest.get(
      {
      "url":urlString
      ,"onSuccess":function(req){ document.getElementById(boxId).innerHTML=req.responseText; }
      ,"onError":function(req){ document.getElementById(boxId).innerHTML=""; }
      }
    );
}

function ajaxPopup(boxId, urlString, boxPosition) {
  var popupDiv = document.getElementById(boxId);
  if (!popupDiv) {
    popupDiv = document.createElement('div');
    popupDiv.setAttribute('id',boxId);
    popupDiv.style.position = "absolute";
    popupDiv.style.visibility = "hidden";
    //popupDiv.onclick = function (e) { popupDiv.style.visibility = "hidden"; };
    document.body.appendChild(popupDiv);
  }
  
  AjaxRequest.get(
    {
    "url":urlString
    ,"onSuccess":function(req){ 
        popupDiv.innerHTML=req.responseText; 
        if (boxPosition) { layerPositioning(popupDiv, boxPosition); } 
        popupDiv.style.visibility = "visible"; 
      }
    ,"onError":function(req){ popupDiv.innerHTML=""; }
    }
  );

  return false;
}

function ajaxPopupClose(boxId) {
  var popupDiv = document.getElementById(boxId);
  popupDiv.style.visibility = "hidden";
  return false;
}

function ajaxSlideshowPlay(boxId, urlString, boxPosition) {
  var popupDiv = document.getElementById(boxId);
  document.body.style.overflow = "hidden";
  slideshowTimeoutId = setTimeout("ajaxPopup('"+boxId+"', '"+urlString+"', '"+boxPosition+"')", 4000); 
  return false;
}

function ajaxSlideshowPause(boxId, urlString, boxPosition) {
  clearTimeout(slideshowTimeoutId);
  ajaxPopup(boxId, urlString, boxPosition); 
  return false;
}

function ajaxSlideshowClose(boxId) {
  var popupDiv = document.getElementById(boxId);
  ajaxPopupClose(boxId);
  clearTimeout(slideshowTimeoutId);
  document.body.style.overflow = "auto";
  return false;
}
