/* <![CDATA[ */
/*
 *	starRating - 10/08/2006
 *	copyright (c) Bestofmedia - infos-du-net.com
 *	Auteur : Frantz Gauthier
 * 	Description : systeme de notation par etoile
 *	Require : prototype.js
 */

starRating = Class.create();

starRating.prototype = {
	initialize: function(elm, init, star_height) {
		if (typeof init != 'undefined') {
			this.actual_note = init
		} else {
			this.actual_note = 0;
		}
		if (typeof star_height != 'undefined') {
			this.star_height = star_height
		} else {
			this.star_height = 20;
		}
		this.legend = legend;
		this.elm = elm;
		this.name = elm.id;
		this.all_stars = this.elm.getElementsByTagName('a');

		for (i=0; i < this.all_stars.length; i++)
		 {
		 	 this.all_stars[i].onmouseover = this.getAndShowNote.bindAsEventListener(this);
		 	 this.all_stars[i].onclick = this.getAndSetNote.bindAsEventListener(this);
		 }
		 this.elm.onmouseout = this.showInitialState.bindAsEventListener(this);
	},
	showNote: function(note) {
		 var note = Math.round(note);
		 for (i=0; i < this.all_stars.length; i++)
		 {
		 	if (i < note) {
		 		this.all_stars[i].style.backgroundPosition = 'left ' + (-note*this.star_height) + 'px';
		 	} else {
		 		this.all_stars[i].style.backgroundPosition = 'left top';
		 	}
		 }
		 this.showLegend(note);
	},
	getNote: function(elm) {
		if (elm.srcElement) {
			return elm.srcElement.firstChild.nodeValue;
		} else {
			return elm.target.firstChild.nodeValue;
		}
	},
	getAndShowNote: function(elm) {
		this.showNote(this.getNote(elm));
	},
	showInitialState: function() {
		this.showNote(this.actual_note);
	},
	setNote: function(note) {
		this.actual_note = note;
	},
	getAndSetNote: function(elm) {
		this.setNote(this.getNote(elm));
		this.setHiddenInput(this.actual_note);
		if (elm.srcElement) {
			elm.srcElement.blur();
		} else {
			elm.target.blur();
		}
		return false;
	},
	showLegend: function(note) {
		var id = this.elm.id + '-legend';
		var conteneur = $(id);
		conteneur.innerHTML = this.legend[note];
	},
	setHiddenInput: function(note) {
		var parent = this.elm.parentNode;
		if (parent.className.indexOf('notation-box') != -1) {
			parent.getElementsByTagName('input')[0].value = note;
		}
	}
}


 Event.observe(window,'load', function() {
 	$$('.notation-box').each(function(box){
 		var elm = box.getElementsByTagName('ul')[0];
 		new starRating(elm);
 	});
 });


 function validComment() {
 	avis_positif = document.getElementById('comment_plus').value;
 	avis_negatif = document.getElementById('comment_minus').value;

 	note1 = document.getElementById('js-note[1]').value;
 	
 	if(idSite == 3)
 	{
	 	note2 = document.getElementById('js-note[2]').value;
	 	note3 = document.getElementById('js-note[3]').value;
	 	note4 = document.getElementById('js-note[4]').value;
 	}

 	if ((avis_positif!="")||(avis_negatif!="")) {
 		if(idSite == 3)
 		{
	 		if (((note1!="") && (note2!="")) && ((note3!="") && (note4!=""))) {
	 			this.form.submit();
	 		} else {
	 			window.alert(error);
	 		}
 		}
 		if(idSite == 12)
 		{
	 		if (note1!="") {
	 			this.form.submit();
	 		} else {
	 			window.alert(error);
	 		}
 		}
 	} else {
 		window.alert(error1);
 	}
 }
 
/* ]]> */