/*
 * Notification module.
 *
 * This module contains the API necessary for notifying the user.
 *
 * Every page requires a means of user notification.  Each page will have a
 * different notification area.  For instance, the login dialog has a small
 * area for login messages.  While other pages have a different area for their
 * various messages.
 *
 * This notification area is a div with a specific id.  Once the notification
 * module knows the div's id, notification calls may be made.
 *
 * Usage:
 *
 *     1.  Set the id of the notification div by calling notify_set_id()
 *     2.  (Optional) - Set CSS classes for the messages.
 */

var notify_id = '';

var notify_error_class = 'notify-error';
var notify_info_class = 'notify-info';

// Set the id of the div used for notification messages.
// Returns the old id.
function notify_set_id(id) {
    var old_id = notify_id;
    notify_id = '#' + id;
    return old_id.substr(1);
}

// Set the error class
function notify_set_error_class(_class) {
    notify_error_class = _class;
}

// Set the info class
function notify_set_info_class(_class) {
    notify_info_class = _class;
}

// Send an informational message.
function notify_info(msg) {
    if (notify_id == null) {
        return alert(msg);
    }

    $(notify_id).html(msg).removeClass();
    $(notify_id).addClass(notify_info_class);
}

// Send an error message.
function notify_error(msg) {
    if (notify_id == null) {
        return alert(msg);
    }

    $(notify_id).html(msg).removeClass();
    $(notify_id).addClass(notify_error_class);
}