// browser identity
// browser identity
isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
//document.onmouseup=function(){alert('document.onmouseup');};
var PopUp ;
var PopUp1 ;
var iBig = 1;

function imgview(id,th) {
var url = "common/image2.php?id="+id+"&amp;thumb="+th; //http://www.domcar.pl/
var name = 'image'+id;
if (PopUp && !PopUp.closed && PopUp.location) {
	//resize(644,594);
	if (PopUp.name != name){
		PopUp.document.close();
		//alert(PopUp.document.getElementById("big").src );
		PopUp.location.href = url;
		PopUp.name = name;
	
		PopUp.focus();
	}
}else {
	PopUp = window.open(url,name,"height=594,width=644,status=no,scrollbars=no,menubar=no,menubar=no,location=no");
	PopUp.name	= name;
	if (!PopUp.opener)
		PopUp.opener = self;
		
}
if (window.focus) {PopUp.focus()}
return false;
}
/*var hasInnerText =
(document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
var elem = document.getElementById('id');
var elem2 = document.getElementById ('id2');

if(!hasInnerText){
    elem.textContent = value;
    elem2.textContent = value;
} else{
    elem.innerText = value;
    elem2.innerText = value;
}

*/

function imgview1(id,th) {
var url = "common/image1.php?id="+id+"&amp;thumb="+th;
var name = 'image'+id;
//alert(url);
if (PopUp1 && !PopUp1.closed && PopUp1.location) {
	//var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	if (PopUp1.name != name){
		var doc = PopUp1.document;
		xmlhttp=PopUp1.GetXmlHttpObject();
		if (xmlhttp==null){
		  alert ("Browser does not support HTTP Request");
		  return;
		  }
		PopUp1.hideEl("big");
		PopUp1.hideEl("popContens");	
		PopUp1.document.getElementById("big").src = "picture.php?id="+id+"&amp;thumb=1";	
		//while (!IsImageOk(PopUp1.document.getElementById("big")));
		//if  (!IsImageOk(PopUp1.document.getElementById("big"))){alert("IsImageOk");};
		//		while (!PopUp1.document.getElementById("big").complete);

		var url="cardesc.php?id="+id;
		url=url=url+"&sid="+Math.random();
		//stateChanged;
		xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState == 4)
        {
          	PopUp1.document.getElementById("popContens").innerHTML=xmlhttp.responseText;
				if (is_chrome) {PopUp1.parent.blur();}
				else {	PopUp1.focus();}

        }};
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		PopUp1.showEl("big");	
		PopUp1.showEl("popContens");		
		PopUp1.name = name;
		

		//while (!PopUp1.document.getElementById("big").complete)
	}
	else{
	if (isChrome) {PopUp1.parent.blur();}
	else {	PopUp1.focus();}
	}
}else {
	PopUp1 = window.open(url,name,"width=644,height=490,resizable=no,scrollbars=no,menubar=no,status=no,location=no");	
	PopUp1.name	= name;
	if (!PopUp1.opener)
		PopUp1.opener = self;
	//alert(PopUp1);
}
if (window.focus) {PopUp1.focus()}
return false;
}

/*
function imgview1(id,th) {
var url = "common/image1.php?id="+id+"&amp;thumb="+th;
var name = 'image'+id;
//alert(url);
if (PopUp1 && !PopUp1.closed && PopUp1.location) {
	if (PopUp1.name != name){
		PopUp1.document.close();
		PopUp1.location.href = url;
		PopUp1.name = name;
		PopUp1.focus();
	}
	
}else {
	PopUp1 = window.open(url,name,"width=644,height=490,resizable=no,scrollbars=no,menubar=no,status=no,location=no");	
	PopUp1.name	= name;
	if (!PopUp1.opener)
		PopUp1.opener = self;
}
if (window.focus) {PopUp1.focus()}
return false;
}
*/
function isVisibleEl(id) {
	if (document.getElementById) { 
		if (document.getElementById(id).style.display == 'none') return false;
		}
	else {
		if (document.layers) { // Netscape 4
			if (document.id.display == 'none') return false;
		}
		else { // IE 4
			if (document.all.id.style.display == 'none') return false;
		}
	}
	return true;
}

function hideEl(id) {
	//safe function to hide an element with a specified id
	
	if (document.getElementById) { 
		// DOM3 = IE5, NS6
		var obj = document.getElementById(id);
		if (obj) obj.style.display = 'none';
		}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showEl(id) {
	//safe function to show an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		var obj = document.getElementById(id)
		if (obj) document.getElementById(id).style.display = 'block';
		}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
			}
		else { // IE 4
			document.all.id.style.display = 'block';
			}
		}
	}
