	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	// RS. 
	// AJAX Interaction function, which separates object creation, request, and callback.
	// This function allows passing of parameters to whatever is specified as the callback() function.
	// Requirements:
	// - url: the URL of the asp page that loads the data in the background
	// - callback: the function to call when the AJAX load is complete
	// - destinationobject: the object to pass to the callback function, which is to receive the data
	// - param1: an additional parameter that will be passed to the callback function. This could carry
	// anything you like. For select boxes, it carries a possible preselect value.
	// - It is also required that the destinationobject has a corresponding <DIV> tag with an
	// ID value of "<destinationobjectname>AJAXloading". This is for the display of an animated
	// .GIF beside the destinationobject.
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	function AJAXInteraction(url, callback, destinationobject, param1) {
		var MyAJAXdiv;
		var MySelectBox;

		if (document.getElementById(destinationobject + 'AJAXloading')) { 
			MyAJAXdiv = document.getElementById(destinationobject + 'AJAXloading');
		}
		if (document.getElementById(destinationobject)) { 
			MySelectBox = document.getElementById(destinationobject);
		}

		var http_request = init();
		http_request.onreadystatechange = processRequest;

		function init() {
		  if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		  } else if (window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP");
		  }
		}
		
		//The function needs to check for the state of the request. If the state has the value of 4, that means that the full 
		//server response is received and it's OK for you to continue processing it.
		//The full list of the readyState values is as follows:
		//* 0 (uninitialized)
		//* 1 (loading)
		//* 2 (loaded)
		//* 3 (interactive)
		//* 4 (complete) 
		// Not all of these readyState values behave as expected in different browser. In fact, only 0 and 4 are truly reliable. - RS.

		function processRequest () {
			if (http_request.readyState == 4) {
				if (http_request.status == 200) {

					if (MyAJAXdiv) {
						MyAJAXdiv.innerHTML = "";
					}
					if (MySelectBox) {
						MySelectBox.disabled=false;
					}

					if (callback) callback(http_request.responseText, destinationobject, param1);

					//http_request.abort(); //Prevents known minor memory leak in IE, but crashes Safari.
				}
			}
			else {
				if (MyAJAXdiv) {
					MyAJAXdiv.innerHTML = "<img src='images/load.gif' border='0'>";
				}

				if (MySelectBox) {
					MySelectBox.disabled=true;
				}
			}
		}

		this.doGet = function() {
		  http_request.open('GET', url, true);
		  http_request.send(null);
		}
		
		this.doPost = function(body) {
		  http_request.open("POST", url, true);
		  http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		  http_request.send(body);
		}	
	}
 

	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	// RS. 
	// Global AJAX Request handler. Use this function to set up a call to retrieve data via AJAX.
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	function AJAXRequest(url, outputfunction, destinationobject, param1) {
		var ai = new AJAXInteraction(url, eval(outputfunction), destinationobject, param1);
		ai.doGet();	 
		ai = null;
	}


	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	// RS. 
	// Global LoadSelectBox handler. Use this function to load up any SelectBox via AJAX.
	// Requirements:
	// - destinationobject - the select box to receive the JSON data.
	// - preselect - the index of the select box item to be preselected, if any.
	// - Data being returned must be JSON format.
	// - The existence of a <DIV> tag on the calling page, with an ID of "<destinationobject ID>AJAXloading"
	//////////////////////////////////////////////////////////////////////////////////////////////////////////
	function LoadSelectBox(JSONData, destinationobject, preselect) {
				
		var SelectBoxName = destinationobject;  //First value is always the name of the object being populated (REQUIRED)
		var SelectBoxSelectItemID = preselect; //Second value is always the ID value of the item that is to be preselected (OPTIONAL)
		var MySelectBox;
		var MyAJAXdiv;
		var nPreselectIndex;

		if (document.getElementById(SelectBoxName + 'AJAXloading')) { 
			MyAJAXdiv = document.getElementById(SelectBoxName + 'AJAXloading');
		}

		if (document.getElementById(SelectBoxName)) { 
			MySelectBox = document.getElementById(SelectBoxName);
		}
		
		var myJSONtext = JSONData;
		var objData = JSON.parse(myJSONtext);
		
		if (MySelectBox) {
			MySelectBox.options.length= 0;
			// Old method of populating select boxes that while not using DOM, works on all browsers, except Opera 5.02. Works fine on later Operas.
			myOption = new Option("Select One", "", true, true); //Text, Value, Selected, Default Selected. The last two appear to be dead ducks in most browsers.
			MySelectBox.options[MySelectBox.options.length] = myOption;
		}
		
		nPreselectIndex = -1;
		if (objData) {
			for(i=0;i<objData.items.length;i++) {
				// Old method of populating select boxes that while not using DOM, works on all browsers, except Opera 5.02. Works fine on later Operas.
				if (objData.items[i].id==SelectBoxSelectItemID){
					//alert(SelectBoxSelectItemID);
					myOption = new Option(objData.items[i].name, objData.items[i].id, false, false); //Text, Value, Selected, Default Selected. The last two appear to be dead ducks in most browsers.
					myOption.selected = true; //Preselect this item on the fly. Works on most browsers

					//Some browsers require the setting of a flag, in order to force the preselect of a chosen option, after the whole <Select> has finished building.
					//One example is Opera. 
					nPreselectIndex = i + 1; // i + 1 because we already added an option called [select]
				}
				else {
					myOption = new Option(objData.items[i].name, objData.items[i].id, false, false); //Text, Value, Selected, Default Selected. The last two appear to be dead ducks in most browsers.
				}
				MySelectBox.options[MySelectBox.options.length] = myOption;
				MySelectBox.select
			}

			//Force a preselect here, after building the select box. Required on browsers like Opera which won't preselect elements on the fly.
			if (nPreselectIndex > -1) {
				MySelectBox.options[nPreselectIndex].selected = true; //This forces a preselect if necessary.
			}
		}
		
		myOption = null;
		MySelectBox = null;
		MyAJAXdiv = null;
		objData = null;
	}
/*	
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false");
*/