function toggleAll(cb, inputName, formName) {
    var val = cb.checked;
	var frm = document.forms[formName];
	var len = frm.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (frm.elements[i].name==inputName) {
			frm.elements[i].checked=val;
		}
	}
}

function show_hide(laCase,leCalk)
{
    if (laCase.checked)
    {
        document.getElementById(leCalk).style.visibility="visible";
    }
    else
    {
        document.getElementById(leCalk).style.visibility="hidden";
    }
}

/*	Envoie un formulaire
*************************************************/
function submitForm (form, action) {
	document.forms[form].sendForm.value = action;
	document.forms[form].submit();
}
function transfertDate(date, form, field)
{
 window.opener.document.forms[form].elements[field].value=date;
 window.close();
}
function sendData(arg1) {

	if(arg1 != '')	alert(arg1);
	//document.forms.site.submit();
	//document.forms[form].submit();
}

/*	PopUp
*************************************************/
function limite(zone,max) {
	if(zone.value.length>=max){zone.value=zone.value.substring(0,max);}
}
function ouvrirpop(page, width, height) {
	/*var width="350",height="150";*/
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleFen = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	window.open('script.inc/'+page,'Impression',styleFen);
}

function newFen(larg, haut, lien) {
	var width=larg,height=haut;
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleFen = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	window.open(lien,'',styleFen);
}

/*	enregistrement des caracteres
*************************************************/
function storeCaret(ao_txtfield,as_mf){
var isIE = (document.all);
if(!isIE){
//mozilla
//recuperation du txt selectionné
oField = ao_txtfield;
oFieldValue = oField.value;
deb = oField.selectionStart;
fin = oField.selectionEnd;
Deb = oFieldValue.substring( 0 , oField.selectionStart );
Fin = oFieldValue.substring( oField.selectionEnd , oField.textLength );
Sel = oFieldValue.substring( oField.selectionStart ,oField.selectionEnd );
oField.value = Deb + '[' + as_mf + "]" + Sel + "[/" + as_mf + ']' + Fin;
oField.selectionStart = Deb.length;
tmps =Deb + '[' + as_mf+']' + Sel +"[/" + as_mf + ']'
oField.selectionEnd = tmps.length+2;
oField.setSelectionRange(Deb.length+as_mf.length+2,tmps.length-as_mf.length-3);
oField.focus();
}else{
//IE
var str = document.selection.createRange().text;
if (str.length>0){
//recuperation du txt selectionné
var select = document.selection.createRange();
select.text = '[' + as_mf + ']' + str + "[/" + as_mf + ']';
select.collapse();
select.select();
}else{
ao_txtfield.focus(ao_txtfield.caretPos);
ao_txtfield.focus(ao_txtfield.value.length);
ao_txtfield.caretPos = document.selection.createRange().duplicate();
var bidon = "%~%";
var original = ao_txtfield.value;
ao_txtfield.caretPos.text = bidon;
var i = ao_txtfield.value.search(bidon);
ao_txtfield.value = original.substr(0,i) + '[' + as_mf + "][/" + as_mf + ']' + original.substr(i, ao_txtfield.value.length);
var temp = original.substr(0,i);
var nbretour =0;
for (var cpt=0;cpt<temp.length;cpt=cpt+1){
if(temp.charAt(cpt)=="\n"){
nbretour=nbretour+1;
}
}
pos = i + 2 + as_mef.length - nbretour;
var r = oField.createTextRange();
var r = ao_txtfield.createTextRange();
r.moveStart('character', pos);
r.collapse();
r.select();
}
}
}


