//********
//
//	FILE INFORMATION
//
//******
//
//	File Name:
//		lb_ajax.js
//
//	Purpose:
//		Defines the LB_Ajax object, used for making AJAX calls.
//
//********

//************************************************************************
//
//	$g_lb_ajax_queue
//
//	Keeps track of all active LB_Ajax calls.
//
var g_lb_ajax_queue = new Array();

LB_Ajax = function(){

	//	POST Parameters
	this.params = '';
	
	//********************************************************************
	//
	//	@getAjaxObject
	//
	//	Create a new AJAX object... however our browser may want us to do
	//		that.
	//
	this.getAjaxObject = function() {
		//	First, check for the NORMAL... you know, STANDARD way to do
		//		things...
		if(window.XMLHttpRequest)
			return new XMLHttpRequest();
		
		//	And now for the [expletive removed] Microsoftie ways
		//		(note plural).
		if(window.ActiveXObject) {
			var newObject;
			if((newObject = new ActiveXObject('Msxml2.XMLHTTP')) || (newObject = new ActiveXObject('Microsoft.XMLHTTP')))
				return newObject
		}
	}
	
	//********************************************************************
	//
	//	@onError
	//
	//	Our default error callback.
	//
	this.onError = function(error) {
		alert(error);
	}
	
	//********************************************************************
	//
	//	@getPage
	//
	//	Send our Ajax request out.
	//
	this.getPage = function(url, callBack) {
		try {
			var a_ob = this.getAjaxObject();
			a_ob.onreadystatechange = function() {
				if(a_ob.readyState == 4 || a_ob.readyState == "complete")
					callBack(a_ob.responseText);
			};
			
			a_ob.open("POST", url, true);
			a_ob.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        a_ob.setRequestHeader("Content-length", this.params.length);
			a_ob.send(this.params);
			
		} catch(ex){
			this.onError(ex);
		}
	}
	
	//********************************************************************
	//
	//	@addParam
	//
	//	Adds a POST parameter.
	//
	this.addParam = function(key, value) {
		if(this.params == "")
			this.params = key + '=' + value;
		else
			this.params += '&' + key + '=' + value;
	}	
}