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

 Set the Code to execute at the 
 end of the Request.
 To get Request result use "<XHRObject>.getData()" method */
function EXHRSetCodeToExecute (codeString)
{
	_XHRCodeToExecute = codeString;
}

/**  */
function EXHRSetMethodGet() { _XHRMethod = 'GET'; }
/**  */
function EXHRSetMethodPost() { _XHRMethod = 'POST'; }
/**  */
function EXHRSetModalityAsync() { _XHRAsyncronous = true; }
/**  */
function EXHRSetModalitySync() { _XHRAsyncronous = false; }
/**  */
function EXHRGetData() { return _XHRResponseData; }

/**

 Do the effective request.
 Use that method after you have set the "codeToExecute".

 	(ex. pippo=pluto&paperino=minnie&gino=gay) */
function EXHRDoRequest(requestURL, parametersString)
{	
	// Force XHR Object Reinit
	_XHRInit();
	
	switch ( _XHRMethod )
	{
		case "POST":
		{
			// Open a XHR Request
			_XHRObject.open(_XHRMethod, requestURL, _XHRAsyncronous);
			_XHRObject.setRequestHeader("Method", "POST " + requestURL + 
				" HTTP/1.1");
			_XHRObject.setRequestHeader("Content-Type", 
				"application/x-www-form-urlencoded");
			// Sending parameter and start the Request
			_XHRObject.send(parametersString);
			break;
		}
		case "GET":
		{
			if ( parametersString != '' )
			{
				if ( requestURL.indexOf('?') == -1 )
					requestURL = requestURL + "?" + parametersString;
				else
					requestURL = requestURL + "&" + parametersString;
			}
			_XHRObject.open(_XHRMethod, requestURL, _XHRAsyncronous);
			_XHRObject.send('');
			break;
		}
	}
}

/**

 Force the Initialization of EXHR.
 Use only if change any parameter like "method". */
function EXHRForceInit() { _XHRInit(); }
