// One object tracks the current modal dialog opened from this window.
var dialogWin = new Object( );
function focus_SimDialog()
{ try { dialogWin.win.focus();} catch(e) {};
}  
function close_SimDialog()
{ //try { dialogWin.win.close(); } catch(e) {};
  window.detachEvent("onfocus",focus_SimDialog);  // 7/26/10
  var bg=GetElementById("pleasewait_bg",window.document);
  bg.detachEvent("onfocus",focus_SimDialog);
  window.focus();
  screen_greyout_cancel();
  bg=GetElementById("pleasewait_bg",window.top.left.document);
  bg.detachEvent("onfocus",focus_SimDialog);
  screen_greyout_cancel(window.top.left);
  dialogWin = new Object( );
}  
// Generate a modal dialog.
// Parameters:
//    url -- URL of the page/frameset to be loaded into dialog
//    width -- pixel width of the dialog window
//    height -- pixel height of the dialog window
//    returnFunc -- reference to the function (on this page)
//                  that is to act on the data returned from the dialog
//    args -- [optional] any data you need to pass to the dialog
function open_SimDialog(url, width, height, args) 
{  if(width == null) width=100;
   if(height== null) height=100;
    if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) 
	{	screen_greyout(false,window.top.left);
		screen_greyout(false);
// Initialize properties of the modal dialog object.
        dialogWin.url = url;
        dialogWin.name = "SimDialog";
        // Assemble window attributes and try to center the dialog.
        // Generate the dialog and make sure it has focus.
		dialogWin.win=window.open(dialogWin.url,dialogWin.name,"scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+screen.availWidth/4+",top="+screen.availHeight/2);//, attr
//cannot attach here, must attach to ssl task and post out to this one!!!!!!!!!!		
//		dialogWin.win.attachEvent("onunload",close_dialog);
		if(dialogWin.win)
		{  var bg=GetElementById("pleasewait_bg",window.document);
		   bg.attachEvent("onfocus",focus_SimDialog);
		   bg=GetElementById("pleasewait_bg",window.top.left.document);
		   bg.attachEvent("onfocus",focus_SimDialog);
		   window.attachEvent("onfocus",focus_SimDialog);	// 7/26/10
		   dialogWin.win.focus( );
		}
		else
		{  close_SimDialog();
   		   alert("ERROR: Your Browser is Blocking PopUps, which are needed to use this feature.\n\nYou MUST enable popups,\nthen close your browser and login again.\nProceeding from this point without them is impossible.\n\nThe HNS Licensing Team.");
		};
	} else {
        dialogWin.win.focus( );
    }
  return(dialogWin);	
}
 
