function getWindowSize(){
    var wsize={height:0,width:0};

    var d=document;
    if (typeof window.innerWidth!='undefined')
    {
       winWidth = window.innerWidth;
       winHeight = window.innerHeight;
    }
       else
    {
       if (d.documentElement && (typeof d.documentElement.clientWidth != 'undefined') && (d.documentElement.clientWidth != 0))
       {
           winWidth = d.documentElement.clientWidth;
           winHeight = d.documentElement.clientHeight;
       }
       else
       {
           if (d.body && (typeof d.body.clientWidth != 'undefined'))
           {
               winWidth = d.body.clientWidth;
               winHeight = d.body.clientHeight;
           }
       }
    }
    wsize.width=winWidth;
    wsize.height=winHeight;
    return wsize;
}

function openImageWindow( img, name, width, height ) {
  var sz=getWindowSize();
  
  var imw=width;
  var imh=height;
  
  width=width+10;
  height=height+10;

  if (width>sz.width) width=sz.width;
  var left=(sz.width-width)/2;
  if (height>sz.height) height=sz.height;
  var top=(sz.height-height)/2;

  var pars="left="+left+",top="+top+",width=" +width+ ",height=" +height+ ",toolbar=0,location=0,directories=0,menubar=0,resizable=1,status=1,dialog=yes,modal=yes,minimizable=no,scrollbars=yes"
  var win = window.open( "", "image_show_window", pars );
  win.document.writeln( "<html>" );
  win.document.writeln( "  <head><title> " + name + " </title></head>" );
  win.document.writeln( "  <body style='margin: 0px; padding: 5px;'>" );
  win.document.writeln( "    <a href='Javascript:window.close();'><img src='" + img + "' border='0'/></a>" );
  win.document.writeln( "  </body>" );
  win.document.writeln( "</html>" );
  win.document.close();

  return true;
}