var pop = null;

function popdown() {
  if (imgWin && !imgWin.closed) imgWin.close();
}


window.onunload = popdown;
window.onfocus = popdown;

function popUpImg(img,title,w,h) {

   myImg = new Image();
   myImg.src = img;
/*   var width = myImg.width;
   var height = myImg.height;*/
      var width = w;
   var height =h;
   LeftPos=(screen.width) ? (screen.width-width)/2 :0;
   TopPos=(screen.height) ? (screen.height-height)/2 :0;
   imgWin = window.open('', 'imgWinName', 'width=' + width + ', height=' + height +',top='+TopPos+',left='+LeftPos);
 
   with (imgWin.document) {
      open();
      write('<HTML>');
      write(' <HEAD>');
      write(' <title>'+title+'</title>');
      write(' </HEAD>');
      write(' <BODY style="margin: 0px;" onLoad="self.focus();">');
      write(' <a href="" onClick="JavaScript:self.close()">')
      write(' <img src="' + img + '" alt="popUpImage"  border="0"></a>');
      write(' </BODY>');
      write('</HTML>');
      close();
   }
   
 if (imgWin) return false;

} 