function file_old(fichier)
{
	var data=null;
	var xhr_object=null;
	if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else return(false);
	xhr_object.open("GET",fichier,false);
	xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xhr_object.send(data);
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else return(false);
}

function file(fichier,d)
{
	var data=null;
	var xhr_object=null;
	if(window.XMLHttpRequest) xhr_object=new XMLHttpRequest();
	else if(window.ActiveXObject) xhr_object=new ActiveXObject("Microsoft.XMLHTTP");
	else return(false);
	xhr_object.open("POST",fichier,true);
	xhr_object.onreadystatechange = function()
	{
		if(xhr_object.readyState==4)
		{
			if(xhr_object.status==200)
			{
				if(d!="") writediv(xhr_object.responseText,d);
			}

		}
		else
		{
			if(d=="droite") writediv('<div class="loading"><img src="images/loader.gif" alt="loading" /></div>','desc_action');
		}
	}
	xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xhr_object.send(data);
}


function writediv(texte,div)
{
    if((document.getElementById(div) && div!='voisins') || (div=='voisins' && texte.search("object")>-1)) document.getElementById(div).innerHTML=texte;
}


function aff_voisins(){
	 file('../ajax/js.php?method=aff_voisins','voisins');
}


function verif_voisins()
{
	aff_voisins();
	window.setInterval('aff_voisins();',5000);
}

function webcam_ok(p){
	 file('../ajax/js.php?method=webcam_ok&param='+encodeURIComponent(p),'webcam');
	 if (p=='1')
	 	{document.getElementById('okweb').style.background='orange';document.getElementById('nokweb').style.background='#FFF';}
		 else
		 {document.getElementById('nokweb').style.background='orange';document.getElementById('okweb').style.background='#FFF';}
}

function play(p)
{
    //var reponse = file_old('../ajax/js.php?method=play&param='+encodeURIComponent(p));
    file('../ajax/js.php?method=play&param='+encodeURIComponent(p),'droite');

    /*if (false)//(reponse.search("#REFRESH#")>-1)
    {
		writediv(reponse,'droite');
		window.setTimeout('play();',4000);
    }
    else
    {
		writediv(reponse,'droite');
    }*/
}

function vet(id_membre,id_vet)
{
	var reponse = file_old('../ajax/js.php?method=vet&id_membre='+encodeURIComponent(id_membre)+'&id_vet='+encodeURIComponent(id_vet));
    play();
}

function accessoire(id_acc)
{
	var reponse = file_old('../ajax/js.php?method=accessoire&id_acc='+encodeURIComponent(id_acc));
    play();
}

function inter(m1,m2,niveau)
{
	var reponse = file_old('../ajax/js.php?method=inter&m1='+encodeURIComponent(m1)+'&m2='+encodeURIComponent(m2)+'&niveau='+encodeURIComponent(niveau));
    play();
}

function scenar(id_scenario)
{
	var reponse = file_old('../ajax/js.php?method=scenar&param='+encodeURIComponent(id_scenario));
    play();
}

function insc(id,mod,valeur)
{
    var reponse = file_old('../ajax/js.php?method=insc&id='+encodeURIComponent(id)+'&mod='+encodeURIComponent(mod)+'&valeur='+encodeURIComponent(valeur));
    play();
}

function insc_invite()
{
    var mail_invite="";
    var homme_invite="";
    var femme_invite="";
    mail_invite=document.getElementById('mail_invite').value;
    homme_invite=document.getElementById('homme_invite').value;
    femme_invite=document.getElementById('femme_invite').value;

    var reponse = file_old('../ajax/js.php?method=insc_invit&param='+encodeURIComponent(mail_invite)+'&param1='+encodeURIComponent(homme_invite)+'&param2='+encodeURIComponent(femme_invite));
    if(reponse=="Ok") alert("L'invitation a bien été envoyée, Merci !"); else if(reponse=="deja") alert('Vous avez déjà inscrit ce couple'); else alert('Erreur');
}

function insc_suivant()
{
    var login="";
    var pass="";
    if(document.getElementById('mail_groupe')) login=document.getElementById('mail_groupe').value;
    if(document.getElementById('pass_groupe')) pass=document.getElementById('pass_groupe').value;
    var reponse = file_old('../ajax/js.php?method=insc_suivant&param1='+encodeURIComponent(login)+'&param2='+encodeURIComponent(pass));
    if(reponse=="") play(); else alert('Entrez une adresse e-mail correcte');
}

function insc_precedent()
{
    var reponse = file_old('../ajax/js.php?method=insc_precedent');
    play();
}


function boucle(i)
{
	window.setInterval('aff_time('+i+');',3000);
}

function verif_invit()
{
	window.setInterval('aff_invit();',5000);
	webcam();
}

function aff_time(i)
{
	var reponse = file_old('../ajax/js.php?method=aff_time&param='+i);
	if(reponse!='' && document.getElementById('wait'))
	{
		writediv(reponse,'wait');
		if (reponse.match('partie'))
		{
		    window.setTimeout("play();",2000);
		}
	}

	file('../ajax/js.php?method=aff_time&param='+i,'wait_header');
}

function aff_invit()
{
	file('../ajax/js.php?method=verif_invit','info_invit');
	aff_time();
}

/**
 *
 * @access public
 * @return void
 **/
function webcam()
{
	file('../ajax/js.php?method=webcam','webcam2');
}
