var result_vote = "";

function maj_liste_filiere(filiere){
	var url = '/ajax/maj_liste_filiere.php';
	var myAjax = new Ajax.Request(
      url,
      {
        method: 'post',
        postBody: 'niveau=' + $("id_niveau").value + '&checked=' + filiere,
        onComplete: function (xhr){
		        		if (xhr.status == 200)
					    {
					        $("id_liste_filiere").innerHTML = xhr.responseText;
					    }
		        	}
      });
}

function addVote(){
	var url = '/ajax/addVote.php';
	var myAjax = new Ajax.Request(
      url,
      {
      	asynchronous: false,
        method: 'post',
        postBody: 'vote=' + $("vote").value,
        onComplete: function (xhr){
		        		if (xhr.status == 200)
					    {
					        return xhr.responseText;
					    }
		        	}
      });
}

function showVote(){
	//Dialog.alert({url: "/ajax/views/view_add_logo.html", options: {method: 'get'}}, {className: "alphacube", width:540, okLabel: "Close"});
	Dialog.confirm($('zone_vote').innerHTML, {
		className:"alphacube", 
		width:400,
		okLabel: "Valider", 
		cancelLabel: "Annuler", 
		onOk:function(win){ 
				// Effectuer le vote			
				// Extraction du vote
				var mon_vote = 0;
				for ($i=1;$i<6;$i++){
					//alert($("vote"+$i).value);
					if ($("vote"+$i).checked){
						mon_vote = $("vote" + $i).value;
					}
				}				
					
				var url = '/ajax/addVote.php';
				var myAjax = new Ajax.Request(
			      url,
			      {
			      	asynchronous: false,
			        method: 'post',
			        postBody: 'vote=' + mon_vote + '&id_ecole=' + $('id_ecole').value,
			        onComplete: function (xhr){
					        		if (xhr.status == 200)
								    {
								        result_vote = xhr.responseText;
								    }
					        	}
			      });
				
				if (result_vote == "OK"){
					$("message_valide").innerHTML = "Merci d'avoir voté.";
					// Fermer la fenêtre
					win.close();
					// Recharger la fenêtre
					window.location.reload();
				}
				if (result_vote == "DEJA"){
					$("message_valide").innerHTML = "Votre vote est mise à jour.";
					// Fermer la fenêtre
					win.close();
					// Recharger la fenêtre
					window.location.reload();
				}
				if (result_vote == "ERR"){
					$("message_erreur").innerHTML = "Erreur lors du vote.";			
				}		
				
				//$('login_error_msg').innerHTML='Login or password inccorect'; 
				//$('login_error_msg').show(); 
				//Windows.focusedWindow.updateHeight(); 
				//new Effect.Shake(Windows.focusedWindow.getId()); 
				return false;
		}
	}); 
}
