// **************************************************************** //
//		Document créé par Mathieu Gauthier 7 mai 2009               //
// **************************************************************** //
$(document).ready(function(){
						   
	for(var cpt=1;cpt<=5;cpt++){
		if ( $("#etoile"+cpt).length > 0 ) {
			$("#etoile"+cpt).click(function(){
				id=(this.id).charAt((this.id).length-1)
				rate(id)
				return false;
			})
		}
	}
	for(var cpt=1;cpt<=5;cpt++){
		if ( $("#etoile-concours"+cpt).length > 0 ) {
			$("#etoile-concours"+cpt).click(function(){
				id=(this.id).charAt((this.id).length-1)
				$('#box-vote-concours').fadeIn('slow');
				$('#concoursVote').attr('value',id);
				rating = parseInt(id) * 16;
				$('.concours-rating').width(rating+"px");
				return false;
			})
		}
	}
	//Formulaires validés en Jquery
	if ( $("#fConcoursContenu").length > 0 ) {
		var formValidator = new ValidatorClass();
		formValidator.init({
		  form:           "#fConcoursContenu",
		  isRequired:     ['adresse', 'codepostal', 'ville', 'telephone'],
		  bindElement:    '#submit-concours-contenu',
		  callback:       function() {
			$('#fConcoursContenu').submit();
		  }
		});	
	}
});
function rate(vote)  {

	dataToSend = {

				'rating': vote,

				'typeTable': $('#typeTable').attr('value'),
				
				'idMembre': $('#idMembre').attr('value'),
				
				'id': $('#id').attr('value')

			 };

	$.ajax({

	  data:dataToSend,

	  type: "POST",
	  
	  url: "/public/ajax/rater.php",

	  success: function(msg){
			var splitted = msg.split(" ");
			
			rating = splitted[0] * 16;
			
			$('.user-rating').width(rating+"px");
			
			var moyenne = splitted[1] / splitted[2];
			var nbrVote = splitted[2];
			
			$('.current-rating').width(moyenne*16+"px");
			$('.totalRate').html((Math.round(moyenne*10)/10)+"/5 | "+nbrVote+" votes (Votre &eacute;valuation :")	
			
	  }

	});
}
