function getXHR()
{
    var xr = null;
	if (window.XMLHttpRequest) // Firefox et autres
		{
			xr = new XMLHttpRequest();
		}
	else if (window.ActiveXObject) // Internet Explorer  
	{
		try
			{
				xr = new ActiveXObject("Msxml2.XMLHTTP" );
			}
		catch (e)
			{
				xr = new ActiveXObject("Microsoft.XMLHTTP" );
			}
	}
	else // XMLHttpRequest non supporté par le navigateur  
	{
		xr = false;
	}
	return xr;
}

function adherent(adh,id)
{
      // L'objet XMLHttpRequest, global pour la fonction callback
       xhr = getXHR();
	
	if (xhr == null) 
	{
	    alert("XMLHttpRequest non supporté !");
	    return;
	 }
	 // Ouverture d'une connexion en mode synchrone (on attend les données)
	 xhr.open("GET", "adherent.php?adh="+adh+"&idsitra="+id, true);
	 xhr.send(null);
	 xhr.onreadystatechange = function()
	 {
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200)
		 {
			 erreur = xhr.responseText.split('|');
			 if ( erreur[1] != "false")
			 {
				 // Données disponibles
				//j'efface les présentes lignes
				var a = document.getElementById(id);
				if (adh == 'n')
					{
					a.src="images/pasok.png"; 
					a.onclick = function () { adherent('o',id); }
					}
				if (adh == 'o')
					{
					a.src="images/ok.png";
					a.onclick = function () { adherent('n',id); } 
					}
			}
			
		 }
	 }

} 

function dispoenligne(id, enligne)
{
      // L'objet XMLHttpRequest, global pour la fonction callback
       xhr = getXHR();
	
	if (xhr == null) 
	{
	    alert("XMLHttpRequest non supporté !");
	    return;
	 }
	 // Ouverture d'une connexion en mode synchrone (on attend les données)
	 xhr.open("GET", "dispoenligne.php?id="+id+"&enligne="+enligne, true);
	 xhr.send(null);
	 xhr.onreadystatechange = function()
	 {
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200)
		 {
			 erreur = xhr.responseText.split('|');
			 if ( erreur[1] != "false")
			 {
				 // Données disponibles
				//j'efface les présentes lignes
				var a = document.getElementById('dispo-'+id);
				if (enligne == 'n')
					{
					a.src="images/dispoenligne-n.png"; 
					a.onclick = function () { dispoenligne(id,'o'); }
					}
				if (enligne == 'o')
					{
					a.src="images/dispoenligne-o.png";
					a.onclick = function () { dispoenligne(id,'n'); } 
					}
			}
			
		 }
	 }

} 

function aff_tarif(aff,id)
{
	
    // L'objet XMLHttpRequest, global pour la fonction callback
    xhr = getXHR();
	
	if (xhr == null) 
	{
	    alert("XMLHttpRequest non supporté !");
	    return;
	 }
	 // Ouverture d'une connexion en mode synchrone (on attend les données)
	 xhr.open("GET", "tarif.php?aff="+aff+"&id="+id, true);
	 xhr.send(null);
	
	 xhr.onreadystatechange = function()
	 { 
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200)
		 { 
			 erreur = xhr.responseText.split('|');
			 
			 if ( erreur[1] != "false")
			 {

				var a = document.getElementById(id);
			
				if (aff == 'n')
					{
					a.src="images/pasok.png"; 
					a.onclick = function () { aff_tarif('o',id); }
					}
				if (aff == 'o')
					{
					a.src="images/ok.png";
					a.onclick = function () { aff_tarif('n',id); } 
					}

			}
			
		 }
	 }

} 

