// ----------------------------------------------------------------------------
// BWXml
// ----------------------------------------------------------------------------
function BWXml()
{
	// Object
}

BWXml.parse = function(xmlString)
{
	try
	{
		if (window.ActiveXObject)
		{
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = false;
			xmlDoc.loadXML(xmlString);
		}
		else if (document.implementation && document.implementation.createDocument)
		{
			// code for Mozilla, etc.
			var objDOMParser = new DOMParser();
			var xmlDoc = objDOMParser.parseFromString(xmlString, "text/xml");
			return xmlDoc;
		}
		else
		{
			alert('Error creating xml document');
		}
	} catch(e)
	{
		alert("An exception occurred in the script. Error name: " + e + ". Error message: " + e.message);
	}
	
	return xmlDoc;
}

// ----------------------------------------------------------------------------
// BWXmlHttp
// ----------------------------------------------------------------------------
function BWXmlHttp() {}

BWXmlHttp.create = function()
{
	var xmlHttpReq = null;

	if (window.XMLHttpRequest)
	{
		// Mozilla/Safari
		xmlHttpReq = new XMLHttpRequest();
		if (xmlHttpReq.overrideMimeType)
			xmlHttpReq.overrideMimeType('text/xml');
	}
	else if (window.ActiveXObject)
	{
		// IE
		try
		{
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e)
		{
			try
			{
				xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e)
			{
				xmlHttpReq = null;
			}
		}
	}

	return xmlHttpReq;
}

BWXmlHttp.prototype.request = function(host, query, handler)
{
	var xmlHttpReq = BWXmlHttp.create();

	if (xmlHttpReq)
	{
		xmlHttpReq.open('POST', host, true);
		xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpReq.onreadystatechange = function()
		{
			if (xmlHttpReq.readyState == 4)
			{
				handler(xmlHttpReq.responseText);
			}
		}
		xmlHttpReq.send(query);
	}
	else
	{
		alert("Unable to create xmlHttpReq");
	}
}
