

/* Creates and returns an XMLhttp object that can be used for AJAX control */
function createRequestObject() {
	// Get the XML http object which will be used to make requests to the server
	// If in any browser but IE, just use the XMLhttp object
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		return new XMLHttpRequest();
	} 
	// Otherwise, use the Microsoft ActiveX control
	else if (window.ActiveXObject) { // IE
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

// Create a global variable, which represents the XMLhttp object we are passing
// back and forth with the server to answer our queries
var http = createRequestObject();
function getStateOffices(state, country) {
	http.abort();
	//CMhideLayer('ajaxWarning',0);
	thisUrl = 'find_office_actionSTATE_ajax.php?state=' + state + "&country_id=" + country;
	http.onreadystatechange = handleStateOffices;
	http.open('GET', thisUrl, true);
	http.send(null);
}
/*
function getStateOffices(state) {
	//alert('getContent called: ' + pageTitle);
	thisUrl = '/training_online/index.cfm';
	queryString = 'state=' + state
	http.abort();
	http.open('POST', thisUrl);
	http.onreadystatechange = handleStateOffices;
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send(queryString);
}
*/
function handleStateOffices() {
	if(http.readyState == 1) {
		// Allow for at least 1 second for the data to arrive
		//setTimeout("CMshowLayer('ajaxWarning',0)",1000);
	}
	if(http.readyState == 4) {
		// Hide the warnig now that the data has arrived
		//CMhideLayer('ajaxWarning',0);
		// Get the response from the server as plain text
		var response = http.responseText;
		response = response.trim();
		//alert(response);
		document.getElementById('stateContent').innerHTML = response;
	}
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
// CMshowLayer takes two variables,
// The layer to be revealed and the number of milliseconds before that happens
function CMshowLayer(showIt,waitForIt) {
	if (document.layers) {
		commandLine = "document." + showIt + ".visibility = 'show'";
	} else if (document.all) {
		commandLine="document.all." + showIt + ".style.visibility='visible';";
	} else if (document.getElementById) {
		commandLine = "document.getElementById('" + showIt + "').style.visibility = 'visible'";
	}
	// Only do this if the data still hasn't arrived
	if (http.readyState == 1) {
		setTimeout("eval(commandLine)", waitForIt);
	}	
}
// CMhideLayer takes two variables,
// The layer to be hidden and the number of milliseconds before that happens
function CMhideLayer(hideIt, waitForIt) {
	if (document.layers) {
		commandLine = "document." + hideIt + ".visibility = 'hidden'";
		setTimeout("eval(commandLine)", waitForIt);
	} else if (document.all) {
		commandLine="document.all." + hideIt + ".style.visibility='hidden';";
		setTimeout("eval(commandLine)", waitForIt)
	} else if (document.getElementById) {
		commandLine = "document.getElementById('" + hideIt + "').style.visibility = 'hidden'";
		setTimeout("eval(commandLine)", waitForIt);
	}
}