//These are the global container for the currently selected options
var g_eventType		= 'all';
var g_nameSpace		= 'any';
var g_specificFile	= '';

//
function setEventType(eventType) {
	g_eventType = eventType;
	generateLink( );	
}

//	
function setNameSpace(nameSpace) {
	g_nameSpace = nameSpace;
	generateLink( );	
}

//	
function setSpecificFile(fileName) {
	g_specificFile = fileName;
	if (g_specificFile == '') {
		currentAdvFilter.innerHTML = "Not filtering entries based on a specific filename.";
	}
	else {
		currentAdvFilter.innerHTML = "Show only the entries originating from the file '<b>" + g_specificFile + "</b>'."
	}
	generateLink( );	
}

//
function generateLink( ) {
	var linkText = "<br>";
	linkText = linkText + "<a href=\"javascript:onViewLog( );\">";
	linkText = linkText + "<font size=\"2\" face=\"Arial\" color=\"#2060AA\">";
	linkText = linkText + "<i>";
	linkText = linkText + "Click here to generate a report showing events of type '<b>" + g_eventType + "</b>' ";

	if (g_specificFile == '') {
		linkText = linkText + "from <b>all files</b> in the code namespace '<b>" + g_nameSpace + "</b>'.";
	}
	else {
		linkText = linkText + "from <b>'";
		linkText = linkText + g_specificFile;
		linkText = linkText + "'</b> in the code namespace '<b>" + g_nameSpace + "</b>'.";
	}

	linkText = linkText + "</i>";
	linkText = linkText + "</font>";
	linkText = linkText + "</a>";
	linkText = linkText + "<br>";
	linkText = linkText + "<br>";
	
	//Commit the compiled string to the display
	eventTypeLabel.innerHTML = linkText;
}

// Global vars for usage
var xmlDoc = null;
var xslDoc = null;
var xslProcessor = null;
var xmlOutput = null;
	
//	
function onViewLog_IE() {
	// IE code
	xmlDoc = new ActiveXObject( "MSXML2.DOMDocument.3.0" );
	xslDoc = new ActiveXObject( "MSXML2.FreeThreadedDOMDocument.3.0" );
	var xslTemplate = new ActiveXObject( "MSXML2.XSLTemplate.3.0" );

	xmlDoc.async="false";
	xmlDoc.load( 'Log.xml' );

	xslDoc.async="false";
	xslDoc.load( 'Log.xsl' );

	xslTemplate.stylesheet = xslDoc;

	xslProcessor = xslTemplate.createProcessor( );
	xslProcessor.input = xmlDoc;
	xslProcessor.addParameter( "eventType",		g_eventType );
	xslProcessor.addParameter( "nameSpace",		g_nameSpace );
	xslProcessor.addParameter( "specificFile",	g_specificFile );
	xslProcessor.transform();

	logview.innerHTML = xslProcessor.output;
}

//
function onViewLog_Mozilla() {
	// Do mozilla code
	xmlDoc = document.implementation.createDocument("", "", null);
	xmlDoc.load( 'Log.xml' );
	xmlDoc.onload = readXML;
}

//
function readXML() {
	xslDoc = document.implementation.createDocument("", "test", null);
	xslProcessor = new XSLTProcessor();

	xslDoc.addEventListener("load", xslLoad, false);
	xslDoc.load( 'Log.xsl' );
}

//
function xslLoad() {
	xslProcessor.importStylesheet( xslDoc );
	
	xslProcessor.setParameter( "", "eventType",	g_eventType );
	xslProcessor.setParameter( "", "nameSpace",	g_nameSpace );
	xslProcessor.setParameter( "", "specificFile",	g_specificFile );

	xmlOutput = xslProcessor.transformToDocument( xmlDoc );

	var xmlSerializer = new XMLSerializer();
	logview.innerHTML = xmlSerializer.serializeToString( xmlOutput );
}

//
function onViewLog() {
	// Test for Mozilla
	var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');

	if (moz) {
		onViewLog_Mozilla();
	}
	else {
		onViewLog_IE();
	}
}