/*for view, AddEdit*/
function xdelete(id,page){
	if (confirm("Czy potwierdzasz usuniecie rekordu ?")){
		window.location.href = "admin.php?action=deletesave&id="+id+"&page="+page;
		}
	}
function xedit(id,page){
	ret=document.getElementById("btnSubmit");
	document.getElementById("mode").value=0;	
	document.getElementById("id").value=id;
	document.getElementById("page").value=page;	
	ret.click();
	}
function showHighlight(td) {
	var rowObj=td.parentNode;
	var tds	= rowObj.getElementsByTagName('td');
	for (var i=0;i < tds.length;i++){
		tds[i].className = 'tdHighlight';
		}
	}			
function clearHighlight(row) {
	// obsługuje  IE & FF
	//alert(row);
	var Table = document.getElementById("mainTable");
	var rows	= Table.getElementsByTagName('tr');
	var tds	= rows[row+1].getElementsByTagName('td');
	for (var k=0;k< tds.length;k++){
		tds[k].className = (row%2?'main':'tdNormal2');
		}
	}
	
/************************************************************************
Script made by Martial Boissonneault © 2001 http://getElementById.com/
This script may be used and changed freely as long as this msg is intact
Visit http://getElementById.com/ for more free scripts and tutorials.
*************************************************************************/
var ie5=(document.getElementById && document.all);
var ns6=(document.getElementById && !document.all);

nPlus = -5 ;  //the % of fading for each step
speed = 40 ; //the speed
myTimer = 0;
// You don't have to edit below this line
nOpac = 100;
fading = false;
/**********************************/
iBig		=1;
iSmall1	=2;
iSmall2	=3;
function xChange(big,small,i){
	var bClone;
	var oBig = document.getElementById(big);
	var bSrc = oBig.src;
	var sSrc = document.getElementById(small).src;
	var ib	= "thumb.php";
	var is 	= "picture.php";
	var temp = (i==2?iSmall1:iSmall2);

	//document.getElementById(big).style.visibility=="hidden";
	//if (!document.getElementById('Clone')){
	while (fading) FadeBigImg();
	if (!fading){	
		bClone 		= oBig.cloneNode(true);
		bClone.id	= "Clone";
		nOpac = 100;		
		}
	else{
		return false;
		}

	//bClone.style.visibility="hidden";	
	//bClone.style.z-index	=2;	
	bClone.style.position="absolute";		
	bClone.style.left	= 1+"px";			
	bClone.style.top	= 1+"px";				
	document.getElementById(big).parentNode.appendChild(bClone);		
	
	document.getElementById(small).src = ib.concat(bSrc.substring(bSrc.indexOf("?")));
	document.getElementById(small).title = "Powiększ zdjęcie "+iBig;	
//	document.getElementById(big).style.visibility="hidden";
//	document.getElementById(big).style.z-index	=1;
	oBig.src = is.concat(sSrc.substring(sSrc.indexOf("?")));
	oBig.title='Zdjęcie '+temp;
	oBig.style.left	= 1 ;//+"px";			
	oBig.style.top		= 1;//+"px";		
	
	FadeBigImg();
		
	if (i==2){
		iSmall1 = iBig;
	}else{ 
		iSmall2 = iBig;
	}
	iBig = temp;
	 //alert("created clone node:"+bClone.src);
	return false; 
	}
function FadeBigImg(){
	if(document.getElementById){
      oClone = document.getElementById('Clone');
		if (!oClone) {return;}  // konieczne - szybkie  przelączanie
		opacity = nOpac+nPlus;
		if (opacity <= 0){
			//alert(opacity);
			clearTimeout(myTimer);
			oClone.parentNode.removeChild(oClone);
			nOpac = 100;
			fading = false;
			if (document.getElementById('loading'))
				hideEl('loading');
			return;
			}

		nOpac = opacity;
		myTimer = setTimeout('FadeBigImg()',speed);
		fading = true;		
		
	   if (opacity>100 || opacity<0){
	        nPlus=-nPlus;
	    }
		if (isChrome ){
			oClone.style.opacity = opacity/100;
			return true;
			}
		if(ie5){
			oClone.style.filter="alpha(opacity=0)";
			oClone.filters.alpha.opacity = opacity;
			return true;			
	    }
		if(ns6){
	      //  oClone.style.MozOpacity = 0;
			oClone.style.MozOpacity = opacity/100;
			return true;			
	    }
	  }
	}
	
