var s_county;
var s_city;
var s_city_part;
var d_defaults;

function s_is_default(B, A) {
    return s_defaults !== null && s_defaults[B].length > 0 && s_defaults[B] == A
}
function update_cities() {
    var A = $F(s_county);
    s_city.update();
    s_city.insert({
        bottom: new Element("option", {
            value: -1
        })
    });
    if (A >= 0) {
        (location_info.get(A)).cities.each(function (E) {
            var D = E.value;
            var B = E.key;
            var C = new Element("option", {
                value: B
            }).update(D.name);
            if (s_is_default(1, B)) {
                C.selected = true
            }
            s_city.insert({
                bottom: C
            })
        })
    } else {
        location_info_special.each(function (C) {
            var B = new Element("option", {
                value: C.id
            }).update(C.name);
            s_city.insert({
                bottom: B
            })
        })
    }
    update_city_parts()
}
function update_city_parts() {
    var C = $F(s_county);
    var B = $F(s_city);
    s_city_part.disable();
    s_city_part.update();
    s_city_part.insert({
        bottom: new Element("option", {
            value: -1
        })
    });
    if (B == -1) {
        return
    }
    if (C == -1) {
        var A;
        A = B.split("_");
        if (A.length != 2) {
            return
        }
        C = A[0];
        B = A[1]
    }
    if (C >= 0 && B >= 0) {
        ((location_info.get(C)).cities.get(B)).city_parts.each(function (G) {
            var D = G.value;
            var E = G.key;
            var F = new Element("option", {
                value: E
            }).update(D);
            if (s_is_default(2, E)) {
                F.selected = true
            }
            s_city_part.insert({
                bottom: F
            })
        });
        s_city_part.enable()
    }
}
function hookup_locations() {
    s_county = $("info_location_level1");
    s_city = $("info_location_level2");
    s_city_part = $("info_location_level3");
    s_defaults = ($F($("info_location"))).split("_");
    s_county.disable();
    s_city.disable();
    s_city_part.disable();
    s_county.insert({
        bottom: new Element("option", {
            value: -1
        })
    });
    location_info.each(function (C) {
        var A = C.value;
        var D = C.key;
        var B = new Element("option", {
            value: D
        }).update(A.name);
        if (s_is_default(0, D)) {
            B.selected = true
        }
        s_county.insert({
            bottom: B
        })
    });
    s_county.enable();
    update_cities();
    s_city.enable();
    s_defaults = null;
    Event.observe(s_county, "change", update_cities);
    Event.observe(s_city, "change", update_city_parts)
}
