function okno(nazwa,adres,w,h) {
  NoweOkno = window.open(adres , nazwa, "toolbar=no,menubar=no,resizable=yes,scrollbars=yes,width="+w+",height="+h);
  NoweOkno.focus();
}


function ajax_fetch(datafile) {
 if (!document.all) {
  objXml = new XMLHttpRequest();
  objXml.open("GET","/pub/ajax.php?"+datafile,false);
  objXml.setRequestHeader("Content-Type", "text/plain; charset=UTF-8");
  objXml.send(null);
  output=objXml.responseText;
  } 
  else {
   objXml = new ActiveXObject("Microsoft.XMLHTTP");
   //objXml = new ActiveXObject("Msxml2.XMLHTTP"); older version
   objXml.open("GET","/pub/ajax.php?"+datafile, false);
   objXml.onreadystatechange=function() {
    if (objXml.readyState==4) {
     output=objXml.responseText;
    }
   }
   objXml.setRequestHeader("Content-Type", "text/plain; charset=UTF-8");
   objXml.send(null);
  }
}

var output="";
function showGal(idGal) {
  ajax_fetch("a=isGal&idGal="+idGal);
  var out = JSON.decode(output);
  if(out[0]=="OK") {
    location.href="/"+out[2]+","+out[1]+",4.html";
  }
}

function showPhoto(idPhoto) {
  ajax_fetch("a=isPhoto&idPhoto="+idPhoto);
  var out = JSON.decode(output);
  posY = getScreenCenterY();
  posX = getScreenCenterX();
  if(out[0]=="OK") {
    document.getElementById("photoBox").style.visibility="visible";
    document.getElementById("photoBox").className="photoB1";
    document.getElementById("photoBox").style.top=parseInt(posY-200)+"px";
    document.getElementById("photoBox").style.left=parseInt(posX-250)+"px";
    document.getElementById("photoBox").innerHTML="<span class=\"photoB2\" onclick=\"hidePhoto();return false;\"><img src=\"/pub/zamknij.jpg\" border=\"0\"></span><img src=\"/foto/galeria2/"+out[1]+".jpg\" border=\"0\" /><br /><span>"+out[2]+"</span>";

    document.getElementById("shader").style.visibility="visible";
    document.getElementById("shader").className="photoS1";

    document.getElementById("shader").style.top=parseInt(posY-800)+"px";


  }
}

function showPhoto2(idPhoto) {
  ajax_fetch("a=isPhoto2&idPhoto="+idPhoto);
  var out = JSON.decode(output);
  posY = getScreenCenterY();
  posX = getScreenCenterX();
  if(out[0]=="OK") {
    if(out[3] == "art") {
      var typ = "artykul2";
    }
    if(out[3] == "news") {
      var typ = "news2";
    }
    document.getElementById("photoBox").style.visibility="visible";
    document.getElementById("photoBox").className="photoB1";
    document.getElementById("photoBox").style.top=parseInt(posY-200)+"px";
    document.getElementById("photoBox").style.left=parseInt(posX-250)+"px";

    document.getElementById("photoBox").innerHTML="<span class=\"photoB2\" onclick=\"hidePhoto();return false;\"><img src=\"/pub/zamknij.jpg\" border=\"0\"></span><img src=\"/foto/"+typ+"/"+out[1]+".jpg\" border=\"0\" /><br /><span>"+out[2]+"</span>";
    document.getElementById("shader").style.visibility="visible";
    document.getElementById("shader").className="photoS1";
    document.getElementById("shader").style.top=parseInt(posY-800)+"px";
  }
}


function hidePhoto() {
    document.getElementById("photoBox").style.visibility="hidden";
    document.getElementById("shader").style.visibility="hidden";
    document.getElementById("shader").className="photoS2";
    document.getElementById("photoBox").className="photoB3";
    document.getElementById("photoBox").innerHTML="";
}

function getScreenCenterY() {
  var y = 0;
  y = getScrollOffset()+(getInnerHeight()/2);
  return(y);
}

function getScreenCenterX() {
  return(document.body.clientWidth/2);
}

function getInnerHeight() {
  var y;
  if (self.innerHeight) {
    y = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight) {
    y = document.documentElement.clientHeight;  
  }
  else if (document.body) {
    y = document.body.clientHeight;  
  }
  return(y);
}

function getScrollOffset() {
  var y;
  if (self.pageYOffset) {
    y = self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop) {
    y = document.documentElement.scrollTop;
  }
  else if (document.body) {
    y = document.body.scrollTop;
  }
  return(y);
}

function add2bookmarks() {
  if (document.all) {
    window.external.AddFavorite(location.href,document.title);
  }
  else if (window.sidebar) {
    window.sidebar.addPanel(document.title,location.href,'');
  }
}
