function RatingStarsSelector(fieldId, ratingStarsId)
{
	this.field = document.getElementById(fieldId);
	this.ratingStars = document.getElementById(ratingStarsId);
	this.verboseElement = document.createElement("div");
	this.stars = new Array();
	this.saved = new Array();
	this.savedVerbose;
	
	this.build = function()
	{
		this.field.style.visibility = "hidden";
        this.field.style.position = "absolute";
		
		this.ratingStars.parentNode.removeChild(this.ratingStars);
        this.field.parentNode.appendChild(this.ratingStars);
	
	    for (iChildNodes = 0 ; iChildNodes < ratingStars.childNodes.length ; iChildNodes++)
	    {
	        var childNode = ratingStars.childNodes[iChildNodes];
	        if (childNode.nodeName.toLowerCase() == "div" && childNode.className == "star")
	        {
	            this.registerStar(childNode);
	        }
	    }
		
		this.ratingStars.selector = this;
		this.ratingStars.onmouseout = function() { this.selector.restore(); }
    }
	
	this.setVerbose = function(state)
	{
		if (state)
		{
			this.ratingStars.appendChild(this.verboseElement);
		}
		else if (this.verboseElement.parentNode === this.ratingStars)
		{
			this.ratingStars.removeChild(this.verboseElement);
		}
	}
	
	this.registerStar = function(star)
	{
		this.stars.push(star);
        star.selector = this;
        star.style.cursor = "pointer";
        star.onmouseover = function() { this.selector.highlight(this); }
		star.onclick = function() { this.selector.save(); }
	}
	
	this.highlight = function(star)
	{
		var activeCount = 0;
		var imageName = "rating";
		for (iStars = 0 ; iStars < this.stars.length ; iStars++)
		{
			this.stars[iStars].style.backgroundImage = "url(/client/mbo2010/images/layout/" + imageName + ".gif)";
			this.stars[iStars].isActive = imageName == "rating";
            if (imageName == "rating")
			{
				activeCount++;
			}
			if (this.stars[iStars] === star)
			{
				imageName = "ratingBlank";
			}
		}
		this.verboseElement.style.fontWeight = "normal";
		this.verboseElement.innerHTML = activeCount;
	}

    this.restore = function()
	{
		for (iStars = 0 ; iStars < this.stars.length ; iStars++)
        {
			var imageName = (this.saved[iStars])? "rating" : "ratingBlank";
			this.stars[iStars].style.backgroundImage = "url(/client/mbo2010/images/layout/" + imageName + ".gif)";
		}

		this.verboseElement.style.fontWeight = "bold";
		this.verboseElement.innerHTML = (this.savedVerbose != undefined)? this.savedVerbose : "";
	}
	
	this.save = function()
	{
		for (iStars = 0 ; iStars < this.stars.length ; iStars++)
		{
			this.saved[iStars] = this.stars[iStars].isActive;
		}
		this.savedVerbose = this.verboseElement.innerHTML;
        this.field.options.selectedIndex = this.savedVerbose - 1;
	}
}