// This source code is property of Poeware Sp. z o.o.
// This page holds the java script code for popup window management.

// by Nannette Thacker
// http://www.shiningstar.net
// This script allows you to display a popup that does not pop
// off the edge of the screen if the link is toward the edge
// If the link sits on the edge of the screen, the popup will
// pop the other direction
// also allows a popcenter in the middle of the screen --%>

var version4 = (navigator.appVersion.charAt(0) == "4");

function closePopup(popupHandle) {
	if(popupHandle != null && !popupHandle.closed) popupHandle.close()
}

// Nannette Thacker http://www.shiningstar.net
// height and width, if 0 or negative, are understood as the boundary that is
// substracted from the full visible screen, i.e. 0 means full screen, and -20
// means an almost full screen, except a narrow stripe of 20 pixels around the popup.
// position=1 POPUP: makes screen display up and/or left,
//    down and/or right
// depending on where cursor falls and size of window to open
// position=2 CENTER: makes screen fall in center
// asWindow, if true, shows the popup with scrollbars, and resizable, in order
// to show the contents
function displayPopup(position,url,name,height,width,asWindow)
{
	var popupHandle
	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt
    var evnt = (version4 ? event : null)	
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		screenY = top.document.body.offsetHeight
		screenX = window.screen.availWidth
	}
	else
	{ // Navigator coordinates
			screenY = screen.height;
			screenX = screen.width;
	}
	if(height <= 0)
	{
		height += screenY;
	}
	if(width <= 0)
	{
		width += screenX;
	}
	var properties = "toolbar=0,location=0,height="+height
	properties = properties+",width="+width	
	if(position == 1)	// if POPUP not CENTER
	{
		cursorX = evnt.screenX
		cursorY = evnt.screenY
		padAmtX = 10
		padAmtY = 10
		
		if((cursorY + height + padAmtY) > screenY)	
		// make sizes a negative number to move left/up
		{
			padAmtY = (-30) + (height*-1);	
			// if up or to left, make 30 as padding amount
		}
		if((cursorX + width + padAmtX) > screenX)
		{
			padAmtX = (-30) + (width*-1);	
			// if up or to left, make 30 as padding amount
		}
	
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			leftprop = cursorX + padAmtX
			topprop = cursorY + padAmtY
		}
		else
		{ // adjust Netscape coordinates for scrolling
			leftprop = (cursorX - pageXOffset + padAmtX)
			topprop = (cursorY - pageYOffset + padAmtY)
		}
	}
	else	// CENTER
	{
		leftvar = (screenX - width) / 2
		rightvar = (screenY - height) / 2
			
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			leftprop = leftvar
			topprop = rightvar
		}
		else
		{ // adjust Netscape coordinates for scrolling
			leftprop = (leftvar - pageXOffset)
			topprop = (rightvar - pageYOffset)
		}
	}	
	if(evnt != null)
	{
		properties = properties+",left="+leftprop
		properties = properties+",top="+topprop
	}
	if(asWindow == true)
	{
		properties = properties+",scrollbars=yes,resizable=yes"
	}
	popupHandle = open(url,name,properties)
	popupHandle.focus();
	return popupHandle
}

// this functionn opens an invisible window with the passed url (useful to launch parallel requests to the server)
function openInvisibleWindow(url,name)
{
	window.open(url,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=10,height=10,left=5000,top=5000');	
}

// this function will refresh the opener of this window with the passed url, and if 'closeMe' is true, will close this window.
function refreshOpener(url,closeMe)
{
	self.opener.location=url;
	if (closeMe == true)
	{
		window.close();
	}
}
