//review stars' hover
function reviewStarsHover2(stars) {	//hovers the stars before index	
	if (stars != null && stars > 0) {
		for (var i=1; i<=5; ++i) {					//hiding the star hovers and showing original stars
			if (i <= stars)
				document.getElementById('star_' + i).className = 'starFull';	//full star
			else
				document.getElementById('star_' + i).className = 'starEmpty';	//empty star
		}
	}
}
//review stars back to original
function reviewStarsHoverOff2() {	//hovers off. span with id elementID, has the starvalue
	var starValue = 0;
	try {
		starValue = document.getElementById('starValue').className;	//getting the original star value
		
	} catch (err) {
	}
	
	for (var i=1; i<=5; ++i) {					//hiding the star hovers and showing original stars
		if (i <= starValue)
			document.getElementById('star_' + i).className = 'starFull';	//full star
		else
			document.getElementById('star_' + i).className = 'starEmpty';	//empty star
	}
}


function reviewSubmit2(uniqueID, starValue) {	//submits the review element form
	if (uniqueID != null && uniqueID != '' && starValue != null && starValue > 0 && starValue <= 5) {
		$("#reviewStars a").each(function() {
		    $(this).attr('onclick',""); 
		    $(this).attr('onmouseover','');
		});

		$.ajax({
		   type: "POST",
		   url: "/stc/review/submit.jsp",
		   data: "recipeID="+uniqueID+"&voteValue="+starValue,
		   success: function(msg){
                        var score = msg.split(';');
			updateStars(score[0],score[1]);
		  }
		 });

	}
}

function updateReview(uniqueID) {
	$.ajax({
	   type: "POST",
	   url: "/stc/review/fetch.jsp",
	   data: "recipeID="+uniqueID,
	   success: function(msg){
                var score = msg.split(';');
		updateStars(score[0],score[1]);
	  }
	 });
	
}

function updateStars(votes, score) {
    votes = parseInt(votes);
    score = parseInt(parseFloat(score/votes)+0.5);
    $('#starValue').attr('class', score);
    for(i = 1; i <= 5; i++) {
        if(score >= i) {
            $("#star_"+i).attr("class", "starFull");
        } else {
            $("#star_"+i).attr("class", "starEmpty");
        }
    }

   $(".reviewExtraInfo span").html(""+votes);
    
}

