/* TODO:
    -   Figure out what/where the other moderation options are
*/

var Moderation = new Class({
    Implements: Options,

    selectors: {
        'form': 'form.moderation_actions',
        'actions': 'form.moderation_actions select'
    },

    initialize: function(selectors) {
        if($chk(selectors)){
            this.selectors = $H(this.selectors).extend(selectors).getClean();
        }

        // If there isn't a moderation form, quit.
        if (!$$(this.selectors.form)) return false;

        this.form = $(this.selectors.form);

        this.actions = this.form.getElements(this.selectors.actions);
        //this.actions.removeEvent('change', function(e) {
        //    this.moderate(e.target.options[e.target.selectedIndex]);
        //}.bind(this));
        this.actions.addEvent('change', function(e) {
            e.stop();
            this.moderate(e.target);
        }.bind(this));
    },

    moderate: function(select) {
        var option = select.getElement('option[selected]');
        var action = option.get('text');
        var value = option.get('value');
        var iNumDays = null;

        if (!$chk(option) || !$chk(value)){
            return;
        }

        this.form.getElement('input[name=user_cmd]').set('value', action);
        switch (action) {
            case 'Delete Message':
                if(!confirm("Are you sure you want to delete this message?")) {
                    this.form.reset();
                    return;
                }
                break;
            case 'Delete This Topic':
                if(!confirm("Are you sure you want to delete this ENTIRE topic?")) {
                    this.form.reset();
                    return;
                }
                break;
            case 'Move This Topic':
                //openChooser("/forums/board_chooser.php");
                //storedData = this.value;
                return;
                break;
            case 'Ban This User':
                if(!confirm("Are you sure you want to ban this user?")) {
                    this.form.reset();
                    return;
                }
                iNumDays = prompt("How many days (-1 is indefinite)?", "7");
                if (iNumDays != null) {
                    this.form.getElement('input[name=user_cmd_extra_data]').set('value', iNumDays);
                } else {
                    this.form.reset();
                    return;
                }
                break;
            case 'Suspend This User':
                iNumDays = prompt("How many days (-1 is indefinite, Moderators may only select 1-7 days)?", "7");
                if (iNumDays != null) {
                    this.form.getElement('input[name=user_cmd_extra_data]').set('value', iNumDays);
                } else {
                    this.form.reset();
                    return;
                }
                break;
            case 'View Edit History':
                if (window.opener) {
                    this.form.set('target','_blank');
                }
                break;
            case 'Moderate':
                if(!confirm("This will automatically mark the message as abusive and take you to the moderation page. Are you sure?")) {
                    this.form.reset();
                    return;
                }
                break;
        }
        this.form.submit();
    }
});