

function SmartPopup(sUrl,iWidth,iHeight)
{	var smartSizeMargin = 200;
	// Close popup window if already open, so we can size it for new content
	if(window.win){window.win.close();}
	// Get screen dimensions
	var screenWidth = screen.availWidth;
	var screenHeight = screen.availHeight;
	// Downsize popup window if it would be bigger than available screen size
	if(iWidth > screenWidth){iWidth = (screenWidth - smartSizeMargin);}
	if(iHeight > screenHeight){iHeight = (screenHeight - smartSizeMargin);}
	// Get left and top position to center popup window
	var x = (screenWidth - iWidth) / 2;
	var y = (screenHeight - iHeight) / 2;
	// Create options string to pass to window.open() method
	var sOptions = "left=" + x + ",screenX=" + x;
	sOptions += ",top=" + y + ",screenY=" + y;
	sOptions += ",width=" + iWidth + ",height=" + iHeight;
	sOptions += ",toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1";
	// Open popup
    win = window.open(sUrl, 'popup', sOptions);
	// If main window is in front, which is most likely the case, then bring popup window to front
	if(window.focus){win.focus();}
	// Return false to keep HTML link from being followed if this function used in onclick event of <a> element
	return false;
}



