/**
Author: Ng, Chun-Kwong
File name: popbox.js

By getting the values of three variables from the user to run this script.
First variable: image file location, e.g. ('../image.jpg').
Second variable: screen width, e.g. (800).
Third variable: screen height, e.g. (600).

To use this script, plugin the lines below into your html code:
Inside the <header> tag:
<script language="JavaScript" type="text/javascript" src="popbx.js"></script>
Inside the <body> tag:
<a href="javascript:openBox('image.jpg',800,600);"><img src="myimage.jpg"></a>
Or:
<a href="javascript:openDisplay('image.jpg',800,600);"><img src="myimage.jpg"></a>
*/

// test browser for script runability
var browserName = navigator.appName;
var browserVersion = parseInt(navigator.appVersion);
var passTest = false;

if (browserName == "Microsoft Internet Explorer" && browserVersion >= 4)
  passTest = true;
else if	(browserName == "Netscape" && browserVersion >= 3)
  passTest = true;

function openBox(displayImage, screenWidth, screenHeight) {
  var screenSize = "width="+screenWidth+","+"height="+screenHeight;
  var screenOption = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes,"+screenSize;
  var display = window.open(displayImage,"Enlarge",screenOption);
  if (passTest) {
    display.focus();
  }
}

function openDisplayOLD(displayImage, screenWidth, screenHeight) {
  var screenSize = "width="+screenWidth+","+"height="+screenHeight;
  var screenOption = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,"+screenSize;
  var display = window.open(displayImage,"Enlarge",screenOption);
  if (passTest) {
    display.focus();
  }
}

function openDisplay(url, w, h)
{
  
  myImage = new Image()
  myImage.src = url

if (myImage.width != 0){
  w = myImage.width
  h = myImage.height
}
  w += 25;
  h += 70;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  var win = window.open(url, "details", 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}
