
var just_voted = false;
function update_user_stars_from_review(score,item_type,in_form)
{				
	if(!just_voted)
	{		
		update_user_star(score,item_type,in_form)
	}
}

function submitArticleRating(item_id, user_rating, novoting,markold)
{
	if(!just_voted)
	{
		url = "/u/ranking.php?id=" + item_id  + "&mark=" + user_rating + "&novoting=" + novoting + "&markold=" + markold;
		
		var xmlHttpReq = getXMLObject();
		xmlHttpReq.open("GET", url, true);
		xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpReq.onreadystatechange = function() 
		{
			if (xmlHttpReq.readyState == 4)
			{
				var result = new Array();
				result = xmlHttpReq.responseText.split(' ');			
								
				document.getElementById('ranking_count').innerHTML = result[1] + " (" + result[2] + " times)";		
				update_user_star(result[0], '');
			}	
		}
		
		xmlHttpReq.send(null);    
	}
	else
	{
		document.getElementById('ranking').innerHTML = 'You have already ranked';
	}
}

function getXMLObject()
{
	var xmlHttpReq = false;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		try
		{
			xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)		
		{
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	
	return xmlHttpReq;
}

function update_user_star(score,item_type,in_form)
{
	var rate_item = 'rate_' + item_type;	

	var score_inc = new Array(rate_item+'_1',rate_item+'_2',rate_item+'_3',rate_item+'_4',rate_item+'_5');	
			
	if (!in_form || document.getElementById('user_score_with_review').value == '' || document.getElementById('user_score_with_review').value == '0')
	{	
		for(var i=0; i < score_inc.length; i++)
		{												
			if ( (i+1)*2 <= score )
			{
				document.getElementById(score_inc[i]).className = 'star2';
			}
			else if ( (i+1)*2-1 <= score )
			{				
				document.getElementById(score_inc[i]).className = 'star1';
			}
			else
			{
				document.getElementById(score_inc[i]).className = '';
			}
		}
		


		if (score > 0 )
		 {
			 document.getElementById('ranking').innerHTML = '<b>Your Ranking: <font color="#FF0000 ">' + score + '</font></b> ';
		 }
		 else
		 {
			 document.getElementById('ranking').innerHTML = '<b>Click at the star to rank</b>';				 
		 }
	}
}
