function AutoResize(img, div){ 
  foto1= new Image(); 
  foto1.src=(img); 
  Controlla(img, div); 
} 
function Controlla(img, div){ 
  if((foto1.width!=0)&&(foto1.height!=0)){ 
    viewFoto(img, div); 
  } 
  else{ 
    funzione="Controlla('"+img+"')"; 
    intervallo=setTimeout(funzione,20); 
  } 
} 
function viewFoto(img, div){ 
	if (foto1.width > 1024){
		largh=1024;
	}else{
		largh= foto1.width + 20;
	}

	if (foto1.height > 768){
		altez= 768; 
	}else{
		altez= foto1.height + 4;
	}
  stringa="width="+largh+", height="+altez+", top=40, left=40, scrollbars=yes"; 
  finestra=window.open('/include/AuotoImg.asp?IMG='+ img,"",stringa); 
}