//===============================================================================================
// Zestaw funkcji do kontrolki powiekszania zdjec
//===============================================================================================

function loaderGraphic(id) {
	var div = getByID(id); 
	div.innerHTML = '<div style=\"width:200px;height:200px;background:white\"><center><br /><br /><br /><img src=\"pics/loader.gif\"></center></div>';
}

function pokazZdjecieOferty(plik, id, i) {
	pokazEkran();
	pokaz_on('extraLayer1');pokaz_on('extraLayer2');
	loaderGraphic('nakladka');
	makeHttpRequest('pictureloop.php?type=pokazZdjecieOferty&plik='+plik+'&id='+id+'&i='+i, 'nakladkaShow', false);
}

function pokaz_on(co) {
	jest="block";
	if (document.getElementById) document.getElementById(co).style.display = jest;
	else if (document.all) document.all[co].style.display = jest;
}

function pokaz_off(id) {
	if (document.getElementById) document.getElementById(id).style.display = "none";
	else if (document.all) document.all[id].style.display = "none";
}

function getByID(id) {
	return document.getElementById(id);
}

function makeHttpRequest(url, callback_function, return_xml) { 
	var http_request = false; 

            if (window.XMLHttpRequest) { // Mozilla, Safari,... 
               http_request = new XMLHttpRequest(); 
               if (http_request.overrideMimeType) { 
                  http_request.overrideMimeType('text/html'); 
               } 
            } else if (window.ActiveXObject) { // IE 
               try { 
                  http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
               } catch (e) { 
                  try { 
                     http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
                  } catch (e) {} 
               } 
            } 

            if (!http_request) { 
               alert('Unfortunatelly you browser doesn\'t support this feature.'); 
               return false; 
            } 

            http_request.onreadystatechange = function() { 
               if (http_request.readyState == 4) { 
                  if (http_request.status == 200) { 
                     if (return_xml) { 
                        eval(callback_function + '(http_request.responseXML)'); 
                     } else { 
                        eval(callback_function + '(http_request.responseText)'); 
                     } 
                  } else { 
                     alert('There was a problem with the request. URL='+url+' CODE: ' + http_request.status); 
                  } 
               } 
            } 

            http_request.open('GET', url, true); 
            http_request.send(null); 
} 

function pokazEkran() {
	x = wysOkna();
	z = getVPos();
	w = getElementTop('dolStrony');
	w2 = getElementTop('dolEkranu');

	if (w2>w) {
		w=w2;
	}

	div = document.getElementById("extraLayer1");

	if (x>w) {
		div.style.height = (x+40)+"px";
	} else {
		div.style.height = (w+40)+"px";
	}

	ustawTop('extraLayer2',z);
}

function nakladkaShow(doc) {
	var div = getByID('nakladka');
	div.innerHTML = doc;
	pokazEkran();
}

function wysOkna() {
	if (window.innerHeight != null)
		return window.innerHeight;
	if (document.body.clientHeight != null)
		return document.body.clientHeight;
	
	return (0);
}

function szerOkna() {
	if (window.innerWidth != null)
		return window.innerWidth;

	if (document.body.clientWidth != null)
		return document.body.clientWidth;

	return (0);
}

function getVPos() {
	var scrolled; //Declaring a local variable
	if (document.documentElement && document.documentElement.scrollTop) { scrolled = document.documentElement.scrollTop; } //Sniffing for IE5
	else if (document.body) { scrolled = document.body.scrollTop; } //Sniffing for IE6
	else { scrolled = window.pageYOffset; } //Sniffing for Netscape

	return scrolled; //Returning the variable
}
      
function ustawTop(co, ile) {
	if (document.getElementById) document.getElementById(co).style.top = ile;
	else if (document.all) document.all[co].style.top = ile;
}

function getElementTop(Elem) {

	if(document.getElementById) {	
		var elem = document.getElementById(Elem);
	} else if (document.all) {
		var elem = document.all[Elem];
	}

	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
  	}
	
	return yPos;
} 