function storeCaretSmiley(ao_txtfield,as_mf){
var isIE = (document.all);
if(!isIE){
//mozilla
//recuperation du txt selectionné
oField = ao_txtfield;
oFieldValue = oField.value;
deb = oField.selectionStart;
fin = oField.selectionEnd;
Deb = oFieldValue.substring( 0 , oField.selectionStart );
Fin = oFieldValue.substring( oField.selectionEnd , oField.textLength );
Sel = oFieldValue.substring( oField.selectionStart ,oField.selectionEnd );
oField.value = Deb + Sel + ' ' + as_mf + ' ' + Fin;
oField.selectionStart = Deb.length;
 tmps = Deb + Sel + as_mf+2;
 oField.selectionEnd = tmps.length+2;
 oField.setSelectionRange(Deb.length+as_mf.length+2,tmps.length-as_mf.length+as_mf.length);
 oField.focus();
}else{
//IE
var str = document.selection.createRange().text;
if (str.length>0){
//recuperation du txt selectionné
var select = document.selection.createRange();
select.text = str + as_mf;
select.collapse();
select.select();
}else{
ao_txtfield.focus(ao_txtfield.caretPos);
ao_txtfield.focus(ao_txtfield.value.length);
ao_txtfield.caretPos = document.selection.createRange().duplicate();
var bidon = "%~%";
var original = ao_txtfield.value;
ao_txtfield.caretPos.text = bidon;
var i = ao_txtfield.value.search(bidon);
ao_txtfield.value = original.substr(0,i) + as_mf + original.substr(i, ao_txtfield.value.length);
var temp = original.substr(0,i);
var nbretour =0;
for (var cpt=0;cpt<temp.length;cpt=cpt+1){
if(temp.charAt(cpt)=="\n"){
nbretour=nbretour+1;
}
}
pos = i + 2 + as_mef.length - nbretour;
var r = oField.createTextRange();
var r = ao_txtfield.createTextRange();
r.moveStart('character', pos);
r.collapse();
r.select();
}
}
}

/*	 XmlHttpRequest
*************************************************/
// Déclaration de la fonction de Callback
// + ----------------------------------------------------------------------------------
// + afficherResultats
// + Affiche ou non le conteneur en fonction du résultat de la recherche
// + ----------------------------------------------------------------------------------
function afficherResultats(obj) {
     // Construction des noeuds
     var tabResult = obj.responseXML.getElementsByTagName('resultat');
     document.getElementById('zoneResultats').innerHTML = '';
     if (tabResult.length > 0) {
          // On définit la hauteur de la liste en fonction du nombre de rsultats et de la hauteur de ligne
          var hauteur = tabResult.length * 15;
          with(document.getElementById('zoneResultats').style) {
               visibility = 'visible';
               height = hauteur + 'px';
          };
          for (var i = 0; i < tabResult.length; i++) {
               resultat = tabResult.item(i);
               var egt = document.createElement('li');
               var lnk = document.createElement('a');
               var texte = document.createTextNode(resultat.getAttribute('libelle'));
			   var url = null;

			   url=resultat.getAttribute('url');
			   if(url != null) {
				   while(url.indexOf('@') != -1) {
					url=url.replace('@','&');
				   }
			   }
			   lnk.appendChild(texte);
			   lnk.setAttribute('href', url);
			   lnk.setAttribute('onclick', resultat.getAttribute('onclick'));
               lnk.setAttribute('title', resultat.getAttribute('title'));
               egt.appendChild(lnk);
               document.getElementById('zoneResultats').appendChild(egt);
          }
     }
     else {
          document.getElementById('zoneResultats').style.visibility = 'hidden';
     }
}
// Déclaration de la fonction qui lance la recherche
function loadData() {
     // Création de l'objet
     var XHR = new XHRConnection();
     XHR.appendData("foo", document.getElementById('foo').value);
     XHR.appendData("table", document.getElementById('table').value);
     XHR.appendData("url", document.getElementById('url').value);
     XHR.appendData("title", document.getElementById('title').value);
     XHR.appendData("param", document.getElementById('param').value);
     // On soumet la requête
     // Signification des paramètres:
     //      + On indique à l'objet qu'il faut appeler le fichier search.php
     //      + On utilise la méthode POST, adaptée l'envoi d'information
     //      + On indique quelle fonction appeler lorsque l'opération a été effectuée
     XHR.sendAndLoad("script.inc/xml.recherche.php", "POST", afficherResultats);
}

