//show_picture-PV-CLASSIC-V3.40.00
//No customization required
//
// JavaScript Document
// Opens new window without menus to display a picture
// typically used to enlarge a thumbnail
// 
// THE PICTURE FILENAME IS CASE SENSITIVE, INCLUDING THE EXTENSION
// in other words, referencing picture.jp will not work if the filename is picture.JPG
//
// The lay-out is defined in the file _show_picture.php
// the width and height of the window are defined in common_php_variables-C.php
//
// Insert the following as a link:
// 			javascript:show_picture(picture,caption,width,height)
//
// caption, width and height are optional
// default width and height are set in the code,
// The width and height are computed as follows:
// - if the width and height are defined in the arguments, they will be used
// - if they are not defined, the script will look for dimensions in the picture filename (see examples)
// - if there are none in the filename, the script will fall back to the default values
// WARNING: putting ONLY COMMAS DOES NOT WORK. YOU MUST ENTER a numerical value (0 for default) 
//
// Examples:
// 			javascript:show_picture('pictures/photo.JPG')
// 			javascript:show_picture('pictures/photo.JPG','Caption',0,0,'yes')
// 			javascript:show_picture('pictures/photo.JPG','Caption on top',800,550)
// 			javascript:show_picture('pictures/photo_600x450.JPG')
// 			javascript:show_picture('pictures/photo_600x450.JPG','Caption on top')

function show_picture(picture,caption,width,height,scrollbars) {
if (isUndefined(width)) {
	var Wwidth = extractWidth(picture);
	var width = 0;
}
else {
	var Wwidth = width;
}
if (Wwidth < 120) {
	var Wwidth = 600;
}
if (isUndefined(height)) {
	var Wheight = extractHeight(picture);
	var height = 0;
}
else {
	var Wheight = height;
}
if (Wheight < 90) {
	var Wheight = 450;
}
if ((width > 800) || (height > 600) || (scrollbars == 'yes')) {
	var scrollbars = 'yes';
}
else var scrollbars = 'no';
if (isUndefined(caption)) {
	var caption = ''; var Wheight = Number(Wheight) - 12;
}
var Wwidth = Number(Wwidth) + 48;
var Wheight = Number(Wheight) + 110;
var newWindow = window.open('_show_picture.php?pic=' + picture + '&cap=' + escape(caption) + '&w=' + width + '&h=' + height,'PVpicture','scrollbars=' + scrollbars + ',menubar=no,height=' + Wheight + ',width=' + Wwidth + ',resizable=no,toolbar=no,location=no,status=no');
newWindow.focus ( );
}

function isUndefined(a) {
    return typeof a == 'undefined';
} 

// PV - extracts the width and height of a filename formatted as filename_WWWxHH.jpg
// example: pictures/monflanquin_600x350.jpg
// returns -1 if not found
function extractWidth(filename) {
var x = filename.lastIndexOf('x');
var start = filename.lastIndexOf('_',x) + 1;
if ((x < 0) || (start < 0)) {
	return -1;
}
else return filename.slice(start,x);
}
function extractHeight(filename) {
var x = filename.lastIndexOf('x');
var end = filename.indexOf('.',x);
if ((x < 0) || (end < 0)) {
	return -1;
}
return filename.slice(x + 1, end);
}
	