/*
Add the following JavaScript from the line:

	<!-- Begin System Z JavaScript -->

thru the line:

	<!-- End of System Z JavaScript -->

////////////////////////////////////////
<!-- Begin System Z JavaScript -->
<script language="JavaScript">
<!--
var ZSessionStr = '__HTML_COOKIE__';
var ZSequenceStr = '__HTML_SEQUENCE__';
function onLoadZ()
{
	return onLoadNZ();
}
function onloadz() { return onLoadZ(); }
function onLoadz() { return onLoadZ(); }
function onloadZ() { return onLoadZ(); }
function OnLoadZ() { return onLoadZ(); }
function OnLoadz() { return onLoadZ(); }
function Onloadz() { return onLoadZ(); }
function ONLOADZ() { return onLoadZ(); }
//-->
</script>
<script language="JavaScript" src="/JavaScript/default.js"></script>
<!-- End System Z JavaScript -->
/////////////////////////////////////////

The System-Z Web Portal runtime must substitue the values of
__HTML_COOKIE__ and __HTML_SEQUENCE__ as it processes the page.
onLoadZ() must be referenced in the BODY tag.
The Web Portal runtime will automatically insert JavaScript code at the top
of this function to populate fields that are currently being input by
the System-Z application.
*/

var Submitted = false;
var ZSessionID = ZSessionStr.valueOf();
var ZSequence = ZSequenceStr.valueOf();
var ZLoaded = false;

// SubmitZ()
// Referenced in the FORM tag.
// This function sets the global Submitted to 1 so that when onUnloadZ() executes
// (e.g. the user hits the back button or jumps to a different URL), the
// page is not opened in a separate window.
//
function SubmitZ()
{
	if (ZSessionStr.search(/HTML_COOKIE/) >= 0
	||  ZSequenceStr.search(/HTML_SEQUENCE/) >= 0)
	{
		alert('Warning:\nThis is an unprocessed application page.\nThis sumbit will be ignored.');
		return false;
	}
	if (Submitted)
	{
		alert('Warning:\nThis page has already been submitted.\nThis submit will be ignored.');
		return false;
	}
   	if (!ZLoaded)
		onLoadZ();

	Submitted = true;
	return true;
}
function submitz() {return SubmitZ(); }
function submitZ() {return SubmitZ(); }
function Submitz() {return SubmitZ(); }
function SUBMITZ() {return SubmitZ(); }

// onNavigateZ()
// Refrenced in onLoadNZ() and in the BODY tag
// This function notifies the user that attempting to navigate away from
// a page produced by a System-Z application is not allowed because the
// application would lose its context.
//
function onNavigateZ()
{
	window.focus();
	alert("Error:\nThis context sensitive application page\nwill not function if displayed out of context.\nClosing this window.");
	return false;
}

// PostZ()
// Referenced in onUnloadZ()
// This function is used to assign a file to the hidden field, "cmd", and
// submit the page.
//
function PostZ(avalue)
{
	if (Submitted)
	{
		alert('Warning:\nThis page has already been submitted.\nThis submit will be ignored.');
		return false;
	}
	if (!ZLoaded)
		onLoadZ();
	Submitted = true;
	document.zform.cmd.value = avalue;
	document.zform.submit();
	return true;
}

function PickZ(run, lineno)
{
	if (Submitted)
	{
		alert('Warning:\nA selection has already been made\nand the page has already been submitted.\nThis submit will be ignored.');
		return false;
	}
	Submitted = true;
	link = run + '?session=' + ZSessionID + '&sequence=' + ZSequence
	           + '&lineno=' + lineno + '&fkey=' + 'OK';

	return link;
}