function identifiant(id)
{
    // L'objet XMLHttpRequest, global pour la fonction callback
   
   xhr = getXHR();
	if (xhr == null) 
	{
	    alert("XMLHttpRequest non supporté !");
	    return;
	 }
	 // Ouverture d'une connexion en mode synchrone (on attend les données)
	 var login = 	document.getElementById("id"+id).value; 
	 var mdp =  	document.getElementById("mdp"+id).value;
	 var url =  	document.getElementById("url"+id).value;
	 var orisite =  document.getElementById("orisite"+id).value;
	 xhr.open("GET", "identifiant.php?login="+login+"&mdp="+mdp+"&id="+id+"&url="+url+"&orisite="+orisite, true);
	 xhr.send(null);
	 
	 xhr.onreadystatechange = function()
	 {
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200)
		 {
		
			erreur = xhr.responseText.split('|');
			if ( erreur[1] == "ok")
			{
				var tables = document.getElementsByTagName("input");
				for (i=0;i<tables.length;i++)
				{
					tables[i].style.backgroundColor='#FFFFFF';
				}
				document.getElementById('id'+id).style.backgroundColor='#5BC25B';
				document.getElementById('mdp'+id).style.backgroundColor='#5BC25B';
				document.getElementById('url'+id).style.backgroundColor='#5BC25B';
			}
			else
			{
				var tables = document.getElementsByTagName("input");
				for (i=0;i<tables.length;i++)
				{
					tables[i].style.backgroundColor='#FFFFFF';
				}
				document.getElementById('id'+id).style.backgroundColor='#FD3846';
				document.getElementById('mdp'+id).style.backgroundColor='#FD3846';
				document.getElementById('url'+id).style.backgroundColor='#FD3846';
				alert (erreur[1]);
			}
		
			
		 }
	 }

}    

function supprphoto(id)
{
    // L'objet XMLHttpRequest, global pour la fonction callback
	if (confirm("Etes-vous sur de vouloir supprimer la photo de cette adhérent?"))
	{
		xhr = getXHR();
		if (xhr == null) 
		{
	   	 	alert("XMLHttpRequest non supporté !");
	    	return;
		 }
		 // Ouverture d'une connexion en mode synchrone (on attend les données)
		 xhr.open("GET", "supprphoto.php?id="+id, true);
		 xhr.send(null);
		
		 xhr.onreadystatechange = function()
		 {
			// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
			
			if (xhr.readyState == 4 && xhr.status == 200)
				{
					erreur = xhr.responseText.split('|');
					if (erreur[1] == "o") {
					document.getElementById('supprphoto').innerHTML="<img src=images/ok.png border=0 align=absmiddle>&nbsp;La photo a bien été supprimée.";
					}
					if (erreur[1] == "n") {
					document.getElementById('supprphoto').innerHTML="<img src=images/pasok.png border=0 align=absmiddle>&nbsp;Photo introuvable, contactez votre administrateur.";
					}
				}
		 }
	}
} 

function active()
{
	document.getElementById('datedeb').style.backgroundColor='#FFFFFF';
	document.getElementById('datefin').style.backgroundColor='#FFFFFF';
	document.getElementById('titre').style.backgroundColor='#FFFFFF';
	document.getElementById('lib').style.backgroundColor='#FFFFFF';
	document.getElementById('datedeb').disabled = '';
	document.getElementById('datefin').disabled = '';
	document.getElementById('titre').disabled = '';
	document.getElementById('lib').disabled = '';
}

function activepost()
{
	
	document.getElementById('datedeb').disabled = '';
	document.getElementById('datefin').disabled = '';
	document.getElementById('titre').disabled = '';
	document.getElementById('lib').disabled = '';
	document.getElementById('datedeb').style.color='#ACB5C0';
	document.getElementById('datefin').style.color='#ACB5C0';
	document.getElementById('titre').style.color='#ACB5C0';
	document.getElementById('lib').style.color='#ACB5C0';
}

function desactive()
{
	document.getElementById('datedeb').style.backgroundColor='#ECE9D8';
	document.getElementById('datefin').style.backgroundColor='#ECE9D8';
	document.getElementById('titre').style.backgroundColor='#ECE9D8';
	document.getElementById('lib').style.backgroundColor='#ECE9D8';
	document.getElementById('datedeb').disabled = 'disabled';
	document.getElementById('datefin').disabled = 'disabled';
	document.getElementById('titre').disabled = 'disabled';
	document.getElementById('lib').disabled = 'disabled';
}

