/**
@file EXHR.js
@author Ivan De Marino
@created 2005-12-02
@updated 2005-12-02
@version 0.2
@description EXHR.core */

/* --- --- --- EXHR CORE FUNCTIONS and VARS START (ignore that code) --- --- --- */
var _XHRObject = null;

var _XHRResponseData = "";
var _XHRCodeToExecute = "";
var _XHRMethod = "GET";
var _XHRAsyncronous = true;

/** Init the XHR Object.
 Cross-Broser method that initialize the XmlHttpRequest
 and set-up the Status-Change handler. */
function _XHRInit() {
    // branch for native XMLHttpRequest object
	if( window.XMLHttpRequest )
	{
		try 
		{
			_XHRObject = new XMLHttpRequest();
		} catch(e) 
		{
			_XHRObject = null;
		}

	} 
	// branch for IE/Windows ActiveX version
	else if(window.ActiveXObject)
	{
	   	try 
	   	{
		    	_XHRObject = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) 
		{
		    	try 
		    	{
		    		_XHRObject = new ActiveXObject("Microsoft.XMLHTTP");
		    	} catch(e) 
		    	{
		    		_XHRObject = null;
		    		alert('This Browser do not support XmlHttpRequest!');
				return;
		    	}
		}
	}
	
	// If XHR object correctly created
	if( _XHRObject != null )
	{
		// Executed at the end of the Request
		_XHRObject.onreadystatechange = _XHRProcessReqChange;
	}
}

/**
 @do-not-use
 Manage the State Change and execute the code
 setted with the function "EXHRSetCodeToExecute(...)" */
function _XHRProcessReqChange() {
	// only if the request shows "loaded"
	if ( _XHRObject.readyState == 4) 
	{
		// only if "OK"
		if ( _XHRObject.status == 200) 
		{
			_XHRResponseData = _XHRObject.responseText;
			eval( _XHRCodeToExecute );
		} 
		else 
		{
			alert("There was a problem retrieving the XML data:\n" +
			    _XHRObject.statusText);
		}
	}
}
/* --- --- --- END --- --- --- */

