
function ProductRating(updatefield, locked) {
	this.updatefield = updatefield;
	this.locked = locked;

	this.init = function() {
		window.__product_ratings = this;

		this.imgStar0 = new Image();
		this.imgStar0.src = '/images/prating-star-0.png';

		this.imgStar5 = new Image();
		this.imgStar5.src = '/images/prating-star-5.png';
		
		this.imgStar10 = new Image();
		this.imgStar10.src = '/images/prating-star-10.png';

		this.draw();
	}


	this.draw = function() {
		var buf = '';

		buf += '<div id="divprating">';

		for(var i=1; i<=5; ++i) {
			buf += '<img id="pratingStar'+i+'" src="'+this.imgStar0.src+'" width="23" height="23" border="0" style="cursor:pointer;" onmouseover="window.__product_ratings.starOver(this)" onclick="window.__product_ratings.starClick(this)" align="absmiddle">';
		}
		buf += '  &nbsp;<span id="idCurStars" style="font-size:11px;color:gray;">'+this.curval+' stars</span>';
		buf += '</div>';


		document.write(buf);

		this.curval = document.getElementById(this.updatefield).value;
		this.update();
	}


	this.starOver = function(that) {
		if(this.locked) return;
		var starid = that.id.substr(11);
		this.curval = starid * 1;
		this.update();
	}

	this.update = function() {
		for(var i=1; i<=5; ++i) {
			if(this.curval >= i) {
				document.getElementById('pratingStar'+i).src = this.imgStar10.src;
			} else {
				document.getElementById('pratingStar'+i).src = this.imgStar0.src;
			}
		}

		document.getElementById('idCurStars').innerHTML = this.curval+' stars';
		document.getElementById(this.updatefield).value = this.curval;


	}

	this.starClick = function(that) {
		this.locked = (this.locked) ? 0 : 1;

		this.starOver(that);
	}

	this.init();
}












