// JavaScript Document

/****************************

	étoiles dynamiques

****************************/

function dynamicStars(total, id, prefix)
{
	for ( i=1; i<=total; i++)
	{
		document.getElementById(prefix+i).src='/images/votes/emptystar.png';
	}
	
	for ( i=1; i<=id; i++)
	{
		document.getElementById(prefix+i).src='/images/votes/fullstar.png';
	}
	
}

/**************************
		 Votes 
***************************/


function updateAverage(item_id)
{
	xhr_object = AjaxObject();
	var param = no_cache();
	
	xhr_object.onreadystatechange = function()
	{
		if(xhr_object.readyState == 4 && xhr_object.status == 200)
		{
			var reponse = xhr_object.responseText;
			document.getElementById('moyenne_vote').src = reponse;
		}
	}
	
	xhr_object.open('GET','http://'+window.location.host+'/updateaverage/' + item_id + '/' + param,true);
	xhr_object.send(null);
}


function addVote(item_id, user_id, score_value)
{
	xhr_object = AjaxObject();
	var param = no_cache();
	
	
	
	xhr_object.onreadystatechange = function()
	{
		if(xhr_object.readyState == 4 && xhr_object.status == 200)
		{
			
			var reponse = xhr_object.responseText;
			document.getElementById('formu_vote').innerHTML = reponse;
			
			updateAverage(item_id);
		}
	}
	
	
	xhr_object.open('GET','http://'+window.location.host+'/addvote/' + item_id + '/' + user_id + '/' + score_value + '/' + param,true);
	xhr_object.send(null);
	
}