/**
 *
 */

function createDelegate(scope, func, v) {
	f=function() {
		scope[func](v);
	};

	return f;
}

/**
 *
 *  Text input hinter.
 *
 */

function RatingEditor(hiddenId, emptyStarUrl, fullStarUrl) {

	/**
	 *
	 */
	this.getValue=function() {
		return this.hiddenEl.value;
	}

	/**
	 *
	 */
	this.setValue=function(v) {
		this.hiddenEl.value=v;
		this.update();
	}

	/**
	 *
	 */
	this.getImage=function(index) {
		return document.getElementById(this.idPrefix+"_img"+index);
	}

	/**
	 *
	 */
	this.getAnchor=function(index) {
		return document.getElementById(this.idPrefix+"_"+index);
	}

	/**
	 *
	 */
	this.update=function() {
		for (i=0; i<5; i++) {
			var im=this.getImage(i);

			if (this.getValue()>i)
				im.src=this.fullStarUrl;

			else
				im.src=this.emptyStarUrl;
		}
	}

	/**
	 *
	 */
	this.outputHtml=function() {
		var i;

		for (i=0; i<5; i++) {
			document.write("<a id='"+this.idPrefix+"_"+i+"' href='javascript:void(0);'><img id='"+this.idPrefix+"_img"+i+"' ></a>&nbsp;");
			this.getAnchor(i).onclick=createDelegate(this,"onStarClick",i);
		}

		this.update();
	}

	/**
	 *
	 */
	this.onStarClick=function(index) {
		this.setValue(index+1);
	}

	/**
	 *  Construct.
	 */

	this.emptyStarUrl=emptyStarUrl;
	this.fullStarUrl=fullStarUrl;
	this.idPrefix=hiddenId;
	this.hiddenEl=document.getElementById(hiddenId);
}
