// JavaScript Document
var xhr = null;
var backgroundVar = "#dcedd4";
var timeoutImage;
var timeoutImageLoad;
 
// 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; 
   } 
 }
	
	function getCtn(section,id)
	{
		getXhr();
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				$('lightbox').innerHTML = xhr.responseText;
			}
		}
		
		xhr.open("POST",'includes/js/ajax.php',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		xhr.send("action=getCtn&section="+section+id);
	}
	
 	
	function ct_detail_change_txt(id,type)
	{
		getXhr();
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				document.getElementById('ct_detail_texte_more').style.background = '';
				document.getElementById('ct_detail_texte_more').innerHTML = xhr.responseText;
			}
		}
		
		document.getElementById('ct_detail_texte_more').innerHTML = '';
		document.getElementById('ct_detail_texte_more').style.background = 'url(includes/js/lightbox/images/loading.gif) center 20px no-repeat';
		
		xhr.open("POST",'includes/js/ajax.php?action=ct_detail_change_txt',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  
		xhr.send("id="+id+"&type="+type);
	}
	
	
	function add_to_chlorophyllien(id)
	{
		getXhr();
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				document.getElementById('add_to_chlorophyllien').innerHTML = xhr.responseText;
			}
		}
		
		xhr.open("POST",'includes/js/ajax.php?action=add_to_chlorophyllien',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  
		xhr.send("id="+id);
	}
	
	
	function del_liste_chlorophyllien(id)
	{
		getXhr();
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				document.getElementById(id).style.display = 'none';
			}
		}
		
		xhr.open("POST",'includes/js/ajax.php?action=del_liste_chlorophyllien',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  
		xhr.send("id="+id);
	}
	
	
	function aff_image_produit_mi_thumbs(id,fiche_id)
	{
		getXhr();
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				document.getElementById('mi_thumbs_image').style.background = 'none';
				document.getElementById('mi_thumbs_image').innerHTML = trim(xhr.responseText);
			}
		}
		
		if(timeoutImage)
			clearTimeout(timeoutImage);
		
		
		if(timeoutImageLoad)
			clearTimeout(timeoutImageLoad);
		
		document.getElementById('mi_thumbs_image').style.innerHTML = '';
		document.getElementById('mi_thumbs_image').style.background = 'url(includes/js/lightbox/images/loading.gif) center no-repeat #fff';
		
		xhr.open("POST",'includes/js/ajax.php?action=aff_image_produit_mi_thumbs',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  
		xhr.send("id="+id+"&fiche_id"+fiche_id);
	}
	
	
	function aff_image_produit(id)
	{
		getXhr();
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				var retour = xhr.responseText.split("@");
				document.getElementById('big_image').style.background = '#fff';
				document.getElementById('big_image').innerHTML = trim(retour[0]);
				
				new Draggable('image_drag_'+trim(retour[1]), { 
					zindex:1010,
					handle:'handle',
					starteffect:false,
					endeffect:false,
					change:function() { dragChanged('image_drag_'+retour[1],retour[2],retour[3]); }
				});
				
				//setTimeout("addDragDrop('"+retour[1]+"')",1000);
			}
		}
		
		if(timeoutImage)
			clearTimeout(timeoutImage);
		
		
		if(timeoutImageLoad)
			clearTimeout(timeoutImageLoad);
		
		if(document.getElementById('big_image').style.display == 'block')
		{
			document.getElementById('big_image').style.background = 'none';
			document.getElementById('big_image').style.display = 'none';
			document.getElementById('big_image').innerHTML = '';
			return;
		}
		else
		{
			document.getElementById('big_image').style.display = 'block';
			document.getElementById('big_image').style.background = 'url(includes/js/lightbox/images/loading.gif) center no-repeat #fff';
		}
		
		xhr.open("POST",'includes/js/ajax.php?action=aff_image_produit',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  
		xhr.send("id="+id);
	}
	
	
	function photoClear(fiche_id)
	{
		getXhr();
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				document.getElementById('big_image').style.background = 'none';
				document.getElementById('big_image').innerHTML = trim(xhr.repsonseText);
				
				
				document.getElementById('big_image').style.display = 'none';
				document.getElementById('big_image').innerHTML = '';
			}
		}
		
		if(timeoutImage)
			clearTimeout(timeoutImage);
		
		
		if(timeoutImageLoad)
			clearTimeout(timeoutImageLoad);
		
		document.getElementById('big_image').style.display = 'block';
		document.getElementById('big_image').style.background = 'url(includes/js/lightbox/images/loading.gif) center no-repeat #fff';
		
		xhr.open("POST",'includes/js/ajax.php?action=photoClear',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  
		xhr.send("id="+fiche_id);
	}
	
	
	/*function nextKit(id,where)
	{
		getXhr();
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				document.getElementById('big_image').style.background = 'none';
				document.getElementById('big_image').innerHTML = trim(xhr.repsonseText);
				
				
				document.getElementById('big_image').style.display = 'none';
				document.getElementById('big_image').innerHTML = '';
			}
		}
		
		xhr.open("POST",'includes/js/ajax.php?action=nextKit',true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	  
		xhr.send("id="+id+"&where="+where);
	}*/