function cityPlacesSearchStateChanged() {
    var value = '22';
    var text = 'Louisiana';
    var map = GCROUtils.getMap();
   
    //get server url
    var url = EsriUtils.getServerUrl(map.formId);
    
    if (text != 'Select a State') {
        var params = new Array();
        params.push("STATE=" + value);
        
        var responseHandler = new ResponseHandler();
        responseHandler.getResponseProcessor = function () {
            return function(xmlHttp) {
                // Dispose the wait panel.
                waitPanel.hide();
                    
                cityPlacesSearchresponse(xmlHttp);
            };
        };    
        
        var waitMessage = "Loading City list for " + text + ", please wait....";
        
        GCROUtils.performCommand(url, true, "cityPlacesList", currentViewId, params, responseHandler, waitMessage);
    } else {
        var newText = "<option value=\"\" disabled=\"true\" selected=\"true\">";
        newText += "Select a city ";
        newText += "</option>";
        
        $('cityPlacesSearchSelect').innerHTML = newText;
        $('cityPlacesSearchSelect').disabled = true;
    }
}

function cityPlacesSearchresponse(xh) {
    if (xh != null && xh.readyState == 4 && xh.status == 200) {
        var xml = xh.responseXML;
        var resultTags = xml.getElementsByTagName("result");
        if (resultTags.length > 0) {
            var select_html = "";
            var cityPlaces = [];
            var objectIds = new Object();
            for (var j = 0; j < resultTags.length; j++) {
                var resultTag = resultTags.item(j);
                var details = resultTag.getElementsByTagName("detail");
                var fullname = "";
                var cofips = "";

                $("cityPlacesSearchSelect").disabled = false;
                $("cityPlacesSearchSelect").options.length = 1;
                
                var name = details.item(0).getAttribute("value").toString().trim();
                var objectId = details.item(1).getAttribute("value").toString().trim();
                if (name == "") {
                    fullname =  "Unknown";
                } else {
                    fullname = name;
                }
                
                cofips = objectId;
                
                cityPlaces[j] = fullname;
                objectIds[fullname] = cofips;
            }//for j
            cityPlaces.sort();
            for (k = 0; k < cityPlaces.length; k++) {
                var co = cityPlaces[k];
                var fps = objectIds[cityPlaces[k]];
                $("cityPlacesSearchSelect").options[k + 1] = new Option(co, fps);
            }
        }//if
    }//if
}

function cityPlacesSearcher() {}
cityPlacesSearcher.prototype = new Searcher();
cityPlacesSearcher.prototype.name = "cityPlacesSearch";
cityPlacesSearcher.prototype.mapUpdateAction = "zoomToCity";
cityPlacesSearcher.prototype.searchType = "Spatial";
cityPlacesSearcher.prototype.doAfterInit = function () {
	cityPlacesSearchStateChanged();
        						  
    YAHOO.util.Event.addListener("cityPlacesSearchSubmit", "click", function () {
        cityPlacesSearcher.handleSubmit();
    });
    YAHOO.util.Event.addListener("cityPlacesSearchCancel", "click", function () {
        cityPlacesSearcher.handleCancel();
    });
};
cityPlacesSearcher.prototype.validateUserInputs = function () {
    var cityPlacesSelectedIndex = $('cityPlacesSearchSelect').selectedIndex;
    
    if (cityPlacesSelectedIndex == 0) {
        alert("Please narrow your search to a specific city.");
        return false;
    }
    
    return true;
};
cityPlacesSearcher.prototype.getUserInputs = function () {
    var cityPlacesSelectedIndex = $('cityPlacesSearchSelect').selectedIndex;
    
    var params = new Array();
    params.push('objectId=' + $('cityPlacesSearchSelect')[cityPlacesSelectedIndex].value);
   
    return params;
};
var cityPlacesSearcher = new cityPlacesSearcher();
searchers.set(cityPlacesSearcher.name, cityPlacesSearcher);
