// JavaScript Document
// JavaScript Document
var xmlHttp;
var response;
var req;


function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    }
}



//drop down code
function subDropCheck(setCatID, setSubCatID){
	if (setCatID != ''){
		loadDropDownXML(setCatID);
	}
	
}



function loadDropDownXML(catID){
		createXMLHttpRequest();
		var url  = '/properties/process/cityarea_xml.cfm?cityID=' + catID;
		req.onreadystatechange = processDropDown;
		req.open("GET",url,true);
		req.send(null);
}
 
//this is used to get the sub category info based on the first selected dropdown
function processDropDown() {
    // only if req shows "complete"
    if (req.readyState == 4) {
		// only if "OK"
        if (req.status == 200) {
			
			var dropForm = document.form1.subcat;
			for (x=dropForm.options.length; x>1; x--){
                    dropForm.options[x]=null;	
            	} 
			//parse the xml document 
			var list = req.responseXML.getElementsByTagName('city');
	
			//clear drop down if there are no items to be selected
			 if(list.length<=0){
			 	//remove elements from drop down menu
				for (x=dropForm.options.length; x>1; x--){
                    dropForm.options[x]=null;	
            	} 
				//hide drop down menu
				document.getElementById('drop1').style.display='none'
			}else{
				//show drop down menu
				document.getElementById('drop1').style.display='block'
				//populate drop down menu
				for(var i=0; i<list.length; i++){
					//grab values from xml document	
			
					var cityareaID = list[i].getAttribute("cityareaID");
					var ListName = list[i].getAttribute("name");
					
					var selectedDropDown = document.form1.subcityHolder.value;
					
					//create drop down
					listOpt = document.createElement("option");
					listOpt.value = cityareaID;
					listOpt.text = ListName;
					//oSelect.options.dropForm.add(listOpt); 
					if(cityareaID == (parseFloat(selectedDropDown,10)+1)){
						//alert(parseFloat(selectedDropDown,10)+1);
						listOpt.selected = "selected";
                	}				
					dropForm.add(listOpt) ;
      			}
				
			}	
			
        } 
    }
}


