/* Client-side code for Interscape.Web.Rater control. */
function Rater(uniqueId, rateCount, displayMode, onUrl, offUrl, onColor, offColor, notSetText)
{
	this.ScriptVersion = "1.0";
	this.UniqueId = uniqueId;
	this.RateTextId = uniqueId + "_RateText";
	this.RateText = document.getElementById(this.RateTextId);
	this.RateCommentsRowId = uniqueId + "_RateCommentsRow";
	this.RateCommentsRow = document.getElementById(this.RateCommentsRowId);
	this.RateValueId = uniqueId + "_RatingValue";
	this.RateValueText = document.getElementById(this.RateValueId);
	this.RateNotSetText = notSetText;
	this.DisplayMode = displayMode;
	this.OnUrl = onUrl;
	this.OffUrl = offUrl;
	this.OnColor = onColor;
	this.OffColor = offColor;
	this.CurrentRate = 0;
	this.RateCount = rateCount;
	this.OnImage = new Image();
	this.OffImage = new Image();

	if (this.DisplayMode=='Images')	{
		this.OnImage.src = onUrl;
		this.OffImage.src = offUrl;
	}
}
function Rater_Clear() {
	if (this.CurrentRate==0){
		this.setRatingLevel(0);
		this.RateText.innerText=this.RateNotSetText;
	}
}
function Rater_SetRatingLevel(level) {
	if (this.CurrentRate==0) {
		if (level>0)
			this.RateText.innerText=document.getElementById(this.UniqueId + "_Rate" + level).attributes['RateText'].value;
		for (var x=1; x<=this.RateCount; x++) {
			if (this.DisplayMode=='Images')
			{
				var img=document.getElementById(this.UniqueId + "_Rate" + x.toString()).childNodes[0];
				var ImageOn, ImageOff;
				
				if (img.attributes['OnUrl'])
					ImageOn=img.attributes['OnUrl'].value;
				else
					ImageOn=this.OnImage.src;
					
				if (img.attributes['OffUrl'])
					ImageOff=img.attributes['OffUrl'].value;
				else
					ImageOff=this.OffImage.src;

				img.src=((x>level)?ImageOff:ImageOn);
			}
			else
			{
				var cell=document.getElementById(this.UniqueId + "_Rate" + x.toString());
				var ColorOn, ColorOff;
				
				if (cell.attributes['OnColor'])
					ColorOn=cell.attributes['OnColor'].value;
				else
					ColorOn=this.OnColor;
					
				if (cell.attributes['OffColor'])
					ColorOff=cell.attributes['OffColor'].value;
				else
					ColorOff=this.OffColor;
					
				cell.style.backgroundColor=((x>level)?ColorOff:ColorOn);
			}
		}
	}
}
function Rater_GetOnColor(cell) {
	if (cell.attributes['OnColor'])
		return cell.attributes['OnColor'].value;
	else
		return this.OnColor;
}
function Rater_PerformRate(level) {
	var ret=false;
	if (this.CurrentRate==0) {
		var cell=document.getElementById(this.UniqueId + "_Rate" + level.toString());
		var req=cell.attributes["ReqComment"].value;
		this.CurrentRate=level;
		this.RateValueText.value = level;
		if (req=='True' && this.RateCommentsRow.style.display!='block')
			this.RateCommentsRow.style.display='block';
		else
			ret=true;
	}
	return ret;
}
Rater.prototype.clear = Rater_Clear;
Rater.prototype.setRatingLevel = Rater_SetRatingLevel;
Rater.prototype.performRate = Rater_PerformRate;
Rater.prototype.getOnColor = Rater_GetOnColor;
