
function addLine(Location,IdProduit,LnkId)
{
	
	var RefPhoto=document.forms['frmPanier'].elements['refPhoto'].value
	var IdPhoto=document.forms['frmPanier'].elements['idphoto'].value; 
	var IdEvent=document.forms['frmPanier'].elements['IdEvent'].value; 
	var PhotoRootString=document.forms['frmPanier'].elements['PhotoRootString'].value; 
	var CurrentLnk = document.getElementById(LnkId);
	var xhr=null;

		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					CurrentLnk.innerHTML = "<span class='InCaddy'>Déjà dans mon panier</span>";
					refreshNbArticlesPanier(Location);
					refreshTotalPanier(Location);
					refreshNbArticlesPanierB(Location);
					refreshTotalPanierB(Location);
					if (confirm("Le produit a été ajouté à votre panier.\nSouhaitez-vous terminer votre commande maintenant ?"))
					{
						document.getElementById('listeProduits').style.visibility='hidden';
						location.href=Location + "Panier/";
					}

					}
						else
						{
					CurrentLnk.innerHTML = "<span class='WaitCaddy'>Patientez...</span>";
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=addLine&IdProduit="+IdProduit+"&RefPhoto="+RefPhoto+"&IdPhoto="+IdPhoto+"&PhotoRootString="+PhotoRootString+"&IdEvent="+IdEvent+"&Location="+Location);	
}

function showListProduct(Location,RefPhoto,IdPhoto,Photo)
{
document.getElementById('listeProduits').style.visibility='visible';
document.forms['frmPanier'].elements['refPhoto'].value = RefPhoto; 
document.forms['frmPanier'].elements['idphoto'].value = IdPhoto; 
document.getElementById('LblRefPhoto').innerHTML=RefPhoto;
	}