// onLoadNZ()
// Referenced by onLoadZ()
// This function verifies that this page was reached in the proper context
// of the underlying System-Z program.
//
function onLoadNZ()
{
	if (ZLoaded)
		return true;

	ZLoaded = true;

	// If window.opener is not null, then this window was opened by
	// another browser window.
	//
	if (window.opener)
	{
		// The "cmd=copywin" parameter indicates that this window was
		// generated as a copy of its parent window because the user
		// chose to navigate away from the parent.
		//
		if (window.location.search.search(/cmd=copywin/i) >= 0)
		{
			// If the parent is closed, assume that the parent page was
			// unloaded because the closed the browser.  Terminate the
			// System-Z application and close this window.
			//
			if (window.opener)
			{
				if (window.opener.closed)
				{
					if (confirm('Confirmation:\nOK to close this application?'))
					{
						PostZ('close');
						window.close();
						return false;
					}
				}
				else
					window.opener.focus();
			}
		}
		window.opener = null;
	}
	if (ZSessionStr.search(/HTML_COOKIE/) >= 0
	||  ZSequenceStr.search(/HTML_SEQUENCE/) >= 0)
	{
		alert('Information:\nThis is an unprocessed application page.');
		return true;
	}

	// If this is a new window or it's associated with a new System-Z
	// application session or the host site has changed, initialize
	// the navigator properties.
	//
	if (!navigator.ZSessionID
	||  navigator.ZHost != location.host
	||  navigator.ZSessionID != ZSessionID)
	{
		navigator.ZSessionID = ZSessionID;
		navigator.ZSequence = ZSequence;
		navigator.ZHost = location.host;
	}

	// If the System-Z application session ID doesn't match or
	// this page has the wrong session sequence number, assume
	// the this page was not displayed by the System-Z application.
	// Notify the user and close this window.
	//
	if (navigator.ZSequence != ZSequence)
	{
		onNavigateZ();
		Submitted = true;
		return window.close();
	}
	navigator.ZSequence++;	// Keep the session sequence number in sync
				// with the System-Z application.

	document.cookie='id=' + ZSessionID;
	//document.zform.cmd.value = 'none';

	if (document.zform.session)
		document.zform.session.value = ZSessionID;
	else
		document.zform.cookie.value = ZSessionID;

	if (document.zform.sequence)
		document.zform.sequence.value = ZSequence;

	return ZLoaded;
}

function erroroff(errtxt, errurl, errlin)
{
	return true;
}

function erroron(errtxt, errurl, errlin)
{
	return false;
}

// onUloadZ()
// Refrenced in the BODY tag.
// If the page is unloaded without being submitted
// (e.g. the user hits the back button or jumps to a different URL), then the
// global Submitted will not be set to 1.  A new window will be opened that
// will contain a copy of the current one.  Navigation will continue in the
// current window.
//
function onUnloadZ()
{
//	if (!ZLoaded)
//		onLoadZ();
//
//	if (!Submitted)
//	{
//	var currhref = '';
//
//		if (ZSessionStr.search(/HTML_COOKIE/) >= 0
//		||  ZSequenceStr.search(/HTML_SEQUENCE/) >= 0)
//		{
//		//	window.opener = null;
//		//	window.onerror = erroroff;
//		//	if (navigator.ZSequence)
//		//		navigator.ZSequence = -1;
//		//	window.onerror = erroron;
//			return true;
//		}
//		//currhref = location.pathname
//		//         + '?session='
//		//         + ZSessionID
//		//         + '&cmd=copywin';
//
//		//newWin = window.open(currhref);
//		//Submitted = true;
//
//		//window.history.go(1);	// Navigate to the requested page
//		//window.moveBy(32, 32);	// Offset the current window a bit.
//	}
	return true;
}
function onunloadz() { return onUnloadZ(); }
function onunLoadz() { return onUnloadZ(); }
function onunloadZ() { return onUnloadZ(); }
function OnunLoadZ() { return onUnloadZ(); }
function OnunLoadz() { return onUnloadZ(); }
function Onunloadz() { return onUnloadZ(); }
function onUnloadz() { return onUnloadZ(); }
function onUnLoadz() { return onUnloadZ(); }
function OnUnLoadZ() { return onUnloadZ(); }
function OnUnLoadz() { return onUnloadZ(); }
function OnUnloadz() { return onUnloadZ(); }
function ONUNLOADZ() { return onUnloadZ(); }
