function newXMLHttpRequest() {

	/*
	 * Returns an new XMLHttpRequest object, or false if the browser
	 * doesn't support it
	 */

	var xmlreq = false;

	// Create XMLHttpRequest object in non-Microsoft browsers
	if (window.XMLHttpRequest) {
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			// Try to create XMLHttpRequest in later versions
			// of Internet Explorer
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			// Failed to create required ActiveXObject
			try {
				// Try version supported by older versions
				// of Internet Explorer
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				// Unable to create an XMLHttpRequest by any means
				xmlreq = false;
			}
		}
	}

	return xmlreq;
}

function getReadyStateHandler(req, responseHandler, errorHandler) {

	/*
	 * Returns a function that waits for the specified XMLHttpRequest
	 * to complete, then passes the response to the given handler function.
	 * req - The XMLHttpRequest whose state is changing
	 * responseHandler - Function to pass the response to
	 * errorHandlker - Element used to display processing errors
	 */

	// Return an anonymous function that listens to the XMLHttpRequest instance
	return function () {
		// If the request's status is "complete"
		if (req.readyState == 4) {
			// Check that we received a successful response from the server
			if (req.status == 200) {
				// Pass the XML payload of the response to the handler function.
				responseHandler(req);
			} else {
				// An HTTP problem has occurred, throw an error
				if (errorHandler == null || errorHandler == "") {
					alert("We are unable to process your request at this time.");
				} else {
					//alert("HTTP error "+req.status+": "+req.statusText);
					errorHandler("inline");
				}
			}
		}
	}
}

function updateStatus(elementID, msg, display) {
	try {
		var elStatus = document.getElementById(elementID);
		elStatus.innerHTML = msg;
		elStatus.style.display = display;
	} catch (e) {
		;
	}
}

function ajaxError(elementID, display) {
	/*
	 * Show the selected error message.
	 */
	try {
		if (display == null || display == "") {
			display = "inline";
		}
		document.getElementById(elementID).style.display = display;
	} catch (e) {
		;
	}
}
