function popupimg(img){
  foto1= new Image();
  foto1.src=(img);
  controle(img);
}
function controle(img){
  if((foto1.width!=0)&&(foto1.height!=0)){
    viewFoto(img);
  }
  else{
    functie="controle('"+img+"')";
    intervallo=setTimeout(functie,20);
  }
}
function viewFoto(img){
  largh=foto1.width+20;
  altez=foto1.height+30;
  stringa="width="+largh+",height="+altez;
  finestra=window.open(img,"Test",stringa);
}