/***************************************************************************
*                            Barracuda Collaborative Directory Software
*                              -----------------
*     begin                : Mon Mar 23 2006
*     copyright            : (C) 2006 BoonEx Group
*     website              : http://www.boonex.com
* This file is part of Barracuda - Collaborative Directory Software
*
* Barracuda is free software; you can redistribute it and/or modify it under 
* the terms of the GNU General Public License as published by the 
* Free Software Foundation; either version 2 of the 
* License, or  any later version.      
*
* Barracuda is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. 
* You should have received a copy of the GNU General Public License along with Barracuda, 
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/
/**
 * 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
		{
			r = new ActiveXObject("Microsoft.XMLHTTP")

			// register handler function
			r.onreadystatechange = function(  ) 
			{
				f (r, url, h);
			}

			r.open("GET", url, async);
			r.send();  
		}
		catch(a)
		{
		}
	}
	else  if (window.XMLHttpRequest)
	{
		r = new XMLHttpRequest();
	
		// register handler function
		r.onload = function () 
		{
			f (r, url, h);
		}

		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;
	}

}   

