/// <reference name="MicrosoftAjax.js"/>
/// <reference path="../WebServices/Rating.asmx" />
/// ----------------------------------------------------------------------------
/// --- All elements copyright (c) 1999 - 2009 by
/// --- SFW - Stefan Falz Webconsulting
/// --- http://www.asp-solutions.de/
/// --- 
/// --- Unauthorized use is strongly prohibited
/// ----------------------------------------------------------------------------
/// --- Article JavaScript functions
/// ---
/// --- Created on: 28.02.2000 von SFW (SF)
/// ----------------------------------------------------------------------------
/// --- Last changed on  : 07.08.2009
/// --- Last changed from: SFW (SF)
/// --- Reason           : Add methods
/// ----------------------------------------------------------------------------

function showRatingDiv( elementId, elementTitle )
{
    document.getElementById( elementId ).style.display = '';
    document.getElementById( elementId ).title         = elementTitle;
}

function rateArticle( articleId, rateValue, message, containerId )
{
    SFW.iWeb.Services.Rating.Rate( articleId, rateValue, message, rateSuccess, rateFailed, containerId );
}

function rateSuccess( message, containerId, methodName )
{
    //alert( containerId );
    document.getElementById( containerId ).innerHTML = message;
    //alert( message );
}

function rateFailed( message, containerId, methodName )
{
    //alert( containerId );
    alert( message );
}

function AddNewRatingHandler()
{
AjaxControlToolkit.RatingBehavior.prototype._onStarClick = 
    function( e )
    {
        if ( this._readOnly )
        {
            return;
        }
        //   if (this._ratingValue != this._currentRating) {                    
        this.set_Rating( this._currentRating );
        // }
    };

AjaxControlToolkit.RatingBehavior.prototype.set_Rating = 
    function( value )
    {
        //   if (this._ratingValue != value) {
        this._ratingValue   = value;
        this._currentRating = value;
        if (this.get_isInitialized())
        {
            if ( ( value < 0) || ( value > this._maxRatingValue ) )
            {
                return;
            }
            this._update();

            AjaxControlToolkit.RatingBehavior.callBaseMethod( this, 'set_ClientState', [this._ratingValue] );
            this.raisePropertyChanged( 'Rating' );
            this.raiseRated( this._currentRating );
            this._waitingMode( true );

        var args      = this._currentRating + ";" + this._tag;
        var id        = this._callbackID;
        var article   = this._tag.split( "|" )[0];
        var container = this._tag.split( "|" )[1];
        //alert( this._tag );

            rateArticle( article, value, "", container );
        }
        //  }
    };                
}
