var popup;

function openPopup( strUrl, strTitle, strFeatures )
{
	closePopupIfOpen();
	
	popup = window.open( strUrl, strTitle, strFeatures );
		
	return false;
}

function closePopupIfOpen()
{
	try
	{
		if ( popup.document.body )
			popup.close();
	}
	catch( e )
	{
		// Fail gracefully
	}
		
	return false;
}

function openDialog( strUrl, strTitle, iWidth, iHeight, bResizable, bScrollbars )
{
	if ( window.showModalDialog )
	{
		var strFeatures = "dialogWidth:" + iWidth + "px;dialogHeight:" + iHeight + "px";
		
		if ( bResizable )
			strFeatures += ";resizable:yes";
			
		if ( bScrollbars )
			strFeatures += ";scroll:yes";

		window.showModalDialog( strUrl, "", strFeatures );
	}
	else
	{
		var strFeatures = "width=" + iWidth + ",height=" + iHeight;
		
		if ( bResizable )
			strFeatures += ",resizable=1";
			
		if ( bScrollbars )
			strFeatures += ",scrollbars=1";

		openPopup( strUrl, strTitle, strFeatures );
	}
	
	return false;
}