function maj_cal(action, id, mes)
{
	// L'objet XMLHttpRequest, global pour la fonction callback
   xhr = getXHR();
	if (xhr == null) 
	{
	    alert("XMLHttpRequest non supporté !");
	    return;
	 }
	 // Ouverture d'une connexion en mode synchrone (on attend les données)
	 xhr.open("GET", "maj_cal.php?action="+action+"&id="+id+"&mes="+mes, true);
	 xhr.send(null);
	 
	 xhr.onreadystatechange = function()
	 {
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			document.getElementById('fr').style.backgroundColor='#FFFFFF';
			document.getElementById('en').style.backgroundColor='#FFFFFF';
			document.getElementById('de').style.backgroundColor='#FFFFFF';
			document.getElementById('nl').style.backgroundColor='#FFFFFF';
			switch (action)
			{
				case "fr":
					document.getElementById('fr').style.backgroundColor='#5BC25B';
				break;
				case "en":
					document.getElementById('en').style.backgroundColor='#5BC25B';
				break;
				case "de":
					document.getElementById('de').style.backgroundColor='#5BC25B';
				break;
				case "nl":
					document.getElementById('nl').style.backgroundColor='#5BC25B';
				break;
				case "maj":
					if (mes=="1")
					{
						document.getElementById('maj').innerHTML="Masquer la date de mise à jour";
						document.getElementById('maj').onclick = function () { maj_cal('maj', '<?php echo $id; ?>', '0'); }
					}
					else
					{
						document.getElementById('maj').innerHTML="Afficher la date de mise à jour";
						document.getElementById('maj').onclick = function () { maj_cal('maj', '<?php echo $id; ?>', '1'); }
					}
				break;
				case "gestion":
					if (mes=="o")
					{
						document.getElementById('fr').style.backgroundColor='#ECE9D8';
						document.getElementById('en').style.backgroundColor='#ECE9D8';
						document.getElementById('de').style.backgroundColor='#ECE9D8';
						document.getElementById('nl').style.backgroundColor='#ECE9D8';
						document.getElementById('fr').disabled = 'disabled';
						document.getElementById('en').disabled = 'disabled';
						document.getElementById('de').disabled = 'disabled';
						document.getElementById('nl').disabled = 'disabled';
						document.getElementById('imgfr').onclick = '';
						document.getElementById('imgen').onclick = '';
						document.getElementById('imgde').onclick = '';
						document.getElementById('imgnl').onclick = '';
						document.getElementById('maj').style.visibility='hidden';
						document.getElementById('img1').style.visibility='hidden';
						document.getElementById('img2').style.visibility='hidden';
						document.getElementById('img3').style.visibility='hidden';
						document.getElementById('img4').style.visibility='hidden';
						document.getElementById('img5').style.visibility='hidden';
						document.getElementById('img6').style.visibility='hidden';
						document.getElementById('img7').style.visibility='hidden';
						document.getElementById('img8').style.visibility='hidden';
						document.getElementById('img9').style.visibility='hidden';
						document.getElementById('img10').style.visibility='hidden';
						document.getElementById('img11').style.visibility='hidden';
						document.getElementById('img12').style.visibility='hidden';
					}
					else
					{
						document.getElementById('fr').style.backgroundColor='#FFFFFF';
						document.getElementById('en').style.backgroundColor='#FFFFFF';
						document.getElementById('de').style.backgroundColor='#FFFFFF';
						document.getElementById('nl').style.backgroundColor='#FFFFFF';
						document.getElementById('fr').disabled = '';
						document.getElementById('en').disabled = '';
						document.getElementById('de').disabled = '';
						document.getElementById('nl').disabled = '';
						document.getElementById('imgfr').onclick = function () { maj_cal('fr', '<?php echo $id; ?>', document.getElementById('fr').value); }
						document.getElementById('imgen').onclick = function () { maj_cal('en', '<?php echo $id; ?>', document.getElementById('en').value); }
						document.getElementById('imgde').onclick = function () { maj_cal('de', '<?php echo $id; ?>', document.getElementById('de').value); }
						document.getElementById('imgnl').onclick = function () { maj_cal('nl', '<?php echo $id; ?>', document.getElementById('nl').value); }
						document.getElementById('maj').style.visibility='';
						document.getElementById('img1').style.visibility='';
						document.getElementById('img2').style.visibility='';
						document.getElementById('img3').style.visibility='';
						document.getElementById('img4').style.visibility='';
						document.getElementById('img5').style.visibility='';
						document.getElementById('img6').style.visibility='';
						document.getElementById('img7').style.visibility='';
						document.getElementById('img8').style.visibility='';
						document.getElementById('img9').style.visibility='';
						document.getElementById('img10').style.visibility='';
						document.getElementById('img11').style.visibility='';
						document.getElementById('img12').style.visibility='';
					}
				break;
			}
		}
	 }
}

