// Popup Window class.
// PopUpWindow creates the necessary object to handle.
// the popup window routines.  This is not designed to replace the popup server and popup client.
// combination but rather to provide a flexible way of opening generic windows.
//
// 
//	this.handle = null;
//	this.scrollBars = show scroll bars on popup window.
//	this.resizable = popwindow is resizable.
//	this.menuBar = show the menu bar on the window.
//	this.statusBar = show the status bar on the window.
//	this.modal = flag for the check routine.  If true the focus with be set on the popup
//	this.name = this is the name of the window.  If not unique the all windows will be open in the same space.
//

function PopUpWindow(windowName){
	this.initPopUp(windowName);
}

function PopUpWindow_Initialize(windowName) {
	this.handle = null;
	this.resizable = "no";
	this.width = 100;
	this.height = 100;
	this.menuBar = "no";
	this.statusBar = "no"; 
	this.location = "no";
	this.toolBar = "no";
	this.scrollBars = "no";
	this.modal = true;
	this.name = windowName;	
	this.isNav = navigator.userAgent.indexOf("MSIE") == -1;
}
	
function PopUpWindow_Reset(){
// reset the window properties.

	this.scrollBars = "no";
	this.resizable = "no";
	this.width = 100;
	this.height = 100;
	this.menuBar = "no";
	this.statusBar = "no"; 
	this.modal = true;
}	

function PopUpWindow_OpenModal(file2open,width,height){
// shortcut for opening a modal type window.

	this.reset();
	this.open(file2open,width,height);
}

function PopUpWindow_OpenNonModal(file2open,width,height){
//  short cut for opening a specific type of window

	this.reset();
	this.modal = false;
	this.scrollBars = "yes";
	this.statusBar = "yes";
	this.resizable = "yes";
	this.open(file2open,width,height);
}

function PopUpWindow_Open(file2open,width,height) {
// open a window centered on the parent window.

	this.height = height;
	this.width = width;
	
	if (this.handle != null) {
//		if (!this.handle.closed) {
			this.handle.close()
			};
//		};
						
	var top = window.screen.availHeight/2 - height/2;
	var left = window.screen.availWidth/2 - width/2;

	if (this.isNav) {
		top = ",screeny=" + top;
		left = ",screenx=" + left;
	} else {
		top = ",top=" + top;
		left = ",left=" + left;
	}
	self.childClosing = false;	
	this.handle=window.open(file2open,this.name,"titlebar=yes,menubar=" + this.menuBar +",status=" + this.statusBar + ",location=" + this.location + ",toolbar=" + this.toolBar + ",scrollbars=" + this.scrollBars + ",resizable=" + this.resizable + ",height=" + this.height + ",width=" + this.width + top + left);
//	this.handle.parentClosing = false;
//	this.handle.focus();
};
			

function PopUpWindow_Check(){
// this routine is called by the body onfocus event of the parent window.
// and set the focus to the popup window if not closing and is modal.

	if (this.handle != null) {
		if (this.modal && self.childClosing != true) {
			if (this.handle != null) {
				if (!this.handle.closed) {
					this.handle.focus();
				}
			}
		}
	}
}

function PopUpWindow_Message(msg){
// display small message window.
	
	this.reset();
	this.open("",120,100);
	with (this.handle.document) {
		open();
		writeln("<html>");
		writeln("<head><title>Message</title>");
		writeln("<style>");
		writeln("body {");
		writeln("	BACKGROUND-COLOR: SILVER;");
		writeln("	BORDER-BOTTOM: medium none;");
		writeln("	BORDER-LEFT: medium none;");
		writeln("	BORDER-RIGHT: medium none;");
		writeln("	BORDER-TOP: medium none;");
		writeln("   BORDERBOTTOMWIDTH: 0;");
		writeln("	FONT-FAMILY: arial,helvetica;");
		writeln("	FONT-SIZE: 10pt;");
		writeln("	MARGIN-LEFT: 5px;");
		writeln("	MARGIN-TOP: 5px");
		writeln("}");
		writeln("</style>");
		writeln("</head>");
		writeln("<body onUnload='if (!self.parentClosing){self.opener.closing=true}'><center><br>");
		writeln("<b>" + msg + "</b>");
		writeln("<br><img src='images/hourglass.gif'>");
		writeln("</center>");
		writeln(String.fromCharCode(60) + 'script language="javascript">');
		writeln('function isOrphaned(){');
//		writeln('alert(self.opener.closed)');
//		writeln('if (self.opener.closed) {;');
		writeln('   self.parentClosing = true;');
//		writeln('   self.close()');
//		writeln('}');
		writeln('} ');
//		writeln('setInterval("isOrphaned()","1000")');
		writeln(String.fromCharCode(60) + '/script>');
		writeln("</body>");
		writeln("</html>");
		close();
	}
}
			
function PopUpWindow_Close(){
// close popup.
		
	if (this.handle != null) {
		if (!this.handle.closed) {
			if (!self.childClosing) {
				this.modal = false;
				this.handle.parentClosing = true;
				this.handle.close()
			}
		}
	}
	this.handle = null;
}

function PopUpWindow_IsNav(){
	return this.isNav;
}

PopUpWindow.prototype.initPopUp = PopUpWindow_Initialize;
PopUpWindow.prototype.message = PopUpWindow_Message;
PopUpWindow.prototype.open = PopUpWindow_Open;
PopUpWindow.prototype.close = PopUpWindow_Close;
PopUpWindow.prototype.check = PopUpWindow_Check;
PopUpWindow.prototype.reset = PopUpWindow_Reset;
PopUpWindow.prototype.openModal = PopUpWindow_OpenModal;
PopUpWindow.prototype.openNonModal = PopUpWindow_OpenNonModal;
PopUpWindow.prototype.isNav = PopUpWindow_IsNav;


function openNewPopUp( pageName, x, y )
{
  var popUp = new PopUpWindow("popup");	
  popUp.scrollBars = "no";
  popUp.open( pageName, x, y );
}

function openSecurePopUp( pageName, x, y )
{
  var popUp = new PopUpWindow("login");	
  popUp.scrollBars = "no";
  popUp.statusBar = "yes";
  popUp.open( pageName, x, y );
}

function openSecureScrollPopUp( pageName, x, y )
{
  var popUp = new PopUpWindow("secure");	
  popUp.scrollBars = "yes";
  popUp.statusBar = "yes";
  popUp.open( pageName, x, y );
}

function openNewScrollPopUp( pageName, x, y )
{
  var popUp = new PopUpWindow("popup");	
  popUp.scrollBars = "yes";
  popUp.open( pageName, x, y );
}

function openNewWindow(pageName,x,y)
{
  	var popUp = new PopUpWindow("popup");	
	popUp.scrollBars = "yes";
	popUp.menuBar = "yes";
	popUp.statusBar = "yes"; 
	popUp.resizable = "yes";
   popUp.open( pageName, x, y );
}

function openNamedPopUp( windowName, pageName,x,y)
{
  	var popUp = new PopUpWindow(windowName);	
	popUp.scrollBars = "yes";
	popUp.menuBar = "yes";
	popUp.statusBar = "yes"; 
	popUp.resizable = "yes";
   popUp.open( pageName, x, y );
}