﻿//*********************************************************
// 2008-09-29: ASC:
//	JavaScript part of experimental trace system
//	for Silverlight apps.
//	The trace file is stored in Silverlight isolated 
//	storage.  The system can show the contents of the 
//	trace file in an HTML window.
//
//*********************************************************
var _oWindow_TraceReportPopup = null;

var _strBigStringOfTraceText = "still empty";

//*******************************************************
function vFunctionToOpenTraceWindow(
	strBigStringOfTraceText_In 
	)
{
	//debugger;
	
	_strBigStringOfTraceText = strBigStringOfTraceText_In;

	var oWindow = _oWindow_TraceReportPopup;

	if( (oWindow != null) && (oWindow.closed == false) )
	{
		// 2008-09-24: ASC:
		//	We should be able to close this existing 
		//	popup window instance without
		//  any prompt from IE because we are the window
		//  that openned it originally.
		//
		oWindow.close();

		oWindow = null;
		_oWindow_TraceReportPopup = null;
	}
	
	if( oWindow == null || oWindow.closed )
	{
		oWindow = window.open( 
			// Technique 7B works fast too, but uses
			//	a lot more code than the document.write()
			//	technique used by TraceLogReportWindow.htm:
			//"TraceSystem_Window7B.htm"
			
			"TraceLogReportWindow.htm"
			);
		if( oWindow != null )
		{
			_oWindow_TraceReportPopup = oWindow;
			
			// 2008-09-24: ASC:
			// Is my rewriting of this condition correct?
			//if( oWindow.opener == null )
			if( !oWindow.opener )
			{	
				// 2008-09-24: ASC: Do we ever get here?
				//  Normally it should already be set
				//	to this.Window, since we just 
				//	created it.
				//
				alert( "@.114 oWindow.opener != null" );
				oWindow.opener = this.window; 
			}
		}
	}
	else
	{	// Get here if we previously openned a window
		//	and it is still open.
		
		debugger;
	}


// This doesn't work because you need to give the new window
//	time to load.  Instead we let TraceSystem_Window.htm
//	open and let it reach back to access our global variable 
//	_strBigStringOfTraceText (above).
//
//			if( oWindow != null )
//			{	var oPre = oWindow.document.getElementById(
//					"id_pre_ForTraceText" 
//					);
//				if( oPre != null )
//				{	debugger;
//				}
//			}

	//debugger;

}	// end function
