/**
*	Class representing the XMLHttpRequest browser specific component required to exchange data with a web server via HTTP
**/

/**
*  bswXMLHttpRequest Constructor - instantiates the browser specific XMLHttpRequest object
**/
function bswXMLHttpRequest()
{

	this.XMLHttpRequest = null;
	
	try{
		if(document.all)
		{
			this.XMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		else
		{
			this.XMLHttpRequest = new XMLHttpRequest();	
		} 
	} catch (e){
		
		alert(e);
	
	}
	
	
}

/**
*	Abort(): Cancels the current HTTP request.
*   The request will be returned to the UNINITIALIZED state, and the
*	.Open() method must be called next.
**/
bswXMLHttpRequest.prototype.Abort = function()
{
	this.XMLHttpRequest.abort();
}

/**
*	GetAllResponseHeaders(): Returns complete set of headers (labels and values) as a string
*   Must only be called after the .Send() method has been completed
**/
bswXMLHttpRequest.prototype.GetAllResponseHeaders = function()
{
	return this.XMLHttpRequest.getAllResponseHeaders();
}

/**
*	GetResponseHeader(): Returns the string value of a single header label
*   Must only be called after the .Send() method has been completed
*	Parameters:
*		strHeader: the case insensetive string value of the desired header's name
**/
bswXMLHttpRequest.prototype.GetResponseHeader = function(strHeader)
{
	return this.XMLHttpRequest.getResponseHeader(strHeader);
}

/**
*	OnReadyStateChange(): Specifies the event handler to be called when the readyState property changes
**/
bswXMLHttpRequest.prototype.SetOnReadyStateChange = function(eventFunction)
{
	this.XMLHttpRequest.onreadystatechange = eventFunction;
}

/**
*	Open(): Responsible for instantiating the connection to the server at the specified URL
*	Parameters:
*		requestMethod: "GET" || "POST" request method
*		URL: web server destination
*		aysnc: true || false indicator whether the request should be made within a synchronous or asynchronous thread
**/
bswXMLHttpRequest.prototype.Open = function(requestMethod, URL, async) 
{

	try
	{
		this.XMLHttpRequest.open(requestMethod, URL, async);
	}
	catch (e)
	{
		alert(e);
	}
}

/**
*	ReadyState(): Represents the state of a request as an int between 0 and 4
*	Returns:
*		0 == UNINITIALIZED - The object has been created, but not initialized (the .Open() 
*			method has not been called.)
*		1 == LOADING - The object has been created, but the .Send() method has not been called.
*		2 == LOADED - The .Send() method has been called, but the status and headers are 
*			not yet available.
*		3 == INTERACTIVE - Some data has been received. Calling the .ResponseText() properties 
*			at this state to obtain partial results will return an error, because status and 
*			response headers are not fully available.
*		4 == COMPLETED - All the data has been received, and the complete data is available 
*			in the .ResponseText() properties.
**/
bswXMLHttpRequest.prototype.ReadyState = function() 
{
	return this.XMLHttpRequest.readyState;
}

/**
*	ResponseText(): Responsible for returning the returned server data as a string
**/
bswXMLHttpRequest.prototype.ResponseText = function() 
{
	return this.XMLHttpRequest.responseText;
}

/**
*	ResponseXML(): Responsible for returning the returned server data as an xml DOM
**/
bswXMLHttpRequest.prototype.ResponseXML = function() 
{
	return this.XMLHttpRequest.responseXML;
}

/**
*	Send(): Responsible for sending XML HTTP request
**/
bswXMLHttpRequest.prototype.Send = function() 
{
	if(document.all){
	
		this.XMLHttpRequest.send();
		
	} else {
	
		this.XMLHttpRequest.send(null);
	}
	
	
}

/**
*	Send(): Responsible for sending XML HTTP request
**/
bswXMLHttpRequest.prototype.SendPost = function(params) 
{	try 
	{
		this.XMLHttpRequest.send(params);		
	} 
	catch (e) 
	{
		alert(e);
	}
}

/**
*	SetRequestHeader(): Adds or replaces the string of a http request header 
*		and the string of it's associated value
*	If a request header already exists with the name of strHeader, it and it's value are replaced
*	Parameters:
*		strHeader: the case insensetive string value of the request header
*			This parameter should not contain a colon and should be the actual text of the HTTP header.
*		strValue: the string value to be associated with the header (above)
**/
bswXMLHttpRequest.prototype.SetRequestHeader = function(strHeader, strValue)
{
	this.XMLHttpRequest.setRequestHeader(strHeader, strValue);
}

/**
*	Status(): Represents the HTTP status code returned by a request.
*	Returns:
*		a bunch of different seemingly random numbers between 100 and 505
*		200 == OK, 404 == Not Found, etc.
**/
bswXMLHttpRequest.prototype.Status = function() 
{
	return this.XMLHttpRequest.status;
}

/**
*	StatusText(): The property is read-only. It represents the HTTP response as a string. 
*		This value is valid only after the .Send() method returns successfully.
**/
bswXMLHttpRequest.prototype.StatusText = function() 
{
	return this.XMLHttpRequest.statusText;
}

