
function sendDate(uri) {
	var url = "http://www.jcauto.com.cn/carsNews.xml";
	var params = 0;
	var sendRequest = new Ajax.Request(url, {method:"GET", parameters:params, onComplete:showResponse, asynchronous:true});
}
function showResponse(request) {
	var obj = request.responseXML;
	var xmlobj = obj.getElementsByTagName("ROW");
	var brand = document.getElementById("brand");
	var catena = document.getElementById("catena");
	if(brand.value.length==1 && catena.value.length==1){
			var  typeElements=obj.getElementsByTagName("CAR_TYPE_ID");
		    for(i=0;i<typeElements.length;i++){
			  var option = document.createElement("option");
				var txtNode = document.createTextNode(typeElements[i].getAttribute("NAME"));
				option.setAttribute("value", typeElements[i].getAttribute("ID"));
				option.appendChild(txtNode);
				brand.appendChild(option);        
			}
		}
	for (var i = 0; i < xmlobj.length; i++) {
		if(brand.value.length<=4 && catena.value.length==1){
			var carId = xmlobj[i].getAttribute("CAR_ID");
			var catTypeId= xmlobj[i].getAttribute("CAR_TYPE_ID");
			var carParentId=xmlobj[i].getAttribute("CAR_PARENT_ID");
			var carCnName=xmlobj[i].getAttribute("CAR_CN_NAME");
			if (carId.length <= 4 && brand.value==catTypeId) {
				var option = document.createElement("option");	
				var txtNode = document.createTextNode(xmlobj[i].getAttribute("CAR_CN_NAME"));
				option.setAttribute("value", xmlobj[i].getAttribute("CAR_ID"));
				option.appendChild(txtNode);
				catena.appendChild(option);
					for (var j = 0; j < xmlobj.length; j++) {
							var carSeriId = xmlobj[j].getAttribute("CAR_ID");
							var carSeriParentId=xmlobj[j].getAttribute("CAR_PARENT_ID");
							var carSeriCnName=xmlobj[j].getAttribute("CAR_CN_NAME");	
							if(carId==carSeriParentId){					
										var option2 = document.createElement("option");	
										var txtNode2 = document.createTextNode("  "+carSeriCnName);
										option2.setAttribute("value", carSeriId);
										option2.appendChild(txtNode2);
										catena.appendChild(option2);
					}
					
			}
		}
	}
	}

}
function getCar(obj, uri) {
	var brand = document.getElementById("brand");
	var catena = document.getElementById("catena");
	if (obj != null) {
		if (obj.id == "brand") {
			for (var i = catena.length - 1; i >= 1; i--) {
				catena.options[i] = null;
			}
		}
	}
	if (obj.selectedIndex != 0) {
		sendDate(uri);
	}
}

