/*extern ActiveXObject */
/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Create and return an AJAX request object
handles support for all AJAX-enabled IE versions, and Mozilla/Firefox
this function is silent.  The caller can test the returned object and 
handle user notifications.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
function ajax_getRqObj() {
	var request = false;
	try {
		request = new XMLHttpRequest();									// Firefox, IE7?, other?
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");			// IE6
		} catch (othermicrosoft) {
			try {
	      	request = new ActiveXObject("Microsoft.XMLHTTP");	// Other IE (5.5?)
			} catch (failed) {
				request = null;
			}
		}
	}
 	return request;
}

/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ajax_POST(lsUrl, lsParams, loResultAction)
Wrapper function for making AJAX calls to server-side programs via HTTP.
This function takes a few parameters, and does the whole ball of AJAX wax.
POSTs lsParams to lsUrl, and calls loResultAction with the responseText.
If a HTTP response other than 200 is received from the server, loResultAction
is called with a pipe-delimited list like, "500|HTTP Error".
the function in lfCallback is responsible for all response processing.
	string:lsUrl - page to call;  Can be a fully-qualified, or relative URL
	string:lsParams - URLEncoded list of name/value pairs to send to lsUrl
	object:loResultAction - a JavaScript function object whose code will handle
			the results when the HTTP exchange is complete.
This function returns null if it can't create the AJAX object, otherwise,
returns the AJAX object to the caller, but does not wait for the server
response.  The calling script is responsible for all error handling.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
function ajax_POST(lsUrl, lsParams, loResultAction) {
	if (!lsUrl || !lsParams || !loResultAction) { return null; }
	var loRq = ajax_getRqObj();
	if (!loRq) { return loRq; }
	loRq.open('POST', lsUrl, true);
	loRq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	loRq.setRequestHeader("Content-length", lsParams.length);
	loRq.setRequestHeader("Connection", "close");
	loRq.onreadystatechange = 	function () {	//AJAX http response handler
		if (loRq.readyState == 4) {
			if (loRq.status != 200) {
				loResultAction(loRq.status+'|HTTP Error');
			} else {
				loResultAction(loRq.responseText);
			}
		}
	};	// end callback
	loRq.send(lsParams);
 	return loRq;
}

function canDoAJAX() { return (ajax_getRqObj())?true:false; }

/*
		function pasteSql(loList) {
			var oid = loList.options[loList.selectedIndex];
			if ( !oid || ! /^[0-9]+\$/.test(oid.value) ) return;			// test to make sure you get the input value you need
			ebid('submitButton').disabled = true;								// inactivate UI widgets so the user can't do something we don't want while the request is processing
			var params = 'lsAction=get_sql_stmt&sql_oid=' + oid.value;	// build the urlencoded parameter string
			var url = "$scriptName";												// URL to POST to
			var rc = ajax_POST(url, params, _paste);							// send the request
		}

		// A very simple callback function
		function _paste(rsp) {
			ebid('submitButton').disabled = false;								// re-enable any UI widgets you disabled
			var laR = rsp.split('|');												// split the result string into an array
			if (laR[0] != 0) {														// not zero is an error of some kind
				// message the user;  We stick some text in a div here, but alert() works too
				ebid('resultDiv').innerHTML = "Error "+laR[0]+"<br>"+laR[1];
			} else {
				ebid('stmt').value = laR[1];										// do something with the result string/array 
//				ebid('resultDiv').innerHTML = '<b style="color: Blue;">SQL pasted!</b>';
			}
			// optionally clear the user message in five seconds
			setTimeout("ebid('resultDiv').innerHTML=''", 5000);
		}

*/