var CurrWindow = null;

function Controlla(img, nomefinestra)
{
 if((foto1.width!=0)&&(foto1.height!=0))
  {
   viewimage(img, nomefinestra);
  }
 else
  {
   funzione="Controlla('"+img+"')";
   intervallo=setTimeout(funzione,20);
  }
}

function showimage(nomefile, nomefinestra)
{
 foto1= new Image();
 foto1.src=(nomefile);
 Controlla(nomefile,nomefinestra);
}

function ChiudiFinestraCorrente()
{
 if (CurrWindow != null) 
  CurrWindow.close();
}

function viewimage(nomefile, nomefinestra)
{
 largh = foto1.width + 20;
 altez = foto1.height + 20;
 
 stringa = "toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, width=" + largh + ",height=" + altez;
 
 ChiudiFinestraCorrente();
 
 //if (CurrWindow != null)
 // {
 //  CurrWindow.close();	
   //alert('Vecchia finestra chiusa!');
 // }
 //else
 // {
   //alert('Nessuna finestra aperta trovata!');
 // }
  
 CurrWindow = window.open(nomefile, 'foto', stringa);  
 CurrWindow.focus();
}


