function XajaxNotificationsButton ( button, nodeID, add ) {
    this.buttonElement = button;
    this.nodeID = nodeID;
    this.add = add;
    this.registerEventHandlers();
}

XajaxNotificationsButton.prototype = {

    registerEventHandlers : function() {
        // for god sake don't touch the var in front of oThis ! :-)
        var oThis = this;
        var func = function (oEvent) {
            if( !oEvent ) {
                oEvent = window.event;
            }

            oThis.onClick( oEvent );
        };

        this.addEvent( this.buttonElement, 'click', func );
    },

    onClick : function( oEvent ) {
        if ( this.add )
        {
            this.addNotification();
        }
        else
        {
            this.removeNotification();
        }
    },

    addNotification : function() {
        xajax.call( "addNotification", {parameters:[ this.nodeID, 1 ], context:this} );
    },

    removeNotification : function() {
        xajax.call( "removeNotification", {parameters:[ this.nodeID, 1 ], context:this} );
    },

    addNotificationCallback : function( resultCode, message ) {
        // xajax currently passes all variables as strings, so we do some type conversion here first
        if ( typeof resultCode == 'string' )
        {
            resultCode = parseInt(resultCode);
        }

        if ( resultCode === 0 )
        {
            this.buttonElement.value = "Remove notification";
            this.add = false;
        }
        else
        {
            window.alert( message );
        }
    },

    removeNotificationCallback : function ( resultCode, message ) {
        // xajax currently passes all variables as strings, so we do some type conversion here first
        if ( typeof resultCode == 'string' )
        {
            resultCode = parseInt(resultCode);
        }

        if ( resultCode === 0 )
        {
            this.buttonElement.value = "Add notification";
            this.add = true;
        }
        else
        {
            window.alert( message );
        }
    },

    addEvent : function ( elm, evType, fn, useCapture )
    // addEvent and removeEvent
    // cross-browser event handling for IE5+, NS6 and Mozilla
    // By Scott Andrew
    {
      if (elm.addEventListener){
        elm.addEventListener(evType, fn, useCapture);
        return true;
      } else if (elm.attachEvent){
        var r = elm.attachEvent("on"+evType, fn);
        return r;
      } else {
        //alert("Handler could not be added");
        return false;
      }
    }
}