function popup(adres,szer,wys) 
{
okno = window.open(adres,'', 'width='+szer+',height='+wys+',scrollbars=yes');
okno.focus();
}

/*
<script language=javascript>
window.onload = init;
function init() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getXY(e) {
  x = (window.Event) ? e.pageX : event.clientX;
  y = (window.Event) ? e.pageY : event.clientY;

  window.status = x+":"+y;
}
</script>
*/

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}



function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;	
}

function popup_still()
{
	var popup = document.getElementById("fpopup");
	popup.closing = false;
	popup.style.display = "block";
}

function popup_on(gdzie,opis,width,onLeft)
{
//alert(gdzie.offsetParent.offsetTop);
	var popup = document.getElementById("fpopup");
	popup.closing = false;
	popup.style.width = width+"px";
	popup.style.top = findPosY(gdzie)+0+"px";
	
	popup.style.top = (gdzie.offsetParent.offsetTop+0)+"px";
	
	var x = findPosX(gdzie)+20;
	var clientWidth = document.body.clientWidth;
	if ((x > (clientWidth-(width+30))) || (onLeft))
		x = x - width;
	popup.style.left = x+"px";
	
	popup.style.left = (gdzie.offsetParent.offsetLeft+40)+"px";
	
	popup.innerHTML = opis;
	popup.style.display = "block";
}

function popup_off()
{
	var popup = document.getElementById("fpopup");
	if(popup)
	{
		popup.closing = true;
		setTimeout('var popup = document.getElementById("fpopup"); if (popup.closing) { popup.style.display="none"; }', 500);
	}
}

function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 

function show_popup(uri,obiekt)
{
advAJAX.get({
    url: uri,
	onSuccess: function(obj) { popup_on(obiekt,obj.responseText,0,false); }
});
}
