function XmlAjaxLoader()
{	
	var m_Form;
	var m_TargetContainer;
	var m_Timeout;
	var m_RequestMethod;
	var m_Url;
	
	var m_XmlResponse;
	var m_XslResponse;
	var m_XslDocument;
	
	var m_ErrorEventHandler;
	var m_LoadedEventHandler;
	
	m_Timeout = 5000;
	
	this.GetForm = function()
	{
		return m_Form;
	};//endmethod GetForm
	
	this.SetForm = function(form)
	{
		m_Form = form;
	};//endmethod SetForm
	
	this.GetTargetContainer = function()
	{
		return m_TargetContainer;
	};//endmethod GetTargetContainer
	
	this.SetTargetContainer = function(targetContainer)
	{
		m_TargetContainer = targetContainer;
	};//endmethod SetTargetContainer
	
	this.GetTimeout = function()
	{
		return m_Timeout;
	};//endmethod GetTimeout
	
	this.SetTimeout = function(timeout)
	{
		m_Timeout = timeout;
	};//endmethod SetTimeout
	
	this.GetRequestMethod = function()
	{
		return m_RequestMethod;
	};//endmethod GetRequestMethod
	
	this.SetRequestMethod = function(requestMethod)
	{
		m_RequestMethod = requestMethod;
	};//endmethod SetRequestMethod
	
	this.GetUrl = function()
	{
		return m_Url;
	};//endmethod GetUrl
	
	this.SetUrl = function(url)
	{
		m_Url = url;
	};//endmethod SetUrl
	
	this.GetErrorEventHandler = function()
	{
		return m_ErrorEventHandler;
	};//endmethod GetErrorEventHandler;
	
	this.SetErrorEventHandler = function(eventHandler)
	{
		m_ErrorEventHandler = eventHandler;
	};//endmethod SetErrorEventHandler;
	
	this.GetLoadedEventHandler = function()
	{
		return m_LoadedEventHandler;
	};//endmethod GetLoadedEventHandler;
	
	this.SetLoadedEventHandler = function(eventHandler)
	{
		m_LoadedEventHandler = eventHandler;
	};//endmethod SetLoadedEventHandler;
	
	this.SendRequest = function()
	{
		var requestMethod = new AjaxRequestMethod();
		
		if (m_RequestMethod == requestMethod.Get)
		{
			if (m_Form == null)
			{
				dojo.xhrGet({ 
					url: 		m_Url,
					
					handleAs: 	"xml",
					
					//Time in milliseconds								 
					timeout: 	m_Timeout,
					
					//The LOAD function will be called on a successful response.
					load: 		OnXmlDocumentLoaded,
					
					// The ERROR function will be called in an error case.
					error: 		OnXmlDocumentLoadError
		       });
			}
			else
			{
				dojo.xhrGet({ 
					url: 		m_Url, 
					
					handleAs: 	"xml",
					
					form:		m_Form,
					
					//Time in milliseconds								 
					timeout: 	m_Timeout,
					
					//The LOAD function will be called on a successful response.
					load: 		OnXmlDocumentLoaded,
					
					// The ERROR function will be called in an error case.
					error: 		OnXmlDocumentLoadError
		       });
			}//endif
		}
		else if (m_RequestMethod == requestMethod.Post)
		{
			if (m_Form == null)
			{
				dojo.xhrPost({ 
					url: 		m_Url, 
					
					handleAs: 	"xml",
					
					//Time in milliseconds								 
					timeout: 	m_Timeout,
					
					//The LOAD function will be called on a successful response.
					load: 		OnXmlDocumentLoaded,
					
					// The ERROR function will be called in an error case.
					error: 		OnXmlDocumentLoadError
		       });
			}
			else
			{
				dojo.xhrPost({ 
					url: 		m_Url, 
					
					handleAs: 	"xml",
					form:		m_Form,
					
					//Time in milliseconds								 
					timeout: 	m_Timeout,
					
					//The LOAD function will be called on a successful response.
					load: 		OnXmlDocumentLoaded,
					
					// The ERROR function will be called in an error case.
					error: 		OnXmlDocumentLoadError
		       });
			}//endif
		}//endif
	};//endmethod SendReponse
	
	function OnXmlDocumentLoadError(response, ioArgs)
	{
		if (m_ErrorEventHandler != null)
		{
			m_ErrorEventHandler(response, ioArgs);
		}
		else
		{
			alert(response);
		}//endif
	}//endfunction OnXmlDocumentLoadError
	
	function OnXmlDocumentLoaded(response, ioArgs)
	{
		m_XmlResponse = response;
		
		//after loading the xml
		//we can try to filter the stylesheet
		var xmlDocument 	= response;
		var xPathContext  	= new ExprContext(response);
		
		var xslBaseUri  = null;
		var xslDocument = null;
		
		for (i = 0; i < xmlDocument.childNodes.length; i++) 
		{
			//check if actual node is processing instruction
			if (xmlDocument.childNodes[i].nodeType == 7)
			{
				if (xmlDocument.childNodes[i].nodeName == "xml-stylesheet")
				{
					xslBaseUri 	= xmlDocument.childNodes[i].baseUri;
					xslDocument	= xmlDocument.childNodes[i].nodeValue;					
					break;
				}//endif
			}//endif
		}//endfor
		
		if (xslDocument != null)
		{
			xslDocument = xslDocument.substring(xslDocument.indexOf("href") + 4, xslDocument.lastIndexOf(".xsl") + 4);
			xslDocument = xslDocument.substring(xslDocument.indexOf('"') + 1, xslDocument.length);						
			
			LoadXslDocument(xslDocument);
		}//endif
	}//endfunction OnXmlDocumentLoaded
	
	function OnXslDocumentLoadError(response, ioArgs)
	{
		if (m_ErrorEventHandler != null)
		{
			m_ErrorEventHandler(response, ioArgs);
		}
		else
		{
			alert(response);
		}//endif
	}//endfunction OnXslDocumentLoadError
	
	function OnXslDocumentLoaded(response, ioArgs)
	{
		m_XslResponse = response;
		
		TransformOutput();
		
		if (m_LoadedEventHandler != null)
		{
			m_LoadedEventHandler();
		}//endif
	}//endfunction OnXslDocumentLoaded
	
	function LoadXslDocument(xslDocument)
	{
		m_XslDocument = xslDocument;
		
		if (window.XSLTProcessor)
		{
			dojo.xhrGet({ 
							url: 		xslDocument, 
							handleAs: 	"xml",
						
							//Time in milliseconds								 
							timeout: 	2500,
						
							//The LOAD function will be called on a successful response.
							load: 		OnXslDocumentLoaded,
							
							// The ERROR function will be called in an error case.
							error: 		OnXslDocumentLoadError
			           });
		}
		else
		{
			//Internet explorer
			TransformOutput();
		}//endif
	}//endfunction LoadXslDocument
	
	function TransformOutput()
	{
		var targetContainer 	= document.getElementById(m_TargetContainer);
		var transformedOutput	= null;
		
		targetContainer.innerHTML = "";
		
		//transform response
		if (window.XSLTProcessor)
		{
			// support Mozilla/Gecko based browsers
			var xsltProcessor = new XSLTProcessor();
			xsltProcessor.importStylesheet(m_XslResponse);
			transformedOutput = xsltProcessor.transformToFragment(m_XmlResponse, document);
		}
		else
		{
			//support IE / ActiveX
			var xslt = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
			xslt.async = false;
			xslt.load(m_XslDocument);
			var template = new ActiveXObject("MSXML2.XSLTemplate");
			template.stylesheet = xslt;
			var process = template.createProcessor();
			process.input = m_XmlResponse;
			process.transform();
			
			transformedOutput = process.output;
		}//endif
		
		try
		{
			targetContainer.appendChild(transformedOutput);
		}//endtry
		catch (e) 
		{
			targetContainer.innerHTML = transformedOutput;
		}//endcatch
	}//endfunction TransformOutput
}//endclass XmlAjaxLoader

