var dlg, dlg_eval, dlg_val;

// open a new dialog window
function dlg_open(url,width,height,return_eval) {	
  dlg_eval=return_eval;
  	    
  var sx=(screen.availWidth-width)/2, sy=(screen.availHeight-height)/2;                    
  dlg = window.open(url,"Dialog","left="+sx+",top="+sy+",directories=no,width="+width+",height="+height+",location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no,status=no");
	dlg.focus();
}

// close an open dialog window
function dlg_close() {
	if (dlg != null) dlg.close();
}

// called by dialog window when returning a value
function dlg_return(val) {  
	dlg_close();
    dlg_val=val;
    eval(dlg_eval);
}

// release dialog
function dlg_release() {
	dlg = null;
}

// refreshing or clicking on the browser window will close the dialog harmlessly
window.onunload = dlg_close;
window.onfocus = dlg_close;
