var preloaddiapo='';
var start =0;
function createXHR() 
{
    var request = false;
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (err2) {
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (err3) {
		try {
			request = new XMLHttpRequest();
		}
		catch (err1) 
		{
			request = false;
		}
            }
        }
    return request;
}

function diaporama()
{ 
    var xhr = createXHR(); 

 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
			          document.getElementById("diaporamapreload").innerHTML = xhr.responseText;
								document.getElementById("diaporama").innerHTML = preloaddiapo;
								preloaddiapo= xhr.responseText;
								if(start==0){start=1;window.setTimeout("diaporama()",1);}
								else{window.setTimeout("diaporama()",10000);}
			}
         else {
                 document.getElementById("diaporama").innerHTML ="Error code " + xhr.status;
        }
      }
   }; 
	var tmp ='';
	var script = "diaporama.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("tmp=" + tmp);
} 

function blogreaction(idblog, action, id)
{ 
    var xhr = createXHR(); 

 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
			          document.getElementById("divREACTION").innerHTML = xhr.responseText;
			}

      }
   }; 
	var tmp ='';
	var script = "/gestion/blogreaction.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("idblog=" + idblog + "&action=" + action + "&id_rep=" + id );
} 

function forumreponse()
{ 
    var xhr = createXHR();  
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) { 	
              	if(reply=='-1'){
              		var nb =parseInt(nbaffnumpost) +1 ;
	             	 document.getElementById('affsalonnbpost' + s).innerHTML = nb ;
	             	 document.getElementById('affsaloncomptpost' + s).innerHTML ='<a  style=\"cursor:pointer\" onClick=\"ajoutpost('+s+',' + nb + ',' + reply + ',\'' + description + '\')\"><img src=images/form_blue_add.gif border=0>&nbsp;Post</a>';
             	 }
              	if(nbaffnumpost =='post'){
	             	 document.getElementById('affpost').innerHTML = xhr.responseText;
	             	 document.getElementById('affpost').style.display = 'block';
             	 }
              	if(nbaffnumpost =='touspost'){
	             	 document.getElementById('afftouspost').innerHTML = xhr.responseText;
	             	 document.getElementById('afftouspost').style.display = 'block';
             	 }
             	 
			     document.getElementById("contenerformrep").style.display = 'none';
			}

      }
   }; 
      
    var reply =document.getElementById("reply").value ;
    if(reply=='-1'){
    	var description ='Proposer un nouveau sujet ';
    }
    else{
    	var description = 'Répondre ';
    }
    var nbaffnumpost =document.getElementById("nbaffnumpost").value ;
    var offset=document.getElementById("offset").value ;
    var s =document.getElementById("formrep_s").value ;
	var auteur =document.getElementById("formrep_auteur").value ;
	var titre =document.getElementById("formrep_titre").value ;
	var message =document.getElementById("formrep_message").value ;
	if(auteur=="" || titre=="" || message==""){
		alert('Veuillez remplir tous les champs ! ');
		return false;
	}
	var id_smiley =document.getElementById("formrep_smiley").value ;
	var script = "/gestion/ajoutpost.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("s=" + s + "&auteur=" + auteur + "&titre=" + titre+ "&message=" + message + "&id_smiley=" + id_smiley+ "&reply=" + reply + "&nbaffnumpost=" + nbaffnumpost +"&offset=" + offset);
}

function annoncevalid(requete, action, id)
{ 
    var xhr = createXHR(); 

 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
			          document.getElementById('affreqannonce').innerHTML = xhr.responseText;
			}

      }
   }; 
	var datfin =document.getElementById('date_fin'+id).value;
	var script = "/gestion/annoncevalid.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("requete=" + requete + "&action=" + action + "&id=" + id + "&date_fin=" + datfin);
} 
function desphotocat(id)
{ 
    var xhr = createXHR(); 
 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
			          document.getElementById('affdesphotocat').innerHTML = xhr.responseText;
			}

      }
   }; 

	var script = "/gestion/desphotocat.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("cat=" + id );
} 
function affrchannuaire(rch,champ_rch){
    var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
			          document.getElementById('resultat').innerHTML = xhr.responseText;
			}
      }
   }; 
	var script = "/gestion/annuaireaffrch.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("rch=" + rch + "&champ_rch=" + champ_rch);

}
function affformcontact(id,util){
    var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
			          document.getElementById("contenerformrep").innerHTML = xhr.responseText;
					  document.getElementById("contenerformrep").style.display = 'block';

			}
      }
   }; 
	var script = "/gestion/annuaireaffrch.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("id=" + id + "&util=" +util);

}
function lister_champs(theform)//icic la fonction qui va générer les éléments a envoyer
{
   var url='';
   for (i=0; i<theform.elements.length; i++)
   {
       if(((theform.elements[i].type=='radio' ||theform.elements[i].type=='checkbox') && theform.elements[i].checked==true) || (theform.elements[i].type!='radio' &&theform.elements[i].type!='checkbox'))//control si c'est des radio ou check box et incrémente le résultat QUE si c'est coché (sans ça il prendrais les deux)
           {
   if(theform.elements[i].type=='select-multiple' || theform.elements[i].type=='select' )//si c'est un select multiple 
   {
    for(j = theform.elements[i].length-1; j >= 0; j-=1)//on parcours les element du select multiple
       {
          if(theform.elements[i].options[j].selected)//si selectionné on incremente
             {
                             if(url){url+='&';}
           url+=theform.elements[i].name+'='+theform.elements[i].options[j].value;
             }
     }
   }
   if(url){url+='&';}
   if(theform.elements[i].type!='select-multiple'){  url+=theform.elements[i].name+'='+theform.elements[i].value;}
           }
        }
return url;//onretourne le resultat vers la fonction appelée
}

function ajoutmodifcontact(form){
	var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
		              affrch();
					  document.getElementById("contenerformrep").style.display = 'none';
			}
      }
   };   
	if(document.getElementById("nom").value=="" ){
		alert('Veuillez remplir le champ nom ! ');
		return false;
	}

	var script = "/gestion/annuaireaffrch.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(lister_champs(form));
	return false;
}

function ouverturefiche(mapage, color){
		var xhr = createXHR(); 
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
            if(xhr.status  == 200) {
			 var w_s=win_size();
			 var lardiv=parseInt(document.getElementById("divfiche").style.width)*1;
			   document.getElementById('divfiche').style.top=Math.floor(w_s[2])+parseInt(100)+'px'; 
               document.getElementById("divfiche").style.left=Math.floor(w_s[0]/2)-parseInt(lardiv/2)+'px'; 
			   document.getElementById("divfiche").style.display = 'block';
			   document.getElementById("divfiche").innerHTML = xhr.responseText;
			}
      }
   };   

	var script = "/selfiche.php";   // local script
	xhr.open("POST", script, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("page=" + mapage + "&color=" + color);

}
function fermefiche(){
	document.getElementById("divfiche").style.display = 'none';
}
