/* city, county, and state function */ var _stateSelect = null; var _countySelect = null; var _citySelect = null; var _areaSelect = null; var _districtSelect = null; var _state_id = 10; var _state = 'CO'; var _states = new Array(); var _counties = new Array(); var _listSources = new Array(); var _areas = new Array(); var _districts = new Array(); var _default_state_obj = null; var ListSource = Class.create(); ListSource.prototype= { initialize: function(id, name, prefix) { this.id = id; this.name = name; this.prefix = prefix; this.counties = new Array(); this.districts = new Array(); }, addCounty: function (county) { this.counties[this.counties.length] = county; }, createOption: function() { return new Option(this.name, this.prefix); }, createCountyOptions: function() { if (this.counties.length == 0) { ajaxEngine.sendRequest('doListSourceUpdate', "list_id=" + this.id, "object_id=listSourceUpdater", "prefix="+this.prefix); } else { var size = _countySelect.options.length; for (var i = 0; i < this.counties.length; i++) { _countySelect.options[i + 1] = this.counties[i].createOption(); } //remove any other counties from the previous county listing for (var i = this.counties.length; i < size; i++) { _countySelect.options[this.counties.length + 1] = null; } if (this.counties.length == 1) { _countySelect.options[1].selected = true; this.counties[0].createCityOptions(); } this.updateCounties(); } }, updateCounties: function() { _counties = new Array(); for (var i=0; i 0) { countyId = city.getAttribute("county_id"); var county = getCountyById(countyId); if (county != null) { for (var i = 0; i < cities.length; i++) { var city = cities[i]; county.addCity(new City(city.getAttribute("id"), city.firstChild.nodeValue, city.getAttribute("zip"), city.getAttribute("lat"), city.getAttribute("lng"), city.getAttribute("zoom"))); } county.createCityOptions(); } } if (this.cb != null) { this.cb(countyId); } } }; var AreaUpdater = Class.create(); AreaUpdater.prototype = { initialize: function() { this.cb = null; ajaxEngine.registerRequest('doAreaUpdate', '/ajax/county_list.php'); ajaxEngine.registerAjaxObject("areaUpdater", this); }, ajaxUpdate: function(ajaxResponse) { var areaList = ajaxResponse.childNodes[0]; var areas = countyList.childNodes; var new_areas = Array(); if (areas.length > 0) { for (var i=0; i 0) { for (var i=0; i 0) { var stateId = countyList.getAttribute("state_id"); var state = getStateById(stateId); if (state != null) { for (var i = 0; i < counties.length; i++) { var county = counties[i]; state.addCounty(new County(county.getAttribute("id"), county.firstChild.nodeValue, county.getAttribute("lat"), county.getAttribute("lng"), state.id, null)); } state.createCountyOptions(); } } if (this.cb != null) { this.cb(); } } }; var ListSourceUpdater = Class.create(); ListSourceUpdater.prototype = { initialize: function() { this.cb = null; ajaxEngine.registerRequest('doListSourceUpdate', '/ajax/county_list.php'); ajaxEngine.registerAjaxObject("listSourceUpdater", this); }, ajaxUpdate: function(ajaxResponse) { var countyList = ajaxResponse.childNodes[0]; if (countyList != null) { var counties = countyList.childNodes; if (counties.length > 0) { var listSourceId = countyList.getAttribute("list_id"); var listSource = getListSourceById(listSourceId); if (listSource != null) { _counties = new Array(); for (var i = 0; i < counties.length; i++) { var county = counties[i]; var newCounty = new County(county.getAttribute("id"), county.firstChild.nodeValue, county.getAttribute("lat"), county.getAttribute("lng"), -1, listSource.id); listSource.addCounty(newCounty); } listSource.createCountyOptions(); listSource.updateCounties(); } } if (this.cb != null) { this.cb(); } } } }; var ListSourceUpdaterDistrict = Class.create(); ListSourceUpdaterDistrict.prototype = { initialize: function() { this.cb = null; ajaxEngine.registerRequest('doListSourceUpdateDistrict', '/ajax/district_list.php'); ajaxEngine.registerAjaxObject("listSourceUpdaterDistrict", this); }, ajaxUpdate: function(ajaxResponse) { var districtList = ajaxResponse.childNodes[0]; if (districtList != null) { var districts = districtList.childNodes; if (districts.length > 0) { var listSourceId = districtList.getAttribute("list_id"); var listSource = getListSourceById(listSourceId); if (listSource != null) { _districts = new Array(); for (var i = 0; i < districts.length; i++) { var district = districts[i]; listSource.addDistrict(new District(district.getAttribute("id"), district.firstChild.nodeValue, district.getAttribute("lat"), district.getAttribute("lng"), -1, listSource.id)); } listSource.createDistrictOptions(); listSource.updateDistricts(); } } if (this.cb != null) { this.cb(); } } } }; function getCountyById(county_id) { var county = null; if (_states.length != 0) { var state = getSelectedState(); if (state != null) county = state.getCountyById(county_id); } if (county == null) { for (var i = 0; i < _counties.length; i++) { if (_counties[i].id == county_id) { county = _counties[i]; } } } return county; } function getStateById(state_id) { for (var i = 0; i < _states.length; i++) { if (_states[i].id == state_id) { return _states[i]; } } return null; } function getListSourceById(list_source_id) { for (var i = 0; i < _listSources.length; i++) { if (_listSources[i].id == list_source_id) { return _listSources[i]; } } return null; } function getListSourceByPrefix(prefix) { for (var i = 0; i < _listSources.length; i++) { if (_listSources[i].prefix == prefix) { return _listSources[i]; } } return null; } function getAreaById(area_id) { for (var i=0; i< _areas.length; i++) { if (_areas[i].id == area_id) { return(_areas[i]); } } return(null); } function getDistrictById(district_id) { for (var i=0; i< _districts.length; i++) { if (_districts[i].id == district_id) { return(_districts[i]); } } return(null); } function getAreaByName(name) { for (var i=0; i< _areas.length; i++) { if (_areas[i].name == name) { return(_areas[i]); } } return(null); } function getDistrictByName(name) { for (var i=0; i< _districts.length; i++) { if (_districts[i].name == name) { return(_districts[i]); } } return(null); } function updateCitySelect() { var countyId = _countySelect.options[_countySelect.selectedIndex].value; var county = getCountyById(countyId); if (county != null) county.createCityOptions(); else if (_citySelect != null) { _citySelect.options[0].selected = true; } } function updateCountySelect() { var stateId = _stateSelect.options[_stateSelect.selectedIndex].value; var state = getStateById(stateId); if (state != null) state.createCountyOptions(); } function updateCountySelect2() { var prefix = _search.getTablePrefix(); var listSource = getListSourceByPrefix(prefix); if (listSource != null) listSource.createCountyOptions(); } function updateDistrictSelect() { var prefix = _search.getTablePrefix(); var listSource = getListSourceByPrefix(prefix); if (listSource != null) listSource.createDistrictOptions(); } function getSelectedCounty() { var county = null; if (_countySelect == null) { return(null); } var countyId = _countySelect.options[_countySelect.selectedIndex].value; if (_states.length == 0) { return getCountyById(countyId); } else { var state = getSelectedState(); if (state != null) county = state.getCountyById(countyId); if (county == null) county = getCountyById(countyId); } return(county); } function getSelectedCity() { var county = getSelectedCounty(); if (county == null) { return null; } if (_citySelect) var cityId = _citySelect.options[_citySelect.selectedIndex].value; else return null; return county.getCityById(cityId); } function getSelectedState() { var stateId; if (_stateSelect == null) { stateId = 10; } else { stateId = _stateSelect.options[_stateSelect.selectedIndex].value; } return getStateById(stateId); } function getSelectedArea() { var area_id= _areaSelect.options[_areaSelect.selectedIndex].value; return getAreaById(area_id); } function getSelectedDistrict() { var district_id= _districtSelect.options[_districtSelect.selectedIndex].value; return getDistrictById(district_id); }