/**
 *	@file		JS for pages.
 *
 *	@brief		Open pop up window for show images.
 *
 *	@copyright	Copyright(C) 2007 Pantacle, All Rights Reserved.
 *	@copyright	Copyright(C) 2007 Kawanagare workshop, All Rights Reserved.
 */

Event.observe( window, 'unload', __prdfwc_view_images_window_onunload, false );

var g_prdfwc_view_images_window = null;

function __prdfwc_view_images_window_onunload()
{
	if ( g_prdfwc_view_images_window && ! g_prdfwc_view_images_window.closed )
	{
		g_prdfwc_view_images_window.close();
	}
}

function prdfwc_open_view_images_window( aURL, aLabel, aWidth, aHeight )
{
	var width = 0;
	var height = 0;
	var scrollbar = 0;

	if ( aWidth != 0 )
	{
		var limit = screen.width - 120;
		width = aWidth + 20;
		if ( width > limit )
		{
			width = limit;
			scrollbar = 1;
		}
	}
	if ( aHeight != 0 )
	{
		var limit = screen.height - 120;
		height = aHeight + 20;
		if ( height > limit )
		{
			height = limit;
			scrollbar = 1;
		}
	}

	var winpara = '';
	if ( width != 0 )
	{
		winpara = winpara + 'width=' + width + ',';
	}
	if ( height != 0 )
	{
		winpara = winpara + 'height=' + height + ',';
	}
	winpara = winpara + 'status=0,scrollbars=' + scrollbar + ',menubar=0,location=0,toolbar=0,resizable=1';

	if ( g_prdfwc_view_images_window && ! g_prdfwc_view_images_window.closed )
	{
		g_prdfwc_view_images_window.close();
	}

	g_prdfwc_view_images_window = window.open( '', 'image', winpara );
	g_prdfwc_view_images_window.document.write('<html>');
	g_prdfwc_view_images_window.document.write('<head>');
	g_prdfwc_view_images_window.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');
	g_prdfwc_view_images_window.document.write('<title>' + aLabel + '</title>');
	g_prdfwc_view_images_window.document.write('</head>');
	g_prdfwc_view_images_window.document.write('<body style="margin:0;padding:10;">');
	g_prdfwc_view_images_window.document.write('<img src="' + aURL + '" />');
	g_prdfwc_view_images_window.document.write('</body>');
	g_prdfwc_view_images_window.document.write('</html>');
	g_prdfwc_view_images_window.document.close();

	g_prdfwc_view_images_window.focus();
}
