/***************************************************************************
 *                            Barracuda Traffic Development Software
 *                              -------------------
 *     begin                : Mon Mar 23 2006
 *     copyright            : (C) 2006 BoonEx Group
 *     website              : http://www.boonex.com
 *
 *     
 *
 ****************************************************************************/

/***************************************************************************
 *
 *   This is a free software; you can modify it under the terms of BoonEx 
 *   Product License Agreement published on BoonEx site at http://www.boonex.com/downloads/license.pdf
 *   You may not however distribute it for free or/and a fee. 
 *   This notice may not be removed from the source code. You may not also remove any other visible 
 *   reference and links to BoonEx Group as provided in source code.
 *
 ***************************************************************************/

/**
 * load xml data object
 *
 * methods:
 *
 * properties:
 *		request - XMLHttpRequest or 'Microsoft.XMLHTTP' ActiveX object
 */


/**
 * constructor
 *		url	- url with xml data to open
 *		h	- handler function
 */
function BxXmlRequest(url, h, async)
{	
	/**
	 * local handler function
	 */
	var f = function (r, url, h)
	{
		if (r.readyState == 4) // only if req shows "loaded"
	    {
		    if (r.status == 200 || r.status == 304) // only if "OK"
			{
				h(r);
		    }
			else
	        {
				var s = '';
				for (var i in r) s += i + "      ";
		        BxError("XML read failed:" + r.status, "There was a problem retrieving the XML data:\n" + url);
			}
	    }
	}

	var r;

	// IE
	if(typeof ActiveXObject!="undefined")
	{
		try
		{
			xmlhttp.open("GET", url, async);
			xmlhttp.onreadystatechange = function ()
			{
				if (4 == xmlhttp.readyState)
				{
					if (200 == xmlhttp.status)
					{
						h (r);
					}
				}
			};
			xmlhttp.send(null);
		}
		catch(a)
		{
		}
	}
	else  if (window.XMLHttpRequest)
	{
		r = new XMLHttpRequest();
	
		// register handler function
		r.onload = function () 
		{
			f(r, url, h);
		}
		
		if(opera == 'opera')
			r.onload();
		
		r.open("GET", url, async);
		r.send(null);  
	}	

	if (!r)
	{
		var e = new BxError("httpxml object creation failed", "please upgrade your browser");
	}
	else
	{
		this.request = r.responseText;
	}

}   

