var ZoekenController = Class.create({
    initialize: function(){
        this.start();
        this.cat = "";
        this.type = "";
        this.offset = 0;
        this.pageLimit = 10;
        this.previous = false;
        this.sort = 1;
        this.order = 2;
        this.match = false;
        this.down = false;
        this.sliders = [];
    },
    start: function(){
        var func = this.populate.bind(this);
        var obj = {};
        obj.newType = 'ZoekenController';
        obj.newMethod = 'loadZoek';
        ARRM.jsonRequest(obj, func);
    },
    populate: function(obj){
        this.buildCategorieList(obj.categorie);
        this.buildGasTagCloud(obj.tagGas);
        this.populateSelects(obj.select);
        this.catObj = obj.categorie;
    },
    populateSelects: function(obj){
        for (var x = 0, len = obj.selectCategorie.length; x < len; ++x) {
            var opt = new Element("option", {
                id: obj.selectCategorie[x].id,
                value: obj.selectCategorie[x].id
            }).update(obj.selectCategorie[x].naam).observe('click', this.setCat.bind(this, obj.selectCategorie[x].id), false);
            $('categorie').insert(opt);
        }
    },
    buildGasTagCloud: function(obj){
        if ($('tagcloud')) {
            $('tagcloud').update();
            for (var x = 0, len = obj.tagGas.length; x < len; ++x) {
                var a = new Element("a", {
                    href: "javascript:void(0);"
                }).update(obj.tagGas[x].naam);
                var func = this.searchTag.bind(this, obj.tagGas[x].naam);
                var span = new Element("span").update(a).addClassName("spanCloud" + obj.tagGas[x].score).observe('click', func, false);
                $('tagcloud').insert(span);
                $('tagcloud').insert('&nbsp; ');
            }
        }
    },
    searchTag: function(naam){
        this.offset = 1;
        $('trefwoord').value = naam.unescapeHTML();
        this.selectSearch(1);
    },
    haalTypen: function(id){
        var func = this.invoegenTypen.bind(this);
        var obj = {};
        obj.newType = 'Bericht';
        obj.newMethod = 'HaalTemplatesBijCategorie';
        obj.categorie_id = id;
        ARRM.jsonRequest(obj, func);
    },
    invoegenTypen: function(obj){
        $('type').disabled = false;
        $('type').update();
        var option = new Element('option').update(NF.notificatieObj[83]);
        $('type').insert(option);
        for (var x = 0, len = obj.templates.length; x < len; ++x) {
            option = new Element('option', {
                id: obj.templates[x].id,
                value: obj.templates[x].id
            }).update(obj.templates[x].naam).observe('click', this.setType.bind(this, obj.templates[x].id), false);
            $('type').insert(option);
        }
    },
    setType: function(id){
        this.type = id;
    },
    setCat: function(id){
        this.cat = id;
    },
    showExtraSearch: function(){
        Effect.toggle(('zoekenInputExtra'), 'blind', {
            duration: 0.3
        });
        Effect.toggle(('zoekenInput'), 'blind', {
            duration: 0.3
        });
        this.locatie();
        this.groep();
        this.lid();
        this.up = 1;
    },
    hideExtraSearch: function(){
        Effect.toggle(('zoekenInputExtra'), 'blind', {
            duration: 0.3
        });
        Effect.toggle(('zoekenInput'), 'blind', {
            duration: 0.3
        });
        this.up = 0;
    },
    buildDatePicker: function(divOutput){
        this.floatDiv = new Div(tempY, tempX, true);
        $('floatDiv').innerHTML = "<div class=\"popup\"><div class=\"popupHeader\"><a href=\"javascript:void(0);\" onclick=\"ZC.floatDiv.close();\"><img src=\"/img/btnPopupClose.gif\" alt=\"Sluiten\" /></a><h3>Datum selecteren</h3></div><div id=\"datePicker\" class=\"popupBody\"></div></div>";
        var div = new Element("div").addClassName("stPicker");
        var upDiv = new Element("div");
        $('datePicker').insert(div);
        $('datePicker').insert(upDiv);
        var func = this.updatePickeryear.bind(this, divOutput);
        this.picker = new scal(div, func, {
            titleformat: 'mmmm yyyy',
            closebutton: 'X',
            dayheadlength: 2,
            weekdaystart: 1
        });
        this.picker.showCalendar();
    },
    updatePickeryear: function(divOutput){
        $(divOutput).value = this.picker.selecteddate.format('dd/mm/yyyy');
        this.floatDiv.close();
    },
    selectSearch: function(id){
        this.match = /#/.test(window.location);
        switch (id) {
            case 1:
                document.location.href = "#zoek";
                this.match = false;
                if ($F('trefwoord') === "") {
                    $('Message').update(NF.notificatieObj[107]);
                    return;
                }
                if (this.up == 1) {
                    Effect.toggle(('zoekenInputExtra'), 'blind', {
                        duration: 0.3
                    });
                    this.up = 2;
                }
                $('Message').update();
                this.offset = 1;
                this.selected = 1;
                this.searchSimple();
                if (this.down) {
                }
                else {
                    Effect.BlindDown('zoekenSorteer', {
                        duration: 1
                    });
                    this.down = true;
                }
                break;
            case 2:
                document.location.href = "#zoek";
                this.match = false;
                if ($F('trefwoord') === "") {
                    $('Message').update(NF.notificatieObj[107]);
                    return;
                }
                if (this.up == 1) {
                    Effect.toggle(('zoekenInputExtra'), 'blind', {
                        duration: 0.3
                    });
                    this.up = 2;
                }
                $('Message').update();
                this.offset = 0;
                this.selected = 2;
                this.searchAdv();
                if (this.down) {
                }
                else {
                    Effect.BlindDown('zoekenSorteer', {
                        duration: 1
                    });
                    this.down = true;
                }
                break;
            case 3:
                if (this.match) {
                    this.offset = 0;
                    this.selected = 2;
                    this.searchBack();
                    if (this.down) {
                    }
                    else {
                        Effect.BlindDown('zoekenSorteer', {
                            duration: 1
                        });
                        this.down = true;
                    }
                }
                break;
        }
        if (this.match || id == 1 || id == 2) {
            Effect.BlindUp('catList', {
                duration: 0.3
            });
            if (this.up > 0) {
                Effect.BlindDown('zoekenInput', {
                    duration: 0.3
                });
            }
        }
    },
    searchSimple: function(){
        var func = this.buildResults.bind(this);
        var obj = {};
        obj.queryString = $F('trefwoord');
        obj.sort = $F('sortSelect');
        obj.order = $F('orderSelect');
        obj.offset = this.offset;
        obj.newType = 'ZoekenController';
        obj.newMethod = 'SearchSimple';
        ARRM.jsonRequest(obj, func);
    },
    searchAdv: function(){
        var func = this.buildResults.bind(this);
        var obj = {};
        obj.datum = $F('begin');
        obj.datumEind = $F('eind');
        obj.queryString = $F('trefwoord');
        if ($("aanLid").checked) {
            obj.lid = $("lid").getValue();
        }
        if ($("aanGroep").checked) {
            obj.groep = $("groep").getValue();
        }
        obj.catId = this.cat;
        obj.typeId = this.type;
        obj.locatie = $("locatie").getValue();
        obj.sort = $F('sortSelect');
        obj.order = $F('orderSelect');
        obj.offset = this.offset;
        obj.newType = 'ZoekenController';
        obj.newMethod = 'SearchAdvanced';
        ARRM.jsonRequest(obj, func);
    },
    searchBack: function(){
        var func = this.buildResults.bind(this);
        var obj = {};
        obj.newType = 'ZoekenController';
        obj.newMethod = 'SearchBack';
        ARRM.jsonRequest(obj, func);
    },
    lid: function(){
        this.lidId = "";
        var updateAfter = this.getLidId.bind(this);
        new Ajax.Autocompleter("lid", "autocomplete_choicesLid", "/classes/objects/Autocomplete.class.php", {
            paramName: "query",
            parameters: "type=leden",
            minChars: 2,
            afterUpdateElement: updateAfter
        });
    },
    getLidId: function(text, li){
        this.lidId = li.id;
    },
    groep: function(){
        this.groepId = "";
        var updateAfter = this.getGroepId.bind(this);
        new Ajax.Autocompleter("groep", "autocomplete_choicesGroep", "/classes/objects/Autocomplete.class.php", {
            paramName: "query",
            parameters: "type=groepen",
            minChars: 2,
            afterUpdateElement: updateAfter
        });
    },
    getGroepId: function(text, li){
        this.groepId = li.id;
    },
    locatie: function(){
        this.locatieId = "";
        var updateAfter = this.getLocatieId.bind(this);
        new Ajax.Autocompleter("locatie", "autocomplete_choices", "/classes/objects/Autocomplete.class.php", {
            paramName: "query",
            parameters: "&type_id=1",
            minChars: 2,
            afterUpdateElement: updateAfter
        });
    },
    getLocatieId: function(text, li){
        this.locatieId = li.id;
    },
    observeClick: function(id, targetdiv){
        this.changeActiveState(id);
        this.sliders[targetdiv].slide("bericht_" + id + "");
    },
    changeActiveState: function(id){
        if (this.previous > 0) {
            if ($(this.previous)) {
                $(this.previous).removeClassName("active");
            }
        }
        if (this.previous != id) {
            if ($(id)) {
                $(id).addClassName("active");
            }
            this.previous = id;
        }
        else {
            this.previous = 0;
        }
    },
    buildResults: function(obj){
        this.searchObj = obj;
	if (obj.status == 1) {
	    $("zoekresultaten").update("<div class=\"padded grey1\"><h2>Zoekresultaten (" +obj.zoekresultaten.length+ ")</h2><span style=\"float:right;margin-top:-15px;\"><a href=\"/zoeken/\">opnieuw zoeken</a></span></div>");
	} else {
	    $("zoekresultaten").update("<div class=\"padded grey1\"><h2>Zoekresultaten</h2><span style=\"float:right;margin-top:-15px;\"><a href=\"/zoeken/\">opnieuw zoeken</a></span></div>");
	}
        obj.targetdiv = "zoekresultaten";
        this.sliders[obj.targetdiv] = new Accordion("", 0.3);
        this.sliders[obj.targetdiv].accord = [];
        if (obj.status == 1) {
            for (var x = 0, len = obj.zoekresultaten.length; x < len; ++x) {
                var maindiv = new Element("div", {
                    id: obj.zoekresultaten[x].id
                }).addClassName('bericht');
                if (obj.zoekresultaten[x].gelezen == 1) {
                    maindiv.addClassName("gelezen");
                }
                if (obj.zoekresultaten[x].commercieel == 1) {
                    maindiv.addClassName("ad");
                }
                var func = this.observeClick.bind(this, obj.zoekresultaten[x].id, obj.targetdiv);
                var div = new Element("div").observe('mouseup', func, false);
                if (obj.zoekresultaten[x].categorie_id >= 0) {
                    var newDiv = new Element("div");
                    newDiv.addClassName('berichtIcoon');
                    newDiv.addClassName('cat-' + obj.zoekresultaten[x].categorie_id);
                    div.insert(newDiv);
                }
                maindiv.insert(div);
                div.insert("<strong>" + obj.zoekresultaten[x].templatenaam + ":</strong> " + obj.zoekresultaten[x].datum + " erbij gezet door <a href=\"" + obj.zoekresultaten[x].profiellink + "\" title=\"" + obj.zoekresultaten[x].gebruikersnaam + "\" class=\"profile\">" + obj.zoekresultaten[x].gebruikersnaam + "</a>");
                div.insert("<h2>" + obj.zoekresultaten[x].titel + "</h2>");
                maindiv.insert(div);
                div = new Element("div", {
                    id: "bericht_" + obj.zoekresultaten[x].id
                }).addClassName("berichtBody");
                div.insert(obj.zoekresultaten[x].inhoud);
                div.insert("<ul class=\"meta\"><li>bekeken: " + obj.zoekresultaten[x].bekeken + "</li><li>reacties: " + obj.zoekresultaten[x].reactiecount + "</li></ul>");
                div.setStyle("display: none;");
                maindiv.insert(div);
                div = new Element("div", {
                    id: "leesverder_" + obj.zoekresultaten[x].id + ""
                }).setStyle({
                    display: "none"
                });
                maindiv.insert(div);
                div = new Element("div").addClassName("spacer");
                maindiv.insert(div);
                $(obj.targetdiv).insert(maindiv);
                this.sliders[obj.targetdiv].accord.push('bericht_' + obj.zoekresultaten[x].id);
            }
            if (obj.totalpages > 1) {
                this.showPages(obj);
            }
        }
        else 
            if (obj.status === 0) {
                maindiv = new Element("div").addClassName('bericht').update(obj.message);
                $("zoekresultaten").insert(maindiv);
            }
        if (this.match) {
            $('zoekresultaten').show();
        }
        else {
            $('zoekresultaten').show();
        }
    },
    buildCategorieList: function(obj){
        $('catList').update("<h2>Categorie&euml;n</h2>");
        for (var x = 0, len = obj.categorie.length; x < len; ++x) {
            var func = this.retrieveCat.bind(this, obj.categorie[x].id, this.offset, this.pageLimit);
            var a = new Element("a", {
                href: "javascript:void(0);"
            }).update("" + obj.categorie[x].naam).observe('click', func, false);
            var div = new Element("div").insert(a);
            div.insert(" &nbsp;(" + obj.categorie[x].count + ")");
            $('catList').insert(div);
        }
        $('catList').insert("<div class=\"spacer\"></div>");
    },
    retrieveCat: function(id){
        this.BrowseId = id;
        this.selected = 3;
        this.catId = id;
        Effect.BlindUp('catList', {
            duration: 0.3
        });
        if (this.down) {
        }
        else {
            Effect.BlindDown('zoekenSorteer', {
                duration: 1
            });
            this.down = true;
        }
        var func = this.browseCat.bind(this);
        var obj = {};
        obj.newType = 'ZoekenController';
        obj.newMethod = 'browseCat';
        obj.id = id;
        obj.sort = $F('sortSelect');
        obj.order = $F('orderSelect');
        if (this.offset === 0) {
            obj.offset = 1;
        }
        else {
            obj.offset = this.offset;
        }
        ARRM.jsonRequest(obj, func);
    },
    showCategories: function(){
        Effect.BlindUp('zoekresultaten', {
            duration: 0.3
        });
        Effect.BlindDown('catList', {
            duration: 1
        });
    },
    browseCat: function(obj){
        $("zoekresultaten").update("<div class=\"padded grey1\"><h2>Zoekresultaten (" +obj.categorie.length+ ")</h2><span style=\"float:right;margin-top:-15px;\"><a href=\"/zoeken/\">opnieuw zoeken</a></span></div>");
        obj.targetdiv = "zoekresultaten";
        this.sliders[obj.targetdiv] = new Accordion("", 0.3);
        this.sliders[obj.targetdiv].accord = [];
        if (obj.categorie) {
            for (var x = 0, len = obj.categorie.length; x < len; ++x) {
                var maindiv = new Element("div", {
                    id: obj.categorie[x].id
                }).addClassName('bericht');
                if (obj.categorie[x].gelezen == 1) {
                    maindiv.addClassName("gelezen");
                }
                if (obj.categorie[x].commercieel == 1) {
                    maindiv.addClassName("ad");
                }
                var func = this.observeClick.bind(this, obj.categorie[x].id, obj.targetdiv);
                var div = new Element("div").observe('mouseup', func, false);
                if (obj.categorie[x].categorie_id >= 0) {
                    var newDiv = new Element("div");
                    newDiv.addClassName('berichtIcoon');
                    newDiv.addClassName('cat-' + obj.categorie[x].categorie_id);
                    div.insert(newDiv);
                }
                maindiv.insert(div);
                div.insert("<strong>" + obj.categorie[x].templatenaam + ":</strong> " + obj.categorie[x].datum + " erbij gezet door <a href=\"" + obj.categorie[x].profiellink + "\" title=\"" + obj.categorie[x].gebruikersnaam + "\" class=\"profile\">" + obj.categorie[x].gebruikersnaam + "</a>");
                div.insert("<h2>" + obj.categorie[x].titel + "</h2>");
                maindiv.insert(div);
                div = new Element("div", {
                    id: "bericht_" + obj.categorie[x].id
                }).addClassName("berichtBody");
                div.insert(obj.categorie[x].inhoud);
                div.insert("<ul class=\"meta\"><li>bekeken: " + obj.categorie[x].bekeken + "</li><li>reacties: " + obj.categorie[x].reactiecount + "</li></ul>");
                div.setStyle("display: none;");
                maindiv.insert(div);
                div = new Element("div", {
                    id: "leesverder_" + obj.categorie[x].id + ""
                }).setStyle({
                    display: "none"
                });
                maindiv.insert(div);
                div = new Element("div").addClassName("spacer");
                maindiv.insert(div);
                $(obj.targetdiv).insert(maindiv);
                this.sliders[obj.targetdiv].accord.push('bericht_' + obj.categorie[x].id);
            }
            if (obj.totalpages > 1) {
                this.showPages(obj);
            }
        }
        else {
            div = new Element("div").addClassName("berichtBody").insert(NF.notificatieObj[84]);
            maindiv = new Element("div").addClassName('bericht').insert(div);
            div = new Element("div").addClassName("spacer");
            maindiv.insert(div);
            $("zoekresultaten").insert(maindiv);
        }
        $('zoekenInputExtra').hide();
        $('zoekresultaten').show();
    },
    showPages: function(obj){
        var div = new Element("div").addClassName("spacer");
        var maindiv = new Element("div").addClassName('paginering').insert(div);
        if (obj.page_id === 0) {
            obj.page_id = 1;
        }
        if (obj.page_id > 1) {
            var img = new Element("img", {
                src: "/img/paginasBegin.jpg"
            });
            var func = this.sortResults.bind(this, 1);
            var a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
            img = new Element("img", {
                src: "/img/paginasVorige.jpg"
            });
            func = this.sortResults.bind(this, Number(obj.page_id) - 1);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
        }
        var pageCount = 1;
        if (obj.totalpages > 11) {
            if (obj.page_id > 5) {
                if (obj.page_id > (obj.totalpages - 6)) {
                    pageCount = obj.totalpages - 10;
                }
                else {
                    pageCount = obj.page_id - 5;
                }
            }
        }
        if (pageCount > 1) {
            maindiv.insert(' ...');
        }
        if (pageCount + 10 > obj.totalpages) {
            pagecountEnd = obj.totalpages;
        }
        else {
            pagecountEnd = pageCount + 10;
        }
        for (i = pageCount; i <= pagecountEnd; i++) {
            if (i == obj.page_id) {
                maindiv.insert('<span>' + i + '</span>');
            }
            else {
                func = this.sortResults.bind(this, i);
                a = new Element('a', {
                    href: "javascript: void(0);"
                }).insert(i).addClassName("page").observe('click', func, false);
                maindiv.insert(a);
            }
        }
        if (pageCount + 10 < obj.totalpages) {
            maindiv.insert('... ');
        }
        if (obj.page_id < obj.totalpages) {
            img = new Element("img", {
                src: "/img/paginasVolgende.jpg"
            });
            func = this.sortResults.bind(this, Number(obj.page_id) + 1);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
            img = new Element("img", {
                src: "/img/paginasEind.jpg"
            });
            func = this.sortResults.bind(this, obj.totalpages);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
        }
        $("zoekresultaten").insert(maindiv);
    },
    sortResults: function(offset){
        if (offset) {
            this.offset = offset;
        }
        else {
            this.offset = 1;
        }
        switch (this.selected) {
            case 1:
                this.searchSimple();
                break;
            case 2:
                this.searchAdv();
                break;
            case 3:
                this.retrieveCat(this.BrowseId);
                break;
        }
    }
});
var ZoekenLedenController = Class.create({
    initialize: function(ledenCheck){
        this.build = true;
        this.zoekenDiv = $("zoekAreaLeden");
        this.buildSearch();
        if (ledenCheck == 1) {
            this.searchLeden(1);
        }
    },
    searchLike: function(event){
        if (event.keyCode == 13) {
            window.location.hash = "#Leden";
            this.searchLeden();
        }
    },
    buildSearch: function(){
        var bigDiv = new Element("div").setStyle("float:left;");
        var div = new Element("div").addClassName("firstcol").setStyle("float:left;").update("<strong>Voornaam:</strong>");
        var funcTwo = this.searchLike.bind(this);
        var input = new Element("input", {
            id: "voornaam"
        }).addClassName("tb").observe('keypress', funcTwo, true);
        var nextDiv = new Element("div").setStyle("float:left;").update(input);
        bigDiv.update(div);
        bigDiv.insert(nextDiv);
        this.zoekenDiv.update(bigDiv);
        bigDiv = new Element("div").setStyle("float:left;");
        div = new Element("div").addClassName("firstcol").setStyle("float:left;").update("<strong>Nickname:</strong>");
        funcTwo = this.searchLike.bind(this);
        input = new Element("input", {
            id: "nickname"
        }).addClassName("tb").observe('keypress', funcTwo, true);
        nextDiv = new Element("div").setStyle("float:left;").update(input);
        bigDiv.update(div);
        bigDiv.insert(nextDiv);
        this.zoekenDiv.insert(bigDiv);
        bigDiv = new Element("div").setStyle("float: left;");
        div = new Element("div").addClassName("firstcol").setStyle("float:left;").update("<strong>Achternaam:</strong>");
        input = new Element("input", {
            id: "achternaam"
        }).addClassName("tb").observe('keypress', funcTwo, true);
        nextDiv = new Element("div").setStyle("float:left;").update(input);
        bigDiv.update(div);
        bigDiv.insert(nextDiv);
        this.zoekenDiv.insert(bigDiv);
        bigDiv = new Element("div").setStyle("float: left;");
        div = new Element("div").addClassName("firstcol").setStyle("float:left;").update("<strong>Woonplaats:</strong>");
        input = new Element("input", {
            id: "woonplaats"
        }).addClassName("tb").observe('keypress', funcTwo, true);
        nextDiv = new Element("div").setStyle("float:left;").update(input);
        bigDiv.update(div);
        bigDiv.insert(nextDiv);
        this.zoekenDiv.insert(bigDiv);
        bigDiv = new Element("div").setStyle("width: 290px; float: left;");
        div = new Element("div").setStyle("float:right;");
        var img = new Element("img", {
            src: "/img/btns/btnOKZoekenL.gif"
        }).setStyle("border:none;");
        this.errorDiv = new Element("div");
        div.insert(this.errorDiv);
        var func = this.searchLeden.bind(this);
        var a = new Element("a", {
            href: "#Leden"
        }).update(img).observe('click', func, false);
        div.insert(a);
        bigDiv.update(div);
        this.zoekenDiv.addClassName("padded").insert(bigDiv);
        this.resultatenDiv = new Element("div").setStyle("width: 500px; clear: left; margin-top: 10px;");
        this.zoekenDiv.insert(this.resultatenDiv);
    },
    searchLeden: function(ledenCheck){
        this.errorDiv.update();
        if (ledenCheck == 1) {
            var obj = {};
            var func = this.buildLeden.bind(this);
            obj.newType = 'ZoekenController';
            obj.newMethod = 'zoekLedenBack';
            obj.ledenBack = 1;
            ARRM.jsonRequest(obj, func);
        }
        else {
            if (this.checkLedenFields()) {
                obj = {};
                func = this.buildLeden.bind(this);
                obj.newType = 'ZoekenController';
                obj.newMethod = 'zoekLeden';
                obj.ledenBack = 2;
                obj.offset = 1;
                obj.voornaam = $F('voornaam');
                obj.nickname = $F('nickname');
                obj.achternaam = $F('achternaam');
                obj.woonplaats = $F('woonplaats');
                ARRM.jsonRequest(obj, func);
            }
            else {
                this.errorDiv.update(NF.notificatieObj[107]);
            }
        }
    },
    checkLedenFields: function(){
        if ($F('voornaam') === "" && $F('achternaam') === "" && $F('woonplaats') === "" && $F('nickname') === "") {
            return false;
        }
        else {
            return true;
        }
    },
    buildLeden: function(obj){
        var spacer = new Element("div").addClassName("spacer");
        this.resultatenDiv.update(spacer);
        if (obj.leden) {
            for (var x = 0, len = obj.leden.length; x < len; ++x) {
                var FI = new FotoItem(obj.leden[x], true, false);
                this.resultatenDiv.insert(FI.div);
            }
            spacer = new Element("div").addClassName("spacer");
            $(this.resultatenDiv).insert(spacer);
            $('zoekAreaLeden').insert(this.resultatenDiv);
            if (obj.totalpages > 1) {
                this.showPages(obj);
            }
        }
        else {
            spacer = new Element("div").update(NF.notificatieObj[109]);
            $(this.resultatenDiv).insert(spacer);
            $('zoekAreaLeden').insert(this.resultatenDiv);
        }
    },
    showPages: function(obj){
        var div = new Element("div").addClassName("spacer");
        var maindiv = new Element("div").addClassName('paginering').insert(div);
        if (obj.page_id > 1) {
            var img = new Element("img", {
                src: "/img/paginasBegin.jpg"
            });
            var func = this.sortResults.bind(this, 1);
            var a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
            img = new Element("img", {
                src: "/img/paginasVorige.jpg"
            });
            func = this.sortResults.bind(this, Number(obj.page_id) - 1);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
        }
        var pageCount = 1;
        if (obj.totalpages > 11) {
            if (obj.page_id > 5) {
                if (obj.page_id > (obj.totalpages - 6)) {
                    pageCount = obj.totalpages - 10;
                }
                else {
                    pageCount = obj.page_id - 5;
                }
            }
        }
        if (pageCount > 1) {
            maindiv.insert(' ...');
        }
        if (pageCount + 10 > obj.totalpages) {
            pagecountEnd = obj.totalpages;
        }
        else {
            pagecountEnd = pageCount + 10;
        }
        for (i = pageCount; i <= pagecountEnd; i++) {
            if (i == obj.page_id) {
                maindiv.insert('<span>' + i + '</span>');
            }
            else {
                func = this.sortResults.bind(this, i);
                a = new Element('a', {
                    href: "javascript: void(0);"
                }).insert(i).addClassName("page").observe('click', func, false);
                maindiv.insert(a);
            }
        }
        if (pageCount + 10 < obj.totalpages) {
            maindiv.insert('... ');
        }
        if (obj.page_id < obj.totalpages) {
            img = new Element("img", {
                src: "/img/paginasVolgende.jpg"
            });
            func = this.sortResults.bind(this, Number(obj.page_id) + 1);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
            img = new Element("img", {
                src: "/img/paginasEind.jpg"
            });
            func = this.sortResults.bind(this, obj.totalpages);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
        }
        $(this.resultatenDiv).insert(maindiv);
    },
    sortResults: function(offset, id){
        var obj = {};
        var func = this.buildLeden.bind(this);
        obj.newType = 'ZoekenController';
        obj.newMethod = 'zoekLeden';
        obj.voornaam = $F('voornaam');
        obj.achternaam = $F('achternaam');
        obj.woonplaats = $F('woonplaats');
        obj.offset = offset;
        ARRM.jsonRequest(obj, func);
    }
});
var ZoekenGroepenController = Class.create({
    initialize: function(groepenCheck){
        this.zoekenDiv = $("zoekAreaGroepen");
        this.buildSearch();
        if (groepenCheck == 1) {
            this.searchGroepen(1);
        }
    },
    searchLike: function(event){
        if (event.keyCode == 13) {
            window.location.hash = "#Groepen";
            this.searchGroepen();
        }
    },
    buildSearch: function(){
        var bigDiv = new Element("div").setStyle("float: left;");
        var div = new Element("div").addClassName("firstcol").setStyle("float:left;").update("<strong>Groepsnaam:</strong>");
        var funcTwo = this.searchLike.bind(this);
        var input = new Element("input", {
            id: "groepsnaam"
        }).addClassName("tb").observe('keypress', funcTwo, true);
        var nextDiv = new Element("div").setStyle("float:left;").update(input);
        bigDiv.update(div);
        bigDiv.insert(nextDiv);
        this.zoekenDiv.update(bigDiv);
        bigDiv = new Element("div").setStyle("width: 290px; float: left;");
        div = new Element("div").setStyle("float:right;");
        var img = new Element("img", {
            src: "/img/btns/btnOKZoekenL.gif"
        }).setStyle("border:none;");
        this.errorDiv = new Element("div");
        div.insert(this.errorDiv);
        var func = this.searchGroepen.bind(this);
        var a = new Element("a", {
            href: "#Groepen"
        }).update(img).observe('click', func, false);
        div.insert(a);
        bigDiv.update(div);
        this.zoekenDiv.addClassName("padded").insert(bigDiv);
        this.resultatenDiv = new Element("div").setStyle("width: 500px; clear: left; margin-top: 10px;");
        this.zoekenDiv.insert(this.resultatenDiv);
    },
    searchGroepen: function(groepenCheck){
        this.errorDiv.update();
        if (groepenCheck == 1) {
            var obj = {};
            var func = this.buildGroepen.bind(this);
            obj.newType = 'ZoekenController';
            obj.newMethod = 'zoekGroepenBack';
            obj.groepenBack = 1;
            ARRM.jsonRequest(obj, func);
        }
        else {
            if (this.checkGroepenFields()) {
                obj = {};
                func = this.buildGroepen.bind(this);
                obj.newType = 'ZoekenController';
                obj.newMethod = 'zoekGroepen';
                obj.naam = $F('groepsnaam');
                obj.offset = 1;
                ARRM.jsonRequest(obj, func);
            }
            else {
                this.errorDiv.update(NF.notificatieObj[107]);
            }
        }
    },
    checkGroepenFields: function(){
        if ($F('groepsnaam') === "") {
            return false;
        }
        else {
            return true;
        }
    },
    buildGroepen: function(obj){
        var spacer = new Element("div").addClassName("spacer");
        this.resultatenDiv.update(spacer);
        if (obj.groepen) {
            for (var x = 0, len = obj.groepen.length; x < len; ++x) {
                var FI = new FotoItem(obj.groepen[x], true, false);
                this.resultatenDiv.insert(FI.div);
            }
            spacer = new Element("div").addClassName("spacer");
            $(this.resultatenDiv).insert(spacer);
            $('zoekAreaGroepen').insert(this.resultatenDiv);
            if (obj.totalpages > 1) {
                this.showPages(obj);
            }
        }
        else {
            spacer = new Element("div").update(NF.notificatieObj[110]);
            $(this.resultatenDiv).insert(spacer);
            $('zoekAreaGroepen').insert(this.resultatenDiv);
        }
    },
    showPages: function(obj){
        var div = new Element("div").addClassName("spacer");
        var maindiv = new Element("div").addClassName('paginering').insert(div);
        if (obj.page_id > 1) {
            var img = new Element("img", {
                src: "/img/paginasBegin.jpg"
            });
            var func = this.sortResults.bind(this, 1);
            var a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
            img = new Element("img", {
                src: "/img/paginasVorige.jpg"
            });
            func = this.sortResults.bind(this, Number(obj.page_id) - 1);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
        }
        var pageCount = 1;
        if (obj.totalpages > 11) {
            if (obj.page_id > 5) {
                if (obj.page_id > (obj.totalpages - 6)) {
                    pageCount = obj.totalpages - 10;
                }
                else {
                    pageCount = obj.page_id - 5;
                }
            }
        }
        if (pageCount > 1) {
            maindiv.insert(' ...');
        }
        if (pageCount + 10 > obj.totalpages) {
            pagecountEnd = obj.totalpages;
        }
        else {
            pagecountEnd = pageCount + 10;
        }
        for (i = pageCount; i <= pagecountEnd; i++) {
            if (i == obj.page_id) {
                maindiv.insert('<span>' + i + '</span>');
            }
            else {
                func = this.sortResults.bind(this, i);
                a = new Element('a', {
                    href: "javascript: void(0);"
                }).insert(i).addClassName("page").observe('click', func, false);
                maindiv.insert(a);
            }
        }
        if (pageCount + 10 < obj.totalpages) {
            maindiv.insert('... ');
        }
        if (obj.page_id < obj.totalpages) {
            img = new Element("img", {
                src: "/img/paginasVolgende.jpg"
            });
            func = this.sortResults.bind(this, Number(obj.page_id) + 1);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
            img = new Element("img", {
                src: "/img/paginasEind.jpg"
            });
            func = this.sortResults.bind(this, obj.totalpages);
            a = new Element('a', {
                href: "javascript: void(0);"
            }).insert(img).observe('click', func, false);
            maindiv.insert(a);
        }
        $(this.resultatenDiv).insert(maindiv);
    },
    sortResults: function(offset, id){
        var obj = {};
        var func = this.buildLeden.bind(this);
        obj.newType = 'ZoekenController';
        obj.newMethod = 'zoekGroepen';
        obj.naam = $F('groepsnaam');
        obj.offset = offset;
        ARRM.jsonRequest(obj, func);
    }
});
Event.onDOMReady(function(){
    var arr = [83, 84, 107, 109, 110];
    var Init = new initLoader(arr);
    var SC = new SuperClassZoekenController(1);
});