var y1 = 5;   // change the # on the left to adjuct the Y co-ordinate
shown = false;
shown2 = true;
function hideIt() {
  if (document.getElementById){
   var oLayer1 = document.getElementById("layer1");
	oLayer1.style.visibility='hidden';
  	}
  if (document.layers) {
	var oLayer1 = document.layers["layer1"];
	oLayer1.visibility='hide';
	}
  if (oLayer1){
	oLayer1.style.left=popLeft+"px"; 
	oLayer1.style.top=popTop+"px"; 
	}
	shown = false;
 }

function showIt() {
  if (document.getElementById) {document.getElementById("layer1").style.visibility='visible';}
  if (document.layers) {document.layers["layer1"].visibility='show';}
	shown = true;   }

function showLayer2(){
shown2?hideEl('layer2'):showEl('layer2');
shown2=shown2?false:true;
return false;
}

function placeIt(show){
  if (document.getElementById && !document.all) {document.getElementById("layer1").style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1))}
  if (document.layers) {document.layers["layer1"].top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1))}
  if (document.all && document.all["layer1"]) {document.all["layer1"].style.top = document.body.scrollTop + (document.body.clientHeight - (document.body.clientHeight-y1));}
  window.setTimeout("placeIt()", 10);
	if (show) {showIt();}}

