// IF CHANGED, CHANGE ALSO LITERAL COPY IN PE HELPS.JS

// 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.
	if (typeof(opener.top) == "undefined")
		top.window.close();
}
