if (document.images){
  pic2 = new Image(8,13);
  pic2.src = "http://festivalgeneration80.be/poll/images/non_droite.png";
  pic3 = new Image(1,13);
  pic3.src = "http://festivalgeneration80.be/poll/images/non_mil.jpg";
  pic4 = new Image(1,13);
  pic4.src = "http://festivalgeneration80.be/poll/images/ok_gauche.png";
  pic5 = new Image(2,13);
  pic5.src = "http://festivalgeneration80.be/poll/images/ok_mil.jpg";
  pic6 = new Image(10,13);
  pic6.src = "http://festivalgeneration80.be/poll/images/true.gif";
  pic1 = new Image(16,11);
  pic1.src = "http://festivalgeneration80.be/poll/images/ajax-loader.gif";  
}

function fct(id, nbre)
{
	var count = 0;
	for(var i = 0; i < nbre; i++)
	{
		if(document.getElementById("radio_" + i).checked == true) count++;
	}
	document.getElementById("compteur").value = count;
}
function trim(aString)
{
	var regExpBeginning = /^\s+/;
	var regExpEnd       = /\s+$/;
    return aString.replace(regExpEnd, "");
}

function valide(poll, nbre, max)
{
	var err = "";
    var count = 0;
    var tab = "";

	for(var i = 0; i < nbre; i++)
	{
		if(document.getElementById("radio[" + poll + "]["+ i + "]").checked == true) 
        {
            tab += "&name_" + count + "=" + document.getElementById("radio[" + poll + "]["+ i + "]").name;
		    count++;            
        }
	} 
   	var diff = count - max;
	if(count > max) err = "Vous avez " + diff + " choix de trop\n";

	if(count == 0) err = "Vous devez au mimimum cocher une case";

	if(err != "") alert(err);
	else
	{
		var xhr = getXhr();
		xhr.onloading = showwaitingPoll(poll);
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
                leselect = xhr.responseText;
				document.getElementById("polll[" + poll + "]").innerHTML = leselect;
			}
		}
		xhr.open("POST","../poll/ajax.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("nbre=" + nbre + "&poll=" + poll + "&count=" + count + "&tab=" + tab);
	}
}
function voir(poll, max)
{
	var xhr = getXhr();
	xhr.onloading = showwaitingPoll(poll);
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			document.getElementById("polll[" + poll + "]").innerHTML = xhr.responseText;
		    //xhr.oncomplete = hidewaitingPoll(poll);
		}
	}
	xhr.open("POST","../poll/voir.php", true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("poll=" + poll + "&max=" + max);
}
function voter(poll, max)
{
	var xhr = getXhr();
	xhr.onloading = showwaitingPoll(poll);
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			document.getElementById("polll[" + poll + "]").innerHTML = xhr.responseText;
		}
	}
	xhr.open("POST","../poll/voter.php", true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("poll=" + poll + "&max=" + max);
}
function getXhr()
{
    var xhr = null;
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
	   try
	   {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	else
	{ // XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   xhr = false;
	}
       return xhr;
}

function showwaitingPoll(div)
{
	document.getElementById("waiting_" + div).innerHTML = "<img src='http://festivalgeneration80.be/poll/images/ajax-loader.gif' width='16' height='11' alt='' />";
}
function hidewaitingPoll(div)
{
	document.getElementById("waiting_" + div).innerHTML = "";
}