var XML_UNINITIALIZED = 0;
var XML_LOADING = 1;
var XML_LOADED = 2;
var XML_INTERACTIVE = 3;
var XML_COMPLETE = 4;

document.ELEMENT_NODE = 1;
document.TEXT_NODE = 3;

function ie_importNode(doc,node,importChildNodes)
{
	var newNode = null;

	//alert(node.innerHTML);

	//newNode = doc.createElement(node.nodeName);
	//newNode.loadXml = "<test>test</test>";

	return node;
}

function importNode(doc,node,importChildNodes)
{
	if (!browser.isIE)
		return doc.importNode(node,importChildNodes)
	else
		return ie_importNode(doc,node,importChildNodes);
}

function XMLFactory()
{
	return this;
}

XMLFactory.createHttp = function()
{ 
	if (window.XMLHttpRequest)
		obj = new XMLHttpRequest();
	if (window.ActiveXObject)
		obj = new ActiveXObject(XMLFactory.getValidPrefix()+".XmlHttp");

	if (obj)
	{
		//if (gSid)
		//obj.setRequestHeader("Set-Cookie",gSid+"; path=/");
		
		return obj;
	}

	return null;
}

XMLFactory.createDoc = function()
{
	if (document.implementation && document.implementation.createDocument)
		return document.implementation.createDocument("","",null);
	if (window.ActiveXObject)
	{
		doc = new ActiveXObject(XMLFactory.getValidPrefix()+".XmlDom");
		//doc = new ActiveXObject("MSXML2.DOMDocument.4.0");
		//doc.importNode = ie_importNode;
		return doc;
	}
	
	return null;
}

XMLFactory.getValidPrefix = function()
{
	if (XMLFactory.validPrefix)
		return XMLFactory.validPrefix;

	var prefixes = ["MSXML2","Microsoft","MSXML","MSXML3"];
	for(var i=0; i < prefixes.length; i++)
	{
		try
		{
			xmlhttpobj = new ActiveXObject(prefixes[i]+".XmlHttp");
			xmldomobj = new ActiveXObject(prefixes[i]+".XmlDom");
			XMLFactory.validPrefix = prefixes[i];
			return XMLFactory.validPrefix;
		}
		catch(error)
		{
		}
	}
};



function xmlToString(xml)
{
	if(!browser.isIE)
		return ((new XMLSerializer).serializeToString(xml));
	else
	{
		res = xml.xml;
		if (res == null)
			return xml.innerHTML;
	}
}

function getXml(method,url,data,async,callback)
{
	var xmlhttp = XMLFactory.createHttp();
	xmlhttp.onreadystatechange = function(){ callback.call(xmlhttp); };
	xmlhttp.open(method,url,async);
	xmlhttp.setRequestHeader("Content-Type","text/xml");
	xmlhttp.send(data);

	return xmlhttp;
}

function getXmlFunc(method,url,data,async,func)
{
	var xmlhttp = XMLFactory.createHttp();
	xmlhttp.onreadystatechange = function(){ func(xmlhttp); };
	xmlhttp.open(method,url,async);
	xmlhttp.setRequestHeader("Content-Type","text/xml");
	xmlhttp.send(data);

	return xmlhttp;
}

function onXMLReadyStateChange(xmlobj)
{
	if (xmlobj.readyState == XML_COMPLETE)
	{
		alert(xmlToString(xmlobj.responseXML));
	}
}

//getXml("GET","menu.xml",null,true,onXMLReadyStateChange);