onResize="window.location.href = window.location.href"
function resize(w,h) {
	if (document.all) {
		bodyWidth = document.body.clientWidth;
		bodyHeight = document.body.clientHeight;
		widthOffset = w - bodyWidth;
		heightOffset = h - bodyHeight;
		window.resizeBy(widthOffset, heightOffset);
	} else {
		window.innerWidth = w;
		window.innerHeight = h;
	}
//	Check = prompt("Geben Sie Ihr Passwort fuer diese Seite ein", "");
//	alert(w);
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

popTop=3;
popLeft=5;
function PopImgs(id,header,obj){
	if (shown)
		showEl('loading');
	if (obj){
		if (!(obj.parentNode.lastChild.id=="Loader")){
			path = window.document.location.toString();
			var oImg = img_create("images/transparent_loading.gif", "", "");
			if (oImg ){
				oImg.id	= "Loader";
				oImg.style.position='relative';
				oImg.style.top=24+'px';
				oImg.style.left=50+'px';
				oImg.style.margin='auto';
				oImg.style.zIndex=1;
				obj.parentNode.appendChild(oImg);
				}
			}
		}
	
	Preloader.axit();
	Preloader.add("common/picture.php?id="+id+"&thumb=1");
	Preloader.add("common/thumb.php?id="+id+"&thumb=2");
	Preloader.add("common/thumb.php?id="+id+"&thumb=3");	
	Preloader.id=id;
	Preloader.img=oImg;	
	Preloader.header=header;	
	Preloader.onFinish([PopImgsShow,removeLoader]);
	Preloader.load();	
	return false;
	}
/*
function PopImgsShow(oPL){
	//var oHead=document.getElementById('titleBar');
	var oHead=document.getElementById('titleBar');
	var oBig=document.getElementById('big');
	var oSmall1=document.getElementById('small2');
	var oSmall2=document.getElementById('small3');
	var xButton=document.getElementById('x-button');

//	oHead.firstChild.innerHTML = "&nbsp;"+oPL.header;
	oHead.innerHTML = "&nbsp;"+oPL.header;	
//	oHead.firstChild.style.vertical
	oSmall1.src = oPL.images[1];
	oSmall2.src = oPL.images[2];

	if (!shown){
		oBig.src 	= oPL.images[0];	
		var oLayer1=document.getElementById("layer1");
		oLayer1.style.top = popTop;	
		oLayer1.style.left= popLeft;
		//oLayer1.style.border-wi
		oSmall1.onclick=Function("yChange(2)"); 	
		oSmall2.onclick=Function("yChange(3)"); 
		var imgs=[oBig,oSmall1,oSmall2,xButton];
		for (var i=0; i<imgs.length; i++){
			if (imgs[i].id == 'x-button'){
				imgs[i].onmousedown=function(){
					this.style.marginTop="2px";					
					};
				imgs[i].onmouseup=function(){
					this.style.marginTop="0px";
					};
				document.onmouseup=function(){
					this.style.marginTop="0px";
				 }
				imgs[i].onmouseout=function(){
					this.style.marginTop="0px";
					};
				imgs[i].onmouseover=function(){
//					this.style.border='1px solid yellow';
					}					
				imgs[i].onselectstart=function(){return false;};					
				imgs[i].onselect=function(){return false;};
				imgs[i].ondragstart=function(){return false;};
				imgs[i].ondrag=function(){return false;};						
			} else {	
				imgs[i].oncontextmenu=function(){return false;};
				imgs[i].onselectstart=function(){return false;};
				imgs[i].onselect=function(){return false;};
				imgs[i].ondragstart=function(){return false;};
				imgs[i].ondrag=function(){return false;};	
				imgs[i].onmouseover=function(){
					imgs[i].style.border='1px solid yellow';
					}					
				}
			}
		showIt();
		// remove loader image  and load big Images in the background
		removeLoader(oPL);
		oPL.images = [];
		oPL.loadedImages = [];
		oPL.imagesLoaded = 0;
		oPL.callbacks = [];
		oPL.add("common/picture.php?id="+oPL.id+"&thumb=2");
		oPL.add("common/picture.php?id="+oPL.id+"&thumb=3");
		oPL.onFinish([]);
		oPL.load();		
		}
	else{
		showEl('loading');
		oClone 		= oBig.cloneNode(true);		
		oClone.id	= "Clone";
		oClone.style.position="absolute";
		oClone.style.top=24+"px";
		oClone.style.left=0+"px";	
		//oClone.style.zIndex=13;
		nOpac = 100;		
		oBig.parentNode.appendChild(oClone);		
		oBig.title='Zdjęcie 1';
		oBig.src 	= oPL.images[0];	
		FadeBigImg();
		}
	if (shown2)
		getData("common/cardesc.php?id="+oPL.id);
	else
		hideEl('loading');
	document.onmouseup=Function("ddEnabled=false");
	}*/
function PopImgsShow(oPL){
	//var oHead=document.getElementById('titleBar');
	var oHead=document.getElementById('titleBar');
	var oBig=document.getElementById('big');
	var oSmall1=document.getElementById('small2');
	var oSmall2=document.getElementById('small3');
	var xButton=document.getElementById('x-button');

//	oHead.firstChild.innerHTML = "&nbsp;"+oPL.header;
	oHead.innerHTML = "&nbsp;"+oPL.header;	
//	oHead.firstChild.style.vertical
	oSmall1.src = oPL.images[1];
	oSmall2.src = oPL.images[2];

	if (!shown){
		oBig.src 	= oPL.images[0];	
		var oLayer1=document.getElementById("layer1");
		oLayer1.style.top = popTop;	
		oLayer1.style.left= popLeft;
		//oLayer1.style.border-wi
		oSmall1.onclick=Function("yChange(2)"); 	
		oSmall2.onclick=Function("yChange(3)"); 
		var imgs=[oBig,oSmall1,oSmall2,xButton];
		for (var i=0; i<imgs.length; i++){
			if (imgs[i].id == 'x-button'){
				imgs[i].onmousedown=function(){
					this.style.marginTop="2px";					
					};
				document.onmouseup=function(){
					imgs[i].style.marginTop="1px";
				 }
/*				imgs[i].onmouseout=function(){
					//alert(this.style.bgColor);
					this.style.marginTop="0px";
					};*/
				imgs[i].onselectstart=function(){return false;};					
				imgs[i].onselect=function(){return false;};
				imgs[i].ondragstart=function(){return false;};
				imgs[i].ondrag=function(){return false;};						
				imgs[i].onmouseover=function(){this.style.border='1px solid red';return false;};										
				imgs[i].onmouseout=function(){this.style.border='none';this.style.marginTop="0px";return false;};														
			} else {	
				imgs[i].oncontextmenu=function(){return false;};
				imgs[i].onselectstart=function(){return false;};
				imgs[i].onselect=function(){return false;};
				imgs[i].ondragstart=function(){return false;};
				imgs[i].ondrag=function(){return false;};		
				if (imgs[i].id !=='big'){
					imgs[i].onmouseover=function(){this.style.border='1px solid yellow';return false;};	
					imgs[i].onmouseout=function(){this.style.border='1px solid #000000';return false;};																		
					}
				}
			}
		showIt();
		// remove loader image  and load big Images in the background
		removeLoader(oPL);
		oPL.images = [];
		oPL.loadedImages = [];
		oPL.imagesLoaded = 0;
		oPL.callbacks = [];
		oPL.add("common/picture.php?id="+oPL.id+"&thumb=2");
		oPL.add("common/picture.php?id="+oPL.id+"&thumb=3");
		oPL.onFinish([]);
		oPL.load();		
		}
	else{
		showEl('loading');
		oClone 		= oBig.cloneNode(true);		
		oClone.id	= "Clone";
		oClone.style.position="absolute";
		oClone.style.top=24+"px";
		oClone.style.left=0+"px";	
		//oClone.style.zIndex=13;
		nOpac = 100;		
		oBig.parentNode.appendChild(oClone);		
		oBig.title='Zdjęcie 1';
		oBig.src 	= oPL.images[0];	
		FadeBigImg();
		}
	if (shown2)
		getData("common/cardesc.php?id="+oPL.id);
	else
		hideEl('loading');
	document.onmouseup=Function("ddEnabled=false");
	}
	
function PopImgsShow1(oPL){
	var oHead=document.getElementById('titleBar');
	var oBig=document.getElementById('big');
	var xButton=document.getElementById('x-button');

	oHead.innerHTML = "&nbsp;"+oPL.header;	
	if (!shown){
		oBig.src 	= oPL.images[0];	
		var oLayer1=document.getElementById("layer1");
		oLayer1.style.top = popTop;	
		oLayer1.style.left= popLeft;
		//oLayer1.style.border-wi
		var imgs=[oBig,xButton];
		for (var i=0; i<imgs.length; i++){
			if (imgs[i].id == 'x-button'){
				imgs[i].onmousedown=function(){
					this.style.marginTop="3px";					
					};
				imgs[i].onmouseup=function(){
					};
				document.onmouseup=function(){
					xButton.style.marginTop="1px";
				 }
				imgs[i].onmouseout=function(){
					xButton.style.marginTop="1px";
					};
				imgs[i].onselectstart=function(){return false;};					
				imgs[i].onselect=function(){return false;};
				imgs[i].ondragstart=function(){return false;};
				imgs[i].ondrag=function(){return false;};						
			} else {	
			//imgs[i].onmousedown=Function("return false");
			imgs[i].oncontextmenu=function(){return false;};
			imgs[i].onselectstart=function(){return false;};
			imgs[i].onselect=function(){return false;};
			imgs[i].ondragstart=function(){return false;};
			imgs[i].ondrag=function(){return false;};		
				}
			}
		showIt();
		removeLoader(oPL);
		oPL.images = [];
		oPL.loadedImages = [];
		oPL.imagesLoaded = 0;
		oPL.callbacks = [];
		oPL.add("common/picture.php?id="+oPL.id+"&thumb=2");
		oPL.add("common/picture.php?id="+oPL.id+"&thumb=3");
		oPL.onFinish([]);
		oPL.load();		
		}
	else{
		showEl('loading');
		oClone 		= oBig.cloneNode(true);		
		oClone.id	= "Clone";
		oClone.style.position="absolute";
		oClone.style.top=24+"px";
		oClone.style.left=0+"px";	
		nOpac = 100;		
		oBig.parentNode.appendChild(oClone);		
		oBig.title='Zdjęcie 1';
		oBig.src 	= oPL.images[0];	
		FadeBigImg();
		}
	if (shown2)
		getData("common/cardesc.php?id="+oPL.id);
	else
		hideEl('loading');
	document.onmouseup=Function("ddEnabled=false");
	}
	
function PopImg(id,header,obj){
	if (shown)
		showEl('loading');
	if (obj){
		if (!(obj.parentNode.lastChild.id=="Loader")){
			var oImg = img_create("images/transparent_loading.gif", "", "");
			if (oImg ){
				oImg.id	= "Loader";
				oImg.style.position='relative';
				oImg.style.top=24+'px';
				oImg.style.left=50+'px';
				oImg.style.margin='auto';
				oImg.style.zIndex=1;
				obj.parentNode.appendChild(oImg);
				}
			}
		}
	Preloader.axit();		
	Preloader.add("common/picture.php?id="+id+"&thumb=1");
	Preloader.id=id;
	Preloader.img=oImg;
	Preloader.header=header;	
	Preloader.onFinish([PopImgsShow1,removeLoader]);
	Preloader.load();	
	return false;
	}

/*function PopPicResize(){	
	var oLayer1=document.getElementById("layer1");
	var oDiv=document.getElementById('imgDiv');	
	
	if (shown){
		iLayer1Height	= Preloader.loadedImages[0].height;
		var winWidth = (document.all)?document.body.clientWidth:window.innerWidth;
		var winHeight = (document.all)?document.body.clientHeight:window.innerHeight;
		if ((winHeight-iLayer1Height) < 0){
			oLayer1.style.top = "0px";				
			oLayer1.style.height = (winHeight-6)+"px";
			oLayer1.style.width = parseInt(oLayer1.style.width)+17+"px";			
			oDiv.style.height = winHeight-iHeaderHeight-6+"px";						
			oDiv.style.overflow = "scroll";			
		}else{
			oLayer1.style.top = (winHeight-iLayer1Height)/2+"px";
			oDiv.style.left=2+"px";
			oDiv.style.height = oPL.loadedImages[0].height+"px";						
			oDiv.style.overflow = "hidden";						
			}
		oLayer1.style.left= (winWidth-oPL.loadedImages[0].width)/2+"px";
		}
	}

	*/
function PopPic(obj,picUrl,header){
	if (shown)
		showEl('loading');
	if (obj){
		//alert(document.height);
		if (!(obj.parentNode.lastChild.id=="Loader")){
			var oImg = img_create("images/transparent_loading.gif", "", "");
			if (oImg ){
				oImg.id	= "Loader";
				oImg.style.position='relative';
				oImg.style.top=obj.parentNode.height/2+'px';
				oImg.style.left=obj.parentNode.width/2+'px';
				oImg.style.margin='auto';
				oImg.style.zIndex=10;
				obj.parentNode.appendChild(oImg);
				}
			}
		}
	Preloader.axit();		
	Preloader.add(picUrl);
	Preloader.img=oImg;	
	Preloader.header=header;
	Preloader.onFinish([PopPicShow,removeLoader]);
	Preloader.load();
	return false;
	}	

function PopPicShow(oPL){
// 21.12.2011 poprawki
	var oLayer1=document.getElementById("layer1");
	var oHead=document.getElementById('titleBar');
	var oBig=document.getElementById('imgObj');
	var oDiv=document.getElementById('imgDiv');
	var iLayer1Height;
	var iHeaderHeight=24;
	var winWidth = viewPort(2);
	var winHeight = viewPort(1);
	var children = oHead.childNodes;
	var isFirstTxt = false;
	
	//alert(children);
	for(var i = 0; i < children.length; i++){
		if (children[i].nodeType==3){
			if (isFirstTxt)
				oHead.removeChild(children[i]);
			else{	
				isFirstTxt = true;
				children[i].data = '\u00A0'+oPL.header;
				}
			}
		}
	//alert(oHead.firstChild.nodeValue);
//	oHead.firstChild.data = '\u00A0'+oPL.header; //&nbsp;			
	oBig.src = oPL.images[0];
	if (oPL.loadedImages[0].width > winWidth) {
		x	= (winWidth-10)/(oPL.loadedImages[0].width);
		oBig.style.width = winWidth-10+"px";
		oBig.style.height= x*oPL.loadedImages[0].height+"px";
		oLayer1.style.width = x*oPL.loadedImages[0].width+"px";
		iLayer1Height	= x*oPL.loadedImages[0].height+iHeaderHeight;
		//alert(iLayer1Height);
		}
	else {
		x = 1;
		oBig.style.width = oPL.loadedImages[0].width+"px";
		oBig.style.height= oPL.loadedImages[0].height+"px";
		oLayer1.style.width = oPL.loadedImages[0].width+"px";
		iLayer1Height	= oPL.loadedImages[0].height+iHeaderHeight;		
		}
	oHead.style.width = oLayer1.style.width;
	oHead.style.textAlign = "left";
	oLayer1.style.height = iLayer1Height+"px";	
	//alert(oLayer1.style.height);
	if (!shown){
		//var winHeight = (document.all)?document.body.clientHeight:window.innerHeight;		
		//alert(document.body.clientWidth);
		if ((winHeight - iLayer1Height) < 0){
			oLayer1.style.top = "0px";				
			oLayer1.style.height = (winHeight-6)+"px";
			oLayer1.style.width = parseInt(oLayer1.style.width)+15+"px";			
			oHead.style.width = oLayer1.style.width;			
			oDiv.style.height = winHeight-iHeaderHeight-6+"px";						
			oDiv.style.overflow = "scroll";			
		}else{
			oLayer1.style.top = (winHeight-iLayer1Height)/2+"px";
			oDiv.style.left	= 2+"px";
			oDiv.style.height = x*oPL.loadedImages[0].height+"px";						
			oDiv.style.overflow = "hidden";						
			}
		oLayer1.style.left= (winWidth-x*oPL.loadedImages[0].width)/2+"px";
		//oLayer1.style.left= (winWidth-oLayer1.style.width)/2+"px";
		
		showIt();
		}
	document.onmouseup=Function("ddEnabled=false");
	}
/*function msgBox(message)
 {
  var msgbox = document.getElementById("msgbox");
  msgbox.innerHTML = message;
  var x = (window.innerWidth / 2) - (msgbox.offsetWidth / 2);
  var y = (window.offsetHeight / 2) - (msgbox.offsetHeight / 2);              
  msgbox.style.top = y;
  msgbox.style.left = x;
  msgbox.style.display = "block";
 }
*/
function img_create(src, alt, title) { 
    var img= isIE? new Image() : document.createElement('img'); 
    img.src= src; 
    if (alt!=null) img.alt= alt; 
    if (title!=null) img.title= title; 
    return img;
	}
function removeLoader(oPL){
	if (oPL.img && oPL.img.parentNode)
		oPL.img.parentNode.removeChild(oPL.img);
 }

function IsImageOk(img) {
// During the onload event, IE correctly identifies any images that
// weren’t downloaded as not complete. Others should too. Gecko-based
// browsers act like NS4 in that they report this incorrectly.
if (!img.complete) {
	return false;
}

// However, they do have two very useful properties:naturalWidth and
// naturalHeight. These give the true size of the image. If it failed
// to load, either of these should be zero.
if (typeof img.naturalWidth != 'undefined' && img.naturalWidth== 0) {
	return false;
}

// No other way of checking: assume it’s ok.
return true;
}
/*//Call this function onLoad of body tag
function checkImages() {
	for (var i = 0; i < document.images.length; i++) {
		if (!IsImageOk(document.images[i])) {
			document.images[i].src = “/images/nopic.jpg“;
			}
		}
	}

*/
function getData(url){
	var xmlhttp=window.GetXmlHttpObject();
	var data;
	if (xmlhttp==null){
	  alert ("Przeglądarka nie obsługuje [HTTP Request]");
	  return;
	  }
	url=url=url+"&sid="+Math.random();

	xmlhttp.onreadystatechange=function(){
	  if (xmlhttp.readyState == 4)
	  {
			data=xmlhttp.responseText;
			checkData(data);
			if (document.getElementById('loading'))
				hideEl('loading');
	  }};
		
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	}
/*	
function checkData(data){
	//alert("?"+data);
	oDiv=document.getElementById('popTxt');
	oDiv.innerHTML=data;
	if (shown2){
		//showEl('layer2');
		var  imgs = document.getElementById("layer2");
		if (isChrome ){
			imgs.style.opacity = 0.70;
			return true;
			}
		if(ie5){
			imgs.style.filter="alpha(opacity=70)";
			imgs.filters.alpha.opacity = 70;
			return true;			
	    }
	    if(ns6){
	      //  imgs.style.MozOpacity = 0;
			imgs.style.MozOpacity = 70/100;
	    }
		}
	return true;
	}
*/
function checkData(data){
	//alert("?"+data);
	oDiv=document.getElementById('layer2');
	oDiv.innerHTML='<span style="float:right; background-color:gray; color:white; font-weight:bold; width=\'20px\'; text-align:center; cursor:pointer" onclick="showLayer2()">&nbsp;X&nbsp;</span>';
	oDiv.innerHTML=oDiv.innerHTML+data;
	if (shown2){
		//showEl('layer2');
		var  imgs = document.getElementById("layer2");
		if (isChrome ){
			imgs.style.opacity = 0.70;
			return true;
			}
		if(ie5){
			imgs.style.filter="alpha(opacity=70)";
			imgs.filters.alpha.opacity = 70;
			return true;			
	    }
	    if(ns6){
	      //  imgs.style.MozOpacity = 0;
			imgs.style.MozOpacity = 70/100;
	    }
		}
	return true;
	}
//draggable
isHot=false;	
function ddInit(e){
	topDog=isIE ? "BODY" : "HTML";
	whichDog=isIE ? document.all.layer1 : document.getElementById("layer1");  
	hotDog=isIE ? event.srcElement : e.target;  
	while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
	 hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
	}  
	if (hotDog.id=="titleBar"){
		//alert(hotDog.id);
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;
		nowX=parseInt(whichDog.style.left);
		nowY=parseInt(whichDog.style.top);
		ddEnabled=true;
		document.onmousemove=dd;
		}
	}