function refreshNbArticlesPanier(Location)
{
	
	var NbArticles=document.getElementById('HeaderQteArticles');
	var xhr=null;
	//alert(IdProduit+"//"+IdPhoto+"//"+LnkId);
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					if (tbl=="0")
					{
						
					NbArticles.innerHTML = "&nbsp;";
					//document.getElementById('BtnDetailPanier').style.visibility='hidden';
					document.getElementById('BtnFinaliseCommande').style.visibility='hidden';
					}
					else
					{
							if (tbl=="1")
							{
							NbArticles.innerHTML = "1 article";
							
							}
							else
							{
							NbArticles.innerHTML = tbl+" articles";	
								}
					//document.getElementById('BtnDetailPanier').style.visibility='visible';
					document.getElementById('BtnFinaliseCommande').style.visibility='visible';
			
					}
					}
						else
						{
						}
				}
		xhr.open("POST", Location + "Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=refreshNbArticles&Location=" + Location);
}
function loadPanier(Location,RefPhoto,IdPhoto,IdEvent,RootString,IdDossier)
{
	var background = document.getElementById("BackgroundArea");
	var container = document.getElementById("listeProduits");
	var navigateur=(navigator.appName.substring(0,3)).toUpperCase();
	
	var _BackgroundHeight="";
	var _BackgroundWidth="100%";
	
	if (navigateur=="NET")
	{
		var scrollY=document.body.clientHeight;
		var _currentHeight = 0; //document.height;
		_BackgroundHeight = _currentHeight + scrollY;
		if (scrollY != 0)
		{
		background.style.height = _BackgroundHeight + "px";
		}
		else
		{
		background.style.height = "100%";
		}
	}
	else if (navigateur=="MIC")
	{
		var scrollY=document.body.clientHeight;
		var _currentHeight = screen.height;
		_BackgroundHeight = _currentHeight + scrollY;
		//alert(_BackgroundHeight);
		background.style.height = _BackgroundHeight + "px";
	}
	else
	{
		var scrollY=document.documentElement.scrollTop;
		var _currentHeight = screen.height;
		_BackgroundHeight = _currentHeight + scrollY;
		background.style.height = _BackgroundHeight + "px";
	}
	
	container.style.width= "800px";
	container.style.height= "100%";
	container.style.visibility= "visible";
	background.style.width= _BackgroundWidth;
	
	background.style.visibility= "visible";
	var xhr=null;
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					container.innerHTML = tbl;
					for(i=0;i<tblProduits.length;i++)
					{
					controlIsExist(Location,tblProduits[i],'Lnk'+i)	
					}
					refreshNbArticlesPanierB(Location);
					refreshTotalPanierB(Location);
					}
						else
						{
							container.innerHTML ="<div style='display:block; width:800px; height:600px;  position:relative; top:10px; background-color:#ffffff; text-align:center; color:#444444; font-size:11px;'>Chargement du catalogue en cours...<br /><br /><img src='../Img/Gabarit/loading.gif' /></div>";
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=loadPanier&Location="+Location+"&RootString="+RootString+"&IdEvent="+IdEvent+"&IdDossier="+IdDossier+"&IdPhoto="+IdPhoto+"&RefPhoto="+RefPhoto);
}
/*function loadPanier(Location,RefPhoto,IdPhoto,IdEvent,RootString,IdDossier)
{
var xhr=null;
var containerProductList=document.getElementById('listeProduits');
containerProductList.style.width="800px";
containerProductList.style.height="100%";
containerProductList.style.visibility="visible";

var i=0;
	
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					
							

					containerProductList.innerHTML= tbl;
					for(i=0;i<tblProduits.length;i++)
					{
					controlIsExist(Location,tblProduits[i],'Lnk'+i)	
					}
					refreshNbArticlesPanierB(Location);
					refreshTotalPanierB(Location);
					}
						else
						{
						
						containerProductList.innerHTML="Chargement des produits en cours...";	
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=loadPanier&Location="+Location+"&RootString="+RootString+"&IdEvent="+IdEvent+"&IdDossier="+IdDossier+"&IdPhoto="+IdPhoto+"&RefPhoto="+RefPhoto);
}*/
function refreshTotalPanier(Location)
{
	var Total=document.getElementById('HeaderTotalPanier');
	var xhr=null;
	//alert(IdProduit+"//"+IdPhoto+"//"+LnkId);
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					if (tbl=="0" || tbl=="" || tbl==".00")
					{
					Total.innerHTML = "VOTRE PANIER EST VIDE";
					}
					else
					{
	
						Total.innerHTML = tbl + " &euro;";	
			
					}
					}
						else
						{
						
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
		xhr.send("action=refreshTotalPanier&Location="+Location);
}


function refreshNbArticlesPanierB(Location)
{

	var NbArticlesB=document.getElementById('QteArticles');
	var xhr=null;
	//alert(IdProduit+"//"+IdPhoto+"//"+LnkId);
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					
						if (tbl=="0")
						{
						NbArticlesB.innerHTML = "Aucun";
						}
						else
						{
	
						NbArticlesB.innerHTML = tbl;
				
						}
					}
						else
						{
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=refreshNbArticles&Location="+Location);
}
function refreshTotalPanierB(Location)
{
		
	var TotalB=document.getElementById('TotalPanier');
	var xhr=null;
	//alert(IdProduit+"//"+IdPhoto+"//"+LnkId);
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					if (tbl=="0" || tbl==".00" || tbl=="")
					{
					TotalB.innerHTML = "0.00 &euro;";
					}
					else
					{
	
						TotalB.innerHTML = tbl + " &euro;";	
			
					}
					}
						else
						{
						
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
		xhr.send("action=refreshTotalPanier&Location="+Location);
}
function closeListProduct()
{

var containerProductList=document.getElementById('listeProduits');
var bg = document.getElementById("BackgroundArea");
containerProductList.style.innerHTML="";
containerProductList.style.width="1px";
containerProductList.style.height="1px";
containerProductList.innerHTML="";
containerProductList.style.visibility="hidden";
bg.style.width="1px";
bg.style.height="";
bg.style.visibility="hidden";
}
function controlIsExist(Location,IdProduit,LnkId)
{
var IdPhoto=document.forms['frmPanier'].elements['idphoto'].value; 	
var IdEvent=document.forms['frmPanier'].elements['IdEvent'].value; 	
var PhotoRootString=document.forms['frmPanier'].elements['PhotoRootString'].value; 
var RefPhoto=document.forms['frmPanier'].elements['refPhoto'].value
var CurrentLnk = document.getElementById(LnkId);
var xhr=null;
	//alert(IdProduit+"//"+IdPhoto+"//"+LnkId);
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					
					if (tbl.substring(0,4)=="down")
					{
					CurrentLnk.innerHTML = "<a href=\""+Location+"download.php?selectedFile=" + tbl.substring(4,tbl.length) + "\">Télécharger gratuitement</a>";
					}
					else if (tbl=="IsExist")
					{
					CurrentLnk.innerHTML = "<span class='InCaddy'>Déjà dans mon panier</span>";
					}
					else
					{
					CurrentLnk.innerHTML = "<a href=\"#\" onclick=\"addLine('"+Location+"','"+IdProduit+"','"+LnkId+"'); return false;\">Ajouter au panier</a>";
					}
			
					}
						else
						{
						CurrentLnk.innerHTML = "Vérification";
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=controlIsExist&IdProduit="+IdProduit+"&IdPhoto="+IdPhoto+"&IdEvent="+IdEvent+"&PhotoRootString="+PhotoRootString+"&RefPhoto="+RefPhoto+"&Location="+Location);
}

