﻿Type.registerNamespace( 'ControlTests' );

/// <summary>
/// NewsgroupButton constructor.
/// </summary>

ControlTests.NewsgroupButton = function( element ) {

    ControlTests.NewsgroupButton.initializeBase( this, [element] );

    this._defaultCssClass = null;
    this._hoverCssClass = null;
    this._selectedCssClass = null;
    this._clickPostbackFunction = null;
    this._isSelected = null;

}

/// <summary>
/// NewsgroupButton prototype.
/// </summary>

ControlTests.NewsgroupButton.prototype = {

    /// <summary>
    /// Initializes this object.
    /// </summary>

    initialize : function() {

        ControlTests.NewsgroupButton.callBaseMethod( this, 'initialize' );
        $addHandlers( this.get_element(), { 'mouseover' : this._mouseOver, 'mouseout' : this._mouseOut, 'click' : this._click }, this );

    },
    
    /// <summary>
    /// Gets the ID.
    /// </summary>

    get_ID : function() {
        return this.get_element().id;
    },

    /// <summary>
    /// Gets the default CSS class.
    /// </summary>

    get_defaultCssClass : function() {
        return this._defaultCssClass;
    },
    
    /// <summary>
    /// Sets the default CSS class.
    /// </summary>

    set_defaultCssClass : function( value ) {

        if ( this._defaultCssClass !== value ) {
        
            this._defaultCssClass = value;
            this.raisePropertyChanged( 'defaultCssClass' );
            
        }
        
    },

    /// <summary>
    /// Gets the hover CSS class.
    /// </summary>

    get_hoverCssClass : function() {
        return this._hoverCssClass;
    },
    
    /// <summary>
    /// Sets the hover CSS class.
    /// </summary>

    set_hoverCssClass : function( value ) {
        
        if ( this._hoverCssClass !== value ) {
        
            this._hoverCssClass = value;
            this.raisePropertyChanged( 'hoverCssClass' );
            
        }
        
    },

    /// <summary>
    /// Gets the selected CSS class.
    /// </summary>

    get_selectedCssClass : function() {
        return this._selectedCssClass;
    },
    
    /// <summary>
    /// Sets the selected CSS class.
    /// </summary>

    set_selectedCssClass : function( value ) {
        
        if ( this._selectedCssClass !== value ) {
        
            this._selectedCssClass = value;
            this.raisePropertyChanged( 'selectedCssClass' );
            
        }
        
    },

    /// <summary>
    /// Gets the click postback function.
    /// </summary>

    get_clickPostbackFunction : function() {
        return this._clickPostbackFunction;
    },
    
    /// <summary>
    /// Sets the click postback function.
    /// </summary>
    
    set_clickPostbackFunction : function( value ) {
        
        if ( this._clickPostbackFunction !== value ) {
        
            this._clickPostbackFunction = value;
            this.raisePropertyChanged( 'clickPostbackFunction' );
        
        }
        
    },
    
    /// <summary>
    /// Handles the mouseOver event raised by the DOM element.
    /// </summary>

    _mouseOver : function() {
        
        if ( !this._isSelected ) {
            this.get_element().className = this._hoverCssClass;
        }
        
    },
    
    /// <summary>
    /// Handles the mouseOut event raised by the DOM element.
    /// </summary>

    _mouseOut : function() {
        
        if ( !this._isSelected ) {
            this.get_element().className = this._defaultCssClass;
        }
        
    },

    /// <summary>
    /// Handles the click event raised by the DOM element. Raises the 
    /// newsgroupSelected event.
    /// </summary>
    
    _click : function() {
        this.select();
    },

    /// <summary>
    /// Attaches the provided handler to the newsgroupSelected event.
    /// </summary>
    /// <param name="handler">The handler that is to be attached to the event.</param>

    add_newsgroupSelected : function( handler ) {
        this.get_events().addHandler( 'newsgroupSelected', handler );
    },

    /// <summary>
    /// Detaches the provided handler from the newsgroupSelected event.
    /// </summary>
    /// <param name="handler">The handler that is to be detached from the 
    /// event.</param>

    remove_newsgroupSelected : function( handler ) {
        this.get_events().removeHandler( 'newsgroupSelected', handler );
    },

    /// <summary>
    /// Raises the newsgroupSelected event.
    /// </summary>
    /// <param name="eventArgs">An EventArgs object containing event data.</param>

    raiseNewsgroupSelected : function( eventArgs ) {
    
        var handler = this.get_events().getHandler( 'newsgroupSelected' );

        if ( handler ) {
            handler( this, eventArgs );
        }
    
    },
    
    /// <summary>
    /// Selects the button.
    /// </summary>
    
    select : function() {
        
        this.get_element().className = this._selectedCssClass;
        this._isSelected = true;

        this.raiseNewsgroupSelected( Sys.EventArgs.Empty );
        
    },

    /// <summary>
    /// Deselects the button.
    /// </summary>
    
    deselect : function() {
        
        this.get_element().className = this._defaultCssClass;
        this._isSelected = false;
        
    },
    
    /// <summary>
    /// Selects the button but does not raise the selected event. This is 
    /// used to represent that the button is in a selected state.
    /// </summary>
    
    appearAsSelected : function() {
        
        this.get_element().className = this._selectedCssClass;
        this._isSelected = true;
        
    },
        
    /// <summary>
    /// Release resources before the control is disposed.
    /// </summary>
    
    dispose : function() {

        if ( this._parentElement ) {        
            $clearHandlers( this.get_element() );
        }
        
        ControlTests.NewsgroupButton.callBaseMethod( this, 'dispose' );
        
    }
    
} // ControlTests.NewsgroupButton.prototype

ControlTests.NewsgroupButton.registerClass( 'ControlTests.NewsgroupButton', Sys.UI.Control );

if ( typeof( Sys ) != 'undefined' ) Sys.Application.notifyScriptLoaded();

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();