/* city, county, and state function */ var _stateSelect = null; var _countySelect = null; var _citySelect = null; var _areaSelect = null; var _districtSelect = null; var _state_id = 1; var _state = 'UT'; 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(); }, 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; } 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"))); } 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]; 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]; listSource.addCounty(new County(county.getAttribute("id"), county.firstChild.nodeValue, county.getAttribute("lat"), county.getAttribute("lng"), -1, listSource.id)); } listSource.createCountyOptions(); listSource.updateCounties(); } } if (this.cb != null) { this.cb(); } } }; function getCountyById(county_id) { if (_states.length == 0) { for (var i = 0; i < _counties.length; i++) { if (_counties[i].id == county_id) { return _counties[i]; } } } else { var state = getSelectedState(); if (state != null) return state.getCountyById(county_id); } return null; } 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 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(); } 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 getSelectedCounty() { 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) return state.getCountyById(countyId); } return(null); } function getSelectedCity() { var county = getSelectedCounty(); if (county == null) { return null; } var cityId = _citySelect.options[_citySelect.selectedIndex].value; return county.getCityById(cityId); } function getSelectedState() { var stateId; if (_stateSelect == null) { stateId = 1; } 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); }