var dofade=true;
var center=false;
var centertext=false;

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

var NS4=(navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)?true:false;
var IE4=(document.all && !document.getElementById)?true:false;
var IE5=(document.getElementById && document.all)?true:false;
var NS6=(document.getElementById && navigator.appName.indexOf("Netscape")>=0 )?true:false;
var W3C=(document.getElementById)?true:false;
var w_y,w_x,popuptxt,boxheight,boxwidth;
var ishover=false;
var isloaded=false;
var ieop=0;
var op_id=0;

function getwindowdims(){
	w_y=(NS4||NS6||window.opera)? window.innerHeight : (IE5||IE4)? document.body.clientHeight : 0;
	w_x=(NS4||NS6||window.opera)? window.innerWidth : (IE5||IE4)? document.body.clientWidth : 0;
}

function getboxwidth(){
	if(NS4)boxwidth=(popuptxt.document.width)? popuptxt.document.width : popuptxt.clip.width;
	if(IE5||IE4)boxwidth=(popuptxt.style.pixelWidth)? popuptxt.style.pixelWidth : popuptxt.offsetWidth;
	if(NS6)boxwidth=(popuptxt.style.width)? parseInt(popuptxt.style.width) : parseInt(popuptxt.offsetWidth);
}

function getboxheight(){
	if(NS4)boxheight=(popuptxt.document.height)? popuptxt.document.height : popuptxt.clip.height;
	if(IE4||IE5)boxheight=(popuptxt.style.pixelHeight)? popuptxt.style.pixelHeight : popuptxt.offsetHeight;
	if(NS6)boxheight=parseInt(popuptxt.offsetHeight);
}

function movepopuptxt(x,y){
	if(NS4)popuptxt.moveTo(x,y);
	if(W3C||IE4){
		popuptxt.style.left=x+'px';
		popuptxt.style.top=y+'px';
	}
}

function getpagescrolly(){
	if(NS4||NS6)return window.pageYOffset;
	if(IE5||IE4)return ietruebody().scrollTop;
}

function getpagescrollx(){
	if(NS4||NS6)return window.pageXOffset;
	if(IE5||IE4)return ietruebody().scrollLeft;
}

function writeindiv(text){
	if(NS4){
		popuptxt.document.open();
		popuptxt.document.write(text);
		popuptxt.document.close();
	}
	if(W3C||IE4)popuptxt.innerHTML=text;
}

function writetxt(text){
	if(isloaded){
		if(text!=0){
			ishover=true;
			writeindiv(text);
			getboxheight();
			if((W3C || IE4) && dofade){
				ieop=0;
				incropacity();
			}
		}else{
			if(NS4)popuptxt.visibility="hide";
			if(IE4||W3C){
				if(dofade)clearTimeout(op_id);
				popuptxt.style.visibility="hidden";
			}
			writeindiv('');
			ishover=false;
		}
	}
}

function incropacity(){
	ieop=100;
	if(ieop<=100){
		if(IE4 || IE5)popuptxt.style.filter="alpha(opacity="+ieop+")";
		if(NS6)popuptxt.style.MozOpacity=ieop/100;
		ieop+=7;
		op_id=setTimeout('incropacity()', 50);
	}
}

function moveobj(evt){
	if(isloaded && ishover){
		margin=(IE4||IE5)? 1 : 23;
		if(NS6)if(document.height+27-window.innerHeight<0)margin=15;
		if(NS4)if(document.height-window.innerHeight<0)margin=10;
		if (NS4){
			mx=evt.pageX;
			my=evt.pageY;
		}
		else if (NS6){
	   	mx=evt.clientX;
	   	my=evt.clientY;
		}
		else if (IE5){
			mx=event.clientX;
			my=event.clientY;
		}
		else if (IE4){
	   	mx=0;
			my=0;
		}
		if(NS4){
			mx-=getpagescrollx();
			my-=getpagescrolly();
		}
		xoff=(center)? mx-boxwidth/2 : mx+5;
		yoff=(my+boxheight+30+margin>=w_y)? -10-boxheight: 20;
		movepopuptxt( Math.min(w_x-boxwidth-margin , Math.max(2,xoff))+getpagescrollx() , my+yoff+getpagescrolly());
		if(NS4)popuptxt.visibility="show";
		if(W3C||IE4)popuptxt.style.visibility="visible";
	}
}

function initPopup(){
	popuptxt=document.getElementById('dymek');
	getboxwidth();
	getboxheight();
	getwindowdims();
	isloaded=true;
	if(W3C)popuptxt.style.padding='4px';
	if(IE4 || IE5 && dofade)popuptxt.style.filter="alpha(opacity=0)";
}

if(NS4)document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=moveobj;
window.onresize=getwindowdims;

//pull down menu
MenuTS=null;
LiveMenu=null;
TimeOutS=null;
TimeOutH=null;
initM=0;

function initMenu(){
	setCords('mprz','mmprz');
	setCords('mart','mmart');
	setCords('mforum','mmforum');
	setCords('mmoje','mmmoje');
}

function getPageCoords(el){
	var coords={x:0,y:0 };
	while(el){
		coords.x+=el.offsetLeft;
		coords.y+=el.offsetTop;
		el=el.offsetParent;
	}
	return coords;
}

function setCords(a,b){
	ea=document.getElementById(a);
	eb=document.getElementById(b);
	c=getPageCoords(eb);
	ea.style.left=c.x-5+'px';
	ea.style.top=c.y+17+'px';
}

function menuOver(m){
	MenuTS=document.getElementById(m);
	if(LiveMenu==MenuTS){
		clearTimeout(TimeOutS);
		clearTimeout(TimeOutH);
	}else{
		TimeOutS=window.setTimeout('showNow();',250);
	}
}

function menuOut(){
	clearTimeout(TimeOutS);
	if(LiveMenu!=null){
		TimeOutS=window.setTimeout('hideNow();',250);
	}
}

function hideNow(){
	if (LiveMenu!=null) {
		LiveMenu.style.visibility = 'hidden';
		LiveMenu=null;
	}
}

function showNow(){
	if(LiveMenu!=null){
		clearTimeout(TimeOutH);
		hideNow();
	}
	MenuTS.style.visibility = 'visible';
	LiveMenu=MenuTS;
	MenuTS=null;
}
function bfmovepic(pic,src) { document[pic].src=src; }

function confirmLink(theLink,confirmMsg){
	var is_confirmed = confirm(confirmMsg);
	if (is_confirmed) {
		theLink.href += '&is_js_confirmed=1';
	}
	return is_confirmed;
}

function enlargeimg(id){
	msg=open("zdjecie.php?id="+id+"&d=1","zdjęcie","toolbar=no,directories=no,resizable=yes,menubar=no,width=820,height=620");
}

function makeWait(t,ac){
	a=document.getElementById('action');
	a.value=ac;
	t.disabled=true;
	t.value='Proszę czekać';
}

