// popup loader
var m_strCurrentWindowId = null;

function showPopup(strWindowId)
{
	var divPopup = document.getElementById("popup");

	// some windows need checking for selection
	switch(strWindowId)
	{
	case 'downloadSelected':
		if (!somethingSelected())
		{
			alert('Please select one or more images to download');
			return;
		}
		var divPopup = document.getElementById("popup3");
		break;
	case 'downloadLightbox':
	case 'downloadFooterLightbox':
		var divPopup = document.getElementById("popup3");
		break;
	case 'removeSelected':
		if (!somethingSelected())
		{
			alert('Please select one or more images to remove');
			return;
		}
		break;
	}

	// show the "popup" control
	if (divPopup)	divPopup.style.display = 'block';

	// if a "window" is currently visible, hide it
	if (m_strCurrentWindowId != null)
	{
		var divWindow = document.getElementById(m_strCurrentWindowId);
		if (divWindow)	divWindow.style.display = 'none';
	}

	// show the specified "popup" window
	var divWindow = document.getElementById(strWindowId);
	if (divWindow)	divWindow.style.display = 'block';
	
	// calculate width/height of screen and popup - used to center the "window"
	var	lngHeight	 = divPopup.offsetHeight;
	var	lngWidth	 = divPopup.offsetWidth;

	// get the height/width of window
	var lngWinHeight = window.innerHeight;
	var lngWinWidth	 = window.innerWidth;

	if (!lngWinHeight && document.documentElement && document.documentElement.clientHeight)
	{
		lngWinHeight = document.documentElement.clientHeight;
		lngWinWidth  = document.documentElement.clientWidth;
	}
	if (!lngWinHeight && document.body && document.body.clientHeight)
	{
		lngWinHeight = document.body.clientHeight;
		lngWinWidth  = document.body.clientWidth;
	}

	// get vertical and horizontal scrolling values
	var lngWinTop	 = window.pageYOffset;
	var lngWinLeft	 = window.pageXOffset;

	if (!lngWinTop && document.body && document.body.scrollTop)
	{
		lngWinTop  = document.body.scrollTop;
		lngWinLeft = document.body.scrollLeft;
	}
	if (!lngWinTop && document.documentElement && document.documentElement.scrollTop)
	{
		lngWinTop  = document.documentElement.scrollTop;
		lngWinLeft = document.documentElement.scrollLeft;
	}
	if (!lngWinTop)		lngWinTop = 0;
	if (!lngWinLeft)	lngWinLeft= 0;

	// calculate Left and Top values to center new dialog
	divPopup.style.top  = (((lngWinHeight - lngHeight)/2) + lngWinTop)  + 'px';
	divPopup.style.left = (((lngWinWidth  - lngWidth )/2) + lngWinLeft) + 'px';

	// set this "id" to be the "current" id
	m_strCurrentWindowId = strWindowId;
	
	
	// some windows need special actions after display
	switch(strWindowId)
	{
	case 'createLightbox':
		var newLightbox = document.getElementById('newLightbox');
		if (newLightbox)
			newLightbox.focus();
		break;
	}
}

function hidePopup()
{
	// if a "window" is currently visible, hide it
	var divWindow = document.getElementById(m_strCurrentWindowId);
	if (divWindow)	divWindow.style.display = 'none';
	
	// hide the "popup" control
	var divPopup = document.getElementById('popup');
	if (divPopup)	divPopup.style.display = 'none';
	divPopup	 = document.getElementById('popup2');
	if (divPopup)	divPopup.style.display = 'none';
	divPopup	 = document.getElementById('popup3');
	if (divPopup)	divPopup.style.display = 'none';
}


// custom popup windows:
function loadSearchTips()
{
	var searchTips = document.getElementById('searchTips');
	if (searchTips)		searchTips.style.display = '';
}
function closeSearchTips()
{
	var searchTips = document.getElementById('searchTips');
	if (searchTips)		searchTips.style.display = 'none';
}
