﻿///<reference path="mootools.v1.11.js" />
formFunctions = new Class({
    initialize: function() {
        this.sendBtn = $("sendbtn_form02");
        this.respDiv = new Element("div", { "class": "newsResult" }).inject(this.sendBtn, "after");
        this.sendBtn.addEvent('click', this.sendForm.bind(this));
        this.req = new Request.HTML({ url: "/ajax/sendForm.aspx",
            method: 'post',
            autoCancel: true,
            update: this.respDiv
        });
    },
    sendForm: function() {
        new Element("img", { "src": "/assets/ajax-loader.gif" }).inject(this.respDiv);
        this.req.send("name=" + $("name").get("value") + "&mail=" + $("e_mail").get("value"));
    }
});
formKontaktFunctions = new Class({
    initialize: function() {
        this.sendBtn = $("sendbtn_form03");
        this.respDiv = new Element("div", { "class": "newsResult" }).inject(this.sendBtn, "after");
        this.sendBtn.addEvent('click', this.sendForm.bind(this));
        this.req = new Request.HTML({ url: "/ajax/sendKontaktForm.aspx",
            method: 'post',
            autoCancel: true,
            update: this.respDiv
        });
    },
    sendForm: function() {
        new Element("img", { "src": "/assets/ajax-loader.gif" }).inject(this.respDiv);
        var gender = $$("input[name=gender]:checked").get("value");
        var name = $("name").get("value");
        var firma = $("firma").get("value");
        var mail = $("mail").get("value");
        var adress1 = $("adress1").get("value");
        var adress2 = $("adress2").get("value");
        var adress3 = $("adress3").get("value");
        var tel = $("tel").get("value");
        var notice = $("notice").get("value");
        this.req.send("name=" + name + "&firma=" + firma + "&mail=" + mail + "&adress1=" + adress1 + "&adress2=" + adress2 + "&adress3=" + adress3 + "&tel=" + tel + "&notice=" + notice + "&gender=" + gender);
    }
});

var unterLagenAccordeon = new Class({
initialize: function() {
        var togglers = $('docs').getElements("span.doctypetitle");
        var toToggle = $('docs').getElements("div.formBox");
        var myAccordion = new Fx.Accordion(togglers, toToggle);
    }
});


var formUnterlagenFunctions = new Class({
    initialize: function() {
        $$("input[type=checkbox]").each(function(chkBox) {
            chkBox.addEvent('click', this._toggle.pass(chkBox, this));
            chkBox.set("checked", false);
        }, this);

        this.sendBtn = $("sendbtn_form02");
        this.respDiv = new Element("div", { "class": "newsResult" }).inject(this.sendBtn, "after");
        this.sendBtn.addEvent('click', this.sendForm.bind(this));
        this.req = new Request.HTML({ url: "/ajax/unterlagenForm.aspx",
            method: 'post',
            autoCancel: true,
            update: this.respDiv
        });
    },
    _toggle: function(chkBox) {
        var id = chkBox.get("name");

        if (chkBox.get("value") == 'off')
            chkBox.set('value', 'on');
        else
            chkBox.set('value', 'off');
        var val = chkBox.get("value")
        if (!$chk($(id).getElement("span.radioLang"))) return;

        if (val == "off")
            $(id).getElement("span.radioLang").setStyle('display', 'block');
        else
            $(id).getElement("span.radioLang").setStyle('display', 'none');
    },
    sendForm: function() {
        new Element("img", { "src": "/assets/ajax-loader.gif" }).inject(this.respDiv);
        var gender = $$("input[name=anrede]:checked").get("value");
        var name = $("name").get("value");
        var firma = $("firma").get("value");
        var mail = $("mail").get("value");
        var adress1 = $("adress1").get("value");
        var adress2 = $("adress2").get("value");
        var adress3 = $("adress3").get("value");
        var tel = $("tel").get("value");
        var prodString = "";

        $$("input[type=checkbox]:checked").each(function(chkBox) {
            var id = chkBox.get('name');
            prodString += $(id).getElement("label.prodtitle").get("html");
            if ($(id).getElement("span.radioLang")) {
                var radioId = "dtSelect_" + id;
                if ($(radioId) != null) {
                    if ($("dtSelect_" + id).get("checked")) {
                        var amountId = "dtCount_" + id;
                        prodString += ", amount: " + $(id).getElement("input#" + amountId).get('value') + ", in german";
                    }
                }
                if ($("frSelect_" + id) != null) {
                    if ($("frSelect_" + id).get("checked")) {
                        var amountId = "frCount_" + id;
                        prodString += ", amount: " + $(id).getElement("input#" + amountId).get('value') + ", in french";
                    }
                }
                if ($("enSelect_" + id) != null) {
                    if ($("enSelect_" + id).get("checked")) {
                        var amountId = "enCount_" + id;
                        prodString += ", amount: " + $(id).getElement("input#" + amountId).get('value') + ", in english";
                    }
                }
            }
            else {
                prodString += ", amount: " + $(id).getElement("input[type=text]").get('value')
            }
            prodString += "<br />";
        });

        this.req.send("name=" + name + "&firma=" + firma + "&mail=" + mail + "&adress1=" + adress1 + "&adress2=" + adress2 + "&adress3=" + adress3 + "&tel=" + tel + "&gender=" + gender + "&products=" + prodString);
    }
});

