function PopUp(img){
  foto1= new Image();
  foto1.src=(img);
  CheckImg(img);
}
function CheckImg(img){
  if((foto1.width!=0)&&(foto1.height!=0)){
    viewFoto(img);
  }
  else{
    functionname="CheckImg('"+img+"')";
    interval=setTimeout(functionname,20);
  }
}
function viewFoto(img){
  imgwidth=foto1.width+20;
  imgheight=foto1.height+20;
  dimensions="width="+imgwidth+",height="+imgheight;
  popup=window.open(img,"",dimensions);
}