function popImage(img, title) {
  picfile = new Image();
  picfile.src = (img);
  fileCheck(img, title);
}

function fileCheck(img, title) { 	
  if( (picfile.width!=0) && (picfile.height!=0) ) {
    makeWindow(img, title);
  } else {
    funzione="fileCheck('"+img+"')";
    intervallo=setTimeout(funzione, 50);
  }
}

function makeWindow(img, title) { 	
  wd = picfile.width;
  ht = picfile.height;

  var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
  var args = "resizable=yes";
  if (window.screen) {
    var avwd = screen.availWidth;
    var avht = screen.availHeight;

    if (avwd < wd || avht < ht) { args += ",scrollbars=yes"; }

    var xcen = (avwd > wd) ? (avwd - wd) / 2 : 0;
    var ycen = (avht > ht) ? (avht - ht) / 2 : 0;
    args += ",left=" + xcen + ",screenX=" + xcen;
    args += ",top=" + ycen + ",screenY=" + ycen;	

    if (avwd < wd) { 
      wd = avwd;
      if (isIE) wd -= 12;
    }
    if (avht < ht) {
      ht = avht;
      if (isIE) ht -= 32;
    }
  }
  args += ",width=" + wd + ",innerWidth=" + wd;
  args += ",height=" + ht + ",innerHeight=" + ht;

  popwin = window.open(img, title+'_', args);
  popwin.document.open();
  popwin.document.write('<html><head><title>'+title+'</title></head><body style="margin:0px"><img src="'+img+'" border="0" onClick="window.close(); return true;" alt="Presione para cerrar"></body></html>');
  popwin.document.close();
}