var xmlhttp = createXMLHttpRequest()

function createXMLHttpRequest() {
	var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	if (!xmlhttp) {
		alert("Error initializing XMLHttpRequest!");
	} else {
		return xmlhttp;
	}
}

function select(Object) {
	//encodeURIComponent(Object.value)
	var url = "./ajax_response.php?category=" + encodeURIComponent(Object.value) + "&r=" + Math.random();
	sendAJAXdata(url, Object);
}

function sendAJAXdata(url, obj) {
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = processRequestChange;
	xmlhttp.send(null);
}

function processRequestChange() {
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			var response = xmlhttp.responseText;
			viewSelectOptions(response);
		} else {
			alert("Не удалось получить данные:\n" + xmlhttp.statusText);
		}
	}
}
   
function viewSelectOptions(response) {
	var type = document.getElementById('type');
	var rspArray = response.split(":");
	type.innerHTML = "";

	for (var i = 0; i < rspArray.length; i++) {
		var obj = document.createElement("option");
		obj.value = rspArray[i];
		var txtNode = document.createTextNode(rspArray[i])
		obj.appendChild(txtNode);	//set text to show
		type.appendChild(obj);
	}
}
