var RowHighlighter = Class.create({
    initialize: function (A) {
        this.row = A;
        this.link = this.row.select("a")[0].readAttribute("href");
        Event.observe(this.row, "mouseover", this.highlight.bind(this));
        Event.observe(this.row, "mouseout", this.dehighlight.bind(this));
        Event.observe(this.row, "click", this.go.bind(this))
    },
    highlight: function () {
        this.row.addClassName("over")
    },
    dehighlight: function () {
        this.row.removeClassName("over")
    },
    go: function () {
        document.location = this.link
    }
});
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()
    }
}
Event.observe(window, "load", function () {
    ($$("#arendusprojektid .region tr.project")).each(function (C) {
        new RowHighlighter(C)
    });
    s_county = $("search_county");
    s_city = $("search_city");
    s_city_part = $("search_city_part");
    s_defaults = ($F($("search_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 (E) {
        var C = E.value;
        var F = E.key;
        var D = new Element("option", {
            value: F
        }).update(C.name);
        if (s_is_default(0, F)) {
            D.selected = true
        }
        s_county.insert({
            bottom: D
        })
    });
    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);
    var B = $$("p#disclamer_label span").first();
    B.observe("mouseover", function (C) {
        $("disclamer_text").setStyle({
            display: "block"
        })
    });
    B.observe("mousemove", function (C) {
        $("disclamer_text").setStyle({
            top: (C.pointerY() + 5) + "px",
            left: (C.pointerX()) + "px"
        })
    });
    B.observe("mouseout", function () {
        $("disclamer_text").setStyle({
            display: "none"
        })
    });
    var A = function (D) {
        var E = D.readAttribute("title");
        D.writeAttribute("title", "");
        var C = new Element("div", {
            "class": "notice_popup"
        }).hide();
        C.setStyle({
            color: D.getStyle("color")
        });
        C.update(E);
        D.insert({
            before: C
        });
        D._popup = C;
        D.observe("mouseover", function (G) {
            var F = G.findElement("b");
            F._popup.show()
        });
        D.observe("mouseout", function (G) {
            var F = G.findElement("b");
            F._popup.hide()
        });
        D.observe("mousemove", function (G) {
            var F = G.findElement("b");
            F._popup.setStyle({
                top: (G.pointerY() + 5) + "px",
                left: (G.pointerX() - F._popup.getWidth()) + "px"
            })
        })
    };
    $$(".notice_positive").each(A);
    $$(".notice_neutral").each(A);
    $$(".notice_negative").each(A)
});
