var oXmlHttp = zXmlHttp.createRequest();

function handleChange(changedObj)
{
	var f = document.getElementById('searchForm');
	var str = "ajaxSearchResults.php?ajax=true";

	for (var i=0; i<f.elements.length; i++) {
		var obj = f.elements[i];
		if (obj.type == "checkbox") {
			if (obj.checked) {
				str = str + '&' + obj.name + '=' + obj.value;
			}
		}

		if (obj.type == "select-one") {
			if (obj.value != 0) {
				str = str + '&' + obj.name + '=' + obj.value;
			}
		}

		if (obj.type == "text") {
			if (obj.value.length > 0) {
				str = str + '&' + obj.name + '=' + obj.value;
			}
		}

		if (obj.type == "hidden") {
			str = str + '&' + obj.name + '=' + obj.value;
		}
	}
	
	urlEncoded = encodeURI(str);

	oXmlHttp.open("get", urlEncoded, true);
	oXmlHttp.onreadystatechange = onResponse;
	oXmlHttp.send(null);
}

function onResponse()
{
	if (oXmlHttp.readyState == 4) {
		if (oXmlHttp.status == 200) {
			var obj = document.getElementById('AJAXResults');
			obj.innerHTML = "Total Results: " + oXmlHttp.responseText;
			obj.style.display = "block";
		} else {
			// this triggers when entering text into a text field and hitting search, without
			// hitting tab first. Can't figure out why yet, so I'm just skipping the error alert -AC
			//alert("An error occurred: " + oXmlHttp + oXmlHttp.status + " " + oXmlHttp.statusText);
		}
	}
}

