﻿
        function LookupCities()
        {
            stateCombo = document.getElementById("ctl00_cphBody_ddlState");
            cityCombo = document.getElementById("ctl00_cphBody_listCity");
            
            stateId = stateCombo.options[stateCombo.selectedIndex].value;
            
            if(stateId.match(/^\d+$/))
            {            
                cityCombo.options.length = 0;
                cityCombo.options[0] = new Option("Loading", "Loading");
                cityCombo.disabled = true;
                //PropertySearch.GetCitiesInUse(stateId, LookupCities_cb);   
                $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "/PropertySearch.asmx/GetCitiesInUse",
                        data:"{'stateId': '" + stateId + "'}",
                        dataType: "json",
                        success: function(response) {
                            var d = eval('(' + response + ')');
                            LookupCities_cb(d);
                        }
                    });
            }
            else
            {
                cityCombo.disabled = true;
                LookupCities_cb("");
            }
        }
        
        function LookupCities_cb(result)
        {
            cityCombo = document.getElementById("ctl00_cphBody_listCity");
            arr = result.split(",");
            
            cityCombo.options.length = 0;
            
            for (i=0; i<arr.length; i++)
            {
                cityCombo.options[i] = new Option(arr[i], arr[i]);
            }
            
            if (result.length == 0)
            {
                cityCombo.options[0] = new Option("","");
            }
            else
            {
                cityCombo.disabled = false;
            }
        }
        
        function LookupTypes()
        {
            zoneCombo = document.getElementById("ctl00_cphBody_ddlZone"); 
            typeCombo = document.getElementById("ctl00_cphBody_ddlType");

            zoneId = zoneCombo.options[zoneCombo.selectedIndex].value;
            
            if(zoneId.match(/^\d+$/))
            {            
                typeCombo.options.length = 0;
                typeCombo.options[0] = new Option("Loading", "Loading");
                typeCombo.disabled = true;
                //PropertySearch.GetTypeFromZoneId(zoneId, LookupTypes_cb);   
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "/PropertySearch.asmx/GetTypeFromZoneId",
                        data:"{'zoneId': '" + zoneId + "'}",
                        dataType: "json",
                        success: function(response) {
                            var d = eval('(' + response + ')');
                            LookupTypes_cb(d);
                        }
                    }); 
            }
            else
            {
                typeCombo.disabled = true;
                LookupCities_cb();
            }
        }
        
        function LookupTypes_cb(result)
        {
            typeCombo = document.getElementById("ctl00_cphBody_ddlType");
            arr = result.split(",");
            
            typeCombo.options.length = 0;
            
            for (i=0; i<arr.length; i++)
            {
                typeCombo.options[i] = new Option(arr[i], arr[i]);
            }
            
            if (result.length == 0)
            {
                typeCombo.options[0] = new Option("","");
            }
            else
            {
                typeCombo.disabled = false;
            }
        }