function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}


function vote(id_article, type_vote)
{
	// l'URL appelée pour voter
	var url = '/fr/quizz/ajax_vote.php';
	var httpRequest = false;

	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType)
		{
			httpRequest.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)
	{ // IE
		try
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}

	if (!httpRequest)
	{
		alert('Abandon :( Impossible de créer une instance XMLHTTP');
		return false;
	}
	
	var t = new Date();

	httpRequest.open('GET', url + '?id_article=' + id_article + '&vote=' + type_vote + '&t=' + t.getTime(), true);
	httpRequest.onreadystatechange = function() { alertContents(httpRequest, id_article); };
	httpRequest.send(null);
	//setCookie('cook_vote['+id_article+']',1,30);
	return true;
}

function alertContents(httpRequest, id_article)
{
	if (httpRequest.readyState == 4)
	{
		if (httpRequest.status == 200)
		{
			// Edit page content
			str = httpRequest.responseText;
			var tab = str.split('|');

			// On lit (et on parse) la réponse : 1er nombre = nombre total de votes, puis Plus, puis Moins
			var total_votes = tab[0];
			var total_votes_plus  = tab[1];
			var total_votes_moins = tab[2];
			pc_pl = (total_votes_plus/total_votes)*100;
			pc_mo = (total_votes_moins/total_votes)*100;
			
			// on met à jour la page de présentation, maintenant
			document.getElementById('numvotes').innerHTML = total_votes+' vote(s)';
			//document.getElementById('n_vote_plus').innerHTML = 'Pour&nbsp;: '+Math.round(pc_pl) + ' %';
			//document.getElementById('n_vote_moins').innerHTML = 'Contre&nbsp;: '+Math.round(pc_mo) + ' %';
			aff_vote(Math.round(pc_pl), Math.round(pc_mo));

			// on efface le formulaire de vote
			document.getElementById('form_vote').innerHTML = '';


		}
		else
		{
			alert('Un problème est survenu avec la requête.'+httpRequest.readyState);
		}
	}
}
function aff_vote(plus, moins) {
		lpl = (plus*75/100);
		lmo = (moins*75/100);
		
	   document.getElementById('n_vote_plus').innerHTML = '<div style="width:40px;float:left;"><span class="radio-title">Pour</span></div><div style=" border:1px solid #b6b6b6; width:75px; height:9px;background-color:#f0f0f0;float:left;margin:6px 3px 0;" title="'+plus+' %"><img src="/fr/images/rouge.png" width="'+lpl+'" height="9" style="border:0; margin:0; padding:0;"> </div><!--<div style="float:left;"> &nbsp;'+plus+'&nbsp;% </div>--><br clear="all"><div style="width:40px;float:left;"><span class="radio-title">Contre</span></div><div style="border:1px solid #b6b6b6;width:75px; height:9px; background-color:#f0f0f0;float:left;margin:6px 3px 0;" title="'+moins+' %"><img src="/fr/images/rose.png" width="'+lmo+'" height="9" style="border:0; margin:0; padding:0;"> </div><!--<div style="float:left;"> &nbsp;'+moins+'&nbsp;% </div>--><br clear="all">';
	   //document.getElementById('n_vote_moins').innerHTML = '<div style="width:70px;float:left;">Contre&nbsp;:&nbsp; </div><div style="width:100px; background-color:#090;float:left;"><img src="/fr/images/rouge.png" width="'+moins+'" height="20" style="border:0; margin:0; padding:0;"> </div><div style="float:left;"> &nbsp;'+moins+'&nbsp;% </div><br clear="all"></div>';
	   }