/*	 XmlHttpRequest -> Licenciés
*************************************************/
function afficherResultatsMember(obj) {
     // Construction des noeuds
     var tabResult = obj.responseXML.getElementsByTagName('resultat');
     document.getElementById('showMembers').innerHTML = '';

     if (tabResult.length > 0) {

          // On définit la hauteur de la liste en fonction du nombre de résultats et de la hauteur de ligne
          //var hauteur = (tabResult.length / 3) * 100;

          with(document.getElementById('showMembers').style) {
               visibility = 'visible';
          };

          for (var i = 0; i < tabResult.length; i++) {
               resultat = tabResult.item(i);
               var egt = document.createElement('li');


               var lnk = document.createElement('a');

               var nom = document.createTextNode(resultat.getAttribute('nom'));
               var sexe = document.createTextNode(resultat.getAttribute('sexe'));
               var datenaiss = document.createTextNode(resultat.getAttribute('datenaiss'));
               var poids = document.createTextNode(resultat.getAttribute('poids'));
               var tel1 = document.createTextNode(resultat.getAttribute('tel1'));
               var tel2 = document.createTextNode(resultat.getAttribute('tel2'));
               var tel3 = document.createTextNode(resultat.getAttribute('tel3'));

			   var url = null;

			   url=resultat.getAttribute('url');
			   if(url != null) {
				   while(url.indexOf('@') != -1) {
					url=url.replace('@','&');
				   }
			   }

               var ul = document.createElement('ul');

               var li = document.createElement('li');
               var img = document.createElement('img');
               img.setAttribute('src', resultat.getAttribute('photo'));
               img.style.width = resultat.getAttribute('photo_w') + 'px';
               img.style.height = resultat.getAttribute('photo_h') + 'px';
			   li.appendChild(img);
			   ul.appendChild(li);

               var li = document.createElement('li');
			   li.appendChild(nom);
               ul.appendChild(li);

               var li = document.createElement('li');
			   li.appendChild(datenaiss);
               ul.appendChild(li);

               var li = document.createElement('li');
			   li.appendChild(poids);
               ul.appendChild(li);

               var li = document.createElement('li');
			   li.appendChild(tel1);
			   if(resultat.getAttribute('tel1_private') == '1')
			   {
			   		li.style.color='red';
			   }
               ul.appendChild(li);

               var li = document.createElement('li');
			   li.appendChild(tel2);
			   if(resultat.getAttribute('tel2_private') == '1')
			   {
			   		li.style.color='red';
			   }
               ul.appendChild(li);

			   lnk.appendChild(ul);

			   lnk.setAttribute('href', url);
			   lnk.setAttribute('onclick', resultat.getAttribute('onclick'));
               lnk.setAttribute('title', resultat.getAttribute('title'));
               egt.appendChild(lnk);

               document.getElementById('showMembers').appendChild(egt);
          }
     }
     else {
          document.getElementById('showMembers').style.visibility = 'hidden';
     }
}
// Déclaration de la fonction qui lance la recherche
function loadDataMember() {
     // Création de l'objet
     var XHR = new XHRConnection();
     XHR.appendData("foo", document.getElementById('foo').value);
     XHR.appendData("url", document.getElementById('url').value);
     XHR.appendData("title", document.getElementById('title').value);
     XHR.appendData("param", document.getElementById('param').value);
     XHR.sendAndLoad("script.inc/xml.recherche.member.php", "POST", afficherResultatsMember);
}

/*
function loadVille() {
     var XHR = new XHRConnection();
     XHR.appendData("foo", document.getElementById('foo').value);
     XHR.appendData("table", document.getElementById('table').value);
     XHR.appendData("url", document.getElementById('url').value);
     XHR.sendAndLoad("script.inc/xml.recherche.php", "POST", afficherResultats);
}
*/

/*	 Montrer-Cacher un div
*************************************************/
function DivStatus( nom, numero )
{
	var divID = nom + numero;
	if ( document.getElementById && document.getElementById( divID ) ) // Pour les navigateurs récents
	{
		Pdiv = document.getElementById( divID );
		PcH = true;
	}
	else if ( document.all && document.all[ divID ] ) // Pour les veilles versions
	{
		Pdiv = document.all[ divID ];
		PcH = true;
	}
	else if ( document.layers && document.layers[ divID ] ) // Pour les très veilles versions
	{
		Pdiv = document.layers[ divID ];
		PcH = true;
	}
	else
	{
		PcH = false;
	}
	if ( PcH )
	{
		Pdiv.className = ( Pdiv.className == 'cachediv' ) ? '' : 'cachediv';
	}
}

/*	 Highlight table
******************************/
function highlight(e, o)
{
	if(o)
		e.className='rowHover';
	else
		e.className='row';
}