// Loadervar XML_LOADING = 1;var XML_LOADED = 2;var XML_INTERACTIVE = 3;var XML_COMPLETE = 4;function Loader()
{	this.xmlhttp = null;	this.handlers = null;	this.xmlDoc = null;		// fromFile should be in main.js	this.fromFile = config.fromFile;	if (!this.fromFile)	{		if (window.XMLHttpRequest)
		{			this.xmlhttp = new XMLHttpRequest();		}
		else if (window.ActiveXObject)
		{			try
			{				this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");			}
			catch(e)
			{				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");			}		}		else		{			alert("error creating xmlhttp");		}	}	else	{		if (document.implementation && document.implementation.createDocument)
		{
			this.xmlDoc = document.implementation.createDocument("", "", null);
		}
		else if (window.ActiveXObject)
		{
			this.xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		}
		else
		{
			alert("error creating xmlDoc");
		}
	}		this.handlers = new Array(5);}

Loader.prototype.getXML = function()
{
	if (!this.fromFile)
	{
		if (this.xmlhttp.responseXML)
		{
			return this.xmlhttp.responseXML;
		}
		else
		{
			return null;
		}
	}
	else
	{
		if (this.xmlDoc)
		{
			return this.xmlDoc;
		}
		else
		{
			return null;
		}
	}
}
Loader.prototype.load = function (URL, async)
{	try	{		if (!this.fromFile)		{			this.xmlhttp.open("GET", URL, async);			if (async)
			{
				var ref = this;				this.xmlhttp.onreadystatechange = function()
				{					ref.callHandler(ref);				};				this.xmlhttp.send(null);			}
			else
			{				this.xmlhttp.send(null);				return this.xmlhttp.responseXML;			}		}		else		{			// todo: load for firefox NOK			this.xmlDoc.load(URL);			// simulate async			if (async)
			{				this.callHandler(this);			}			else			{				return this.xmlDoc;			}		}	}	catch(ex)	{		//alert(ex);		alert("Can not load " + URL);		this.xmlhttp.abort();	}}

Loader.prototype.callHandler = function (self)
{		if (!this.fromFile)	{		if (self.handlers[self.xmlhttp.readyState])
		{			if (self.xmlhttp.readyState == XML_COMPLETE)
			{				self.handlers[self.xmlhttp.readyState](self.xmlhttp.responseXML);			}
			else
			{				self.handlers[self.xmlhttp.readyState]();			}		}	}	else	{		self.handlers[4]();	}}
Loader.prototype.setHandler = function (state, pointer)
{	if (this.handlers != null)	{		this.handlers[state] = pointer;	}}

Loader.prototype.clearHandlers = function ()
{	if (this.handlers != null)	{		for (var i=0; i < this.handlers.length; i++)
		{
			this.handlers[i] = null;
		}	}}