//*************************************************************************************
// Defines selectNodes if nessecary 
//*************************************************************************************
if(document.implementation.hasFeature("XPath", "3.0"))
{
	// prototying the XMLDocument
	XMLDocument.prototype.selectNodes=function(cXPathString, xNode)
	{
		if(! xNode) xNode=this;

		var oNSResolver=this.createNSResolver(this.documentElement);
		var aItems=this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		var aResult = new Array();

		for(var i=0; i<aItems.snapshotLength; i++) aResult[i]=aItems.snapshotItem(i);
		return (aResult.length>0) ? aResult : null ;
	}

	// prototying the Element
	Element.prototype.selectNodes=function(cXPathString)
	{
		return this.ownerDocument.selectNodes(cXPathString, this);
	}


	// prototying the XMLDocument
	XMLDocument.prototype.selectSingleNode=function(cXPathString, xNode)
	{
		return this.selectNodes(cXPathString, xNode)[0];
	}

	// prototying the Element
	Element.prototype.selectSingleNode=function(cXPathString)
	{
		return this.ownerDocument.selectSingleNode(cXPathString, this);
	}
}
//*************************************************************************************


//=====================================================================================
// XML Request Queue, version 2
//=====================================================================================
var CALLBACK_ADD_QUEUE=0;	var fnCALLBACK_ADD_QUEUE=null;
var CALLBACK_DEL_QUEUE=1;	var fnCALLBACK_DEL_QUEUE=null;

var VAR_ISDEBUG=0;

function setXmlQueueCallback(type, fn)
{
	switch(type)
	{
		case CALLBACK_ADD_QUEUE:
			fnCALLBACK_ADD_QUEUE=fn;
			break;
		case CALLBACK_DEL_QUEUE:
			fnCALLBACK_DEL_QUEUE=fn;
			break;
	}
}

function xmlrequest(verb, url, body, completion, context)
{
	var request=this;
	var xmldoc;

	if(url.indexOf("?")==-1) url=url+"?";

	this.verb=verb;
	this.url=url+"&rnd="+Math.random()+Math.random();
	this.body=body;
	this.completion=completion;
	this.context=context;
	this.xmlhttp=createxmlhttp();
	this.xmlhttp.onreadystatechange=function()
	{
		if(request.xmlhttp.readyState!=4) return;

if(VAR_ISDEBUG) alert("XML:\n"+request.xmlhttp.responseText);
		if(fnCALLBACK_DEL_QUEUE) fnCALLBACK_DEL_QUEUE();
		xmldoc=request.xmlhttp.responseXML;
		if(xmldoc==null || request.xmlhttp.getResponseHeader("Content-Type")!="text/xml")
		{
			xmldoc=createxmldoc(request.xmlhttp.responseText);
		}
if(VAR_ISDEBUG) alert("XML2:\n"+xmldoc.xml);
if(VAR_ISDEBUG) alert("ERR:\n"+xmldoc.parseError.reason);
if(VAR_ISDEBUG) alert("ERR:\n"+xmldoc.parseError.srcText);
		request.completion(xmldoc, request.context);
	}
}

function execRequest(verb, url, body, completion, context, username, password)
{
	var req;

	if(fnCALLBACK_ADD_QUEUE) fnCALLBACK_ADD_QUEUE();
	req=new xmlrequest(verb, url, body, completion, context);

if(VAR_ISDEBUG) alert("URL:"+req.url);
	if(username)
		req.xmlhttp.open(req.verb, req.url, true, username, password);
	else
		req.xmlhttp.open(req.verb, req.url, true);
	if(verb=="POST" && typeof(body)=="object")
	{
		req.xmlhttp.setRequestHeader("Content-Type", "text/xml");
		if(req.body.xml)
		{
			req.xmlhttp.send(req.body.xml);
		}
		else
		{
			req.xmlhttp.send(req.body);
		}
	}
	else
	{
		req.xmlhttp.send(req.body);
	}
}

function createxmlhttp()
{
	try{
		return new ActiveXObject("Msxml2.XMLHTTP.6.0");
	}catch(e)
	{
		try{
			return new ActiveXObject("Msxml2.XMLHTTP.5.0");
		}catch(e)
		{
			try{
				return new ActiveXObject("Msxml2.XMLHTTP.4.0");
			}catch(e)
			{
				try{
					return new ActiveXObject("Msxml2.XMLHTTP.3.0");
				}catch(e)
				{
					try{
						return new ActiveXObject("Msxml2.XMLHTTP");
					}catch(e)
					{
						try{
							return new ActiveXObject("Microsoft.XMLHTTP");
						}catch(e)
						{
							try
							{
								return new XMLHttpRequest();
							}catch(e)
							{
								alert("Your browser does not support the XML HTTP Request object\nPlease upgrade to a newer browser");
								return null;
							}
						}
					}
				}
			}
		}
	}
}
function createxmldoc(s)
{
	var p;

	try{
		p=new ActiveXObject("Msxml2.DOMDocument.6.0");
		p.loadXML(s);
		return p;
	}catch(e)
	{
		try{
			p=new ActiveXObject("Msxml2.DOMDocument.5.0");
			p.loadXML(s);
			return p;
		}catch(e)
		{
			try{
				p=new ActiveXObject("Msxml2.DOMDocument.4.0");
				p.loadXML(s);
				return p;
			}catch(e)
			{
				try{
					p=new ActiveXObject("Msxml2.DOMDocument.3.0");
					p.loadXML(s);
					return p;
				}catch(e)
				{
					try{
						p=new ActiveXObject("Msxml2.DOMDocument");
						p.loadXML(s);
						return p;
					}catch(e)
					{
						try{
							p=new ActiveXObject("Microsoft.DOMDocument");
							p.loadXML(s);
							return p;
						}catch(e)
						{
							try{
								p=new DOMParser();
								return p.parseFromString(s,"text/xml");
							}catch(e)
							{
								alert("Your browser does not support the XML DOM object\nPlease upgrade to a newer browser");
								return null;
							}
						}
					}
				}
			}
		}
	}
}
//=====================================================================================

