﻿/* NAMESPACE Website.Rating  */

/* Classes used by Controls/Rating.js */

Type.registerNamespace('Website.Rating');


// ratingButton_click
//
// Handles the click event of _ratingButton links (used by Controls/Rating.ascx)
//
Website.Rating.ratingButton_click = function (evt, context) {
    // find the RatingHighlight div 
    var ratingHighlight = $get(this.id.replace(new RegExp('(.*?)Rating.$'), '$1RatingHighlightContainer')); // e.g. if our button is ctl00$ctl06$Rating1, then find $ctl00$ctl06$RatingHighlight
    // hide it
    Relational.Utility.changeClassName(ratingHighlight, 'Visible', 'Hidden');
    // find the ValueHolder textbox (hint: it's in the same naming container as the buttons, and its ClientID ends in "ValueHolder") 
    var valueHolder = $get(this.id.replace(new RegExp('(.*?)Rating.$'), '$1ValueHolder')); // e.g. if our button is ctl00$ctl06$Rating1, then find $ctl00$ctl06$ValueHolder
    // stash the clicked value in the textbox (the link text is the appropriate number)
    valueHolder.value = this.innerHTML; 
    // turn all links off
    var links = this.parentNode.getElementsByTagName('A');
    for (var i=0; i<links.length; i++) {
        Relational.Utility.changeClassName(links[i], 'On', 'Off');
    } 
    // Turn this link on 
    Relational.Utility.changeClassName(this, 'Off', 'On');
    // Get rid of dotted focus line
    if (this.blur) this.blur();
    // Cancel link click from bubbling
    return Relational.Utility.eventCancel(evt);
}

Relational.Utility.Rules.register(
    {

        // Rating button behavior
        'div._RatingButtons a' : function(element){
            var context = null;
            $addHandler(element, 'click', Function.createCallback(Website.Rating.ratingButton_click, context));
        }

    }
);


// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();


