/* -------------------------------------------------------------
	INFOS
		Librairie des fonctions JavaScript et scripts pour MICC module sondage.
	
	INSTRUCTIONS
		1. Ne pas modiffier SVP ! 
	
	LISTE DES FONCTIONS
		1. sendAndLoad() - Envoi le vote et retourne les résultats dans la div #poll #contentPoll
		2. affiche(contenu) - Affiche le resultat dans la zone Sondage
			
	HISTORIQUE
		V 0 (20091025 - Bruno Bouchon - bruno.bouchon@gmail.com)
		

------------------------------------------------------------- */
/* -------------------------------------------------------------
0
Set global variables 
Global Fonction
------------------------------------------------------------- */

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/* -------------------------------------------------------------
1
sendAndLoad()
------------------------------------------------------------- */

function sendAndLoad() {
	
	var choix;
	var contentPoll = MM_findObj('pollReponse');
	
	if (document.formPoll.pollChoix[0].checked) {
		choix = 1;
	} else if (document.formPoll.pollChoix[1].checked) {
		choix = 2;
	} else {
		choix = 0;	
	}

	if (choix == 0) {
		 contentPoll.style.color="#FF0000"; 
	} else {
		phpData = "choix="+choix+"&id_sondage=" + document.formPoll.pollId.value;
		var xhr_object = null;

		if(window.XMLHttpRequest) // Firefox
		   xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
		   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non supporté par le navigateur
		   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		   return;
		}	
	
		xhr_object.open("POST", "../common/inc/vote.php", true);
	
		xhr_object.onreadystatechange = function() {
		   if(xhr_object.readyState == 4) {
			contentPoll.innerHTML = xhr_object.responseText;
			xhr_object.close;
		   } ;
		}
	
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
		xhr_object.send(phpData);
		//affiche(wait);
	}
	
	
   
}

/*
<p class=\"error\">
*/
