var MooFormTipp = new Class({
    Implements: [Options, Events],
    options: {
        optionYes: _('Ja'),
        optionNo: _('Nein'),
        hiddenField: "hiddeninfo",
        notEnough: i18n.errors.notEnoughCrown,
        fatalError: i18n.errors.notEnoughCrown.notOk,
        newSubmit: $empty,
        CaptachCondition: "showyes"
    },
    initialize: function(b, a) {
        this.setOptions(a);
        this.formID = b;
        this.form = $$("." + b)[0];
        $$("." + b).each(function(f) {
            var h = f.getElement("input[type=button]");
            var g = f;
            var d = f.getElement("." + this.options.hiddenField).get("value");
            var e = f.getElement("." + this.options.hiddenField).get("title").toInt();
            var c = f.getElement("." + this.options.hiddenField).getParent();
            h.addEvent("click",
            function(i) {
                $$("." + this.formID + " .formTipp").destroy();
                this.createTipp(f, d, c, e, g, h)
            }.bind(this))
        },
        this)
    },
    shutter: function() {
        var c = $$("body")[0].getCoordinates();
        var a = document.body.getScroll();
        var b = $("wrap").getStyle("height");
        new Element("div", {
            "class": "zabsolute ajaxBigLoader",
            styles: {
                top: "0",
                left: "0",
                opacity: "0.8",
                backgroundPosition: "50% " + a.y + "px",
                width: c.width + "px",
                height: b,
                zIndex: "9999"
            }
        }).injectInside(document.body)
    },
    createTipp: function(c, g, b, f, d, e) {
        if (!e.hasClass(this.options.CaptachCondition)) {
            new Request.HTML({
                url: "/ajax/virtual_currency/",
                method: "post",
                update: false,
                onFaliure: function() {
                    alert("Fehler")
                },
                onComplete: function(k) {
                    var j = k.item(0).get("text");
                    var m = k.item(1).get("text");
                    if (j == "ok") {
                        if (m >= f) {
                            var l = {
                                crownState: f
                            };
                            var i = new Element("div", {
                                "class": "formTipp",
                                html: i18n.hs.hl.substitute(l)
                            });
                            var n = new Element("div", {
                                "class": "zclear yesTip",
                                text: this.options.optionYes,
                                events: {
                                    click: function() {
                                        if (this.options.newSubmit != $empty) {
                                            this.captcha(c)
                                        } else {
                                            this.shutter();
                                            d.submit()
                                        }
                                    }.bind(this)
                                }
                            });
                            var h = new Element("div", {
                                "class": "noTip",
                                text: this.options.optionNo,
                                events: {
                                    click: function() {
                                        $$(".formTipp").destroy()
                                    }.bind(this)
                                }
                            });
                            n.injectInside(i);
                            h.injectInside(i);
                            i.injectInside(c)
                        } else {
                            var o = new Element("div", {
                                "class": "formTipp",
                                text: this.options.notEnough,
                                events: {
                                    click: function() {
                                        this.destroy()
                                    }
                                }
                            }).injectInside(c);
                            var n = new Element("a", {
                                "class": "zclear zblock yesTip",
                                href: "/itemsale/recharge_coins/",
                                text: i18n.buttons.buyCrown
                            }).injectInside(o)
                        }
                    } else {
                        alert(this.options.fatalError)
                    }
                }.bind(this)
            }).send()
        } else {
            var a = c.getElement("." + this.options.hiddenField).get("value");
            setupForm("/skill/upgrade/" + a + "/")
        }
    },
    captcha: function(c) {
        var a = c.getElement("input[type=button]");
        var d = c.getElement("." + this.options.hiddenField).get("value");
        if (d != this.options.CaptachCondition) {
            var b = a.get("id");
            setupForm("/skill/upgrade/" + b + "/")
        }
    }
});
