function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function setWidth(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	}
function setHeight(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	}

function setInnerHTML(element,content) {
		element = $(element);
		element.innerHTML = content;
	}

function setTop(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	}
function setLeft(element,t) {
	   	element = $(element);
	    	element.style.left = t +"px";
			}

function start(szer) {

		//hideSelectBoxes();

		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		setHeight('tlo_block', arrayPageSize[1]);
		//new Effect.Appear('tlo_block', { duration: 0.2, from: 0.0, to: 0.8 });



		// calculate top offset for the lightbox and display
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

		setTop('zoom_galeria', lightboxTop);
		var ile = ((arrayPageSize[0]-szer)/2);

		setLeft('zoom_galeria', ile);
	}

function Galeria(Nazwa,tresc,id) {
objFirma = document.getElementById(Nazwa);
objFirma.style.display="block";
objBlock = document.getElementById('tlo_block');
objBlock.style.display="block";

start(650);

text='<table cellspacing="2" cellpadding="3" width="640">';
text+='<tr><td align="right">';
text+='<img src="tpl/images/zamknij.gif" alt="" onclick="javascript:Galeria_close('+Nazwa+');"; style="cursor: pointer;">';
text+='</td></tr>';
text+='<tr><td style="background-color: #FCFCCA; text-align:center;"><img src="'+tresc+'" alt=""></td></tr>';
text+='</table>';
text+='<div id="komentarze"/>';
document.getElementById(Nazwa).innerHTML=text;
comments(id);
}

function Galeria_close(Nazwa) {
 objFirma = document.getElementById('zoom_galeria');
 objFirma.style.display="none";
 objBlock = document.getElementById('tlo_block');
 objBlock.style.display="none";
}
function comments(id) {
Iner = document.getElementById("komentarze");
advAJAX.get({
    url: "index.php?ajax=1&show=comments&id="+id,
	onLoading: function() {  Iner.innerHTML = "Trwa wczytywanie..."; },
	onSuccess: function(obj) {  Iner.innerHTML = obj.responseText; },
	onError: function() {  Iner.innerHTML = "Błąd wczytywania."; }
	});
}
function zapisz(name) {
Iner = document.getElementById("komentarze");
if (name.nick.value!='' || name.wpis.value!='') {

	advAJAX.get({
    	url: "index.php?ajax=1&show=save&id="+name.id.value+"&nick="+name.nick.value+"&wpis="+name.wpis.value,
		onLoading: function() {  Iner.innerHTML = "Trwa zapisywanie..."; },
		onSuccess: function(obj) {  Iner.innerHTML = obj.responseText; },
		onError: function() {  Iner.innerHTML = "Błąd wczytywania."; }
		});


	}
else alert("Proszďż˝ uzupeďż˝niďż˝ oba pola!");
return false;
}
function checkThis() {
name = document.Form;
if (name.nick.value=='' || name.wpis.value=='') {
	document.getElementById("errors").innerHTML = "<b>Błąd!</b> Proszę uzupełnić wszystkie pola";
	return false;
	}
else {
	document.getElementById("errors").innerHTML = "";
	name.submit();
	return true;
	}

}