var Slide = new Class({
    initialize: function() {
        var s = new Slideshow($("show"), false, { "center": true, "controler": false, paused: false, fast: true, duration: 500, "delay": 5000, "classes": ['slideshow', 'first', 'prev', 'play', 'pause', 'next', 'last', 'images', 'captions', 'controller', 'images', 'hidden', 'visible', 'inactive', 'active', 'loader'], width: 327, height: 210, resize: false });
        if ($("showControl")) {
            if (Browser.Engine.trident) $("showControl").onselectstart = function() { return false };
            else if (Browser.Engine.gecko) $("showControl").style.MozUserSelect = "none";
            else $("showControl").removeEvents("mousedown").addEvent("mousedown", function(e) { e.stop(); return false; });
            var showControlSlide = function(sNum) {
                $("showControl").getElements("a.sController").each(function(el, ind) {
                    if (ind == sNum) el.addClass("active");
                    else el.removeClass("active");
                });
            }
            if (s.data.images.length > 1) {
                s.data.images.each(function(elt, ind) {
                    new Element("a", { "class": "sController", "text": (ind + 1), "events": { "click": function() { s.pause(1); s.fireEvent("start"); s.go(ind); showControlSlide(ind) } } }).inject($("showControl"));
                });
                new Element("a", { "class": "arrowG", "events": { "click": function() {
                    this.prev();
                    this.fireEvent("start");
                    showControlSlide(this.slide);
                } .bind(s)
                }
                }).inject($("showControl"));
                new Element("a", { "class": "arrowD", "events": { "click": function() {
                    this.next();
                    this.fireEvent("start");
                    showControlSlide(this.slide)
                } .bind(s), "dblclick": function(e) { e.stop(); } 
                }
                }).inject($("showControl"));
            }
            s.addEvent("complete", function(ev) {
                showControlSlide((s.slide - 1 + s.data.images.length) % s.data.images.length);
            });
            this.remooz = null;
            s.addEvent("start", function(ev) {
                var linkElt = s.image.getParent("a");
                linkElt.removeEvents("click");
                if (this.remooz) $try(this.remooz.destroy);
                this.remooz = new ReMooz(linkElt, { "resize": false,
                    "onOpen": function() { s.pause(1) },
                    "onClose": function() { s.pause(0) }
                });
            } .bind(this));

            if ($("imagesLegend")) {
                var legendsArr = [];
                $("imagesLegend").getElements(".legends").each(function(elt) {
                    legendsArr.push(elt.setStyles({ "opacity": 0,
                        "position": "absolute"
                    }));
                });
                s.addEvent("start", function(ev) {
                    var num = (s.slide + s.data.images.length) % s.data.images.length;
                    if (legendsArr[num]) {
                        for (var i = 0; i < legendsArr.length; i++) {
                            legendsArr[i].fade("out");
                        }
                        legendsArr[num].fade("in");

                    }
                } .bind(this));
            }
        }
    }
});
var PreviewSlide = new Class({
    initialize: function(containerId, imgArr) {
        this.img = $(containerId).getElement("img");
        this.imgs = imgArr;
        this.c = 1;
        $(containerId).addEvent("click", this.getNext.bind(this));
    },
    getNext: function() {
        this.img.set("src", this.imgs[(this.c++ % this.imgs.length)]);
    }
});

//Mootools extensions

Fx.Elements = new Class({

    Extends: Fx.CSS,

    initialize: function(elements, options) {
        this.elements = this.subject = $$(elements);
        this.parent(options);
    },

    compute: function(from, to, delta) {
        var now = {};
        for (var i in from) {
            var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
            for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
        }
        return now;
    },

    set: function(now) {
        for (var i in now) {
            var iNow = now[i];
            for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
        }
        return this;
    },

    start: function(obj) {
        if (!this.check(obj)) return this;
        var from = {}, to = {};
        for (var i in obj) {
            var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};
            for (var p in iProps) {
                var parsed = this.prepare(this.elements[i], p, iProps[p]);
                iFrom[p] = parsed.from;
                iTo[p] = parsed.to;
            }
        }
        return this.parent(from, to);
    }

});