function modif_cal(id, m, a, maxi, idimg)
{
	add="maj_un_cal.php?id="+id+"&a="+a+"&m="+m+"&maxi="+maxi+"&idimg="+idimg;
	for (i=1; i<=maxi; i++)
	{
		add=add+"&d"+i+"="+document.getElementById("c"+i).value;
	}
	xhr = getXHR();
	if (xhr == null) 
	{
	    alert("XMLHttpRequest non supporté !");
	    return;
	 }
	 // Ouverture d'une connexion en mode synchrone (on attend les données)
	 
	 
	 xhr.open("GET", add, true);
	 xhr.send(null);
	 
	 xhr.onreadystatechange = function()
	 {
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			html=xhr.responseText;
			htm=html.split("</style>");
			index1 = htm[1].indexOf(">");
			index2 = htm[1].lastIndexOf("<");
			ht=htm[1].substring(index1+1, index2);
			document.getElementById(m).innerHTML=ht;
			tb_remove();
			evalMyScripts(m);
			bindThickBoxEvents(); 
		}
	 }
}

var globalEval =  function(script)
{
	if(window.execScript)
	{
		return window.execScript(script);
	}
	else if(navigator.userAgent.indexOf('KHTML') != -1)
	{ //safari, konqueror..
		var s = document.createElement('script');
		s.type = 'text/javascript';
		s.innerHTML = script;
		document.getElementsByTagName('head')[0].appendChild(s);
	}
	else
	{
		return window.eval(script);
	}
}
      

function evalMyScripts(targetId) 
{
	var myScripts = document.getElementById(targetId).getElementsByTagName('script');
	for (var i=0; i<myScripts.length; i++)
	{
		//alert (myScripts[i].innerHTML);
		globalEval(myScripts[i].innerHTML);
	}
}

function removeThickBoxEvents() {
        $('.thickbox').each(function(i) {
            $(this).unbind('click');
        });
    }

function bindThickBoxEvents() {
        removeThickBoxEvents();
        tb_init('a.thickbox, area.thickbox, input.thickbox');
    }

UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};

function maj_promo(id, langue)
{
	// L'objet XMLHttpRequest, global pour la fonction callback
   xhr = getXHR();
	if (xhr == null) 
	{
	    alert("XMLHttpRequest non supporté !");
	    return;
	 }
	 // Ouverture d'une connexion en mode synchrone (on attend les données)
	 xhr.open("GET", "maj_promo.php?id="+id+"&lg="+langue, true);
	 xhr.send(null);
	 
	 xhr.onreadystatechange = function()
	 {
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if (xhr.readyState == 4 && xhr.status == 200)
		{
			html=xhr.responseText;
			htm=html.split('|');
			document.getElementById('titre').value=htm[0];
			s=htm[1];
			document.getElementById('lib').value=s;

			document.getElementById('langue').value=langue;
			switch (langue)
			{
				case "fr":
					document.getElementById('fr').style.textDecoration="underline";
					document.getElementById('en').style.textDecoration="";
					document.getElementById('de').style.textDecoration="";
					document.getElementById('nl').style.textDecoration="";
					document.getElementById('cont').innerHTML="Contenu";
					document.getElementById('tit').innerHTML="&nbsp;Titre (maximum 100 carct&egrave;res)";
					document.getElementById('libel').innerHTML="&nbsp;Libell&eacute; (maximum 500 carct&egrave;res)";
				break;
				case "en":
					document.getElementById('en').style.textDecoration="underline";
					document.getElementById('fr').style.textDecoration="";
					document.getElementById('de').style.textDecoration="";
					document.getElementById('nl').style.textDecoration="";
					document.getElementById('cont').innerHTML="Content";
					document.getElementById('tit').innerHTML="&nbsp;Title (maximum 100 characters)";
					document.getElementById('libel').innerHTML="&nbsp;Read (maximum 500 characters)";
				break;
				case "de":
					document.getElementById('de').style.textDecoration="underline";
					document.getElementById('en').style.textDecoration="";
					document.getElementById('fr').style.textDecoration="";
					document.getElementById('nl').style.textDecoration="";
					document.getElementById('cont').innerHTML="Inhalt";
					document.getElementById('tit').innerHTML="&nbsp;Titel (maximal 100 Zeichen)";
					document.getElementById('libel').innerHTML="&nbsp;Text (max. 500 Zeichen)";
				break;
				case "nl":
					document.getElementById('nl').style.textDecoration="underline";
					document.getElementById('en').style.textDecoration="";
					document.getElementById('de').style.textDecoration="";
					document.getElementById('fr').style.textDecoration="";
					document.getElementById('cont').innerHTML="Inhoud";
					document.getElementById('tit').innerHTML="&nbsp;Titel (max. 100 tekens)";
					document.getElementById('libel').innerHTML="&nbsp;Lezen (maximaal 500 tekens)";
				break;
			}
		}
	 }
	
}