function changeQte(Location,Action,Line,PrixArticle)
{
var CurrentQte=document.getElementById("Qte"+Line);
var NewQte=0;
var LinePrice = document.getElementById("Total"+Line);

var xhr=null;
if (Action=="-")
{
	NewQte = Math.round(CurrentQte.innerHTML)-1;
	if (NewQte==0){
	alert("La quantité ne peut-être égale à zéro");
	return false;
	}
		
}
if (Action=="+")
{
	NewQte = Math.round(CurrentQte.innerHTML)+1;

}
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					LinePrice.innerHTML = tbl + " &euro;";
					loadTotalPanier(Location);
					loadFraisPort(Location);
					loadTotalCommande(Location);
					refreshTotalPanier(Location);
					}
						else
						{
							CurrentQte.innerHTML = NewQte;
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=ChangeQte&IdLine="+Line+"&NewQte="+NewQte+"&PrixArticle="+PrixArticle+"&Location="+Location);
}

function loadTotalPanier(Location)
{
var TotalPanier=document.getElementById("TotalPanier");
var xhr=null;

		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					TotalPanier.innerHTML = tbl + " &euro;";
					}
						else
						{
							
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=refreshTotalPanier&Location="+Location);
}

function loadTotalCommande(Location)
{
var TotalCommande = document.getElementById("TotalCommande");
var xhr=null;

		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;

					TotalCommande.innerHTML = tbl + " &euro;";
					}
						else
						{
							
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=CalculTotalCommande&Location="+Location);
}

function loadFraisPort(Location)
{
var TotalFraisPort=document.getElementById("TotalFraisPort");
var xhr=null;

		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					TotalFraisPort.innerHTML = tbl + " &euro;";
					}
						else
						{
							
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=refreshTotalFraisPort&Location="+Location);
}


function deleteLine(Location,IdLine)
{
var xhr=null;
if (confirm("Voulez-vous supprimer cette ligne ?"))
{
		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					document.location.reload();
					}
						else
						{
							
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=deleteLine&Location="+Location+"&IdLine="+IdLine);
}
}


function clearPanier(Location)
{
var xhr=null;

		if (window.XMLHttpRequest)
		{ 
			xhr = new XMLHttpRequest();
		}
			else if (window.ActiveXObject) 
			{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
				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)
					{
					var tbl = xhr.responseText;
					document.location.reload();
					}
						else
						{
							
						}
				}
		xhr.open("POST", Location+"Ajax/ajaxPanier.php", true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
		xhr.send("action=clearPanier&Location="+Location);
}
