// JavaScript Document
var xhr = null;
 
// Fonction de creation de l'objet XMLHttpRequest qui resservira pour chaques fonctions AJAX
function getXhr()
 {
  if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
  else if(window.ActiveXObject)
   {  
    try
     {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
     }
    catch (e)
     {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
     }
   }
  else 
   { 
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour"); 
    xhr = false; 
   } 
 } 
 
 
 //Construire une liste déroulante selon la une autre liste
function ajax_affiche(envoi)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		
     }
   }
   
  var i = document.getElementsByClassName('sortable').length;
  
  for(var x=0; x<i; x++)
  {
	  if(x/2 == Math.round(x/2))
   	  {
	  	  document.getElementsByClassName('sortable')[x].style.backgroundColor = '#fff';
	  }
	  else
	  {
		  document.getElementsByClassName('sortable')[x].style.backgroundColor = '#f7f6f6';
	  }
  }
   
  xhr.open("POST",'includes/js/ajax_aff.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send(envoi);
 }
 
 
 
 function ajax_affiche2(envoi)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		
     }
   }
   
  var i = document.getElementsByClassName('sortable').length;
  
  for(var x=0; x<i; x++)
  {
	  if(x/2 == Math.round(x/2))
   	  {
	  	  document.getElementsByClassName('sortable')[x].style.backgroundColor = '#fff';
	  }
	  else
	  {
		  document.getElementsByClassName('sortable')[x].style.backgroundColor = '#f7f6f6';
	  }
  }
   
  xhr.open("POST",'includes/js/ajax_aff2.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send(envoi);
 }
 
 function ajax_affiche3(envoi)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		
     }
   }
   
  var i = document.getElementsByClassName('sortable').length;
  
  for(var x=0; x<i; x++)
  {
	  if(x/2 == Math.round(x/2))
   	  {
	  	  document.getElementsByClassName('sortable')[x].style.backgroundColor = '#fff';
	  }
	  else
	  {
		  document.getElementsByClassName('sortable')[x].style.backgroundColor = '#f7f6f6';
	  }
  }
   
  xhr.open("POST",'includes/js/ajax_aff3.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send(envoi);
 }
 
 function ajax_affiche4(envoi)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		
     }
   }
   
  var i = document.getElementsByClassName('sortable').length;
  
  for(var x=0; x<i; x++)
  {
	  if(x/2 == Math.round(x/2))
   	  {
	  	  document.getElementsByClassName('sortable')[x].style.backgroundColor = '#fff';
	  }
	  else
	  {
		  document.getElementsByClassName('sortable')[x].style.backgroundColor = '#f7f6f6';
	  }
  }
   
  xhr.open("POST",'includes/js/ajax_aff4.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send(envoi);
 }
 
 function aff_pic(x,cat)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		var retour = xhr.responseText.split("@");
		next=retour[1];
		prev=retour[3];
		if(retour[0] == "true")
		{
			$('next_photo').style.visibility = 'visible';
			$('next_photo').morph('opacity:0.99; filter:alpha(opacity=100);');
			setTimeout("display('next_photo','<a href=\"javascript:;\" onclick=\"javascript:aff_photo("+next+","+cat+");\"><img src=\"includes/css/img/Next.jpg\" width=\"24\" height=\"24\" alt=\"Suivant\" /></a>')", 800);
		}
		else
		{
			$('next_photo').morph('opacity:0; filter:alpha(opacity=0);');
			setTimeout("visibleFleche('next_photo')",800);
		}
		
		if(retour[2] == "true")
		{
			$('prev_photo').style.visibility = 'visible';
			$('prev_photo').morph('opacity:0.99; filter:alpha(opacity=100);');
			setTimeout("display('prev_photo','<a href=\"javascript:;\" onclick=\"javascript:aff_photo("+prev+","+cat+");\"><img src=\"includes/css/img/Back.jpg\" width=\"24\" height=\"24\" alt=\"Pr&eacute;c&eacute;dente\" /></a>')", 800);
		}
		else
		{
			$('prev_photo').morph('opacity:0; filter:alpha(opacity=0);');
			setTimeout("visibleFleche('prev_photo')",800);
		}
		
		var pos=x*670;
		$('aff_alb_photo').morph('left:-'+pos+'px;');
     }
   }
   
  xhr.open("POST",'includes/js/ajax_aff_pic.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send("page="+x+"&cat="+cat);
 }
 
 
 
 function aff_thumbs(x,cat)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		next=x+1;
		prev=x-1;
		var retour = xhr.responseText.split("@");
		
		if(retour[0] == "true")
		{
			$('next_thumbs').style.visibility = 'visible';
			$('next_thumbs').morph('opacity:0.99; filter:alpha(opacity=100);');
			setTimeout("display('next_thumbs','<a href=\"javascript:;\" onclick=\"javascript:aff_thumbs("+next+","+cat+");\"><img src=\"includes/css/img/Next.jpg\" width=\"24\" height=\"24\" alt=\"Suivant\" /></a>')", 800);
		}
		else
		{
			$('next_thumbs').morph('opacity:0; filter:alpha(opacity=0);');
			setTimeout("visibleFleche('next_thumbs')",800);
		}
		
		if(retour[1] == "true")
		{
			$('prev_thumbs').style.visibility = 'visible';
			$('prev_thumbs').morph('opacity:0.99; filter:alpha(opacity=100);');
			setTimeout("display('prev_thumbs','<a href=\"javascript:;\" onclick=\"javascript:aff_thumbs("+prev+","+cat+");\"><img src=\"includes/css/img/Back.jpg\" width=\"24\" height=\"24\" alt=\"Pr&eacute;c&eacute;dente\" /></a>')", 800);
		}
		else
		{
			$('prev_thumbs').morph('opacity:0; filter:alpha(opacity=0);');
			setTimeout("visibleFleche('prev_thumbs')",800);
		}
		
		var pos=x*560;
		$('aff_alb_thumbs').morph('left:-'+pos+'px;');
     }
   }
   
  xhr.open("POST",'includes/js/ajax_aff_thumbs.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send("page="+x+"&cat="+cat);
 }
 
 
 
 function aff_photo(x,cat)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		next=x+1;
		prev=x-1;
		var retour = xhr.responseText.split("@");
		if(retour[0] == "true")
		{
			$('next_photo').style.visibility = 'visible';
			$('next_photo').morph('opacity:0.99; filter:alpha(opacity=100);');
			setTimeout("display('next_photo','<a href=\"javascript:;\" onclick=\"javascript:aff_photo("+next+","+cat+");\"><img src=\"includes/css/img/Next.jpg\" width=\"24\" height=\"24\" alt=\"Suivant\" /></a>')", 800);
		}
		else
		{
			$('next_photo').morph('opacity:0; filter:alpha(opacity=0);');
			setTimeout("visibleFleche('next_photo')",800);
		}
		
		if(retour[1] == "true")
		{
			$('prev_photo').style.visibility = 'visible';
			$('prev_photo').morph('opacity:0.99; filter:alpha(opacity=100);');
			setTimeout("display('prev_photo','<a href=\"javascript:;\" onclick=\"javascript:aff_photo("+prev+","+cat+");\"><img src=\"includes/css/img/Back.jpg\" width=\"24\" height=\"24\" alt=\"Pr&eacute;c&eacute;dente\" /></a>')", 800);
		}
		else
		{
			$('prev_photo').morph('opacity:0; filter:alpha(opacity=0);');
			setTimeout("visibleFleche('prev_photo')",800);
		}
			
		
		var pos=x*670;
		var pos2=Math.floor(x/7);
		aff_thumbs(pos2,cat);
		setTimeout("time_after("+pos+")",100);
     }
   }
   
  xhr.open("POST",'includes/js/ajax_aff_photo.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send("page="+x+"&cat="+cat);
 }
 
 
 
 function change_cat(cat,ordre,nom)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		$('alb_photo').morph('opacity:0; filter:alpha(opacity=0);');
		
		var i = document.getElementsByClassName('categorie_ordre').length;
  
		  for(var x=0; x<i; x++)
		  {
			  if(x==(ordre-1))
			  {
				  document.getElementsByClassName('categorie_ordre')[x].style.fontWeight = 'bold';
				  document.getElementsByClassName('categorie_ordre')[x].innerHTML = "<span style='display:none;'>t</span><!--<a href='javascript:;' onclick='javascript:change_cat("+cat+","+ordre+",\""+nom+"\");'>-->"+nom+"<!--</a>-->";
			  }
			  else
			  {
				  document.getElementsByClassName('categorie_ordre')[x].style.fontWeight = 'normal';
				  var oldString = document.getElementsByClassName('categorie_ordre')[x].innerHTML;
				  var newString = oldString.replace(/<!--/g,'');
				  var newString = newString.replace(/-->/g,'');
				  document.getElementsByClassName('categorie_ordre')[x].innerHTML = newString;
			  }
		  }
		  
		setTimeout("newDisplay('alb_photo','"+xhr.responseText+"')", 1000);
     }
   }
  xhr.open("POST",'includes/js/ajax_aff_cat.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send("cat="+cat);
 }
 
 
 
 function graphique(page)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
		var retourTXT=xhr.responseText.split("<PAGE>");
		
		$('colsThumbs').innerHTML=retourTXT[0];
		$('displayPage').innerHTML=retourTXT[1];
		
		Effect.Appear('colsThumbs', { duration: 1.0 }); 
     }
   }
  xhr.open("POST",'includes/js/ajax.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  
  xhr.send("action=changepage&page="+page);
 }
