﻿/* Ajax Object Defintion */

function AjaxObject()
{
	// retrieve XML document (reusable generic function);
	// parameter is URL string (relative or complete) to
	// an .xml file whose Content-Type is a valid XML
	// type, such as text/xml; XML source must be from
	// same domain as HTML file
	this.loadXmlDoc = function(url, callBackFunction) {	
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			this.AjaxRequest = new XMLHttpRequest();
			this.AjaxRequest.onreadystatechange = callBackFunction;
			this.AjaxRequest.open("GET", url, true);
			this.AjaxRequest.send(null);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			//isIE = true;
			this.AjaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			if (this.AjaxRequest) {
				this.AjaxRequest.onreadystatechange = callBackFunction;
				this.AjaxRequest.open("GET", url, true);
				this.AjaxRequest.send();
			}
		}
	}
	
	this.loadXSLTDoc = function (url, xslLoadedCallBack)
	{
	    
		if (window.XSLTProcessor)
		{
			// support Mozilla/Gecko based browsers
			this.XsltDocument = document.implementation.createDocument("", "", null);
			this.XsltDocument.addEventListener("load", xslLoadedCallBack, false);
			this.XsltDocument.load(url);
		}
		else if(window.ActiveXObject)
		{
			// support Windows / ActiveX
			this.XsltDocument = new ActiveXObject("Microsoft.XMLDOM");
			this.XsltDocument.async = true;
			this.XsltDocument.ondataavailable = xslLoadedCallBack;
			this.XsltDocument.load(url);
		}
	}
	
	this.loadXSLTDoc = function(url)
	{
		if(window.ActiveXObject)
		{
			// support Windows / ActiveX
			this.XsltDocument = new ActiveXObject("Microsoft.XMLDOM");
			//xsldoc.ondataavailable = xslLoadedCallBack;
			this.XsltDocument.async = false;
			this.XsltDocument.load(url);
		}
	    
		else if (window.XSLTProcessor)
		{
			// support Mozilla/Gecko based browsers
			this.XsltDocument = document.implementation.createDocument("", "", null);
			//xsldoc.addEventListener("load", xslLoadedCallBack, false);
			this.XsltDocument.load(url);
		}
	}
	
	this.transformXml = function(xml, xsl, theDiv)
	{
		//alert(xsl);
		// code for Mozilla, Firefox, Opera, etc.
		if (window.XSLTProcessor)
		{
			xsltProcessor=new XSLTProcessor();
			xsltProcessor.importStylesheet(xsl);
			ex = xsltProcessor.transformToFragment(xml,document);
	        
			// alert(ex);
	        
			//alert(ex.toString());
			theDiv.innerHTML = "";
			theDiv.appendChild(ex);
	        
			//alert(theDiv.innerHTML);
		}
		else if (window.ActiveXObject)
		{
			ex=xml.transformNode(xsl);
	        
			//alert(ex);
	        
			theDiv.innerHTML=ex;
		}
		alert(theDiv.innerHTML);
	}
	
	this.xslLoadedCallBack = function()
	{
		this.XsltLoaded = true;
	}
	
	this.AjaxRequest			= null;
	this.XsltLoaded				= false;
	this.XsltDocument			= null;
}
