
function PopWinScroll( URL, width, height ){
  // poiché dopo c'è l'attributo scrollbars impostato a yes, 
	// devo calcolare la larghezza della barra verticale
	// su Explorer
	if ( navigator.appName.indexOf('Microsoft') != -1 ) {
    width += 16;
  }
	
	var x = screen.width;
	var y = screen.height;

  // chiudi pop-up se aperto precedentemente
	if ( (myWin) && (!myWin.closed) ) {
	  if (debug) debugMsg('Chiudo il popup...');  // Info x debug
	  CloseWin();
	}

  // attributi per pop-up
  var attr = "top=" + parseInt( (y-height)/1.6 ) + ",left=" + parseInt( (x-width)/2 );
	attr += ",width=" + width + ",height=" + height + ",scrollbars=yes,resizable=no";
	
	if ( URL.substring( 0, 1 ) == "#" ) {
	  URL = URL.substr(1);
		myWin = window.open('', 'thewin', attr);
		myWin.document.write(URL);
	}
	else {
    if (debug) debugMsg('Riapro il popup');  // Info x debug
	  myWin = window.open(URL, "thewin", attr);
	}
	// alla chiusura della finestra aggiorna il riferimento
	window.onunload = CloseWin;
	// porta in primo piano
	myWin.focus();
	if (debug) debugMsg('');  // Info x debug
}

function debugMsg( msg ) {
  if ( msg == "" ) {
    debugWin.document.writeln( "myWin: *" + myWin + "*<br>" );
	}
	else {
	  debugWin.document.writeln( msg + '<br>' );
	}	
}

function CloseWin() {
  if (debug) debugMsg('Metodo CloseWin');  // Info x debug
  if ( (myWin) && (!myWin.closed) ) {
	  myWin.close();
		myWin = null;
	}
	if (debug) debugMsg('');		 // Info x debug
}

{ // Creo riferimento alla finestra pop-up
  var myWin = null;
	var debug = false;

  // Info x debug
	if (debug) var debugWin = window.open('', '', 'width=200,height=100,scrollbars=yes,resizable=no');
  if (debug) debugWin.document.write('Inizio debug<br>----------<br>');
  if (debug) debugMsg('');
}