var berichtNonUserController = Class.create({
    initialize: function(){
        this.start();
        this.load = 1;
    },
    start: function(paginaBeveiligd){
        var func = this.reloadLogin.bind(this);
        var obj = {};
        obj.newType = 'Bericht';
        obj.newMethod = 'getMainReactions';
        ARRM.jsonRequest(obj, func);
    },
    reloadLogin: function(obj){
        this.buildReactions(obj.reacties);
    },
    buildReactions: function(obj){
        if ($('berichtReactie')) {
            this.reaction = 2;
            if (obj.reacties != "null") {
                for (var x = 0, len = obj.reacties.length; x < len; ++x) {
                    var divHeader = new Element("div").addClassName('header');
                    var date = new Element("span").insert(obj.reacties[x].datum + " " + obj.reacties[x].tijd).addClassName('date');
                    //jon
                    //var name = new Element("span").insert(obj.reacties[x].gebruikersnaam + ":  ").addClassName('name');
                    var a = new Element ("a", {
                href: obj.reacties[x].profiellink
            }).insert(obj.reacties[x].gebruikersnaam);
                    var name = new Element("span").insert(a).insert(":  ").addClassName('name');
                    divHeader.insert(date);
                    divHeader.insert(name);
                    var message = new Element("span").insert(obj.reacties[x].inhoud);
                    var divMessage = new Element("div").addClassName('message').insert(message);
                    var mainDiv = new Element("div").addClassName('reactie');
                    if (!((x + 1) % 2)) {
                        mainDiv.addClassName('reactieeven');
                    }
                    mainDiv.insert(divHeader);
                    mainDiv.insert(divMessage);
                    $('berichtReactie').insert(mainDiv);
                }
            }
            else {
                this.reaction = 1;
                $('berichtReactie').update("Er zijn nog geen reacties op dit bericht...");
            }
        }
    },
    meldMisbruik: function(id){
        var func = this.alertMisbruik.bind(this);
        var obj = {};
        obj.id = id;
        obj.newType = 'Bericht';
        obj.newMethod = 'MeldMisbruik';
        ARRM.jsonRequest(obj, func);
    },
    alertMisbruik: function(obj){
        var inputHTML = "<div class=\"popup\"><div class=\"popupHeader\"><a href=\"javascript:void(0);\" onclick=\"BC.floatDiv.close();\"><img src=\"/img/btnPopupClose.gif\" alt=\"Sluiten\" /></a><h3>Misbruik gemeld</h3></div><div class=\"popupBody\">" + NF.notificatieObj[129] + "<div class=\"spacer\"></div></div></div>";
        this.floatDiv = new Div(tempY, tempX, true);
        $('floatDiv').innerHTML = inputHTML;
    },
    rateBericht: function(objBericht, doAction){
        var func = this.maakBerichtPopup.bind(this);
        var obj = {};
        obj.newType = 'Bericht';
        obj.newMethod = 'RateBericht';
        obj.id = objBericht.id;
        obj.doAction = doAction;
        ARRM.jsonRequest(obj, func);
    },
    rateBerichtDetail: function(id, doAction){
        var func = this.maakBerichtPopup.bind(this);
        var obj = {};
        obj.newType = 'Bericht';
        obj.newMethod = 'RateBericht';
        obj.id = id;
        obj.doAction = doAction;
        ARRM.jsonRequest(obj, func);
    },
    rateBerichtTags: function(formObj){
        var func = this.sluitPopup.bind(this);
        var obj = {};
        obj = $("rateBerichtForm").serialize(true);
        obj.newType = 'Bericht';
        obj.newMethod = 'RateBerichtTags';
        ARRM.jsonRequest(obj, func);
    },
    sluitPopup: function(obj){
        this.floatDiv.close();
        this.buildTagCloud(obj);
    },
    maakBerichtPopup: function(obj){
        var locX = tempX;
        var locY = tempY;
        var inputHTML = "<div class=\"popup\"><div class=\"popupHeader\"><a href=\"javascript:void(0);\" onclick=\"BC.floatDiv.close();\"><img src=\"/img/btnPopupClose.gif\" alt=\"Sluiten\" /></a><h3>" + obj.titel + "</h3></div><div class=\"popupBody\"><form id=\"rateBerichtForm\" onsubmit=\"BC.rateBerichtTags(this); return false;\">" + obj.nietIngelogd + "</form><div class=\"spacer\"></div></div></div>";
        this.floatDiv = new Div(locY, locX, true);
	$('floatDiv').update(inputHTML);
    },
    tippen: function(id){
        if (TF.tellStatus === 0) {
            this.name = TF.name;
            this.emailValue = TF.emailValue;
            this.email = false;
        }
        else {
            this.name = "";
            this.emailValue = "";
            this.email = false;
        }
        this.berichtId = id;
        this.buildTipHTML();
    },
    buildTipHTML: function(){
        var locX = tempX - 200;
        var locY = tempY - 200;
        this.floatDiv = new Div(locY, locX, true);
        var x = '<form method="get" action="javascript:void(0);" onsubmit="BC.checkTipForm(); return false;" name="formTaf" id="formTaf"><table cellpadding="0" cellspacing="0" border="0"><tr><td class="firstcol">Je naam</td><td class="td"><input type="text" name="je_naam" id="je_naam" class="tb" value="' + this.name + '" /></td></tr><tr><td class="firstcol">Je e-mail</td><td class="td"><input type="text" name="je_e-mail" id="je_e-mail" onblur="BC.checkTipEmail($(\'je_e-mail\').value);" class="tb" value="' + this.emailValue + '" /></td></tr><tr><td class="firstcol">Naam vriend</td><td class="td"><input type="text" name="naam_vriend" id="naam_vriend" class="tb" value="" /></td></tr><tr><td class="firstcol">E-mail vriend</td><td class="td"><input type="text" name="e-mail_vriend" id="e-mail_vriend" onblur="BC.checkTipEmail($(\'e-mail_vriend\').value);" class="tb" value="" /></td></tr><tr><td class="firstcol"></td><td class="td"><input type="image" src="/img/btns/btnOKVersturenS.gif" class="imgBtn" /></td></tr><tr><td class="td" colspan="2"><div id="returnError"></div></div></td></tr></table></form>';
        var popup = new Element("div").addClassName("popup").setStyle("width: 400px");
        var popupHeader = new Element("div").addClassName("popupHeader").setStyle("width: 400px");
        var imgHolder = new Element("img", {
            src: "/img/btnPopupClose.gif",
            alt: "Sluiten"
        });
        var a = new Element("a", {
            href: "javascript:void(0);"
        }).insert(imgHolder);
        var func = this.floatDiv.close.bind(this);
        a.observe('click', func, false);
        popupHeader.insert(a);
        popupHeader.insert("<h3>Tip een vriend</h3>");
        popup.insert(popupHeader);
        popupBody = new Element("div").insert(x).addClassName('popupBody');
        popup.insert(popupBody);
        $('floatDiv').update(popup);
    },
    checkTipForm: function(){
        if ($F('je_naam') !== "" && $F('je_e-mail') !== "" && $F('naam_vriend') !== "" && $F('e-mail_vriend') !== "") {
            this.naam = $F('je_naam').stripScripts().stripTags();
            this.emailInp = $F('je_e-mail').stripScripts().stripTags();
            this.naamVriend = $F('naam_vriend').stripScripts().stripTags();
            this.emailVriend = $F('e-mail_vriend').stripScripts().stripTags();
            this.form = true;
        }
        else {
            this.form = false;
        }
        if (this.email) {
            this.form = true;
        }
        else {
            this.form = false;
        }
        if (this.form && this.email) {
            $('returnError').update();
            this.submitTip();
        }
        else {
            $('returnError').update(NF.notificatieObj[130]).appear();
        }
    },
    checkTipEmail: function(email){
        $('returnError').update().hide();
        var str = email;
        var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (filter.test(str)) {
            this.email = true;
        }
        else {
            $('returnError').insert(NF.notificatieObj[131]).appear();
            this.email = false;
        }
    },
    submitTip: function(){
        var func = this.floatDiv.close.bind(this);
        var obj = {};
        obj.id = this.berichtId;
        obj.naam = this.naam;
        obj.email = this.emailInp;
        obj.naamVriend = this.naamVriend;
        obj.emailVriend = this.emailVriend;
        obj.newType = 'SendMail';
        obj.newMethod = 'TipAFriend';
        ARRM.jsonFormRequest(obj, func);
    }
});
Event.onDOMReady(function(){
    var arr = [38, 39, 40, 129, 130, 131];
    var Init = new initLoader(arr);
    BC = new berichtNonUserController();
});

