// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// IF CHANGED, CHANGE ALSO LITERAL COPY IN PE HELPS.JS
// Revised for PE 2.728 for cross-browser function.
// See tests in 3f/javascri/apoptose.htm
// Results (these work without generating a js error):
//	Value of opener.variablename becomes undefined in IE and N4.8
//	opener.window.closed becomes true in IE
//	(opener == null) is true in FF, N7, Moz, IE, N4.8 if there never was an opener.
//	(opener == null) becomes true on closing the opener only in FF, N7, Moz



// IF DOCUMENT USING APOPTOSE IS NOT IN A WINDOW NEWLY OPENED BY
// window.open(), IT MUST BE IN A NEW TARGET WINDOW (ELSE OLD WINDOW
// MAY INDEED HAVE AN OPENER!)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// apoptose: child windows should expire when opener is gone.

function apoptose()
{
	// If the document has no opener at the outset, don't start the timer.

	// If top.opener is undefined, top.opener.top creates a js error.
	// so ref only opener.top. That works only if the opener formerly
	// existed and then was closed (e.g. pe_tut.htm). If the opener
	// never existed, typeof(opener.top) creates a js error.
	// However if the opener never existed, opener==null is TRUE! (no js error).

//	alert("opener=" + opener); // null or object
//	alert("typeof(opener)=" + typeof(opener)); // object regardless
//	alert("opener=='null' " + (opener==null));
	
		if (opener != null)
			setInterval("close_if_opener_gone()", 1000);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//var apcount = 0;

function close_if_opener_gone()
{
//	alert(typeof(top.opener)); real messy hard to kill loop
//	window.status = apcount++ + ": " + typeof(top.opener); // WORKS!
	
	// the terminal .top is needed here to detect window closing.
	// This worked in N4 but not in FF
//	if (typeof(opener.top) == "undefined")
//		top.window.close();

	// GECKO: use (opener == null)
	if (navigator.userAgent.toLowerCase().indexOf("gecko") != -1)
	{
		if (opener == null)
			top.window.close();
	}

	// IE, N4.8
	// In N4.8, top.opener.top.x and opener.top.x make js errors after closing.
	// opener.x is not an error, but doesn't work!
	// In N4.8 (opener.pe_version == "undefined") remains false, while
	// (opener.pe_version == undefined) goes true.
	else
	{
		if (opener.pe_version == "undefined" || opener.pe_version == undefined)
			top.window.close();
//		else if (confirm(opener.pe_version + " " + (opener.pe_version == undefined)))
//			top.window.close();
	}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
