	//  platformMoz:  http://www.mozilla.org/projects/xslt/js-interface.html
	//  platformIE6:  http://www.perfectxml.com/articles/xml/XSLTInMSXML.asp

	var platformMoz = (document.implementation && document.implementation.createDocument);
	var platformIE6 = (!platformMoz && document.getElementById && window.ActiveXObject);
	var noXSLT      = (!platformMoz && !platformIE6);

	var msxmlVersion = '3.0';

	var urlXML;
	var urlXSL;
	var docXML;
	var docXSL;
	var txx_target;
	var txx_cache;
	var txx_XSLProcessor;   
	var txx_ready=1;
  var i;
  var t;

	var paramNames = new Array;
	var paramValues = new Array;
	var nParams;

	if (platformIE6)
	{
		// TODO... find out version of MSXML installed
		txx_cache = new ActiveXObject('Msxml2.XSLTemplate.' + msxmlVersion);
	}

	function Initialize()
	{
		if (noXSLT)
		{
			FatalError();
			return;
		}
		Defaults();
	}

	function Defaults()
	{
    SetTarget('target');
    SetInput('demo.xml');
    SetStylesheet('demo.xsl');
	}

	function SetTarget(id)
	{
		txx_target = document.getElementById(id);
	}

	function SetInput(url)
	{
		urlXML = url;
	}

	function SetStylesheet(url)
	{
		urlXSL = url;
	}

	function SetParam(name, value)
	{
		var found = false;

		for (i = 0; i< nParams; i++)
		{
			if (paramNames[i] == name)
			{
				paramValues[i] = value;
				found = true;
			}
		}
		if (!found)
		{
			NoSuchParam(name);
		}
	}

	function FatalError()
	{
		alert("Sorry, this doesn't work in your browser");
	}

	function NoSuchParam(name)
	{
		alert("There is no " + name + " parameter");
	}

	function CreateDocument()
	{
		var doc = null;

		if (platformMoz)
		{
			doc = document.implementation.createDocument('', '', null);
		}
		else if (platformIE6)
		{
			doc = new ActiveXObject('Msxml2.FreeThreadedDOMDocument.' + msxmlVersion);
		}
		return doc;
	}

	function Transform() 
	{
		if (noXSLT)
		{
			FatalError();
			return;
		} 
 		docXML = CreateDocument();
		docXSL = CreateDocument();
		
		if (platformMoz)
		{
			docXML.addEventListener('load', DoLoadXSL, false);
			docXML.load(urlXML);
		}
		else if (platformIE6)
		{
			docXML.async = false;
			docXML.load(urlXML);

			docXSL.async = false;
			docXSL.load(urlXSL);
 
			DoTransform();
		}
	}

  function DoLoadXSL()
  {
	  if (platformMoz)
	  {
		  docXSL.addEventListener('load', DoTransform, false);
		  docXSL.load(urlXSL);  
	  } 
  }

	function DoTransform() 
	{
		if (platformMoz)
		{
			txx_XSLProcessor = new XSLTProcessor();
			txx_XSLProcessor.importStylesheet(docXSL);

			AddParams(txx_XSLProcessor);

			var fragment = txx_XSLProcessor.transformToFragment(docXML, document);

			while (txx_target.hasChildNodes())
				txx_target.removeChild(txx_target.childNodes[0]);

			txx_target.appendChild(fragment);
		}
		else if (platformIE6)
		{
			txx_cache.stylesheet = docXSL;

			txx_XSLProcessor = txx_cache.createProcessor();
			txx_XSLProcessor.input = docXML;

			AddParams(txx_XSLProcessor);

			txx_XSLProcessor.transform();

			txx_target.innerHTML = txx_XSLProcessor.output;
		}                                  
		txx_ready=1;    
	}

	function AddParams(txx_XSLProcessor) 
	{
		for (i = 0; i< nParams; i++)
			if (paramValues[i] != '')
				AddParam(txx_XSLProcessor, paramNames[i], paramValues[i]);
	}

	function AddParam(txx_XSLProcessor, name, value) 
	{
		if (platformMoz)
		  txx_XSLProcessor.setParameter(null, name, value);
		else if (platformIE6)
			txx_XSLProcessor.addParameter(name, value);
	}

function transformXML_XSL(targetID,xmlFile,xslFile,xslPars) 
{                                                         
	if (platformMoz && txx_ready==0)
	{                                                      
		// XSLT in Firefox is asynchronous; wait until transformation is ready
		var timeoutOperation = "transformXML_XSL('" + targetID + "','" + xmlFile + "','" + xslFile + "','" + xslPars + "');";
		t=setTimeout(timeoutOperation,50)
	}
	else
	{
		SetTarget(targetID);  
		SetInput(xmlFile);
		SetStylesheet(xslFile);
		if (xslPars)
		{
			var parItem;
			var parList=xslPars.split('&');
			for (i=0; i<parList.length; i++)
			{
				parItem=parList[i].split('=');
				paramNames[i]=parItem[0];
				paramValues[i]=parItem[1];
			}
			nParams=parList.length;
		}
		else {nParams=0;}
		txx_ready=0;
		Transform();  
	}
}

function resizeImages()  
	// resize images that are too wide for printing
{   
	var maxImageWidth = 550;
	for (var i=0; i<document.images.length; i++)
	{                       
		if (document.images[i].width > maxImageWidth)
		{
			document.images[i].height = document.images[i].height/document.images[i].width*maxImageWidth;
			document.images[i].width = maxImageWidth;
		}
	}
}