// Image popup window function with auto-resize
function PopupImage(imageURL,imageTitle,imageWidth,imageHeight)
{
	// Default image width and height values
	imageWidth = (typeof(imageWidth)!='undefined')?imageWidth:0;
	imageHeight = (typeof(imageHeight)!='undefined')?imageHeight:0;
	
	// Set the horizontal and vertical position for the popup
	if (imageWidth==0 && imageHeight==0)
	{
		PositionX = 100;
		PositionY = 100;
	}
	else
	{
		PositionX = (screen.width - imageWidth)/2;
		PositionY = (screen.height - imageHeight)/2;
	}

	var option = 'scrollbars=no,width=700,height=500,left='+PositionX+',top='+PositionY;
	imgWin = window.open('about:blank','',option);
	if ( !imgWin ) 
	{ 
		return true; 
	}
	with ( imgWin.document )
	{
		writeln('<html><head><title>'+imageTitle+'</title><style>body{margin:0px;}</style>');
		writeln('<sc'+'ript>');
		writeln('function ResizeToImage()');
		writeln('{');
		writeln('		var oH = document.images[0].height; ');
		writeln('		var oW = document.images[0].width; ');
		writeln('		var x = window; ');
		writeln('		x.resizeTo( oW + 200, oH + 200 ); ');
		writeln('		var myW = 0; ');
		writeln('		var myH = 0; ');
		writeln('		d = x.document.documentElement; ');
		writeln('		b = x.document.body; ');
		writeln('		if  ( x.innerWidth ) ');
		writeln('		{ ');
		writeln('			myW = x.innerWidth; ');
		writeln('			myH = x.innerHeight; ');
		writeln('		} ');
		writeln('		else if ( d && d.clientWidth ) ');
		writeln('		{ ');
		writeln('			myW = d.clientWidth; ');
		writeln('			myH = d.clientHeight; ');
		writeln('		} ');
		writeln('		else if ( b && b.clientWidth ) ');
		writeln('		{ ');
		writeln('			myW = b.clientWidth; ');
		writeln('			myH = b.clientHeight; ');
		writeln('		} ');
		writeln('		if ( window.opera && !document.childNodes ) ');
		writeln('		{ ');
		writeln('			myW += 16; ');
		writeln('		} ');
		writeln('		x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) ); ');
		writeln('	 	var scW = screen.availWidth ? screen.availWidth : screen.width; ');
		writeln('		var scH = screen.availHeight ? screen.availHeight : screen.height; ');
		writeln('		if ( !window.opera ) ');
		writeln('		{ ');
		writeln('			x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); ');
		writeln('		} ');
		writeln('} ');
		writeln('</sc'+'ript>');
		writeln('</head><body bgcolor="FFFFFF" scroll="no" onload="ResizeToImage();self.focus();">')
		if (imageWidth==0 && imageHeight==0)
		{
			writeln('<img onclick="self.close()" src="'+imageURL+'" style="display:block" alt="'+imageTitle+'">');
		}
		else
		{
			writeln('<img onclick="self.close()" src="'+imageURL+'" style="display:block" alt="'+imageTitle+'" width="'+imageWidth+'" height="'+imageHeight+'" >');
		}
		writeln('</body></html>');
		close();
	}
}

