/**
 * ErrorModule
 * @author Jae Cho
 * Subclass of Module that handles errors.  This module will be included in
 * the base impelemntation of page.
 */
function ErrorModule() {

    /** name of the module */
    this._name="ErrorModule";

    /** array of error messages */
    this.errors = new Array();

    /** path to redirect user after error dialog is closed */
    this._redirectPath = null;

    this._errorDialogControl = null;

    /** set user id */
    this.setUserId = function(userId) {
        this.userId = userId;
    };

    this.setRedirectPath = function(path) {
        this._redirectPath = path;
    };

     this.initialize = function()
    {
         //Initialize the dialog modals
        this._errorDialogControl = new DialogControl($("#errorModDialog"));
        $("#errorModOkButton").click(bindContext(this, this.hideDialog));
    };

    /** show confirmation dialog */
    this.showDialog = function() {
        this._errorDialogControl.showDialog();
        return false;
    };

    /** hide confirmation dialog */
    this.hideDialog = function(e) {
        e.preventDefault();
        this._errorDialogControl.hideDialog();
        if (this._redirectPath) window.location = this._redirectPath;
        return false;
    };

    this.addError = function(message) {
        this.errors.push(message);
    };

    /** handle error */
    this.showErrors = function() {

        if (this.errors.length == 0) return;

        var msg = "";
        for (var i = 0; i < this.errors.length; i++) {
            msg += this.errors[i] + "\n";
        }

        $("#errorModMessage").html(msg);

        this.showDialog();
        delete this.errors;
        this.errors = new Array();
    };
}

ErrorModule.prototype = new Module();