/*
---

script: Fx.Accordion.js

description: An Fx.Elements extension which allows you to easily create accordion type controls.

license: MIT-style license

authors:
- Valerio Proietti

requires:
- core:1.2.4/Element.Event
- /Fx.Elements

provides: [Fx.Accordion]

...
*/

var Accordion = Fx.Accordion = new Class({

    Extends: Fx.Elements,

    options: {/*
		onActive: $empty(toggler, section),
		onBackground: $empty(toggler, section),
		fixedHeight: false,
		fixedWidth: false,
		*/
        display: 0,
        show: false,
        height: true,
        width: false,
        opacity: true,
        alwaysHide: false,
        trigger: 'click',
        initialDisplayFx: true,
        returnHeightToAuto: true
    },

    initialize: function() {
        var params = Array.link(arguments, { 'container': Element.type, 'options': Object.type, 'togglers': $defined, 'elements': $defined });
        this.parent(params.elements, params.options);
        this.togglers = $$(params.togglers);
        this.container = document.id(params.container);
        this.previous = -1;
        this.internalChain = new Chain();
        if (this.options.alwaysHide) this.options.wait = true;
        if ($chk(this.options.show)) {
            this.options.display = false;
            this.previous = this.options.show;
        }
        if (this.options.start) {
            this.options.display = false;
            this.options.show = false;
        }
        this.effects = {};
        if (this.options.opacity) this.effects.opacity = 'fullOpacity';
        if (this.options.width) this.effects.width = this.options.fixedWidth ? 'fullWidth' : 'offsetWidth';
        if (this.options.height) this.effects.height = this.options.fixedHeight ? 'fullHeight' : 'scrollHeight';
        for (var i = 0, l = this.togglers.length; i < l; i++) this.addSection(this.togglers[i], this.elements[i]);
        this.elements.each(function(el, i) {
            if (this.options.show === i) {
                this.fireEvent('active', [this.togglers[i], el]);
            } else {
                for (var fx in this.effects) el.setStyle(fx, 0);
            }
        }, this);
        if ($chk(this.options.display)) this.display(this.options.display, this.options.initialDisplayFx);
        this.addEvent('complete', this.internalChain.callChain.bind(this.internalChain));
    },

    addSection: function(toggler, element) {
        toggler = document.id(toggler);
        element = document.id(element);
        var test = this.togglers.contains(toggler);
        this.togglers.include(toggler);
        this.elements.include(element);
        var idx = this.togglers.indexOf(toggler);
        var displayer = this.display.bind(this, idx);
        toggler.store('accordion:display', displayer);
        toggler.addEvent(this.options.trigger, displayer);
        if (this.options.height) element.setStyles({ 'padding-top': 0, 'border-top': 'none', 'padding-bottom': 0, 'border-bottom': 'none' });
        if (this.options.width) element.setStyles({ 'padding-left': 0, 'border-left': 'none', 'padding-right': 0, 'border-right': 'none' });
        element.fullOpacity = 1;
        if (this.options.fixedWidth) element.fullWidth = this.options.fixedWidth;
        if (this.options.fixedHeight) element.fullHeight = this.options.fixedHeight;
        element.setStyle('overflow', 'hidden');
        if (!test) {
            for (var fx in this.effects) element.setStyle(fx, 0);
        }
        return this;
    },

    detach: function() {
        this.togglers.each(function(toggler) {
            toggler.removeEvent(this.options.trigger, toggler.retrieve('accordion:display'));
        }, this);
    },

    display: function(index, useFx) {
        if (!this.check(index, useFx)) return this;
        useFx = $pick(useFx, true);
        if (this.options.returnHeightToAuto) {
            var prev = this.elements[this.previous];
            if (prev && !this.selfHidden) {
                for (var fx in this.effects) {
                    prev.setStyle(fx, prev[this.effects[fx]]);
                }
            }
        }
        index = ($type(index) == 'element') ? this.elements.indexOf(index) : index;
        if ((this.timer && this.options.wait) || (index === this.previous && !this.options.alwaysHide)) return this;
        this.previous = index;
        var obj = {};
        this.elements.each(function(el, i) {
            obj[i] = {};
            var hide;
            if (i != index) {
                hide = true;
            } else if (this.options.alwaysHide && ((el.offsetHeight > 0 && this.options.height) || el.offsetWidth > 0 && this.options.width)) {
                hide = true;
                this.selfHidden = true;
            }
            this.fireEvent(hide ? 'background' : 'active', [this.togglers[i], el]);
            for (var fx in this.effects) obj[i][fx] = hide ? 0 : el[this.effects[fx]];
        }, this);
        this.internalChain.chain(function() {
            if (this.options.returnHeightToAuto && !this.selfHidden) {
                var el = this.elements[index];
                if (el) el.setStyle('height', 'auto');
            };
        } .bind(this));
        return useFx ? this.start(obj) : this.set(obj);
    }

});
