/**
 * @fileoverview
 * Este archivo contiene la clase SHttpRequest<br> 
 * Encapsula el httpRequest para compatibilidad con varios navegadores<br>
 * @version v.1.0.0<br/>
 * <span style="color:green"><b>&copy;2006 Soluciones Integrales GIS, C.A.</b></span><br/>
 *
 * @author Rafael Pellicer <a href="mailto:rafael.pellicer@sigis.com.ve">rafael.pellicer@sigis.com.ve</a>
 */

/**
 * @class
 * Crea peticiones HTTP (Usando el objeto HttpRequest).
 * @author Rafael Pellicer
 * @constructor
 * @return Devuelve un objeto SHttpRequest
 * @type SHttpRequest
 */
SHttpRequest = function()
{
	/**
	 * @private
	 * @ignore
	 */
	this._url = null;
	/**
	 * @private
	 * @ignore
	 */	
	this._method = null;
	
	/**
	 * @private
	 * @ignore
	 */	
	this._async = true;
	
	/**
	 * @private
	 * @ignore
	 */	
	this._username = null;
	
	/**
	 * @private
	 * @ignore
	 */	
	this._passw = null;
	
	/**
	 * @private
	 * @ignore
	 */	
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	 }
	@end @*/

	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
	  xmlhttp = new XMLHttpRequest();
	}
	this.request = xmlhttp;

};
/**
* Especifica el m&eacute;todo, URL, y otros atributos opcionales de la petici&oacute;n
* @author Rafael Pellicer
* @since v.1.0.0
* @param {String} UrlString Puede ser una url relativa o completa, ejemplo: 'http://midominio.com/midir/mipage.php'
* @param {String} Method Par&aacute;metro opcional (POST por defecto). Puede tener un valor de "GET" &oacute; "POST" (use "GET" cuando este pidiendo data y use "POST" cuando est&eacute; enviando data (especialment si la cantidad de data excede los 512 bytes).
* @param {Boolean} Async Par&aacute;metro opcional (True por defecto).Establece si la petici&oacute;n se realiza de maner&aacute; as&iacute;ncrona (true) o no (false)
* @param {String} Username Par&aacute;metro opcional (Null por defecto). Si el servidor requiere validar la seguridad
* @param {String} Password Par&aacute;metro opcional (Null por defecto). Si el servidor requiere validar la seguridad
* @return void
* @type void
*/
SHttpRequest.prototype.Open = function(UrlString, Method, Async, Username, Password)
{
	if (this.request)
	{
		this._url = UrlString;
		Method = !Method?null:Method.toUpperCase();
		switch(Method)
		{
			case "POST":
			case "GET":
				this._method = Method;
				break;
			default:
				this._method = "POST";
		}

		this._async		= !Async? true:Async;
		this._username	= !Username?null:Username;
		this._passw		= !Password?null:Password;
	}
};
/**
* Env&iacute;a la petici&oacute;n con los valores establecidos en el m&eacute;todo Open
* @author Rafael Pellicer
* @since v.1.0.0
* @param {String} Parameters Serie de par&aacute;metros a enviar en la petici&oacute;n. Ejemplo: "id=100&status=t"
* @param {Function Object} functionHandler Una funci&oacute;n que manejar&aacute; los eventos para un evento que se dispara con cada cambio de estado.
* @return void
* @type void
*/
SHttpRequest.prototype.Send = function(Parameters, functionHandler)
{
	if (this._method!="POST")
	{
		this._url = this._url +"?"+Parameters+"&"+  new Date().getTime( );
		Parameters = !ie?null:"";
	}

	this.request.open(this._method, this._url, this._async, this._username, this._passw);
	this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	this.request.setRequestHeader("Cache-Control", "no-cache");
	this.request.setRequestHeader("Pragma", "no-cache");
	this.request.setRequestHeader("Expires", "-1");
	if (functionHandler)
	{
		this.request.onreadystatechange = functionHandler;
	}
	this.request.send(Parameters);
};
/**
* Aborta la petici&oacute;n enviada al server
* @author Rafael Pellicer
* @since v.1.0.0
* @return void
* @type void
*/
SHttpRequest.prototype.Abort = function()
{
	this.request.abort();
};
