// JavaScript Document

//Objet http
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer")
	{
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function load_button()
{
	$('btn_resultat').style.display = "none";
	this.setTimeout("affiche_button()",14000);
}

function affiche_button()
{
	ajax_resultat();
	//$('btn_resultat').style.display = "block";
}

function ajax_resultat()
{
	http.open('POST', "index.php?page=inscription&action=ajax_resultat");
    http.onreadystatechange = do_ajax_resultat;
    http.send(null);	
}

function do_ajax_resultat()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == "gagnant")
		{
			window.location='p-inscription-gagnant';
		}
		if(response == "perdant")
		{
			window.location='p-inscription-perdant';
		}
		if(response == "erreur")
		{
			window.location='/';
		}
	}
}

function remove_participant()
{
	http.open('POST', "index.php?page=inscription&action=ajax_remove_participant");
    http.onreadystatechange = do_remove_participant;
    http.send(null);	
}

function do_remove_participant()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == "ok")
		{
			window.location='/';
		}
	}
}