function dd(e){
	//alert("ddEnabled="+ddEnabled);
  if (!ddEnabled) return;
  //whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx+"px"; 
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx+"px"; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety+"px";
  return false;  
}
function dragOff(){
	ddEnabled=false;
	var oLayer1 = isIE ? document.all.layer1 : document.getElementById("layer1");
	popTop=parseInt(oLayer1.style.top);
	popLeft=parseInt(oLayer1.style.left);
	}
function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function yChange(i){
	var oClone;
	var small = 'small'+i;
	var oBig = document.getElementById('big');
	var bSrc = oBig.src;
	var sSrc = document.getElementById(small).src;
	var ib	= "common/thumb.php";
	var is 	= "common/picture.php";
	var temp = (i==2?iSmall1:iSmall2);

	while (fading) FadeBigImg();
	if (fading){
		return false;
		}	
	showEl('loading');
	oClone 		= oBig.cloneNode(true);		
	oClone.id	= "Clone";
	oClone.style.position="absolute";
	oClone.style.top=24+"px";
	oClone.style.left=0+"px";	
	//oClone.style.zIndex=13;
	nOpac = 100;		

	//bClone.style.position="absolute";		
	oBig.parentNode.appendChild(oClone);		
	//alert("oClone.style.top="+oClone.getPropertyValue('top')+"\n"+oBig.style.top);		
	
	document.getElementById(small).src = ib.concat(bSrc.substring(bSrc.indexOf("?")));
	document.getElementById(small).title = "Powiększ zdjęcie "+iBig;	
	oBig.src = is.concat(sSrc.substring(sSrc.indexOf("?")));
	oBig.title='Zdjęcie '+temp;
	//alert(oBig.src);

	FadeBigImg();
	
	if (i==2){
		iSmall1 = iBig;
	}else{ 
		iSmall2 = iBig;
	}
	iBig = temp;
	return false; 
}
/*  Object PreLoader
http://warpspire.com/tipsresources/interface-scripting/image-preloading-revisited/
dopisałem axit  i dwie zmienne*/
var Preloader = {
  callbacks: [],
  images: [],
  loadedImages: [],
  imagesLoaded: 0,
  id:0,
  header:"",
  img:null,

  add: function(image){
    if (typeof image == 'string') this.images.push(image);
    if (typeof image == 'array' || typeof image == 'object'){
      for (var i=0; i< image.length; i++){
        this.images.push(image[i]);
      }
    }
  },
  onFinish: function(func){
    if (typeof func == 'function') this.callbacks.push(func);
    if (typeof func == 'array' || typeof func == 'object'){
      for (var i=0; i< func.length; i++){
        this.callbacks.push(func[i]);
      }
    }
  },
  load: function(){
    for(var i=0; i<this.images.length; i++){
      this.loadedImages[i] = new Image();
      this.loadedImages[i].onload = function(){ Preloader.checkFinished.apply(Preloader) }
      this.loadedImages[i].src = this.images[i];
    }
  },

  checkFinished: function(){
    this.imagesLoaded++;
    if (this.imagesLoaded == this.images.length) this.fireFinish();
  },
  fireFinish: function(){
    for (var i=0; i<this.callbacks.length; i++){
      this.callbacks[i](this);
    }
	 this.axit();
  },
  axit: function(){
    this.images = [];
    this.loadedImages = [];
    this.imagesLoaded = 0;
    this.callbacks = [];
	 this.id=0;
	 this.header="";
	 this.img=null;
  }
}
/*koniec preloader*/
function xTest(e){
	return false;
}
function xDown(e){
	if (e.id=="x-button"){
		e.style.marginTop="2px";
		e.style.marginLeft="1px";
		e.draggable=false;
		if(event.preventDefault) event.preventDefault();
		//event.preventDefault();		
	}
	return false;
}
function xOut(e){
	if (e.id=="x-button"){
		e.style.marginTop="0px";
		e.style.marginLeft="0px";		
		}
	return false;
}
function dragInit(e){
	topDog=isIE ? "BODY" : "HTML";
	whichDog=isIE ? document.all.layer1 : document.getElementById("layer1");  
	hotDog=isIE ? event.srcElement : e.target;  
	if (hotDog.id=="x-button")
		return true;
	while (hotDog.id!="titleBar" && hotDog.tagName!=topDog){
	 hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
	}  
	if (hotDog.id=="titleBar"){
		//alert(hotDog.id);
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;
		nowX=parseInt(whichDog.style.left);
		nowY=parseInt(whichDog.style.top);
		ddEnabled=true;
		document.onmousemove=dd;
		}
	}

function viewPort(which){
var viewportwidth;
var viewportheight; 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
 return (which==1?viewportheight:viewportwidth);
  }


