function CreateXMLReq()
{
	if ( typeof XMLHttpRequest == "undefined" ) 
	{
		XMLHttpRequest = function()
		{ 
			return new ActiveXObject( 
				navigator.userAgent.indexOf("MSIE 5") >= 0 ? 
				"Microsoft.XMLHTTP" : "Msxml2.XMLHTTP" 
			); 
		}
	}

	// Create the request object 
	return new XMLHttpRequest(); 
}

function bswAjax( options ) 
{ 
	options = { 
		// The type of HTTP Request 
		type: options.type || "GET", 
		
		// The URL the request will be made to 
		url: options.url || "", 
		
		// How long to wait before considering the request to be a timeout 
		timeout: options.timeout || 5000, 
		
		// Functions to call when the request fails, succeeds, 
		// or completes (either fail or succeed) 
		onComplete: options.onComplete || function(){}, 
		onError: options.onError || function(){}, 
		onSuccess: options.onSuccess || function(){}, 
		
		// The data type that'll be returned from the server 
		// the default is simply to determine what data was returned from the 
		// and act accordingly. 
		data: options.data || "xml" 
	}; 

	// Create the request object 
	var xml = CreateXMLReq();
	if (xml.overrideMimeType)
		xml.overrideMimeType('text/xml');
	
//	console.log("Opening: "+options.type+" , ("+options.data+")"+options.url);
	//alert("Opening: "+options.type+" , ("+options.data+")"+options.url);
	/*
	try {
	    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
	   } catch (e) {
	    alert("Permission UniversalBrowserRead denied.");
	   }
	*/	

	// Open the asynchronous request 
	xml.open(options.type, options.url, true); 

	var timeoutLength = options.timeout; 
	var requestDone = false; 

	setTimeout(function(){ 
		requestDone = true; 
	}, timeoutLength); 

	// watch for state updates
	xml.onreadystatechange = function()
	{
		//console.log("onreadystatechange - HIT! readystate=" + xml.readyState);
		if ( xml.readyState == 4 && !requestDone ) 
		{ 
			if ( httpSuccess( xml ) ) 
			{
				options.onSuccess( httpData( xml, options.type ) ); 
			}
			else
			{
				//console.log("onreadystatechange - ERROR");
				options.onError(); 
			}
			
			options.onComplete(); 
			xml = null; 
		}
		
		if (requestDone)
		{
			options.onError();
			xml=null;
			//console.log("TIMEOUT!!!");
		}
	} 

	// Establish the connection to the server 
	xml.send(null); 

	// was it successfull?
	function httpSuccess(r) 
	{ 
		//console.log("httpSuccess: "+r.status+", "+location.protocol);
		try 
		{ 
			// NOTE: using 302 as OK status because of mod_rewrite!!!
			return !r.status && location.protocol == "file:" || 
				( r.status >= 200 && r.status < 300 ) || 
					r.status == 304 || r.status == 302 ||
					navigator.userAgent.indexOf("Safari") >= 0 
					&& typeof r.status == "undefined"; 
		} 
		catch(e){} 

		//alert("httpSuccess failed!");
		return false; 
	} 

	// Extract the correct data from the HTTP response 
	function httpData(r,type) 
	{ 
		var ct = r.getResponseHeader("content-type"); 
		//console.log("response-type: "+ct);
		var data = !type && ct && ct.indexOf("xml") >= 0;
		//console.log("data = "+data);
		
		//data = type == "xml" || data ? r.responseXML : r.responseText; // !!!
		data = r.responseXML; // NOTE: one2create - your server returns xml only!	// !!!
		if ( type == "script" ) 
			eval.call( window, data ); 

		//console.log("httpData, typeof(data)="+typeof(data));
		//console.log(r.responseText);
		return data; 
	}
}
