//<script language="JavaScript">

//
// Client-side class that manages dialog windows.
//
// Dependencies:
//	Win.js
//
//

function initDialog()
{
	// Public methods
	Dialog.open = _Dlg_open;
	Dialog.openWait = _Dlg_openWait;
	Dialog.close = _Dlg_close;
	
	// Get/set the data to be used by the opened dialog.
	// Typically, the opener sets and the dialog gets.
	Dialog.getInData = function() { return Dialog._inData; }
	Dialog.setInData = function( v ) { Dialog._inData = v; }

	// Get/set the data to be returned by the opened dialog.
	// Typically, the dialog sets and the opener gets.
	Dialog.getOutData = function() { return Dialog._outData; }
	Dialog.setOutData = function( v ) { Dialog._outData = v; }
	
	// Set the callback function invoked via Dialog.onReturn().
	Dialog.setReturnFunc = function ( f ) { Dialog._retFunc = f; }
	
	// Invoke the optional callback function.
	// Typically called when dialog's OK button is pressed.
	Dialog.onReturn = _Dlg_onReturn;
	
	// Block/unblock window events in opener.
	Dialog.blockEvents = _Dlg_blockEvents;
	Dialog.unblockEvents = _Dlg_unblockEvents;
	
	// Private methods.
	Dialog._deadend = _Dlg_deadend;
	Dialog._checkModal = _Dlg_checkModal;
	Dialog._finishChecking = _Dlg_finishChecking;
	
	// State
	Dialog._win = null;
	Dialog._retFunc = null;
	Dialog._inData = null;
	Dialog._outData = null;
	Dialog._args = null;
	Dialog._url = "";
	Dialog._left = 0;
	Dialog._top = 0;
	Dialog._width = 0;
	Dialog._height = 0;
	Dialog._name = "";
	
	Dialog._ieLinkClicks = null;
	
	// Browser version.
	Dialog._nn4 = (navigator.appName=="Netscape") && (parseInt(navigator.appVersion)>=4);
}

// Constructor.
function Dialog() {}


function _Dlg_open( url, w, h, retFunc, args )
{

	var win = Dialog._win;
	if (!win || (win && win.closed)) 
	{
		// Initialize.
		Dialog._retFunc = retFunc;
		Dialog._outData = null;
		Dialog._args = args;
		Dialog._url = url;
		Dialog._width = w;
		Dialog._height = h;
		Dialog._name = new Date().getSeconds().toString();

		var left;
		var top;
		var attr = "";
		if (Dialog._nn4)
		{
			left = window.screenX + ((window.outerWidth - w) / 2);
			top = window.screenY + ((window.outerHeight - h) / 2);
			attr = "screenX=" + left + 
					",screenY=" + top +
					",resizable=no" + 
					",width=" + w +
					",height=" + h
			;
		}
		else
		{
			left = (screen.width - w) / 2;
			top = (screen.height - h) / 2;
			attr = "left=" + left + 
					",top=" + top +
					",resizable=no" + 
					",width=" + w +
					",height=" + h
			;
		}		
		
		// Open the window.
		win = window.open( url, Dialog._name, attr );
		Dialog._win = win;
		
	}	
	// Ensure window has focus.
	win.focus();
	
	return win;
}

// Close the dialog window.
function _Dlg_close() 
{
	var win = Dialog._win;
	if (win && !win.closed)
		win.close();
}

// Block main window's events.
function _Dlg_blockEvents() 
{
	Win.blockEvents( Dialog._checkModal );
}

// As dialog closes, restore the main window's original
// event mechanisms.
function _Dlg_unblockEvents() 
{
	Win.unblockEvents();
}

// Event handler to inhibit Navigator form element
// and IE link activity when dialog window is active.
function _Dlg_deadend()
{
	if (Dialog._win && !Dialog._win.closed)
	{
		Dialog._win.focus();
		return false;
	}
}

// Invoked by onFocus event handler of EVERY frame,
// return focus to dialog window if it's open.
function _Dlg_checkModal() 
{
	window.setTimeout( "_Dlg_finishChecking()", 50 );
	return true;
}
function _Dlg_finishChecking() 	
{
	if (Dialog._win && !Dialog._win.closed) 
		Dialog._win.focus();
}

// Called by dialog window when it returns.
function _Dlg_onReturn()
{
	if (Dialog._retFunc) 
		Dialog._retFunc();
}

function _Dlg_openWait()
{

	var s = 
	'<html><head><link REL="STYLESHEET" HREF="/CorpTrip3/styles/default.css" TYPE="text/css">' +
	'<script language="JavaScript">' +
	'function initialize()' +
	'{' +
		'if (opener && !opener.closed) ' +
		'{' +
			'opener.Dialog.blockEvents();' +
			'var a = opener.Dialog.getInData();' +
			'if (a != null)' +
			'{}' +
		'}' +
	'}' +
	'function terminate()' +
	'{' +
		'if (opener && !opener.closed) ' +
			'opener.Dialog.unblockEvents();' +
	'}' +
	'</scr' + 'ipt></head>' +
	'<body onload="initialize()" onunload="terminate()">' +
	'<span ID="WaitBlock">' +
		'<table border="0" VALIGN="CENTER" WIDTH="100%" HEIGHT="100%">' +
			'<tr>' +
				'<td ALIGN="CENTER">' +
					'<table WIDTH="400">' +
					'<tr>' +
						'<td align="center">' +
							'<img class="waitLogo" src="/CorpTrip3/images/shim.gif">' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td>' +
							'<center>' +
							'<span STYLE="display:block" ID="WaitText">Please wait....</span>' +
							'</center>' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td ALIGN="center">' +
							'<br>' +
							'<span style="display:block" id="WaitImg">' +
								'<img SRC="/CorpTrip3/images/waitPlane.gif" ALT="Please wait">' +
							'</span>' +
						'</td>' +
					'</tr>' +
					'</table>' +
				'</td>' +
			'</tr>' +
		'</table>' +
	'</span>' +
	'</body></html>'
	;

	var win = Dialog.open( '', 500, 350 );
	win.document.write( s );

}

initDialog();