function getXMLHttpRequest() {
	var xhr = null;
	
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
		return null;
	}
	
	return xhr;
}

function vote_rel(note, mark, url)
{
var i=1;
while (i<=note)
	{
	var id = "img_vote_"+mark+i;
	var img_vote = document.getElementById(id);
	img_vote.setAttribute("src", url+"css/images/fail_vote.jpg");		
	img_vote.setAttribute("alt","1pt");
	i++;		
	}

while (i<6)
	{
	var id = "img_vote_"+mark+i;
	var img_vote = document.getElementById(id);
	img_vote.setAttribute("src", url+"css/images/fail_vote_off.jpg");		
	img_vote.setAttribute("alt","0pt");
	i++
	}
		
}

function vote_click(id, ip, i, mark, url) 
{
var xhr = getXMLHttpRequest();
xhr.open("POST", url+"./cont/vote/nouv_vote.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('"&id=' + id + '&ip=' + ip + '&note=' + i + '"');
xhr.onreadystatechange = function() 
	{
	        if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) 
		{
			var rep=xhr.responseText.split(','); // Données textuelles récupérées
			if (rep[0]!=0)
			{
				var note = rep[0];
				// Au cas où il n'y a pas encore de note
				var nb_vote = rep[1] || 1;
				var out = document.getElementById('image_'+mark);
				out.setAttribute("onmouseout","javascript:vote_rel("+note+", "+mark+", \'"+url+"\')");
				var votant = document.getElementById('txt_votant'+mark).firstChild;
				document.getElementById('txt_votant'+mark).removeChild(votant);
				var txt_vote = document.createTextNode(" Nombre de votants : "+nb_vote);				
				document.getElementById('txt_votant'+mark).appendChild(txt_vote);
				var myspan = document.createElement("span");	
				var myspanclass = document.createAttribute("class");
				myspanclass.nodeValue = "textgras";
				myspan.setAttributeNode(myspanclass);				
				var myspantext = document.createTextNode(" Merci pour le vote ! ");		
				myspan.appendChild(myspantext);
				document.getElementById('txt_votant'+mark).appendChild(myspan);
					
				vote_rel(rep[0], mark, url);				
			}
			else
			{
				var node = document.getElementById('txt_votant'+mark);
				node.removeChild(node.lastChild);
				var myspan = document.createElement("span");	
				var myspanclass = document.createAttribute("class");
				myspanclass.nodeValue = "textgras";
				myspan.setAttributeNode(myspanclass);				
				var myspantext = document.createTextNode(" Vous avez déjà voté ! ");		
				myspan.appendChild(myspantext);
				node.appendChild(myspan)	
			}
        	}
	}
}

function vote_lum(i, mark, url)
{
var id = "img_vote_"+mark+i;
var img_vote = document.getElementById(id);
var etat = img_vote.alt
if (img_vote.alt=="1pt") /* si le point est allumé... on utilise la balise alt pour le savoir */ 
	{
	for (j=5; j>i; j--) 
		{
		var id = "img_vote_"+mark+j;
		var img_vote = document.getElementById(id);
		img_vote.setAttribute("src", url+"css/images/fail_vote_off.jpg");		
		img_vote.setAttribute("alt","0pt");
		}
	}
	else
	{
	for (j=1; j<=i; j++)
		{
		var id = "img_vote_"+mark+j;
		var img_vote = document.getElementById(id);
		img_vote.setAttribute("src", url+"css/images/fail_vote.jpg");		
		img_vote.setAttribute("alt","1pt");
		}
	} 
}




