// JavaScript Document
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}
document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}
function addslashes(str) {
	var i=0;
	while (i<str.length) {
		if (str.substr(i,1)=="'") {
			str=str.substr(0, i)+"\\"+str.substr(i, str.length-i);
			i+=2;
		} else if (str.substr(i,1)=='"') {
			str=str.substr(0, i)+"\\"+str.substr(i, str.length-i);
			i+=2;
		} else {
			i++;
		}
	}
	return str;
}
function stripslashes(str) {
	var i=0;
	while (i<str.length) {
		if (str.substr(i,1)=="\\") {
			str=str.substr(0, i)+str.substr(i+1, str.length-(i+1));
		} else {
			i++;
		}
	}
	return str;
}
var arrDess=Array();
var openedDess="";
var numberDess=Array();
numberDess['code']=Array();
numberDess['qte']=Array();
var totalQuantityPRT=0;
var totalQuantityPDEJ=0;
var menuOpened="none";
var disabled=false;
var countClicCForm=0;
var livDej=-1;
var TotalDess=0;
var PMXT=Array();
var PROMOTAB="off";
var mainQtePRM=0;
var cboxChecked=false;
PMXT['deW']=Array();
PMXT['pHT']=Array();
PMXT['pTT']=Array();
PMXT['code']=Array();
var listOpened="";
var MENVEMB=Array();
var authDej=false;
MENVEMB['code']="";
MENVEMB['deW']="";
var activatePTDtab=false;
var commandeLiv=null;
var pdejLiv=null;
var heure=null;
var heurePdej=null;
var is_sncf=false;
var bupoPresent=false;
function implode(sep, arr) {
	var str="";
	for (k=0; k<arr.length; k++) {
		str+=arr[k];
		if (k<arr.length-1) {
			str+=sep;
		}
	}
	return str;
}
function explode(sep, str) {
	var positions=Array();
	var resultats=Array();
	positions.push(-sep.length);
	for (k=0; k<str.length; k++) {
		if (str.substr(k,sep.length)==sep) {
			positions.push(k);
		}
	}
	positions.push(str.length);
	for (k=0; k<(positions.length-1); k++) {
		resultats.push(str.substr((positions[k]+sep.length), (positions[k+1]-(positions[k]+sep.length))));
	}
	return resultats;
}
function fix(price) {
	return Math.round(price*100)/100;
}
function enabledCrayon () {
	$(document).bind('mousemove',moveCrayon);
}
function disableCrayon () {
	$(document).unbind('mousemove',moveCrayon);
}
function moveCrayon(e){ 
	if (parseInt(document.getElementById('crayon').style.marginTop)>=30 && parseInt(document.getElementById('crayon').style.marginTop)<=document.getElementById('menu').offsetHeight+40 || isNaN(parseInt(document.getElementById('crayon').style.marginTop))) {
		document.getElementById('crayon').style.marginTop=e.pageY-$(document).scrollTop()-165+"px";
	}
	if (parseInt(document.getElementById('crayon').style.marginTop)>=document.getElementById('menu').offsetHeight+40) {
		document.getElementById('crayon').style.marginTop=document.getElementById('menu').offsetHeight+40+"px";
	}
	if (parseInt(document.getElementById('crayon').style.marginTop)<=30) {
		document.getElementById('crayon').style.marginTop=30+"px";
	}
}
$(document).ready(function () {
	if (window.navigator.appName.toString().toLowerCase().indexOf("gecko")!=-1) {
		window.onscroll=function () {
			document.getElementById("menuCont").style.marginTop=150+document.body.scrollTop+"px";
			document.getElementById("logo").style.marginTop=20+document.body.scrollTop+"px";
		}
	} else {
		document.getElementById("menuCont").style.position="fixed";
		document.getElementById("logo").style.position="fixed";
	}
	if (document.location.toString().indexOf("plateaux_repas_tradition.php")>-1) {
		updateQtePRT();
	}
	if (activatePTDtab==true) {
		$(".qteoptpdej").focus(function(event) {
			expandPDEJ();
		});
	}
	<!--[if IE]>$(document).pngFix();<![endif]-->
	$('#menu').bind('mouseover',enabledCrayon);
	$('#menu').bind('mouseout',disableCrayon);
	$('a, h4').focus(function() {
	  this.blur();
	});
	if (window.navigator.appName != 'Microsoft Internet Explorer' && window.navigator.userAgent.toLowerCase().indexOf('mozilla')==-1) {
		if (pageType.substr(0, pageType.indexOf("_"))=="traiteur") {
			var lielm=document.getElementById('m1');
			var ulelms=lielm.getElementsByTagName('ul');
			lielm.style.height=ulelms[0].offsetHeight+24+"px";
			ulelms[0].style.opacity=1;
			var theLink=document.getElementById("ml_"+pageType);
			theLink.style.color="#f00";
			menuOpened="boite_1";
		} else if (pageType.substr(0, pageType.indexOf("_"))=="bistrot") {
			var lielm=document.getElementById('m2');
			var ulelms=lielm.getElementsByTagName('ul');
			lielm.style.height=ulelms[0].offsetHeight+24+"px";
			ulelms[0].style.opacity=1;
			var theLink=document.getElementById("ml_"+pageType);
			theLink.style.color="#f00";
			menuOpened="boite_2";
		}
	} else if (window.navigator.userAgent.toLowerCase().indexOf('mozilla')>-1) {
		if (pageType.substr(0, pageType.indexOf("_"))=="traiteur") {
			var lielm=document.getElementById('m1');
			var ulelms=lielm.getElementsByTagName('ul');
			lielm.style.height=ulelms[0].offsetHeight+30+"px";
			ulelms[0].style.opacity=1;
			var theLink=document.getElementById("ml_"+pageType);
			theLink.style.color="#f00";
			menuOpened="boite_1";
		} else if (pageType.substr(0, pageType.indexOf("_"))=="bistrot") {
			var lielm=document.getElementById('m2');
			var ulelms=lielm.getElementsByTagName('ul');
			lielm.style.height=ulelms[0].offsetHeight+30+"px";
			ulelms[0].style.opacity=1;
			var theLink=document.getElementById("ml_"+pageType);
			theLink.style.color="#f00";
			menuOpened="boite_2";
		}
	} else {
		if (pageType.substr(0, pageType.indexOf("_"))=="traiteur") {
			var lielm=document.getElementById('m1');
			var ulelms=lielm.getElementsByTagName('ul');
			lielm.style.height=ulelms[0].offsetHeight+24+"px";
			var theLink=document.getElementById("ml_"+pageType);
			theLink.style.color="#f00";
			menuOpened="boite_1";
		} else if (pageType.substr(0, pageType.indexOf("_"))=="bistrot") {
			var lielm=document.getElementById('m2');
			var ulelms=lielm.getElementsByTagName('ul');
			lielm.style.height=ulelms[0].offsetHeight+24+"px";
			var theLink=document.getElementById("ml_"+pageType);
			theLink.style.color="#f00";
			menuOpened="boite_2";
		}
	}
	if (window.navigator.appName != 'Microsoft Internet Explorer' && window.navigator.appName != 'Opera') {
		$('#menu li.toExpand a.mainLink').bind('mouseover',function (e) {
			var elm=e.target.parentNode.parentNode;
			var theId=elm.id;
			if (theId.substr(0,2)!='m1' && theId.substr(0,2)!='m2' && theId.substr(0,2)!='m3' && theId.substr(0,2)!='m4')  { 
				elm=e.target.parentNode;// hack pour le cas ou l'on clique sur autre chose qu'un des spans dans l'anchor <a>
				theId=elm.id;
			}
			if (theId.substr(0,2)!='m1' && theId.substr(0,2)!='m2' && theId.substr(0,2)!='m3' && theId.substr(0,2)!='m4')  { 
				elm=e.target;
				theId=elm.id;
			}
			var ulelm=elm.getElementsByTagName('ul');
			if (ulelm[0].id!=menuOpened) {
				//alert(elm.parentNode);
				var elms=document.getElementsByClassName('toExpand');
				for (i=0; i<elms.length; i++) {
					var ulelmBis=elms[i].getElementsByTagName('ul');
					if (ulelmBis[0].id==menuOpened && parseInt(elms[i].style.height)>24) {
						$(elms[i]).animate({
							height:24
						}, 500);
						$(ulelmBis).animate({
							opacity:0
						}, 500);
					}
				}
				//alert(ulelm[0].offsetHeight);
				$(elm).animate({
					height:24+ulelm[0].offsetHeight
				}, 500);
				$(ulelm[0]).animate({
					opacity:1
				}, 500);
			}
			menuOpened=ulelm[0].id;
		});
	} else if (window.navigator.appName == 'Microsoft Internet Explorer') {
		$(document).pngFix();
		$('#menu li.toExpand a.mainLink').bind('mouseover',function (e) {
			var elm=e.target.parentNode.parentNode;
			var theId=elm.id;
			if (theId.substr(0,2)!='m1' && theId.substr(0,2)!='m2' && theId.substr(0,2)!='m3' && theId.substr(0,2)!='m4')  { 
				elm=e.target.parentNode;// hack pour le cas ou l'on clique sur autre chose qu'un des spans dans l'anchor <a>
				theId=elm.id;
			}
			if (theId.substr(0,2)!='m1' && theId.substr(0,2)!='m2' && theId.substr(0,2)!='m3' && theId.substr(0,2)!='m4')  { 
				elm=e.target;
				theId=elm.id;
			}
			var ulelm=elm.getElementsByTagName('ul');
			if (ulelm[0].id!=menuOpened) {
				var moins=0;
				var plus=0;
				//alert(elm.parentNode);
				var elms=document.getElementsByClassName('toExpand');
				for (i=0; i<elms.length; i++) {
					var ulelmBis=elms[i].getElementsByTagName('ul');
					if (ulelmBis[0].id==menuOpened && parseInt(elms[i].style.height)>24) {
						moins=ulelmBis[0].offsetHeight;
						$(elms[i]).animate({
							height:24
						}, 500);
					}
				}
				plus=ulelm[0].offsetHeight;
				$(elm).animate({
					height:24+ulelm[0].offsetHeight
				}, 500);
				$('#menu').animate({
					height:$('#menu').offsetHeight-moins+plus
				}, 500);
			}
			menuOpened=ulelm[0].id;
		});
	} else if (window.navigator.appName == 'Opera') {
		$('#menu li.toExpand a.mainLink').bind('mouseover',function (e) {
			var elm=e.target.parentNode.parentNode;
			var theId=elm.id;
			if (theId.substr(0,2)!='m1' && theId.substr(0,2)!='m2' && theId.substr(0,2)!='m3' && theId.substr(0,2)!='m4')  { 
				elm=e.target.parentNode;// hack pour le cas ou l'on clique sur autre chose qu'un des spans dans l'anchor <a>
				theId=elm.id;
			}
			if (theId.substr(0,2)!='m1' && theId.substr(0,2)!='m2' && theId.substr(0,2)!='m3' && theId.substr(0,2)!='m4') {
				elm=e.target;
				theId=elm.id;
			}
			//alert(elm.id);
			var ulelm=elm.getElementsByTagName('ul');
			if (ulelm[0].id!=menuOpened) {
				var moins=0;
				var plus=0;
				//alert(elm.parentNode);
				var elms=document.getElementsByClassName('toExpand');
				for (i=0; i<elms.length; i++) {
					var ulelmBis=elms[i].getElementsByTagName('ul');
					if (ulelmBis[0].id==menuOpened && parseInt(elms[i].style.height)>24) {
						moins=ulelmBis[0].offsetHeight;
						$(elms[i]).animate({
							height:24
						}, 500);
						$(ulelmBis).animate({
							opacity:0
						}, 500);
					}
				}
				plus=ulelm[0].offsetHeight;
				$(elm).animate({
					height:24+ulelm[0].offsetHeight
				}, 500);
				$(ulelm[0]).animate({
					opacity:1
				}, 500);
				$('#menu').animate({
					height:document.getElementById('menu').offsetHeight-moins+plus
				}, 500);
			}
			menuOpened=ulelm[0].id;
		});
	}
});
function deleteContentIf(str, theId) {
	var elm=document.getElementById(theId);
	if (elm.value==str) {
		elm.value="";
	}
}
function submitConnexionForm () {
	var emailField=document.getElementById("mail");
	var email=emailField.value;
	var passField=document.getElementById("pass");
	var pass=passField.value;
	if (email!="" && email!="votre email" && pass!="" && pass!="password") {
		connexion(email, pass);
	}
}
function connexionSHA1(email, pass, id) {
	var str="id="+encodeURIComponent(id)+"&email="+encodeURIComponent(email)+"&pass="+encodeURIComponent(pass)+"&enc="+encodeURIComponent("SHA1");
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				//alert(xhr.responseText);
				if (xhr.responseText.substr(0,12)=='erreur_mysql') {
					alert('erreur mysql lors de la requete');
				} else if (xhr.responseText=='') {
					alert("nous n'avons trouvé aucune concordance avec cet email et ce mot de passe");
				} else if (xhr.responseText.substr(0,3)=='id=') {
					var reg0=/id=(.*)&nom=/;
					var reg1=/nom=(.*)&prenom=/;
					var reg2=/prenom=(.*)&email=/;
					var reg3=/password=(.*)&paiement_differe=/;
					var obj0=reg0.exec(xhr.responseText);
					var obj1=reg1.exec(xhr.responseText);
					var obj2=reg2.exec(xhr.responseText);
					var obj3=reg3.exec(xhr.responseText);
					document.getElementById('_1').innerHTML="Bienvenue, "+obj2[1]+" "+obj1[1]+".";
					$("#connexionForm").animate({
						opacity:0
					}, 500);
					$("#_2").animate({
						width:90,
						opacity:0
					}, 500, function () {
						//document.getElementById('connexionForm').style.visibility="hidden";
						document.getElementById('_2').innerHTML='<a href="#ancre" onClick="deconnexion();">Se déconnecter</a>';
						document.getElementById('_3').innerHTML='<a href="mon_compte.php?id='+obj0[1]+'&pass='+obj3[1]+'">Mon compte</a>';
						$("#_2").animate({
							opacity:1
						}, 500);
						tenS=0;
						intId=setInterval("checkTimer()", 10000);
						mouse["x"]=0;
						mouse["y"]=0;
					});
					logged=true;
				} else {
					alert(xhr.responseText);
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "connexionSHA1.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function connexion(email, pass) {
	var str="email="+encodeURIComponent(email)+"&pass="+encodeURIComponent(pass);
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				//alert(xhr.responseText);
				if (xhr.responseText.substr(0,12)=='erreur_mysql') {
					alert('erreur mysql lors de la requete');
				} else if (xhr.responseText=='') {
					alert("nous n'avons trouvé aucune concordance avec cet email et ce mot de passe");
				} else if (xhr.responseText.substr(0,3)=='id=') {
					var reg0=/id=(.*)&nom=/;
					var reg1=/nom=(.*)&prenom=/;
					var reg2=/prenom=(.*)&email=/;
					var reg3=/password=(.*)&paiement_differe=/;
					var obj0=reg0.exec(xhr.responseText);
					var obj1=reg1.exec(xhr.responseText);
					var obj2=reg2.exec(xhr.responseText);
					var obj3=reg3.exec(xhr.responseText);
					alert("Vous avez été identifié, vous pouvez désormais passer commande.");
					document.getElementById('_1').innerHTML="Bienvenue, "+obj2[1]+" "+obj1[1]+".";
					$("#connexionForm").animate({
						opacity:0
					}, 500);
					$("#_2").animate({
						width:90,
						opacity:0
					}, 500, function () {
						//document.getElementById('connexionForm').style.visibility="hidden";
						document.getElementById('_2').innerHTML='<a href="#ancre" onClick="deconnexion();">Se déconnecter</a>';
						document.getElementById('_3').innerHTML='<a href="mon_compte.php?id='+obj0[1]+'&pass='+obj3[1]+'">Mon compte</a>';
						$("#_2").animate({
							opacity:1
						}, 500);
						tenS=0;
						intId=setInterval("checkTimer()", 10000);
						mouse["x"]=0;
						mouse["y"]=0;
					});
					logged=true;
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "connexion.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function showConnexionForm() {
	countClicCForm++;
	if (countClicCForm%2==1) {
		document.getElementById('connexionForm').style.visibility="visible";
		$("#connexionForm").animate({
			opacity:1
		}, 500);
		$("#_2").animate({
			width:288
		}, 500);
	} else {
		$("#connexionForm").animate({
			opacity:0
		}, 500);
		$("#_2").animate({
			width:58
		}, 500, function () {
			document.getElementById('connexionForm').style.visibility="hidden";
		});
	}
}
function deconnexion() {
	var str="deconnexion=true";
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				if (xhr.responseText=="deconnexion_succeeded") {
					if (document.location.toString().indexOf("php")!=-1) {
						document.location=document.location.toString().substr(0,document.location.toString().indexOf("php")+3);
					} else {
						document.location.reload();
					}
				} else {
					alert("erreur de deconnexion");
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "deconnexion.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function checkOCFormAndSubmit() {
	stopScript=false;
	var formulaire=document.getElementById("ouverture_compte");
	if (formulaire.nom.value=="") {
		alert('le champ "Nom" est obligatoire');
		formulaire.nom.focus();
		stopScript=true;
	} else if (formulaire.prenom.value=="") {
		alert('le champ "Prénom" est obligatoire');
		formulaire.prenom.focus();
		stopScript=true;
	} else if (formulaire.email.value=="") {
		alert('le champ "Email" est obligatoire');
		formulaire.email.focus();
		stopScript=true;
	} else if (formulaire.pass.value=="") {
		alert('le champ "Mot de passe" est obligatoire');
		formulaire.pass.focus();
		stopScript=true;
	} else {
		var reg=new RegExp('([0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?))');
		if (formulaire.tel_liv.value!="") {
			if (!reg.test(formulaire.tel_liv.value)) {
				alert('le champ "Téléphone" est incorrect!');
				formulaire.tel_liv.focus();
				stopScript=true;
			} else {
				var obj=reg.exec(formulaire.tel_liv.value);
				formulaire.tel_liv.value=obj[1];
			}
		}
		var regMail1=new RegExp('[-\. a-zA-Z0-9]+@[-\. a-zA-Z0-9]+\.[a-z]{2,4}');
		if (!regMail1.test(formulaire.email.value)) {
			alert('le champ "Email" semble incorrect!');
			formulaire.email.focus();
			stopScript=true;
		}
		if (is_sncf==true) {
			if (formulaire.bupo.value.length!=5) {
				alert('le champ "BUPO" semble incorrect!');
				stopScript=true;
				formulaire.bupo.focus();
			} else {
				var regBUPO=new RegExp('[0-9]{5}');
				if (regBUPO.test(formulaire.bupo.value)) {
					bupoPresent=true;
				} else {
					alert('le champ "BUPO" semble incorrect!');
					stopScript=true;
					formulaire.bupo.focus();
				}	
			}
			if (formulaire.adresse_liv.value=="") {
				alert('le champ "Adresse" est obligatoire pour la livraison');
				formulaire.adresse_liv.focus();
				stopScript=true;
			} else if (formulaire.cp_liv.value=="") {
				alert('le champ "Code postal" est obligatoire pour la livraison');
				formulaire.cp_liv.focus();
				stopScript=true;
			} else if (formulaire.ville_liv.value=="") {
				alert('le champ "Ville" est obligatoire pour la livraison');
				formulaire.ville_liv.focus();
				stopScript=true;
			} else if (formulaire.tel_liv.value=="") {
				alert('le champ "Téléphone" est obligatoire pour la livraison');
				formulaire.tel_liv.focus();
				stopScript=true;
			}
		} else {
			if (formulaire.adresse.value=="") {
				alert('le champ "Adresse" est obligatoire');
				formulaire.adresse.focus();
				stopScript=true;
			} else if (formulaire.cp.value=="") {
				alert('le champ "Code postal" est obligatoire');
				formulaire.cp.focus();
				stopScript=true;
			} else if (formulaire.ville.value=="") {
				alert('le champ "Ville" est obligatoire');
				formulaire.ville.focus();
				stopScript=true;
			}
			if (formulaire.tel.value=="") {
				alert('le champ "Téléphone" est obligatoire');
				formulaire.tel.focus();
				stopScript=true;
			} else {
				if (!reg.test(formulaire.tel.value)) {
					alert('le champ "Téléphone" est incorrect!');
					formulaire.tel.focus();
					stopScript=true;
				} else {
					var obj=reg.exec(formulaire.tel.value);
					formulaire.tel.value=obj[1];
				}
			}
		}
	}
	if (stopScript==false) {
		var str="email="+encodeURIComponent(formulaire.email.value)+"&pass="+encodeURIComponent(formulaire.pass.value);
		var xhr = null;
		if (window.XMLHttpRequest || window.ActiveXObject) {
			if (window.ActiveXObject) {
				try {
					xhr = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
			} else {
				xhr = new XMLHttpRequest(); 
			}
		} else {
			alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
			return;
		}
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200 || xhr.status == 0) {
					var strRep=xhr.responseText;
					var reg0=new RegExp('email=(.*)&pass=(.*)');
					//alert(strRep);
					if (strRep.substr(0,12)=='erreur_mysql') {
						alert('Erreur lors de la requête, votre mot de passe et l\'adresse email n\'ont pu être testés, merci de nous contacter, le problème sera réglé dans les plus brefs délais.');
					} else if (reg0.test(strRep)==true) {
						var reg1=new RegExp('email=(.*)&pass=');
						var reg2=new RegExp('pass=(.*)');
						var obj1=reg1.exec(strRep);
						var obj2=reg2.exec(strRep);
						if (obj1[1]=="disponible" && obj2[1]=="disponible") {
							if (bupoPresent==false) {
								registerAccount(formulaire.nom.value, formulaire.prenom.value, formulaire.email.value.toString().toLowerCase(), formulaire.pass.value, formulaire.societe.value, formulaire.adresse.value, formulaire.cp.value, formulaire.ville.value, formulaire.tel.value, formulaire.adresse_liv.value, formulaire.cp_liv.value, formulaire.ville_liv.value, formulaire.tel_liv.value, formulaire.newsletter.value);
							} else {
								registerAccountSNCF(formulaire.nom.value, formulaire.prenom.value, formulaire.email.value.toString().toLowerCase(), formulaire.pass.value, formulaire.societe.value, formulaire.adresse.value, formulaire.cp.value, formulaire.ville.value, "", formulaire.adresse_liv.value, formulaire.cp_liv.value, formulaire.ville_liv.value, formulaire.tel_liv.value, formulaire.bupo.value,  formulaire.newsletter.value);
							}
						} else {
							if (obj1[1]=="indisponible") {
								alert('cette adresse email est déjà utilisée dans notre base, veuillez en choisir une autre ou utiliser le lien "Mot de passe oublié?" pour en recevoir un nouveau');
							}
							if (obj2[1]=="indisponible") {
								alert('ce mot de passe déjà utilisé dans notre base, veuillez en choisir un autre');
								formulaire.pass.focus();
							}
						}
					} else {
						alert("Une erreur s'est produite lors de votre inscription, veuillez nous contacter au 01 43 07 93 93");
					}
				} else { 
					alert("error: "+xhr.status+" "+xhr.statusText);
				}
			}
		};
		xhr.open("POST", "checkAccount.php", true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(str);
	}
}
function checkContactFormAndSubmit() {
	stopScript=false;
	var formulaire=document.getElementById("contact_form");
	if (formulaire.nom.value=="") {
		alert('le champ "Nom" est obligatoire');
		formulaire.nom.focus();
		stopScript=true;
	} else if (formulaire.prenom.value=="") {
		alert('le champ "Prénom" est obligatoire');
		formulaire.prenom.focus();
		stopScript=true;
	} else if (formulaire.email.value=="") {
		alert('le champ "Email" est obligatoire');
		formulaire.email.focus();
		stopScript=true;
	} else if (formulaire.message.value=="") {
		alert('le champ "Message" est obligatoire');
		formulaire.message.focus();
		stopScript=true;
	} else {
		var reg=new RegExp('([0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?))');
		if (formulaire.tel.value!="") {
			if (!reg.test(formulaire.tel.value)) {
				alert('le champ "Téléphone" est incorrect!');
				formulaire.tel.focus();
				stopScript=true;
			} else {
				var obj=reg.exec(formulaire.tel.value);
				formulaire.tel.value=obj[1];
			}
		}
		var regMail=new RegExp('[-\. a-zA-Z0-9]+@[-\. a-zA-Z0-9]+\.[a-z]{2,4}');
		if (!regMail.test(formulaire.email.value)) {
			alert('le champ "Email" semble incorrect!');
			formulaire.email.focus();
			stopScript=true;
		}
	}
	if (stopScript==false) {
		var str="nom="+encodeURIComponent(formulaire.nom.value)+"&prenom="+encodeURIComponent(formulaire.prenom.value)+"&email="+encodeURIComponent(formulaire.email.value)+"&tel="+encodeURIComponent(formulaire.tel.value)+"&message="+encodeURIComponent(formulaire.message.value);
		ajaxPostSend(str, "sendMessage.php", "returnContactForm");
	}
}
function returnContactForm(str) {
	var retourContact=document.getElementById("retourContact");
	retourContact.innerHTML=str;
}
function testSNCF(formId) {
	var formulaire=document.getElementById(formId);
	if (is_sncf==false) {
		var regMail2=new RegExp('@sncf.fr');
		if (regMail2.test(formulaire.email.value)) {
			is_sncf=true;
			askForBupo();
		}
	}
}
function askForBupo() {
	$("#sncf_1, #sncf_2").animate({
		height:30
	}, 200, function () {
		var sncf_1=document.getElementById("sncf_1");
		sncf_1.innerHTML='<span class="arial12rouge">*&nbsp;</span><label>N° BUPO&nbsp;</label>';
		var sncf_2=document.getElementById("sncf_2");
		sncf_2.innerHTML='<input type="text" name="bupo" value="" maxlength="5"/>';
	});
	$("#sncf_0").animate({
		height:60
	}, 200, function () {
		var sncf_0=document.getElementById("sncf_0");
		sncf_0.innerHTML='Vous avez été identifié comme un client affilié sncf bénéficiant des conditions de vente particulières à la sncf,<br /> veuillez rentrer ci-dessous votre numéro BUPO :';
	});
	var adresseCont=document.getElementById('adresseCont');
	var cpCont=document.getElementById('cpCont');
	var villeCont=document.getElementById('villeCont');
	var telCont=document.getElementById('telCont');
	var adresse_liv_desc=document.getElementById('adresse_liv_desc');
	var cp_liv_desc=document.getElementById('cp_liv_desc');
	var ville_liv_desc=document.getElementById('ville_liv_desc');
	var tel_liv_desc=document.getElementById('tel_liv_desc');
	adresseCont.innerHTML='<input type="hidden" name="adresse" value="SNCF CCF TSA 50810"/><span class="arial14noir">SNCF CCF TSA 50810</span>';
	cpCont.innerHTML='<input type="hidden" name="cp" value="69008"/><span class="arial14noir">69008</span>';
	villeCont.innerHTML='<input type="hidden" name="ville" value="LYON CEDEX 20"/><span class="arial14noir">LYON CEDEX 20</span>';
	telCont.innerHTML='<input type="hidden" name="tel" value=""/>';
	adresse_liv_desc.innerHTML='<span class="arial12rouge">*&nbsp;</span><label>Adresse&nbsp;</label>';
	cp_liv_desc.innerHTML='<span class="arial12rouge">*&nbsp;</span><label>Code postal&nbsp;</label>';
	ville_liv_desc.innerHTML='<span class="arial12rouge">*&nbsp;</span><label>Ville&nbsp;</label>';
	tel_liv_desc.innerHTML='<span class="arial12rouge">*&nbsp;</span><label>Téléphone&nbsp;</label>';
}
function registerAccount(nom, prenom, email, pass, societe, adresse, cp, ville, tel, adresse_liv, cp_liv, ville_liv, tel_liv, newsletter) {
	var str="nom="+encodeURIComponent(nom)+"&prenom="+encodeURIComponent(prenom)+"&email="+encodeURIComponent(email)+"&pass="+encodeURIComponent(pass)+"&societe="+encodeURIComponent(societe)+"&adresse="+encodeURIComponent(adresse)+"&cp="+encodeURIComponent(cp)+"&ville="+encodeURIComponent(ville)+"&tel="+encodeURIComponent(tel)+"&adresse_liv="+encodeURIComponent(adresse_liv)+"&cp_liv="+encodeURIComponent(cp_liv)+"&ville_liv="+encodeURIComponent(ville_liv)+"&tel_liv="+encodeURIComponent(tel_liv)+"&newsletter="+encodeURIComponent(newsletter);
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				//alert(xhr.responseText);
				if (xhr.responseText.substr(0,12)=='erreur_mysql') {
					alert('erreur mysql lors de la requete');
				} else if (xhr.responseText.substr(0,12)=='erreur_write') {
					alert('erreur lors de l\'écriture de votre fichier client');
				} else if (xhr.responseText.substr(0,2)=="ok") {
					var reg0=new RegExp('&id=(.*)&mail=');
					var reg1=new RegExp('&mail=(.*)&pass=');
					var reg2=new RegExp('&pass=(.*)');
					var obj0=reg0.exec(xhr.responseText);
					var obj1=reg1.exec(xhr.responseText);
					var obj2=reg2.exec(xhr.responseText);
					var formulaire=document.getElementById("ouverture_compte");
					formulaire.nom.value="";
					formulaire.prenom.value="";
					formulaire.societe.value="";
					formulaire.email.value="";
					formulaire.pass.value="";
					formulaire.adresse.value="";
					formulaire.cp.value="";
					formulaire.ville.value="";
					formulaire.tel.value="";
					formulaire.adresse_liv.value="";
					formulaire.cp_liv.value="";
					formulaire.ville_liv.value="";
					formulaire.tel_liv.value="";
					alert("Votre ouverture de compte a bien été enregistrée, vous allez être redirigé(e) vers la page d'accueil dans quelques instants. Vous pouvez désormais passer commande.");
					var strTO='document.location="index.php?id='+obj0[1]+'&connectMail='+obj1[1]+'&connectPass='+obj2[1]+'"';
					setTimeout(strTO, 500);
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "registerAccount.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function registerAccountSNCF(nom, prenom, email, pass, societe, adresse, cp, ville, tel, adresse_liv, cp_liv, ville_liv, tel_liv, bupo, newsletter) {
	var str="nom="+encodeURIComponent(nom)+"&prenom="+encodeURIComponent(prenom)+"&email="+encodeURIComponent(email)+"&pass="+encodeURIComponent(pass)+"&societe="+encodeURIComponent(societe)+"&adresse="+encodeURIComponent(adresse)+"&cp="+encodeURIComponent(cp)+"&ville="+encodeURIComponent(ville)+"&tel="+encodeURIComponent(tel)+"&adresse_liv="+encodeURIComponent(adresse_liv)+"&cp_liv="+encodeURIComponent(cp_liv)+"&ville_liv="+encodeURIComponent(ville_liv)+"&tel_liv="+encodeURIComponent(tel_liv)+"&bupo="+encodeURIComponent(bupo)+"&newsletter="+encodeURIComponent(newsletter);
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				//alert(xhr.responseText);
				if (xhr.responseText.substr(0,12)=='erreur_mysql') {
					alert('erreur mysql lors de la requete');
				} else if (xhr.responseText.substr(0,12)=='erreur_write') {
					alert('erreur lors de l\'écriture de votre fichier client');
				} else if (xhr.responseText.substr(0,2)=="ok") {
					var reg0=new RegExp('&id=(.*)&mail=');
					var reg1=new RegExp('&mail=(.*)&pass=');
					var reg2=new RegExp('&pass=(.*)');
					var obj0=reg0.exec(xhr.responseText);
					var obj1=reg1.exec(xhr.responseText);
					var obj2=reg2.exec(xhr.responseText);
					var formulaire=document.getElementById("ouverture_compte");
					formulaire.nom.value="";
					formulaire.prenom.value="";
					formulaire.societe.value="";
					formulaire.email.value="";
					formulaire.pass.value="";
					formulaire.adresse.value="";
					formulaire.cp.value="";
					formulaire.ville.value="";
					formulaire.tel.value="";
					formulaire.adresse_liv.value="";
					formulaire.cp_liv.value="";
					formulaire.ville_liv.value="";
					formulaire.tel_liv.value="";
					formulaire.bupo.value="";
					alert("Votre ouverture de compte a bien été enregistrée, vous allez être redirigé(e) vers la page d'accueil dans quelques instants. Vous pouvez désormais passer commande.");
					var strTO='document.location="index.php?id='+obj0[1]+'&connectMail='+obj1[1]+'&connectPass='+obj2[1]+'"';
					setTimeout(strTO, 500);
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "registerAccount.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function checkCFormAndSubmit(theId) {
	stopScript=false;
	var formulaire=document.getElementById("modification_compte");
	if (formulaire.nom.value=="") {
		alert('le champ "Nom" est obligatoire');
		formulaire.nom.focus();
		stopScript=true;
	} else if (formulaire.prenom.value=="") {
		alert('le champ "Prénom" est obligatoire');
		formulaire.prenom.focus();
		stopScript=true;
	} else if (formulaire.email.value=="") {
		alert('le champ "Email" est obligatoire');
		formulaire.email.focus();
		stopScript=true;
	} else if (formulaire.pass.value=="") {
		alert('le champ "Mot de passe" est obligatoire');
		formulaire.pass.focus();
		stopScript=true;
	} else if (formulaire.adresse.value=="") {
		alert('le champ "Adresse" est obligatoire');
		formulaire.adresse.focus();
		stopScript=true;
	} else if (formulaire.cp.value=="") {
		alert('le champ "Code postal" est obligatoire');
		formulaire.cp.focus();
		stopScript=true;
	} else if (formulaire.ville.value=="") {
		alert('le champ "Ville" est obligatoire');
		formulaire.ville.focus();
		stopScript=true;
	} else {
		var reg=new RegExp('([0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?)[0-9]{2}(?:[-. ]?))');
		if (formulaire.tel_liv.value!="") {
			if (!reg.test(formulaire.tel_liv.value)) {
				alert('le champ "Téléphone" est incorrect!');
				formulaire.tel_liv.focus();
				stopScript=true;
			} else {
				var obj=reg.exec(formulaire.tel_liv.value);
				formulaire.tel_liv.value=obj[1];
			}
		}
		var regMail1=new RegExp('[-\. a-zA-Z0-9]+@[-\. a-zA-Z0-9]+\.[a-z]{2,4}');
		if (!regMail1.test(formulaire.email.value)) {
			alert('le champ "Email" semble incorrect!');
			formulaire.email.focus();
			stopScript=true;
		}
		if (is_sncf==true) {
			if (formulaire.bupo.value.length!=5) {
				alert('le champ "BUPO" semble incorrect!');
				stopScript=true;
				formulaire.bupo.focus();
			} else {
				var regBUPO=new RegExp('[0-9]{5}');
				if (regBUPO.test(formulaire.bupo.value)) {
					bupoPresent=true;
				} else {
					alert('le champ "BUPO" semble incorrect!');
					stopScript=true;
					formulaire.bupo.focus();
				}	
			}
			if (formulaire.adresse_liv.value=="") {
				alert('le champ "Adresse" est obligatoire pour la livraison');
				formulaire.adresse_liv.focus();
				stopScript=true;
			} else if (formulaire.cp_liv.value=="") {
				alert('le champ "Code postal" est obligatoire pour la livraison');
				formulaire.cp_liv.focus();
				stopScript=true;
			} else if (formulaire.ville_liv.value=="") {
				alert('le champ "Ville" est obligatoire pour la livraison');
				formulaire.ville_liv.focus();
				stopScript=true;
			} else if (formulaire.tel_liv.value=="") {
				alert('le champ "Téléphone" est obligatoire pour la livraison');
				formulaire.tel_liv.focus();
				stopScript=true;
			}
		} else {
			if (formulaire.tel.value=="") {
				alert('le champ "Téléphone" est obligatoire');
				formulaire.tel.focus();
				stopScript=true;
			} else {
				if (!reg.test(formulaire.tel.value)) {
					alert('le champ "Téléphone" est incorrect!');
					formulaire.tel.focus();
					stopScript=true;
				} else {
					var obj=reg.exec(formulaire.tel.value);
					formulaire.tel.value=obj[1];
				}
			}
		}
	}
	if (stopScript==false) {
		var str="";
		if (formulaire.email.value!=emailCompte) {
			str+="email="+encodeURIComponent(formulaire.email.value);
		}
		if (formulaire.pass.value!=passCompte) {
			if (str=="") {
				str+="pass="+encodeURIComponent(formulaire.email.value);
			} else {
				str+="&pass="+encodeURIComponent(formulaire.email.value);
			}
		}
		if (str!="") {
			var xhr = null;
			if (window.XMLHttpRequest || window.ActiveXObject) {
				if (window.ActiveXObject) {
					try {
						xhr = new ActiveXObject("Msxml2.XMLHTTP");
					} catch(e) {
						xhr = new ActiveXObject("Microsoft.XMLHTTP");
					}
				} else {
					xhr = new XMLHttpRequest(); 
				}
			} else {
				alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
				return;
			}
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {
					if (xhr.status == 200 || xhr.status == 0) {
						var strRep=xhr.responseText;
						var reg0=new RegExp('email=(.*)&pass=(.*)');
						//alert(strRep);
						if (strRep.substr(0,12)=='erreur_mysql') {
							alert('Erreur lors de la requête, votre mot de passe et l\'adresse email n\'ont pu être testés, merci de nous contacter, le problème sera réglé dans les plus brefs délais.');
						} else if (reg0.test(strRep)==true) {
							var reg1=new RegExp('email=(.*)&pass=');
							var reg2=new RegExp('pass=(.*)');
							var obj1=reg1.exec(strRep);
							var obj2=reg2.exec(strRep);
							if (obj1[1]=="disponible" && obj2[1]=="disponible") {
								if (is_sncf==false) {
									modifyAccount(formulaire.nom.value, formulaire.prenom.value, formulaire.email.value.toString().toLowerCase(), formulaire.pass.value, formulaire.societe.value, formulaire.adresse.value, formulaire.cp.value.replace(' ', ''), formulaire.ville.value, formulaire.tel.value, formulaire.adresse_liv.value, formulaire.cp_liv.value.replace(' ', ''), formulaire.ville_liv.value, formulaire.tel_liv.value, formulaire.newsletter.value, theId);
								} else {
									modifyAccountSNCF(formulaire.nom.value, formulaire.prenom.value, formulaire.email.value.toString().toLowerCase(), formulaire.pass.value, formulaire.societe.value, formulaire.adresse.value, formulaire.cp.value.replace(' ', ''), formulaire.ville.value, "", formulaire.adresse_liv.value, formulaire.cp_liv.value.replace(' ', ''), formulaire.ville_liv.value, formulaire.tel_liv.value, formulaire.bupo.value, formulaire.newsletter.value, theId);
								}
							} else {
								if (obj1[1]=="indisponible") {
									alert('cette adresse email est déjà utilisée dans notre base, veuillez en choisir une autre ou utiliser le lien "Mot de passe oublié?" pour en recevoir un nouveau');
								}
								if (obj2[1]=="indisponible") {
									alert('ce mot de passe déjà utilisé dans notre base, veuillez en choisir un autre');
									formulaire.pass.focus();
								}
							}
						} else {
							alert("Une erreur s'est rpoduite lors de votre inscription, veuillez nous contacter au 01 43 07 93 93");
						}
					} else { 
						alert("error: "+xhr.status+" "+xhr.statusText);
					}
				}
			};
			xhr.open("POST", "checkAccount.php", true);
			xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xhr.send(str);
		} else {
			if (is_sncf==false) {
				modifyAccount(formulaire.nom.value, formulaire.prenom.value, formulaire.email.value, formulaire.pass.value, formulaire.societe.value, formulaire.adresse.value, formulaire.cp.value.replace(' ', ''), formulaire.ville.value, formulaire.tel.value, formulaire.adresse_liv.value, formulaire.cp_liv.value.replace(' ', ''), formulaire.ville_liv.value, formulaire.tel_liv.value, formulaire.newsletter.value, theId);
			} else if (is_sncf==true) {
				modifyAccountSNCF(formulaire.nom.value, formulaire.prenom.value, formulaire.email.value, formulaire.pass.value, formulaire.societe.value, formulaire.adresse.value, formulaire.cp.value.replace(' ', ''), formulaire.ville.value, "", formulaire.adresse_liv.value, formulaire.cp_liv.value.replace(' ', ''), formulaire.ville_liv.value, formulaire.tel_liv.value, formulaire.bupo.value, formulaire.newsletter.value, theId);
			}
		}
	}
}
function modifyAccount(nom, prenom, email, pass, societe, adresse, cp, ville, tel, adresse_liv, cp_liv, ville_liv, tel_liv, newsletter, theId) {
	var str="id="+encodeURIComponent(theId)+"&nom="+encodeURIComponent(nom)+"&prenom="+encodeURIComponent(prenom)+"&email="+encodeURIComponent(email)+"&pass="+encodeURIComponent(pass)+"&societe="+encodeURIComponent(societe)+"&adresse="+encodeURIComponent(adresse)+"&cp="+encodeURIComponent(cp)+"&ville="+encodeURIComponent(ville)+"&tel="+encodeURIComponent(tel)+"&adresse_liv="+encodeURIComponent(adresse_liv)+"&cp_liv="+encodeURIComponent(cp_liv)+"&ville_liv="+encodeURIComponent(ville_liv)+"&tel_liv="+encodeURIComponent(tel_liv)+"&newsletter="+encodeURIComponent(newsletter);
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				//alert(xhr.responseText);
				if (xhr.responseText.substr(0,12)=='erreur_mysql') {
					alert('erreur mysql lors de la requete');
				} else if (xhr.responseText.substr(0,12)=='erreur_write') {
					alert('erreur lors de l\'écriture de votre fichier client');
				} else if (xhr.responseText.substr(0,2)=="ok") {
					var reg0=new RegExp('&id=(.*)&mail=');
					var reg1=new RegExp('&mail=(.*)&pass=');
					var reg2=new RegExp('&pass=(.*)&encnom=');
					var reg3=new RegExp('&encnom=(.*)');
					var obj0=reg0.exec(xhr.responseText);
					var obj1=reg1.exec(xhr.responseText);
					var obj2=reg2.exec(xhr.responseText);
					var obj3=reg3.exec(xhr.responseText);
					//alert(obj3[1]);
					var formulaire=document.getElementById("modification_compte");
					formulaire.nom.value="";
					formulaire.prenom.value="";
					formulaire.societe.value="";
					formulaire.email.value="";
					formulaire.pass.value="";
					formulaire.adresse.value="";
					formulaire.cp.value="";
					formulaire.ville.value="";
					formulaire.tel.value="";
					formulaire.adresse_liv.value="";
					formulaire.cp_liv.value="";
					formulaire.ville_liv.value="";
					formulaire.tel_liv.value="";
					alert("les informations de votre compte ont bien été modifiées, vous allez être redirigé(e) vers la page d'accueil dans quelques instants.");
					var strTO='document.location="index.php?id='+obj0[1]+'&connectMail='+obj1[1]+'&connectPass='+obj2[1]+'"';
					setTimeout(strTO, 500);
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "modifyAccount.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function modifyAccountSNCF(nom, prenom, email, pass, societe, adresse, cp, ville, tel, adresse_liv, cp_liv, ville_liv, tel_liv, bupo, newsletter, theId) {
	var str="id="+encodeURIComponent(theId)+"&nom="+encodeURIComponent(nom)+"&prenom="+encodeURIComponent(prenom)+"&email="+encodeURIComponent(email)+"&pass="+encodeURIComponent(pass)+"&societe="+encodeURIComponent(societe)+"&adresse="+encodeURIComponent(adresse)+"&cp="+encodeURIComponent(cp)+"&ville="+encodeURIComponent(ville)+"&tel="+encodeURIComponent(tel)+"&adresse_liv="+encodeURIComponent(adresse_liv)+"&cp_liv="+encodeURIComponent(cp_liv)+"&ville_liv="+encodeURIComponent(ville_liv)+"&tel_liv="+encodeURIComponent(tel_liv)+"&bupo="+encodeURIComponent(bupo)+"&newsletter="+encodeURIComponent(newsletter);
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				//alert(xhr.responseText);
				if (xhr.responseText.substr(0,12)=='erreur_mysql') {
					alert('erreur mysql lors de la requete');
				} else if (xhr.responseText.substr(0,12)=='erreur_write') {
					alert('erreur lors de l\'écriture de votre fichier client');
				} else if (xhr.responseText.substr(0,2)=="ok") {
					var reg0=new RegExp('&id=(.*)&mail=');
					var reg1=new RegExp('&mail=(.*)&pass=');
					var reg2=new RegExp('&pass=(.*)&encnom=');
					var reg3=new RegExp('&encnom=(.*)');
					var obj0=reg0.exec(xhr.responseText);
					var obj1=reg1.exec(xhr.responseText);
					var obj2=reg2.exec(xhr.responseText);
					var obj3=reg3.exec(xhr.responseText);
					//alert(obj3[1]);
					var formulaire=document.getElementById("modification_compte");
					formulaire.nom.value="";
					formulaire.prenom.value="";
					formulaire.societe.value="";
					formulaire.email.value="";
					formulaire.pass.value="";
					formulaire.adresse.value="";
					formulaire.cp.value="";
					formulaire.ville.value="";
					formulaire.tel.value="";
					formulaire.adresse_liv.value="";
					formulaire.cp_liv.value="";
					formulaire.ville_liv.value="";
					formulaire.tel_liv.value="";
					alert("les informations de votre compte ont bien été modifiées, vous allez être redirigé(e) vers la page d'accueil dans quelques instants.");
					var strTO='document.location="index.php?id='+obj0[1]+'&connectMail='+obj1[1]+'&connectPass='+obj2[1]+'"';
					setTimeout(strTO, 500);
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "modifyAccount.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function submitPRM(code) {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		if (disabled==false) {
			panier=Array();
			panier['cat']=Array();
			panier['designationWeb']=Array();
			panier['code']=Array();
			panier['prix_unitaire_HT']=Array();
			panier['prix_unitaire_TTC']=Array();
			panier['quantite']=Array();
			panier['identifiant']=Array();
			var id=Math.random().toString().substr(2);
			if (code=="725") {
				var elmQte=document.getElementById('qte_'+code);
				var qte=parseInt(elmQte.value);
				if (!isNaN(qte) && qte>0) {
					var elmDeW=document.getElementById('deW_'+code);
					var elmPHT=document.getElementById('pHT_'+code);
					var elmPTT=document.getElementById('pTT_'+code);
					panier['identifiant'].push(id+"_main");
					panier['designationWeb'].push(elmDeW.value);
					panier['prix_unitaire_HT'].push(elmPHT.value);
					panier['prix_unitaire_TTC'].push(elmPTT.value);
					panier['quantite'].push(qte);
					panier['code'].push(code);
					var selectEopt=document.getElementById(code+"_MINE").getElementsByTagName("option");
					var selectPopt=document.getElementById(code+"_MINP").getElementsByTagName("option");
					var selectDopt=document.getElementById(code+"_MIND").getElementsByTagName("option");
					for (i=0; i<selectEopt.length; i++) {
						if (selectEopt[i].selected) {
							var deWE=document.getElementById('deW_'+selectEopt[i].value);
							panier['identifiant'].push(id+"_sub");
							panier['designationWeb'].push(deWE.value);
							panier['code'].push(selectEopt[i].value);
							panier['quantite'].push(qte);
							panier['prix_unitaire_HT'].push("0");
							panier['prix_unitaire_TTC'].push("0");
						}
					}
					for (i=0; i<selectPopt.length; i++) {
						if (selectPopt[i].selected) {
							var deWP=document.getElementById('deW_'+selectPopt[i].value);
							panier['identifiant'].push(id+"_sub");
							panier['designationWeb'].push(deWP.value);
							panier['code'].push(selectPopt[i].value);
							panier['quantite'].push(qte);
							panier['prix_unitaire_HT'].push("0");
							panier['prix_unitaire_TTC'].push("0");
						}
					}
					for (i=0; i<selectDopt.length; i++) {
						if (selectDopt[i].selected) {
							var deWD=document.getElementById('deW_'+selectDopt[i].value);
							panier['identifiant'].push(id+"_sub");
							panier['designationWeb'].push(deWD.value);
							panier['code'].push(selectDopt[i].value);
							panier['quantite'].push(qte);
							panier['prix_unitaire_HT'].push("0");
							panier['prix_unitaire_TTC'].push("0");
						}
					}
				}
			} else if (code=="711") {
				var elmQte=document.getElementById('qte_'+code);
				var qte=parseInt(elmQte.value);
				if (!isNaN(qte) && qte>0) {
					var elmDeW=document.getElementById('deW_'+code);
					var elmPHT=document.getElementById('pHT_'+code);
					var elmPTT=document.getElementById('pTT_'+code);
					panier['identifiant'].push(id+"_main");
					panier['designationWeb'].push(elmDeW.value);
					panier['prix_unitaire_HT'].push(elmPHT.value);
					panier['prix_unitaire_TTC'].push(elmPTT.value);
					panier['quantite'].push(qte);
					panier['code'].push(code);
					var selectPopt=document.getElementById(code+"_MINP").getElementsByTagName("option");
					var selectDopt=document.getElementById(code+"_MIND").getElementsByTagName("option");
					for (i=0; i<selectPopt.length; i++) {
						if (selectPopt[i].selected) {
							var deWP=document.getElementById('deW_'+selectPopt[i].value);
							panier['identifiant'].push(id+"_sub");
							panier['designationWeb'].push(deWP.value);
							panier['code'].push(selectPopt[i].value);
							panier['quantite'].push(qte);
							panier['prix_unitaire_HT'].push("0");
							panier['prix_unitaire_TTC'].push("0");
						}
					}
					for (i=0; i<selectDopt.length; i++) {
						if (selectDopt[i].selected) {
							var deWD=document.getElementById('deW_'+selectDopt[i].value);
							panier['identifiant'].push(id+"_sub");
							panier['designationWeb'].push(deWD.value);
							panier['code'].push(selectDopt[i].value);
							panier['quantite'].push(qte);
							panier['prix_unitaire_HT'].push("0");
							panier['prix_unitaire_TTC'].push("0");
						}
					}
				}
			} else {
				var elmQte=document.getElementById('qte_'+code);
				var qte=parseInt(elmQte.value);
				if (!isNaN(qte) && qte>0) {
					var elmDeW=document.getElementById('deW_'+code);
					var elmPHT=document.getElementById('pHT_'+code);
					var elmPTT=document.getElementById('pTT_'+code);
					panier['identifiant'].push(id);
					panier['designationWeb'].push(elmDeW.value);
					panier['prix_unitaire_HT'].push(elmPHT.value);
					panier['prix_unitaire_TTC'].push(elmPTT.value);
					panier['quantite'].push(qte);
					panier['code'].push(code);
				}
			}
			if (panier['code'].length>0) {
				var str="action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
				var xhr = null;
				if (window.XMLHttpRequest || window.ActiveXObject) {
					if (window.ActiveXObject) {
						try {
							xhr = new ActiveXObject("Msxml2.XMLHTTP");
						} catch(e) {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");
						}
					} else {
						xhr = new XMLHttpRequest(); 
					}
				} else {
					alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
					return;
				}
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4) {
						if (xhr.status == 200 || xhr.status == 0) {
							var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
							if (!isNaN(parseInt(str)) && parseInt(str)>0) {
								if (parseInt(str)>1) {
									document.getElementById('nb_panier').innerHTML=str+" articles";
								} else {
									document.getElementById('nb_panier').innerHTML=str+" article";
								}
								afficheAjoutPanier(parseInt(str), code);
							} else {
								if (str=="vide") {
									document.getElementById('nb_panier').innerHTML=str;
								}
							}
						} else { 
							alert("error: "+xhr.status+" "+xhr.statusText);
						}
					}
				};
				xhr.open("POST", "fonctions-panier.php", true);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.send(str);
			}
		}
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function afficheAjoutPanier(nb, code) {
	document.getElementById('ajout_'+code).innerHTML='votre <a href="panier.php" target="_self">panier</a> contient désormais '+nb+' produits';
	$('#ajout_'+code).animate({
		opacity:1,
		height:40
	});
}
function reEnable() {
	disabled=false;
}
function addToBasket() {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		if (disabled==false) {
			panier=Array();
			panier['cat']=Array();
			panier['designationWeb']=Array();
			panier['code']=Array();
			panier['prix_unitaire_HT']=Array();
			panier['prix_unitaire_TTC']=Array();
			panier['quantite']=Array();
			panier['identifiant']=Array();
			var designationsWeb=Array();
			var inputs=document.getElementsByTagName('input');
			for (i=0; i<inputs.length; i++) {
				if (inputs[i].name.substr(0,3)=="qte") {
					if (!isNaN(parseInt(inputs[i].value)) && parseInt(inputs[i].value)>0) {
						var id=Math.random().toString().substr(2);
						panier['cat'].push(cat);
						panier['identifiant'].push(id+"_main");
						panier['code'].push(inputs[i].name.substr(4));
						panier['quantite'].push(inputs[i].value);
					}
				}
			}
			for (i=0; i<inputs.length; i++) {
				for (j=0; j<panier['code'].length; j++) {
					if (inputs[i].name=="deW_"+panier['code'][j]) {
						panier['designationWeb'][j]=inputs[i].value;
					} else if (inputs[i].name=="pHT_"+panier['code'][j]) {
						panier['prix_unitaire_HT'][j]=inputs[i].value;
					} else if (inputs[i].name=="pTT_"+panier['code'][j]) {
						panier['prix_unitaire_TTC'][j]=inputs[i].value;
					}
				}
			}
			if (panier['code'].length>0) {
				var str="action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
				var xhr = null;
				if (window.XMLHttpRequest || window.ActiveXObject) {
					if (window.ActiveXObject) {
						try {
							xhr = new ActiveXObject("Msxml2.XMLHTTP");
						} catch(e) {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");
						}
					} else {
						xhr = new XMLHttpRequest(); 
					}
				} else {
					alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
					return;
				}
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4) {
						if (xhr.status == 200 || xhr.status == 0) {
							var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
							//alert(str);
							if (!isNaN(parseInt(str)) && parseInt(str)>0) {
								if (parseInt(str)>1) {
									document.getElementById('nb_panier').innerHTML=str+" articles";
								} else {
									document.getElementById('nb_panier').innerHTML=str+" article";
								}
								afficheAjoutPanier(parseInt(str) , "none");
							}
						} else { 
							alert("error: "+xhr.status+" "+xhr.statusText);
						}
					}
				};
				xhr.open("POST", "fonctions-panier.php", true);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.send(str);
			} else alert("Veuillez entrer une quantité pour au moins un produit");
		}
		disabled=true;
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function addBOISToBasket() {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		if (disabled==false) {
			panier=Array();
			panier['cat']=Array();
			panier['designationWeb']=Array();
			panier['code']=Array();
			panier['prix_unitaire_HT']=Array();
			panier['prix_unitaire_TTC']=Array();
			panier['quantite']=Array();
			panier['identifiant']=Array();
			panier['type']=Array();
			var designationsWeb=Array();
			var inputs=document.getElementsByTagName('input');
			for (i=0; i<inputs.length; i++) {
				if (inputs[i].name.substr(0,3)=="qte") {
					if (!isNaN(parseInt(inputs[i].value)) && parseInt(inputs[i].value)>0) {
						var id=Math.random().toString().substr(2);
						panier['cat'].push(cat);
						panier['identifiant'].push(id);
						panier['code'].push(inputs[i].name.substr(4));
						panier['quantite'].push(inputs[i].value);
					}
				}
			}
			for (i=0; i<inputs.length; i++) {
				for (j=0; j<panier['code'].length; j++) {
					if (inputs[i].name=="deW_"+panier['code'][j]) {
						panier['designationWeb'][j]=inputs[i].value;
					} else if (inputs[i].name=="type_"+panier['code'][j]) {
						panier['type'][j]=inputs[i].value;
					} else if (inputs[i].name=="pHT_"+panier['code'][j]) {
						panier['prix_unitaire_HT'][j]=inputs[i].value;
					} else if (inputs[i].name=="pTT_"+panier['code'][j]) {
						panier['prix_unitaire_TTC'][j]=inputs[i].value;
					}
				}
			}
			if (panier['code'].length>0) {
				var str="action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']))+"&type="+encodeURIComponent(implode('___', panier['type']));
				//alert (str);
				var xhr = null;
				if (window.XMLHttpRequest || window.ActiveXObject) {
					if (window.ActiveXObject) {
						try {
							xhr = new ActiveXObject("Msxml2.XMLHTTP");
						} catch(e) {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");
						}
					} else {
						xhr = new XMLHttpRequest(); 
					}
				} else {
					alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
					return;
				}
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4) {
						if (xhr.status == 200 || xhr.status == 0) {
							var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
							if (!isNaN(parseInt(str)) && parseInt(str)>0) {
								if (parseInt(str)>1) {
									document.getElementById('nb_panier').innerHTML=str+" articles";
								} else {
									document.getElementById('nb_panier').innerHTML=str+" article";
								}
								afficheAjoutPanier(parseInt(str) , "none");
							}
						} else { 
							alert("error: "+xhr.status+" "+xhr.statusText);
						}
					}
				};
				xhr.open("POST", "fonctions-panier.php", true);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.send(str);
			} else alert("Veuillez entrer une quantité pour au moins un produit");
		}
		disabled=true;
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function selDessert(DEGCcode) {
	//alert(totalQuantityPRT);
	if (totalQuantityPRT>0) {
		if (arrDEGC.length>=2 && arrDEGC.indexOf(DEGCcode)==-1) {
			alert("Vous devez choisir les desserts parmi les deux que vous avez déjà sélectionnés.");
		} else if (arrDEGC.length==1) {
			var division=document.getElementById("dess_"+DEGCcode);
			if (arrDess.length==1) {
				if (arrDEGC.indexOf(DEGCcode)!=-1) {
					twoDessChosen=true;
					division.innerHTML='choisissez une quantité pour ce dessert : <input type="text" id="number_'+DEGCcode+'" name="number_'+DEGCcode+'" value="'+(totalQuantityPRT-parseInt(numberDess['qte'][0]))+'" style="width:30px; border:0px solid white;" onchange="changeNumberDess(\''+DEGCcode+'\');"/>';
					numberDess['code'].push(DEGCcode);
					numberDess['qte'].push(totalQuantityPRT-parseInt(numberDess['qte'][0]));
					arrDess.push(DEGCcode);
				} else {
					alert("Vous devez choisir les desserts parmi les deux que vous avez déjà sélectionnés.");
				}
			} else {
				division.innerHTML='choisissez une quantité pour ce dessert : <input type="text" id="number_'+DEGCcode+'"name="number_'+DEGCcode+'" value="" style="width:30px; border:0px solid white;" onchange="changeNumberDess(\''+DEGCcode+'\');"/>';
				openedDess=DEGCcode;
				numberDess['qte'][0]=0;
				numberDess['code'][0]=DEGCcode;
				arrDess.push(DEGCcode);
			}
		} else {
			var division=document.getElementById("dess_"+DEGCcode);
			if (arrDess.length==2) {
				var oldDivision=document.getElementById("dess_"+arrDess[0]);
				oldDivision.innerHTML='';
				arrDess.splice(0,1);
				numberDess['code'].splice(0, 1);
				numberDess['qte'].splice(0, 1);
				division.innerHTML='choisissez une quantité pour ce dessert : <input type="text" id="number_'+DEGCcode+'" name="number_'+DEGCcode+'" value="'+(totalQuantityPRT-parseInt(numberDess['qte'][0]))+'" style="width:30px; border:0px solid white;" onchange="changeNumberDess(\''+DEGCcode+'\');"/>';
				numberDess['code'].push(DEGCcode);
				numberDess['qte'].push(totalQuantityPRT-parseInt(numberDess['qte'][0]));
				arrDess.push(DEGCcode);
			} else if (arrDess.length==1) {
				twoDessChosen=true;
				division.innerHTML='choisissez une quantité pour ce dessert : <input type="text" id="number_'+DEGCcode+'" name="number_'+DEGCcode+'" value="'+(totalQuantityPRT-parseInt(numberDess['qte'][0]))+'" style="width:30px; border:0px solid white;" onchange="changeNumberDess(\''+DEGCcode+'\');"/>';
				numberDess['code'].push(DEGCcode);
				numberDess['qte'].push(totalQuantityPRT-parseInt(numberDess['qte'][0]));
				arrDess.push(DEGCcode);
			} else if (arrDess.length==0) {
				division.innerHTML='choisissez une quantité pour ce dessert : <input type="text" id="number_'+DEGCcode+'"name="number_'+DEGCcode+'" value="" style="width:30px; border:0px solid white;" onchange="changeNumberDess(\''+DEGCcode+'\');"/>';
				openedDess=DEGCcode;
				arrDess.push(DEGCcode);
				numberDess['qte'][0]=0;
				numberDess['code'][0]=DEGCcode;
			}
		}
	} else {
		alert("Merci de sélectionner d'abord vos plateaux.");
	}
}
function changeNumberDess(code) {
	//alert(arrDess);
	if (arrDess.length<2) {
		if (arrDess.indexOf(code)==-1) {
			if (parseInt(document.getElementById("number_"+code).value)<=totalQuantityPRT) {
				numberDess['qte'].push(document.getElementById("number_"+code).value);
				numberDess['code'].push(code);
			} else {
				numberDess['qte'].push(totalQuantityPRT);
				numberDess['code'].push(code);
				document.getElementById("number_"+code).value=totalQuantityPRT;
			}
		} else {
			if (parseInt(document.getElementById("number_"+code).value)<=totalQuantityPRT) {
				numberDess['qte'][numberDess['code'].indexOf(code)]=document.getElementById("number_"+code).value;
			} else {
				numberDess['qte'][numberDess['code'].indexOf(code)]=totalQuantityPRT;
				document.getElementById("number_"+code).value=totalQuantityPRT;
			}
		}
	} else if (arrDess.length==2) {
		for (i=0; i<arrDess.length; i++) {
			if (parseInt(code)!=parseInt(arrDess[i])) {
				if (parseInt(document.getElementById("number_"+code).value)<totalQuantityPRT && parseInt(document.getElementById("number_"+code).value)>0) {
					numberDess['code'][i]=arrDess[i];
					var elmnumber=document.getElementById("number_"+code);
					numberDess['qte'][i]=(totalQuantityPRT-parseInt(elmnumber.value));
					var inputNumber=document.getElementById("number_"+arrDess[i].toString());
					inputNumber.value=totalQuantityPRT-parseInt(elmnumber.value);
					numberDess['code'][1-i]=code;
					numberDess['qte'][1-i]=parseInt(elmnumber.value);
				} else if (parseInt(document.getElementById("number_"+code).value)>=totalQuantityPRT) {
					var division=document.getElementById("dess_"+arrDess[i]);
					division.innerHTML="";
					numberDess['code'][0]=numberDess['code'][1-i];
					numberDess['qte'][0]=totalQuantityPRT;
					numberDess['code'].splice(1,1);
					numberDess['qte'].splice(1,1);
					document.getElementById("number_"+code).value=totalQuantityPRT;
				} else if (parseInt(document.getElementById("number_"+code).value)<=0) {
					var division=document.getElementById("dess_"+code);
					division.innerHTML="";
					numberDess['code'][0]=numberDess['code'][i];
					numberDess['qte'][0]=totalQuantityPRT;
					numberDess['code'].splice(1,1);
					numberDess['qte'].splice(1,1);
					document.getElementById("number_"+numberDess['code'][i]).value=totalQuantityPRT;
				}
			}
		}
	}
	openedDess="";
}
function updateQtePRT() {
	var inputs=document.getElementsByTagName('input');
	totalQuantityPRT=0;
	for (i=0; i<inputs.length; i++) {
		if (inputs[i].name.substr(0,3)=="qte") {
			if (!isNaN(parseInt(inputs[i].value))) {
		 		totalQuantityPRT+=parseInt(inputs[i].value);
			}
		}
	}
	//alert(totalQuantityPRT);
}
function addPRTToBasket() {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		if (disabled==false) {
			panier=Array();
			panier['cat']=Array();
			panier['designationWeb']=Array();
			panier['code']=Array();
			panier['prix_unitaire_HT']=Array();
			panier['prix_unitaire_TTC']=Array();
			panier['quantite']=Array();
			panier['identifiant']=Array();
			var designationsWeb=Array();
			var mainQte=0;
			var inputs=document.getElementsByTagName('input');
			var id=Math.random().toString().substr(2);
			for (i=0; i<inputs.length; i++) {
				if (inputs[i].name.substr(0,3)=="qte" && inputs[i].name.substr(0,8)!="qte_optn") {
					if (!isNaN(parseInt(inputs[i].value)) && parseInt(inputs[i].value)>0) {
						panier['cat'].push("Les plateaux repas tradition");
						panier['identifiant'].push(id+"_main");
						panier['code'].push(inputs[i].name.substr(4));
						panier['quantite'].push(inputs[i].value);
						mainQte+=parseInt(inputs[i].value);
					}
				}
			}
			TotalDess=0;
			DEGC=new Array();
			for (i=0; i<numberDess['code'].length; i++) {
				panier['cat'].push("Les plateaux repas tradition");
				panier['identifiant'].push(id+"_sub");
				panier['code'].push(numberDess['code'][i]);
				panier['quantite'].push(numberDess['qte'][i]);
				DEGC.push(numberDess['code'][i]);
				if (arrDEGC.indexOf(numberDess['code'][i])==-1) {
					arrDEGC.push(numberDess['code'][i]);
				}
				TotalDess+=parseInt(numberDess['qte'][i]);
			}
			var optionsAnnulees=0;
			for (i=0; i<inputs.length; i++) {
				if (inputs[i].name.substr(0,8)=="qte_optn") {
					if (!isNaN(parseInt(inputs[i].value)) && parseInt(inputs[i].value)>0) {
						var countOPT=0;
						for (j=0; j<countOPTS.length; j++) {
							if (countOPTS[j].substr(0, countOPTS[j].indexOf("_"))==inputs[i].name.substr(9)) {
								countOPT+=countOPTS[j].substr(countOPTS[j].indexOf("_")+1);
							}
						}
						if (mainQte+countPRT-countOPT>=parseInt(inputs[i].value)) {
							var deW=document.getElementById("deW_"+inputs[i].name.substr(9));
							if (deW.value.toLowerCase().indexOf("carte noire")!=-1) {
								if (postalCode=="75011" || postalCode=="75012" || postalCode=="75020") {
									if (parseInt(inputs[i].value)>=15) {
										panier['cat'].push("Les plateaux repas tradition");
										panier['identifiant'].push(id+"_opt_"+deW.value);
										panier['code'].push(inputs[i].name.substr(9));
										panier['quantite'].push(inputs[i].value);
									} else {
										alert("la quantité minimum pour l'option café carte noire est de 15, nous sommes désolés!");
										inputs[i].focus();
										return false;
									}
								} else {
									alert("votre localisation ne vous donne pas droit à l'option café carte noire, nous sommes désolés!");
									return false;
								}
							} else {
								panier['cat'].push("Les plateaux repas tradition");
								panier['identifiant'].push(id+"_opt_"+deW.value);
								panier['code'].push(inputs[i].name.substr(9));
								panier['quantite'].push(inputs[i].value);
							}
						} else {
							alert("une option a été prise en plus grand nombre que le nombre total de plateaux choisis!");
							inputs[i].focus();
							return false;
						}
					}
				}
			}
			for (i=0; i<inputs.length; i++) {
				for (j=0; j<panier['code'].length; j++) {
					if (inputs[i].name=="deW_"+panier['code'][j]) {
						panier['designationWeb'][j]=inputs[i].value;
					} else if (inputs[i].name=="pHT_"+panier['code'][j]) {
						panier['prix_unitaire_HT'][j]=fix(parseFloat(inputs[i].value));
					} else if (inputs[i].name=="pTT_"+panier['code'][j]) {
						panier['prix_unitaire_TTC'][j]=fix(parseFloat(inputs[i].value));
					}
				}
			}
			//alert(TotalDess+"_"+totalQuantityPRT);
			if (panier['code'].length>0 && (totalQuantityPRT>0 && TotalDess==totalQuantityPRT) || (totalQuantityPRT==0)) {
				var str="DEGC="+encodeURIComponent(implode('|', DEGC))+"&action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
				//alert(str);
				var xhr = null;
				if (window.XMLHttpRequest || window.ActiveXObject) {
					if (window.ActiveXObject) {
						try {
							xhr = new ActiveXObject("Msxml2.XMLHTTP");
						} catch(e) {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");
						}
					} else {
						xhr = new XMLHttpRequest(); 
					}
				} else {
					alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
					return;
				}
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4) {
						if (xhr.status == 200 || xhr.status == 0) {
							var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
							if (!isNaN(parseInt(str)) && parseInt(str)>0) {
								if (parseInt(str)>1) {
									document.getElementById('nb_panier').innerHTML=str+" articles";
								} else {
									document.getElementById('nb_panier').innerHTML=str+" article";
								}
								afficheAjoutPanier(parseInt(str) , "none");
							}
						} else { 
							alert("error: "+xhr.status+" "+xhr.statusText);
						}
					}
				};
				xhr.open("POST", "fonctions-panier.php", true);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.send(str);
			} else {
				alert("votre panier ne peut pas être validé. vous devez choisir plateaux plus desserts et/ou options");
			}
		}
		disabled=true;
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function actionPMXTOPT(index) {
	if (PMXTOPT[index]=="off") {
		expandPMXTOPT(index);
	} else if (PMXTOPT[index]=="on") {
		reducePMXTOPT(index);
	}
}
function expandPMXTOPT(index) {
	$("#"+index).animate({
		height:document.getElementById('__'+index).offsetHeight+25
	}, 500);
	document.getElementById('img'+index).src="media/fleche_reduce.png";
	PMXTOPT[index]="on";
}
function reducePMXTOPT(index) {
	$("#"+index).animate({
		height:25
	}, 500);
	document.getElementById('img'+index).src="media/fleche_expand.png";
	PMXTOPT[index]="off";
}
function choosePMXT(code, index) {
	var deW=document.getElementById('deW_'+code);
	var pHT=document.getElementById('pHT_'+code);
	var pTT=document.getElementById('pTT_'+code);
	PMXT['code'][parseInt(index)]=code;
	PMXT['deW'][parseInt(index)]=deW.value;
	PMXT['pHT'][parseInt(index)]=pHT.value;
	PMXT['pTT'][parseInt(index)]=pTT.value;
	document.getElementById('__-_'+index).style.opacity=1;
	document.getElementById('__-_'+index).innerHTML="> "+deW.value;
	$("#_-_"+index).animate({
		height:25
	}, 500);
	document.getElementById('img_-_'+index).src="media/fleche_expand.png";
	PMXTOPT['_-_'+index]="off";
}
function addPMXTToBasket(code) {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		if (disabled==false) {
			var qteField=document.getElementById("qte_PMXT");
			var qte=qteField.value;
			var id=Math.random().toString().substr(2);
			var deW=document.getElementById('deW_'+code);
			var pHT=document.getElementById('pHT_'+code);
			var pTT=document.getElementById('pTT_'+code);
			panier=Array();
			panier['cat']=Array();
			panier['designationWeb']=Array();
			panier['code']=Array();
			panier['prix_unitaire_HT']=Array();
			panier['prix_unitaire_TTC']=Array();
			panier['quantite']=Array();
			panier['identifiant']=Array();
			panier['cat'].push("Les paniers mixtes");
			panier['identifiant'].push(id+"_main");
			panier['code'].push(parseInt(code));
			panier['quantite'].push(qte);
			panier['designationWeb'].push(deW.value);
			var pHTtmp=parseFloat(pHT.value);
			var pTTtmp=parseFloat(pTT.value);
			for (i=0; i<PMXT['code'].length; i++) {
				if (parseFloat(PMXT['pHT'][i])>0) {
					pHTtmp+=parseFloat(PMXT['pHT'][i]);
					PMXT['pHT'][i]="0";
				}
				if (parseFloat(PMXT['pTT'][i])>0) {
					pTTtmp+=parseFloat(PMXT['pTT'][i]);
					PMXT['pTT'][i]="0";
				}
			}
			pHTtmp=fix(pHTtmp);
			pTTtmp=fix(pTTtmp);
			panier['prix_unitaire_HT'].push(pHTtmp);
			panier['prix_unitaire_TTC'].push(pTTtmp);
			if (PMXT['code'].length==5) {
				if (parseInt(qte)>0) {
					for (i=0; i<PMXT['code'].length; i++) {
						if (PMXT['deW'][i]!="" && PMXT['pHT'][i]!="" && PMXT['pTT'][i]!="") {
							panier['cat'].push("Les paniers mixtes");
							panier['identifiant'].push(id+"_sub");
							panier['code'].push(PMXT['code'][i]);
							panier['quantite'].push(qte);
							panier['designationWeb'].push(PMXT['deW'][i]);
							panier['prix_unitaire_HT'].push(PMXT['pHT'][i]);
							panier['prix_unitaire_TTC'].push(PMXT['pTT'][i]);
						}
					}
					if (panier['code'].length>0) {
						var str="action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
						var xhr = null;
						if (window.XMLHttpRequest || window.ActiveXObject) {
							if (window.ActiveXObject) {
								try {
									xhr = new ActiveXObject("Msxml2.XMLHTTP");
								} catch(e) {
									xhr = new ActiveXObject("Microsoft.XMLHTTP");
								}
							} else {
								xhr = new XMLHttpRequest(); 
							}
						} else {
							alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
							return;
						}
						xhr.onreadystatechange = function() {
							if (xhr.readyState == 4) {
								if (xhr.status == 200 || xhr.status == 0) {
									//alert(xhr.responseText);
									var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
									if (!isNaN(parseInt(str)) && parseInt(str)>0) {
										if (parseInt(str)>1) {
											document.getElementById('nb_panier').innerHTML=str+" articles";
										} else {
											document.getElementById('nb_panier').innerHTML=str+" article";
										}
										afficheAjoutPanier(parseInt(str) , "none");
										clearPMXTChoice1();
									}
								} else { 
									alert("error: "+xhr.status+" "+xhr.statusText);
								}
							}
						};
						xhr.open("POST", "fonctions-panier.php", true);
						xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
						xhr.send(str);
					}
				} else alert("indiquer une quantité pour ce panier mixte");
			} else alert("merci de terminer votre sélection avant de commander");
		}
		disabled=true;
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function clearPMXTChoice1() {
	var qteField=document.getElementById("qte_PMXT");
	qteField.value="";
	PMXT['code']=Array();
	PMXT['deW']=Array();
	PMXT['pHT']=Array();
	PMXT['pTT']=Array();
	for (var i=0; i<5; i++) {
		var theId='__-_'+i;
		$("#__-_"+i).animate({
			opacity:0
		}, 500, clearPMXTChoice2(theId));
	}
}
function clearPMXTChoice2(theId) {
	var theNode=document.getElementById(theId);
	theNode.innerHTML="";
	theNode.style.opacity=1;
}
function heureDej() {
	var selArr=document.getElementById("selArr");
	if (selArr) {
		var opts=selArr.getElementsByTagName("option");
		for (var i=0; i<opts.length; i++) {
			if (opts[i].selected==true) {
				alert("les frais de livraison seront de "+opts[i].value+" €");
				livDej=opts[i].value;
			}
		}
	}
}
function expandPDEJ() {
	$("#pdej_li").animate({
		height:document.getElementById('pdej_liste').offsetHeight+25
	}, 500);
}
function updateQtePDEJ() {
	var inputs=document.getElementsByTagName('input');
	totalQuantityPDEJ=0;
	//alert(minimumDej);
	for (i=0; i<inputs.length; i++) {
		if (inputs[i].id=="qtedej_1000") {
			if (!isNaN(parseInt(inputs[i].value)) && parseInt(inputs[i].value)>0) {
				if ((parseInt(minimumDej)==10 || parseInt(minimumDej)==20) && codeAuth==false) {
					if (parseInt(inputs[i].value)<parseInt(minimumDej)) {
						alert("la quantité est inférieure à "+minimumDej+", elle va être corrigée.");
						inputs[i].value=minimumDej;
					}
					totalQuantityPDEJ+=parseInt(inputs[i].value);
					authDej=true;
				} else {
					if (codeAuth==false) {
						if (minimumDej=="outside") alert("vous habitez hors des zones où nous livrons les petits déjeuners, merci de nous téléphoner pour obtenir un code d'accès");
						if (minimumDej=="nolog") alert("vous n'êtes pas identifié, nous ne pouvons calculer le minimum de petits déjeuners à commander en fonction de votre localisation.");
					} else {
						if (codeAuth==true) {
							totalQuantityPDEJ+=parseInt(inputs[i].value);
							authDej=true;
						}
					}
				}
			}
		}
	}
	if (authDej==true) {
	updateQteOptPDEJ('none');
	}
}
function updateQteOptPDEJ(code) {
	if (authDej==true) {
		var PDEJ=document.getElementById("qtedej_1000");
		totalQuantityPDEJ=parseInt(PDEJ.value);
		var qteOptChosen=0;
		var inputs=document.getElementsByTagName('input');
		var totalQuantityOptPDEJ=0;
		if (code!="none") {
			for (i=0; i<inputs.length; i++) {
				if (inputs[i].id.substr(0,6)=="qteopt") {
					if (!isNaN(parseInt(inputs[i].value))) {
						qteOptChosen++;
						totalQuantityOptPDEJ+=parseInt(inputs[i].value);
					}
				}
			}
			var toAdd=0;
			var notModified=0;
			if (qteOptChosen==1) {
				totalQuantityOptPDEJ=0;
				for (i=0; i<inputs.length; i++) {
					if (inputs[i].id.substr(0,6)=="qteopt") {
						if (!isNaN(parseInt(inputs[i].value))) {
							if (parseInt(inputs[i].value)<5) {
								alert("une quantité de thé ou de café est inférieure à cinq, elle va être corrigée.");
								inputs[i].value="5";
							}
							if (parseInt(inputs[i].value)>totalQuantityPDEJ) {
								alert("une quantité de thé ou de café est supérieure à la quantité totale, elle va être corrigée.");
								inputs[i].value=totalQuantityPDEJ;
							}
							totalQuantityOptPDEJ+=parseInt(inputs[i].value);
						}
					}
				}
			} else if (qteOptChosen==2) {
				var modified=false;
				var qteAutre=0;
				var qteSel=0;
				if (totalQuantityPDEJ>=10) {
					for (i=0; i<inputs.length; i++) {
						if (inputs[i].id.substr(0,6)=="qteopt") {
							if (inputs[i].id.substr(7)==code) {
								qteSel=parseInt(inputs[i].value);
							}
						}
					}
					for (i=0; i<inputs.length; i++) {
						if (inputs[i].id.substr(0,6)=="qteopt") {
							if (inputs[i].id.substr(7)!=code) {
								if (totalQuantityPDEJ-qteAutre>=5) {
									inputs[i].value=totalQuantityPDEJ-qteSel;
									newqteSel=qteSel;
									modified=true;
								} else {
									inputs[i].value="5";
									newqteSel=totalQuantityPDEJ-5;
								}
							}
						}
					}
					if (newQteAutre!=qteAutre) {
						for (i=0; i<inputs.length; i++) {
							if (inputs[i].id.substr(0,6)=="qteopt") {
								if (inputs[i].id.substr(7)==code) {
									inputs[i].value=newqteSel;
									modified=true;
								}
							}
						}
					}
					if (modified==true) {
						alert("nous corrigeons votre choix de quantités pour qu'il corresponde au nombre de petits déjeuners");
					}
				} else {
					alert("vous devez d'abord choisir une quantité de petits déjeuners");
				}
			}
		} else {
			for (i=0; i<inputs.length; i++) {
				if (inputs[i].id.substr(0,6)=="qteopt") {
					if (!isNaN(parseInt(inputs[i].value))) {
						qteOptChosen++;
						if (parseInt(inputs[i].value)<5) {
							alert("une quantité de thé ou de café est inférieure à cinq, elle va être corrigée.");
							inputs[i].value="5";
						}
						totalQuantityOptPDEJ+=parseInt(inputs[i].value);
					}
				}
			}
			if (totalQuantityOptPDEJ>0) {
				if (totalQuantityOptPDEJ<totalQuantityPDEJ || totalQuantityOptPDEJ>totalQuantityPDEJ) {
					toAdd=totalQuantityPDEJ-totalQuantityOptPDEJ;
					i=0;
					modified=false;
					while(i<inputs.length) {
						if (inputs[i].id.substr(0,6)=="qteopt") {
							if (!isNaN(parseInt(inputs[i].value))) {
								if (toAdd<0) {
									if (parseInt(inputs[i].value)-1>=5) {
										inputs[i].value=parseInt(inputs[i].value)-1;
										toAdd+=1;
										modified=true;
									}
								} else if (toAdd>0) {
									inputs[i].value=parseInt(inputs[i].value)+1;
									toAdd-=1;
									modified=true;
								}
							}
						}
						i++;
						if (i==inputs.length-1 && toAdd!=0)  {
							i=0;
						}
					}
					if (modified==true) {
						alert("nous corrigeons votre choix de quantités pour qu'il corresponde au nombre de petits déjeuners");
					}
				}
			}
		}
	} else {
		alert("vous n'êtes pas autorisé à commander des petits déjeuners, veuillez nous contacter  au  01 43 07 93 93 si vous souhaitez obtenir un code d'autorisation");
	}
}
function prixHorsTaxes(montant) {
	return fix(Math.round(montant/1.07*100)*0.01);
}
function addPTDToBasket(code) {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		var id=Math.random().toString().substr(2);
		if (disabled==false) {
			if (livDej!=-1 && authDej!=false) {
				var inputs=document.getElementsByTagName('input');
				var panier=Array();
				var deW;
				var pHT;
				var pTT;
				var deWbis;
				var pHTbis;
				var pTTbis;
				var codeBis;
				var deWter;
				var pHTter;
				var pTTter;
				var codeTer;
				var idBis;
				var main=false;
				panier['cat']=Array();
				panier['designationWeb']=Array();
				panier['code']=Array();
				panier['prix_unitaire_HT']=Array();
				panier['prix_unitaire_TTC']=Array();
				panier['quantite']=Array();
				panier['identifiant']=Array();
				for (i=0; i<inputs.length; i++) {
					if (inputs[i].id=="qtedej_"+code) {
						if (!isNaN(parseInt(inputs[i].value)) && parseInt(inputs[i].value)>0) {
							var deW=document.getElementById('deW_'+code);
							var pHT=document.getElementById('pHT_'+code);
							var pTT=document.getElementById('pTT_'+code);
							panier['cat'].push("Les petits déjeuners");
							panier['identifiant'].push(id+"_main");
							panier['code'].push(parseInt(code));
							panier['quantite'].push(parseInt(inputs[i].value));
							panier['designationWeb'].push(deW.value);
							panier['prix_unitaire_HT'].push(pHT.value);
							panier['prix_unitaire_TTC'].push(pTT.value);
							main=true;
						}
					} else if (inputs[i].id.substr(0,6)=="qteopt") {
						if (!isNaN(parseInt(inputs[i].value)) && parseInt(inputs[i].value)>0) {
							codeBis=inputs[i].id.substr(inputs[i].id.indexOf("_")+1);
							panier['cat'].push("Les petits déjeuners");
							panier['identifiant'].push(id+"_sub");
							panier['code'].push(parseInt(codeBis));
							panier['quantite'].push(parseInt(inputs[i].value));
							deWbis=document.getElementById('deW_'+codeBis);
							pHTbis=document.getElementById('pHT_'+codeBis);
							pTTbis=document.getElementById('pTT_'+codeBis);
							panier['designationWeb'].push(deWbis.value);
							panier['prix_unitaire_HT'].push(pHTbis.value);
							panier['prix_unitaire_TTC'].push(pTTbis.value);
						}
					} else if (inputs[i].id.substr(0,7)=="qtedej_") {
						if (main==true) {
							if (!isNaN(parseInt(inputs[i].value)) && parseInt(inputs[i].value)>0) {
								codeTer=inputs[i].id.substr(inputs[i].id.indexOf("_")+1);
								panier['cat'].push("Les petits déjeuners");
								panier['identifiant'].push(id+"_opt");
								panier['code'].push(parseInt(codeTer));
								panier['quantite'].push(parseInt(inputs[i].value));
								deWbis=document.getElementById('deW_'+codeTer);
								pHTbis=document.getElementById('pHT_'+codeTer);
								pTTbis=document.getElementById('pTT_'+codeTer);
								panier['designationWeb'].push(deWbis.value);
								panier['prix_unitaire_HT'].push(pHTbis.value);
								panier['prix_unitaire_TTC'].push(pTTbis.value);
							}
						} else {
							alert("la commande d'options seules est impossible");
						}
					}
				}
				if (main==true) {
					var idBis=Math.random().toString().substr(2);
					panier['cat'].push("Livraison petits déjeuners");
					panier['identifiant'].push(idBis+"_liv");
					panier['code'].push(parseInt("9990"));
					panier['quantite'].push("1");
					panier['designationWeb'].push("Livraison petits déjeuners");
					panier['prix_unitaire_HT'].push(prixHorsTaxes(parseInt(livDej)));
					panier['prix_unitaire_TTC'].push(livDej);
				}
				if (panier['code'].length>0) {
					var str="action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
					//alert(str);
					var xhr = null;
					if (window.XMLHttpRequest || window.ActiveXObject) {
						if (window.ActiveXObject) {
							try {
								xhr = new ActiveXObject("Msxml2.XMLHTTP");
							} catch(e) {
								xhr = new ActiveXObject("Microsoft.XMLHTTP");
							}
						} else {
							xhr = new XMLHttpRequest(); 
						}
					} else {
						alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
						return;
					}
					xhr.onreadystatechange = function() {
						if (xhr.readyState == 4) {
							if (xhr.status == 200 || xhr.status == 0) {
									//alert(xhr.responseText);
								var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
								if (!isNaN(parseInt(str)) && parseInt(str)>0) {
									if (parseInt(str)>1) {
										document.getElementById('nb_panier').innerHTML=str+" articles";
									} else {
										document.getElementById('nb_panier').innerHTML=str+" article";
									}
									afficheAjoutPanier(parseInt(str) , "none");
								}
							} else { 
								alert("error: "+xhr.status+" "+xhr.statusText);
							}
						}
					};
					xhr.open("POST", "fonctions-panier.php", true);
					xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xhr.send(str);
				}
			} else {
				alert("vous n'avez pas choisi d'horaire de livraison ou la livraison est refusée sur votre arrondissement.");
			}
		}
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function actionMENUOPT(index) {
	if (MENUOPT[index]=="off") {
		expandMENUOPT(index);
	} else if (MENUOPT[index]=="on") {
		reduceMENUOPT(index);
	}
}
function expandMENUOPT(index) {
	MENUOPT[index]="on";
	var theList=document.getElementById("__"+index);
	theList.innerHTML="";
	for (i=0; i<theListData[index].length; i++) {
		theList.innerHTML+=theListData[index][i];
	}
	$("#"+index).animate({
		height:document.getElementById('__'+index).offsetHeight+25
	}, 500, function () {
		document.getElementById('img'+index).src="media/fleche_reduce.png";
	});
}
function reduceMENUOPT(index) {
	MENUOPT[index]="off";
	$("#"+index).animate({
		height:25
	}, 500, function () {
		document.getElementById('img'+index).src="media/fleche_expand.png";
	});
}
function chooseMENUOPT(code, codeOpt, index, c) {
	var deW=document.getElementById('deWmenuOPT_'+codeOpt);
	var pHT=document.getElementById('pHTmenuOPT_'+codeOpt);
	var pTT=document.getElementById('pTTmenuOPT_'+codeOpt);
	MENU['code'][code][c]=codeOpt;
	MENU['deW'][code][c]=deW.value;
	MENU['pHT'][code][c]=pHT.value;
	MENU['pTT'][code][c]=pTT.value;
	document.getElementById('_'+index).style.opacity=1;
	document.getElementById('_'+index).innerHTML="> "+deW.value;
	reduceMENUOPT(index);
}
function addMENUToBasket(code, imploded, mainIndex) {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		var id=Math.random().toString().substr(2);
		if (disabled==false) {
			var theInput=document.getElementById('qte_MENU_'+code);
			var panier=Array();
			panier['cat']=Array();
			panier['designationWeb']=Array();
			panier['code']=Array();
			panier['prix_unitaire_HT']=Array();
			panier['prix_unitaire_TTC']=Array();
			panier['quantite']=Array();
			panier['identifiant']=Array();
			if (!isNaN(parseInt(theInput.value)) && parseInt(theInput.value)>0) {
				var countElmsPlaced=document.getElementById("countElmsPlaced_"+mainIndex);
				if (countElmsPlaced.value==MENU['code'][code].length) {
					var deW=document.getElementById('deWmenu_'+code);
					var pHT=document.getElementById('pHTmenu_'+code);
					var pTT=document.getElementById('pTTmenu_'+code);
					panier['cat'].push("Les menus à composer");
					panier['identifiant'].push(id+"_main");
					panier['code'].push(parseInt(code));
					panier['quantite'].push(parseInt(theInput.value));
					panier['designationWeb'].push(deW.value);
					var pTTtmp=parseFloat(pTT.value);
					var pHTtmp=parseFloat(pHT.value);
					for (i=0; i<MENU['code'][code].length; i++) {
						if (parseFloat(MENU['pHT'][code][i])>0) {
							pHTtmp+=parseFloat(MENU['pHT'][code][i]);
							MENU['pHT'][code][i]="0";
						}
						if (parseFloat(MENU['pTT'][code][i])>0) {
							pTTtmp+=parseFloat(MENU['pTT'][code][i]);
							MENU['pTT'][code][i]="0";
						}
					}
					pHTtmp=fix(pHTtmp);
					pTTtmp=fix(pTTtmp);
					panier['prix_unitaire_HT'].push(pHTtmp);
					panier['prix_unitaire_TTC'].push(pTTtmp);
					for (i=0; i<MENU['code'][code].length; i++) {
						panier['cat'].push("Les menus à composer");
						panier['identifiant'].push(id+"_sub");
						panier['code'].push(parseInt(MENU['code'][code][i]));
						panier['quantite'].push(theInput.value);
						panier['designationWeb'].push(MENU['deW'][code][i]);
						panier['prix_unitaire_HT'].push(MENU['pHT'][code][i]);
						panier['prix_unitaire_TTC'].push(MENU['pTT'][code][i]);
					}
					if (parseInt(code)==110) {
						panier['cat'].push("Les menus à composer");
						panier['identifiant'].push(id+"_sub");
						panier['code'].push("106");
						panier['quantite'].push(theInput.value);
						panier['designationWeb'].push("Salade verte");
						panier['prix_unitaire_HT'].push("0.00");
						panier['prix_unitaire_TTC'].push("0.00");
					}
				} else {
					alert("choisissez TOUS les ingrédients de votre menu");
				}
			} else {
				alert("la quantité est incorrecte ! ");
			}
			if (panier['code'].length>0) {
				var str="action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
				//alert(str);
				var xhr = null;
				if (window.XMLHttpRequest || window.ActiveXObject) {
					if (window.ActiveXObject) {
						try {
							xhr = new ActiveXObject("Msxml2.XMLHTTP");
						} catch(e) {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");
						}
					} else {
						xhr = new XMLHttpRequest(); 
					}
				} else {
					alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
					return;
				}
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4) {
						if (xhr.status == 200 || xhr.status == 0) {
							var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
							if (!isNaN(parseInt(str)) && parseInt(str)>0) {
								if (parseInt(str)>1) {
									document.getElementById('nb_panier').innerHTML=str+" articles";
								} else {
									document.getElementById('nb_panier').innerHTML=str+" article";
								}
								afficheAjoutPanier(parseInt(str) , code);
								//alert(imploded);
								clearMENUChoice1(code, imploded);
							}
						} else { 
							alert("error: "+xhr.status+" "+xhr.statusText);
						}
					}
				};
				xhr.open("POST", "fonctions-panier.php", true);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.send(str);
			}
		}
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function clearMENUChoice1(code, imploded) {
	var arrExp=explode('_-_', imploded);
	var theInput=document.getElementById('qte_MENU_'+code);
	theInput.value="";
	MENU['code'][code]=Array();
	MENU['deW'][code]=Array();
	MENU['pHT'][code]=Array();
	MENU['pTT'][code]=Array();
	for (var p=0; p<arrExp.length; p++) {
		//alert(arrExp[i]);
		$("#_"+arrExp[p]).animate({
			opacity:0
		}, 500, clearMENUChoice2(arrExp[p]));
	}
}
function clearMENUChoice2(theId) {
	document.getElementById('_'+theId).innerHTML="";
}
function actionPRMOPT(index) {
	if (PRMOPT[index]=="off") {
		expandPRMOPT(index);
	} else if (PRMOPT[index]=="on") {
		reducePRMOPT(index);
	}
}
function expandPRMOPT(index) {
	PRMOPT[index]="on";
	var theList=document.getElementById("__"+index);
	theList.innerHTML="";
	for (i=0; i<theListData[index].length; i++) {
		theList.innerHTML+=theListData[index][i];
	}
	$("#"+index).animate({
		height:document.getElementById('__'+index).offsetHeight+25
	}, 500, function () {
		document.getElementById('img'+index).src="media/fleche_reduce.png";
	});
}
function reducePRMOPT(index) {
	PRMOPT[index]="off";
	$("#"+index).animate({
		height:25
	}, 500, function () {
		document.getElementById('img'+index).src="media/fleche_expand.png";
	});
}
function choosePRMOPT(code, codeOpt, index, c) {
	var deW=document.getElementById('deWprmOPT_'+codeOpt);
	var pHT=document.getElementById('pHTprmOPT_'+codeOpt);
	var pTT=document.getElementById('pTTprmOPT_'+codeOpt);
	PRM['code'][code][c]=codeOpt;
	PRM['deW'][code][c]=deW.value;
	PRM['pHT'][code][c]=pHT.value;
	PRM['pTT'][code][c]=pTT.value;
	document.getElementById('_'+index).style.opacity=1;
	document.getElementById('_'+index).innerHTML="> "+deW.value;
	reducePRMOPT(index);
}
function addPRMToBasket(code, imploded, mainIndex) {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		var id=Math.random().toString().substr(2);
		if (disabled==false) {
			var theInput=document.getElementById('qte_PRM_'+code);
			var panier=Array();
			panier['cat']=Array();
			panier['designationWeb']=Array();
			panier['code']=Array();
			panier['prix_unitaire_HT']=Array();
			panier['prix_unitaire_TTC']=Array();
			panier['quantite']=Array();
			panier['identifiant']=Array();
			if (!isNaN(parseInt(theInput.value)) && parseInt(theInput.value)>0) {
				var countElmsPlaced=document.getElementById("countElmsPlaced_"+mainIndex);
				if (countElmsPlaced.value==PRM['code'][code].length) {
					var deW=document.getElementById('deWprm_'+code);
					var pHT=document.getElementById('pHTprm_'+code);
					var pTT=document.getElementById('pTTprm_'+code);
					panier['cat'].push("Les plateaux repas minute");
					panier['identifiant'].push(id+"_main");
					panier['code'].push(parseInt(code));
					panier['quantite'].push(parseInt(theInput.value));
					mainQtePRM+=parseInt(theInput.value);
					panier['designationWeb'].push(deW.value);
					var pTTtmp=parseFloat(pTT.value);
					var pHTtmp=parseFloat(pHT.value);
					for (i=0; i<PRM['code'][code].length; i++) {
						if (parseFloat(PRM['pHT'][code][i])>0) {
							pHTtmp+=parseFloat(PRM['pHT'][code][i]);
							PRM['pHT'][code][i]="0";
						}
						if (parseFloat(PRM['pTT'][code][i])>0) {
							pTTtmp+=parseFloat(PRM['pTT'][code][i]);
							PRM['pTT'][code][i]="0";
						}
					}
					pHTtmp=fix(pHTtmp);
					pTTtmp=fix(pTTtmp);
					panier['prix_unitaire_HT'].push(pHTtmp);
					panier['prix_unitaire_TTC'].push(pTTtmp);
					for (i=0; i<PRM['code'][code].length; i++) {
						panier['cat'].push("Les plateaux repas minute");
						panier['identifiant'].push(id+"_sub");
						panier['code'].push(parseInt(PRM['code'][code][i]));
						panier['quantite'].push(theInput.value);
						panier['designationWeb'].push(PRM['deW'][code][i]);
						panier['prix_unitaire_HT'].push(PRM['pHT'][code][i]);
						panier['prix_unitaire_TTC'].push(PRM['pTT'][code][i]);
					}
				} else {
					alert("choisisez TOUS les ingrédients de votre menu!");
				}
			} else {
				alert("quantité incorrecte !");
			}
			if (panier['code'].length>0) {
				var str="action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
				//alert(str);
				var xhr = null;
				if (window.XMLHttpRequest || window.ActiveXObject) {
					if (window.ActiveXObject) {
						try {
							xhr = new ActiveXObject("Msxml2.XMLHTTP");
						} catch(e) {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");
						}
					} else {
						xhr = new XMLHttpRequest(); 
					}
				} else {
					alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
					return;
				}
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4) {
						if (xhr.status == 200 || xhr.status == 0) {
							var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
							if (!isNaN(parseInt(str)) && parseInt(str)>0) {
								if (parseInt(str)>1) {
									document.getElementById('nb_panier').innerHTML=str+" articles";
								} else {
									document.getElementById('nb_panier').innerHTML=str+" article";
								}
								afficheAjoutPanier(parseInt(str) , code);
								//alert(imploded);
								clearPRMChoice(code, imploded);
							}
						} else { 
							alert("error: "+xhr.status+" "+xhr.statusText);
						}
					}
				};
				xhr.open("POST", "fonctions-panier.php", true);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.send(str);
			}
		}
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function addOptPRMToBasket(code) {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		var id=Math.random().toString().substr(2);
		if (disabled==false) {
			var theInput=document.getElementById('qte_PRM_'+code);
			var panier=Array();
			panier['cat']=Array();
			panier['designationWeb']=Array();
			panier['code']=Array();
			panier['prix_unitaire_HT']=Array();
			panier['prix_unitaire_TTC']=Array();
			panier['quantite']=Array();
			panier['identifiant']=Array();
			if (!isNaN(parseInt(theInput.value)) && parseInt(theInput.value)>0) {
				var deW=document.getElementById('deWprm_'+code);
				var pHT=document.getElementById('pHTprm_'+code);
				var pTT=document.getElementById('pTTprm_'+code);
				var countOPT=0;
				for (j=0; j<countOPTS.length; j++) {
					if (countOPTS[j].substr(0, countOPTS[j].indexOf("_"))==code) {
						countOPT+=countOPTS[j].substr(countOPTS[j].indexOf("_")+1);
					}
				}
				if (mainQtePRM+countPRM-countOPT>=parseInt(theInput.value)) {
					if (deW.value.toLowerCase().indexOf("carte noire")!=-1) {
						if (postalCode!="75011" && postalCode!="75012" && postalCode!="75020") {
							alert("votre localisation ne vous donne pas droit à l'option café carte noire, nous sommes désolés!");
						} else {
							if (parseInt(theInput.value)>=15) {
								panier['cat'].push("Les plateaux repas minute");
								panier['identifiant'].push(id+"_opt_"+deW.value);
								panier['code'].push(parseInt(code));
								panier['quantite'].push(parseInt(theInput.value));
								panier['designationWeb'].push(deW.value);
								var pTTtmp=parseFloat(pTT.value);
								var pHTtmp=parseFloat(pHT.value);
								pHTtmp=fix(pHTtmp);
								pTTtmp=fix(pTTtmp);
								panier['prix_unitaire_HT'].push(pHTtmp);
								panier['prix_unitaire_TTC'].push(pTTtmp);
							} else {
								alert("la quantité minimum pour l'option café carte noire est de 15, nous sommes désolés!");
							}
						}
					} else {
						panier['cat'].push("Les plateaux repas minute");
						panier['identifiant'].push(id+"_opt_"+deW.value);
						panier['code'].push(parseInt(code));
						panier['quantite'].push(parseInt(theInput.value));
						panier['designationWeb'].push(deW.value);
						var pTTtmp=parseFloat(pTT.value);
						var pHTtmp=parseFloat(pHT.value);
						pHTtmp=fix(pHTtmp);
						pTTtmp=fix(pTTtmp);
						panier['prix_unitaire_HT'].push(pHTtmp);
						panier['prix_unitaire_TTC'].push(pTTtmp);
					}
				} else {
					alert("la quantité d'option est supérieure à la quantité totale de plateaux repas minute!");
				}
			} else {
				alert("la quantité est incorrecte !");
			}
			if (panier['code'].length>0) {
				var str="action=add&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
				//alert(str);
				var xhr = null;
				if (window.XMLHttpRequest || window.ActiveXObject) {
					if (window.ActiveXObject) {
						try {
							xhr = new ActiveXObject("Msxml2.XMLHTTP");
						} catch(e) {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");
						}
					} else {
						xhr = new XMLHttpRequest(); 
					}
				} else {
					alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
					return;
				}
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4) {
						if (xhr.status == 200 || xhr.status == 0) {
							var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
							if (!isNaN(parseInt(str)) && parseInt(str)>0) {
								if (parseInt(str)>1) {
									document.getElementById('nb_panier').innerHTML=str+" articles";
								} else {
									document.getElementById('nb_panier').innerHTML=str+" article";
								}
								afficheAjoutPanier(parseInt(str) , code);
							}
						} else { 
							alert("error: "+xhr.status+" "+xhr.statusText);
						}
					}
				};
				xhr.open("POST", "fonctions-panier.php", true);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.send(str);
			}
		}
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function clearPRMChoice(code, imploded) {
	var arrExp=explode('_-_', imploded);
	var theInput=document.getElementById('qte_PRM_'+code);
	theInput.value="";
	PRM['code'][code]=Array();
	PRM['deW'][code]=Array();
	PRM['pHT'][code]=Array();
	PRM['pTT'][code]=Array();
	for (var p=0; p<arrExp.length; p++) {
		//alert(arrExp[i]);
		$("#_"+arrExp[p]).animate({
			opacity:0
		}, 500, clearPRMChoice2(arrExp[p]));
	}
}
function clearPRMChoice2(theId) {
	document.getElementById('_'+theId).innerHTML="";
}
function passForgotten() {
	$('#_4').animate({
		opacity:0
	}, 500, function () {
		document.getElementById("_4").innerHTML='<input type="text" name="emailForgotten" id="emailForgotten" value="votre email"  class="champ_arrondi" onclick="checkEmailPassForgotten();" style="padding-left:3px; width:72px; height:18px; margin-top:-1px;"/>&nbsp;<input type="button" value="ok" class="champ_arrondi" onclick="sendEmail();" style="width:35px; margin-top:0px; height:23px;"/>';
		$('#_4').animate({
			opacity:1
		}, 500);
	});
}
function checkEmailPassForgotten() {
	var emailForgotten=document.getElementById("emailForgotten");
	if (emailForgotten.value=="votre email") emailForgotten.value="";
}
function sendEmail() {
	var email=document.getElementById("emailForgotten").value;
	var reg=new RegExp('^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9_\.-]+\.[a-z]{2,4}$');
	if (reg.test(email)) {
		var str="email="+encodeURIComponent(email);
		//alert(str);
		var xhr = null;
		if (window.XMLHttpRequest || window.ActiveXObject) {
			if (window.ActiveXObject) {
				try {
					xhr = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
			} else {
				xhr = new XMLHttpRequest(); 
			}
		} else {
			alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
			return;
		}
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200 || xhr.status == 0) {
					var str=xhr.responseText;
					if (str=="email_sent") {
						alert("un email de rappel de mot de passe vous a été envoyé!");
						$('#_4').animate({
							opacity:0
						}, 500, function () {
							document.getElementById("_4").innerHTML='email envoyé.';
							$('#_4').animate({
								opacity:1
							}, 500);
						});
					} else {
						alert("votre email n'a pu être trouvé dans notre base !");
					}
				} else { 
					alert("error: "+xhr.status+" "+xhr.statusText);
				}
			}
		};
		xhr.open("POST", "sendPassword.php", true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(str);
	} else {
		alert("votre email n'est pas au format escompté");
	}
}
function emptyField(theId) {
	document.getElementById(theId).value="";
}
function codAuth() {
	$('#_7').animate({
		opacity:0
	}, 500, function () {
		document.getElementById("_7").innerHTML='<input type="text" name="codeAuth" id="codeAuth" value="code" class="champ_arrondi" onclick="emptyField(\'codeAuth\');" style="width:50px; height:18px; padding-left:3px; margin-top:-1px;"/>&nbsp;<input type="button" value="ok" style="width:35px;" class="champ_arrondi" onclick="sendCodeAuth();" style="width:30px; margin-top:0px; height:23px;"/>';
		$('#_7').animate({
			opacity:1
		}, 500);
	});
}
function sendCodeAuth() {
	var codeAuth=document.getElementById("codeAuth").value;
	var reg=new RegExp('^[a-z]{2}[0-9]{2}$');
	if (reg.test(codeAuth)) {
		var str="codeAuth="+encodeURIComponent(codeAuth);
		//alert(str);
		var xhr = null;
		if (window.XMLHttpRequest || window.ActiveXObject) {
			if (window.ActiveXObject) {
				try {
					xhr = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
			} else {
				xhr = new XMLHttpRequest(); 
			}
		} else {
			alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
			return;
		}
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200 || xhr.status == 0) {
					var str=xhr.responseText;
					if (str=="code_ok") {
						alert("votre code est correct!");
						$('#_7').animate({
							opacity:0
						}, 500, function () {
							document.getElementById("_7").innerHTML='Code identifié.';
							$('#_7').animate({
								opacity:1
							}, 500, function () {
								document.location=document.location;
							});
							
						});
					} else {
						alert("votre code est incorrect!");
					}
				} else { 
					alert("error: "+xhr.status+" "+xhr.statusText);
				}
			}
		};
		xhr.open("POST", "receiveCodeAuth.php", true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(str);
	} else {
		alert("votre code d'autorisation n'est pas au format escompté");
	}
}
function actionMENVOPT(index) {
	if (MENVOPT[index]=="off") {
		expandMENVOPT(index);
	} else if (MENVOPT[index]=="on") {
		reduceMENVOPT(index);
	}
}
function expandMENVOPT(index) {
	MENVOPT[index]="on";
	var theList=document.getElementById("__"+index);
	theList.innerHTML="";
	for (i=0; i<theListData[index].length; i++) {
		theList.innerHTML+=theListData[index][i];
	}
	$("#"+index).animate({
		height:document.getElementById('__'+index).offsetHeight+25
	}, 500, function () {
		document.getElementById('img'+index).src="media/fleche_reduce.png";
	});
}
function reduceMENVOPT(index) {
	MENVOPT[index]="off";
	$("#"+index).animate({
		height:25
	}, 500, function () {
		document.getElementById('img'+index).src="media/fleche_expand.png";
	});
}
function chooseMENVOPT(code, codeOpt, index, c) {
	var deW=document.getElementById('deWmenvOPT_'+codeOpt);
	var pHT=document.getElementById('pHTmenvOPT_'+codeOpt);
	var pTT=document.getElementById('pTTmenvOPT_'+codeOpt);
	MENV['code'][code][c]=codeOpt;
	MENV['deW'][code][c]=deW.value;
	MENV['pHT'][code][c]=pHT.value;
	MENV['pTT'][code][c]=pTT.value;
	document.getElementById('_'+index).style.opacity=1;
	document.getElementById('_'+index).innerHTML="> "+deW.value;
	reduceMENVOPT(index);
}
function chooseEmb() {
	var inputs=document.getElementsByName("cond");
	for (i=0; i<inputs.length; i++) {
		if (inputs[i].checked==true) {
			if (inputs[i].value=="repas") {
				MENVEMB['code']="9998";
				MENVEMB['deW']="Emballage par repas";
			} else if (inputs[i].value=="produit") {
				MENVEMB['code']="9997";
				MENVEMB['deW']="Emballage par produit";
			}
		}
	}
	ajaxPostSend("name="+encodeURIComponent("conditionnement")+"&value="+encodeURIComponent(MENVEMB['deW']),"setCookie.php","");
}
function addMENVToBasket(code, imploded, mainIndex) {
	if (logged==true) {
		var t=setTimeout('reEnable()', 2000);
		var id=Math.random().toString().substr(2);
		if (disabled==false) {
			if ((MENVEMB['deW']!="") && (MENVEMB['code']!="")) {
				var theInput=document.getElementById('qte_MENV_'+code);
				var panier=Array();
				panier['cat']=Array();
				panier['designationWeb']=Array();
				panier['code']=Array();
				panier['prix_unitaire_HT']=Array();
				panier['prix_unitaire_TTC']=Array();
				panier['quantite']=Array();
				panier['identifiant']=Array();
				if (!isNaN(parseInt(theInput.value)) && parseInt(theInput.value)>0) {
					var countElmsPlaced=document.getElementById("countElmsPlaced_"+mainIndex);
					if (countElmsPlaced.value==MENV['code'][code].length) {
						var deW=document.getElementById('deWmenv_'+code);
						var pHT=document.getElementById('pHTmenv_'+code);
						var pTT=document.getElementById('pTTmenv_'+code);
						panier['cat'].push("Les menus Club");
						panier['identifiant'].push(id+"_main");
						panier['code'].push(parseInt(code));
						panier['quantite'].push(parseInt(theInput.value));
						panier['designationWeb'].push(deW.value);
						var pTTtmp=parseFloat(pTT.value);
						var pHTtmp=parseFloat(pHT.value);
						for (i=0; i<MENV['code'][code].length; i++) {
							if (parseFloat(MENV['pHT'][code][i])>0) {
								pHTtmp+=parseFloat(MENV['pHT'][code][i]);
								MENV['pHT'][code][i]="0";
							}
							if (parseFloat(MENV['pTT'][code][i])>0) {
								pTTtmp+=parseFloat(MENV['pTT'][code][i]);
								MENV['pTT'][code][i]="0";
							}
						}
						pHTtmp=fix(pHTtmp);
						pTTtmp=fix(pTTtmp);
						panier['prix_unitaire_HT'].push(pHTtmp);
						panier['prix_unitaire_TTC'].push(pTTtmp);
						for (i=0; i<MENV['code'][code].length; i++) {
							panier['cat'].push("Les menus Club");
							panier['identifiant'].push(id+"_sub");
							panier['code'].push(parseInt(MENV['code'][code][i]));
							panier['quantite'].push(theInput.value);
							panier['designationWeb'].push(MENV['deW'][code][i]);
							panier['prix_unitaire_HT'].push(MENV['pHT'][code][i]);
							panier['prix_unitaire_TTC'].push(MENV['pTT'][code][i]);
						}
					} else {
						alert("choissez TOUS les ingrédients de votre menu !");
					}
				} else {
					alert("la quantité est incorrecte !");
				}
			} else {
				alert("merci de choisir un mode d'emballage !");
			}
			if (panier['code'].length>0) {
				var str="action=addMultiple&cat="+encodeURIComponent(implode('___', panier['cat']))+"&designationWeb="+encodeURIComponent(implode('___', panier['designationWeb']))+"&code="+encodeURIComponent(implode('___', panier['code']))+"&prix_unitaire_HT="+encodeURIComponent(implode('___', panier['prix_unitaire_HT']))+"&prix_unitaire_TTC="+encodeURIComponent(implode('___', panier['prix_unitaire_TTC']))+"&quantite="+encodeURIComponent(implode('___', panier['quantite']))+"&identifiant="+encodeURIComponent(implode('___', panier['identifiant']));
				//alert(str);
				var xhr = null;
				if (window.XMLHttpRequest || window.ActiveXObject) {
					if (window.ActiveXObject) {
						try {
							xhr = new ActiveXObject("Msxml2.XMLHTTP");
						} catch(e) {
							xhr = new ActiveXObject("Microsoft.XMLHTTP");
						}
					} else {
						xhr = new XMLHttpRequest(); 
					}
				} else {
					alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
					return;
				}
				xhr.onreadystatechange = function() {
					if (xhr.readyState == 4) {
						if (xhr.status == 200 || xhr.status == 0) {
							var str=xhr.responseText.substr(0,xhr.responseText.indexOf('__'));
							if (!isNaN(parseInt(str)) && parseInt(str)>0) {
								if (parseInt(str)>1) {
									document.getElementById('nb_panier').innerHTML=str+" articles";
								} else {
									document.getElementById('nb_panier').innerHTML=str+" article";
								}
								afficheAjoutPanier(parseInt(str) , code);
								//alert(imploded);
								clearMENVChoice1(code, imploded);
							}
						} else { 
							alert("error: "+xhr.status+" "+xhr.statusText);
						}
					}
				};
				xhr.open("POST", "fonctions-panier.php", true);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.send(str);
			}
		}
	} else {
		alert("merci de vous identifier ou de créer un compte avant de commander");
	}
}
function clearMENVChoice1(code, imploded) {
	var arrExp=explode('_-_', imploded);
	var theInput=document.getElementById('qte_MENV_'+code);
	theInput.value="";
	MENV['code'][code]=Array();
	MENV['deW'][code]=Array();
	MENV['pHT'][code]=Array();
	MENV['pTT'][code]=Array();
	for (var p=0; p<arrExp.length; p++) {
		//alert(arrExp[i]);
		$("#_"+arrExp[p]).animate({
			opacity:0
		}, 500, clearMENVChoice2(arrExp[p]));
	}
}
function clearMENVChoice2(theId) {
	document.getElementById('_'+theId).innerHTML="";
}
function generePaiement() {
	if ((date=="ok" && heure=="ok") || (dateDej=="ok" && heurePdej=="ok")) {
		var mode="";
		var inputs=document.getElementsByClassName("mode_paiement");
		for (i=0; i<inputs.length; i++) {
			if (inputs[i].checked) {
				mode=inputs[i].value;
			}
		}
		if (mode=="cb") {
			var str="mode="+encodeURIComponent(mode)+"&commandeDLiv="+encodeURIComponent(dCom+"/"+mCom+"/"+yCom)+"&commandeHLiv="+encodeURIComponent(commandeLiv)+"&pdejDLiv="+encodeURIComponent(dDej+"/"+mDej+"/"+yDej)+"&pdejHLiv="+encodeURIComponent(pdejLiv);
			var xhr = null;
			if (window.XMLHttpRequest || window.ActiveXObject) {
				if (window.ActiveXObject) {
					try {
						xhr = new ActiveXObject("Msxml2.XMLHTTP");
					} catch(e) {
						xhr = new ActiveXObject("Microsoft.XMLHTTP");
					}
				} else {
					xhr = new XMLHttpRequest(); 
				}
			} else {
				alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
				return;
			}
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {
					if (xhr.status == 200 || xhr.status == 0) {
						var cbox=document.getElementById("cgvAcc");
						var divCGV=document.getElementById("cgvMention");
						var bouton=document.getElementById("boutonPaiement");
						var str=xhr.responseText.toString();
						//alert(str);
						if (str.substr(0,4)=="http") {
							bouton.onclick=function () { OuvrirSpPlus(str) };
							bouton.value="Payer";
							divCGV.style.visibility="visible";
							cbox.style.visibility="visible";
							bouton.style.visibility="visible";
						}
					} else { 
						alert("error: "+xhr.status+" "+xhr.statusText);
					}
				}
			};
			xhr.open("POST", "initPaymentCB.php", true);
			xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xhr.send(str);
		} else if (mode=="chq" || mode=="diff") {
			var divCGV=document.getElementById("cgvMention");
			var bouton=document.getElementById("boutonPaiement");
			var cbox=document.getElementById("cgvAcc");
			bouton.onclick=function () { sendBasketDiffOrChq(mode) };
			bouton.value="Commander";
			divCGV.style.visibility="visible";
			cbox.style.visibility="visible";
			bouton.style.visibility="visible";
		} else alert ("Veuillez choisir votre mode de paiement!");
	} else alert ("Veuillez d'abord renseigner la date et l'heure de livraison svp!");
}
function sendBasketDiffOrChq(mode) {
	if (cboxChecked==true) {
		if (askforNumCommandeSNCF==true) {
			var numCommandeSNCF=document.getElementById("numCommandeSncf");
			var nSNCF=numCommandeSNCF.value;
			var str="mode="+encodeURIComponent(mode)+"&commandeDLiv="+encodeURIComponent(dCom+"/"+mCom+"/"+yCom)+"&commandeHLiv="+encodeURIComponent(commandeLiv)+"&pdejDLiv="+encodeURIComponent(dDej+"/"+mDej+"/"+yDej)+"&pdejHLiv="+encodeURIComponent(pdejLiv)+"&numCommandeSNCF="+encodeURIComponent(nSNCF);
		} else {
			var str="mode="+encodeURIComponent(mode)+"&commandeDLiv="+encodeURIComponent(dCom+"/"+mCom+"/"+yCom)+"&commandeHLiv="+encodeURIComponent(commandeLiv)+"&pdejDLiv="+encodeURIComponent(dDej+"/"+mDej+"/"+yDej)+"&pdejHLiv="+encodeURIComponent(pdejLiv);
		}
		var xhr = null;
		if (window.XMLHttpRequest || window.ActiveXObject) {
			if (window.ActiveXObject) {
				try {
					xhr = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				}
			} else {
				xhr = new XMLHttpRequest(); 
			}
		} else {
			alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
			return;
		}
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200 || xhr.status == 0) {
					var str=xhr.responseText;
					//alert(str);
					if (str.substr(0,2)=="ok") {
						document.location="retour_internaute.php?retour=paiement_livraison";
					} else if (str.indexOf("already")!=-1) {
						alert("votre commande a déjà été enregistrée");
					} else {
						alert("une erreur s'est produite ("+str+") lors de l'enregistrement de votre commande, veuillez nous contacter afin qu'elle soit résolue!");
					}
				} else { 
					alert("error: "+xhr.status+" "+xhr.statusText);
				}
			}
		};
		xhr.open("POST", "initPaymentDiffOuChq.php", true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.send(str);
	} else {
		alert("Vous devez accepter les conditions de vente avant de commander");
	}
}
function changeDate () {
	var mentionHoraireLiv=document.getElementById("mentionHoraireLiv");
	mentionHoraireLiv.innerHTML="";
	var horaireLiv=document.getElementById("horaireLiv");
	horaireLiv.innerHTML="";
}
function checkDate (d, m, Y) {
	var dateLiv=document.getElementById("dateLiv");
	dateLiv.innerHTML="";
	var mentionHoraireLiv=document.getElementById("mentionHoraireLiv");
	mentionHoraireLiv.innerHTML="";
	var horaireLiv=document.getElementById("horaireLiv");
	horaireLiv.innerHTML="";
	cboxChecked=false;
	document.getElementById("boutonPaiement").style.visibility="hidden";
	document.getElementById("cgvAcc").checked=false;
	document.getElementById("cgvAcc").style.visibility="hidden";
	document.getElementById("cgvMention").style.visibility="hidden";
	heure="non_testé";
	date="non_testé";
	dCom="";
	mCom="";
	yCom="";
	document.getElementById("paiementTxt").style.visibility="hidden";
	document.getElementById("paiement").style.visibility="hidden";
	document.getElementById("mentionPaiement").style.visibility="hidden";
	if (askforNumCommandeSNCF==true) {
		var numCommandeSNCF=document.getElementById("numCommandeSncf");
		var nSNCF=numCommandeSNCF.value;
		if (nSNCF.length!=10) {
			alert("le numéro de commande sncf que vous avez rentré est incorrect!");
			numCommandeSNCF.focus();
			return false;
		}
	}
	if (d.substr(0,1)=="0") { d=d.substr(1,1); }
	if (m.substr(0,1)=="0") { m=m.substr(1,1); }
	if (d.length==0 || parseInt(d)==0) {
		alert("le jour est incorrect");
		return false;
	}
	if (m.length==0 || parseInt(m)==0) {
		alert("le mois est incorrect");
		return false;
	}
	if (Y.length!=4 || parseInt(Y)==0) {
		alert("l'année est incorrecte");
		return false;
	}
	var daysArray=Array();
	if (parseInt(Y)%4==0) {
		daysArray=Array(31,29,31,30,31,30,31,31,30,31,30,31);
	} else {
		daysArray=Array(31,28,31,30,31,30,31,31,30,31,30,31);
	}
	if (parseInt(d)>parseInt(daysArray[parseInt(m)-1]) || parseInt(d)<1) {
		alert("le jour est incorrect");
		return false;
	}
	if (parseInt(m)<1 || parseInt(m)>12) {
		alert("le mois est incorrect");
		return false;
	}
	if (parseInt(Y)==parseInt(year)) {
		if (parseInt(m)<parseInt(month)) {
			alert("le mois est incorrect");
			return false;
		} else if (parseInt(m)==parseInt(month)) {
			if (parseInt(d)<parseInt(day)) {
				alert("le jour est incorrect");
				return false;
			}
		}
	} else if (parseInt(Y)<parseInt(year)) {
		alert("l'année est incorrecte");
		return false;
	}
	dCom=d;
	mCom=m;
	yCom=Y;
	date="ok";
	var dateLiv=document.getElementById("dateLiv");
	dateLiv.innerHTML="Date choisie : le "+d+"/"+m+"/"+Y;
	var mentionHoraireLiv=document.getElementById("mentionHoraireLiv");
	mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>Choisissez ici la tranche horaire de livraison pour votre commande:&nbsp;</b></span>';
	var horaireLiv=document.getElementById("horaireLiv");
	var str='';
	if (parseInt(day)==parseInt(dCom) && parseInt(month)==parseInt(mCom) && parseInt(year)==parseInt(yCom)) {
		str+='<select name="horaire_commande" id="horaire_commande" onchange="changeHoraire();"><option value="none" selected>tranche horaire</option>';
		if (typeLiv=="bistrot") {
			if (locLiv=="11_12_20") {
				if (parseInt(hour)*100+parseInt(minutes)<1330) {
					if (parseInt(minutes)<30) {
						for (i=parseInt(hour); i<=13.5; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes+30).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+1)+'h'+(minutes+30).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad(minutes.toString(), '0')+'-'+(i+1).toString()+'h'+pad(minutes.toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					} else {
						for (i=parseInt(hour)+0.5; i<=13.5; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+1)+'h'+(minutes).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad((minutes-30).toString(), '0')+'-'+(i+1).toString()+'h'+pad((minutes-30).toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					}
				} else {
					str="";
					mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui sans code d\'autorisation!<br />Veuillez nous contacter au 01 43 07 93 93.</b></span>';
					horaireLiv.innerHTML=str;
					return false;
				}
			} else if (locLiv=="3_4_10_13") {
				if (parseInt(hour)*100+parseInt(minutes)<1300) {
					if (parseInt(minutes)<30) {
						for (i=parseInt(hour); i<=13; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes+30).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+pad(minutes.toString(), '0');
							} else {
								var horaire_display=i.toString()+'h'+pad(minutes.toString(), '0')+'-'+(i+1).toString()+'h'+(minutes+30).toString();
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					} else {
						for (i=parseInt(hour)+0.5; i<=13; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+pad((minutes-30).toString(), '0');
							} else {
								var horaire_display=i.toString()+'h'+pad((minutes-30).toString(), '0')+'-'+(i+1).toString()+'h'+(minutes).toString();
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					}
				} else {
					str="";
					mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui sans code d\'autorisation!<br />Veuillez nous contacter au 01 43 07 93 93.</b></span>';
					horaireLiv.innerHTML=str;
					return false;
				}
			} else if (locLiv=="autres_Paris") {
				if (parseInt(hour)*100+parseInt(minutes)<1230) {
					if (parseInt(minutes)<30) {
						for (i=parseInt(hour); i<=12.5; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes+30).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+(minutes+30).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad(minutes.toString(), '0')+'-'+(i+2).toString()+'h'+pad(minutes.toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					} else {
						for (i=parseInt(hour)+0.5; i<=12.5; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+(minutes).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad((minutes-30).toString(), '0')+'-'+(i+2).toString()+'h'+pad((minutes-30).toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					}
				} else {
					str="";
					mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui sans code d\'autorisation!<br />Veuillez nous contacter au 01 43 07 93 93.</b></span>';
					horaireLiv.innerHTML=str;
					return false;
				}
			}	
		} else if (typeLiv=="traiteur") {
			str="";
			mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui sans code d\'autorisation!<br />Veuillez nous contacter au 01 43 07 93 93.</b></span>';
			horaireLiv.innerHTML=str;
			return false;
		} else if (typeLiv=="vs") {
			str="";
			mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui sans code d\'autorisation!<br />Veuillez nous contacter au 01 43 07 93 93.</b></span>';
			horaireLiv.innerHTML=str;
			return false;
		} else if (typeLiv=="sp") {
			if (locLiv=="11_12_20") {
				if (parseInt(hour)*100+parseInt(minutes)<1900) {
					if (parseInt(minutes)<30) {
						for (i=parseInt(hour); i<=19; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes+30).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+1)+'h'+(minutes+30).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad((minutes).toString(), '0')+'-'+(i+1).toString()+'h'+pad((minutes).toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					} else {
						for (i=parseInt(hour)+0.5; i<=19; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+1)+'h'+(minutes).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad((minutes-30).toString(), '0')+'-'+(i+1).toString()+'h'+pad((minutes-30).toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					}
				} else {
					str="";
					mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui selon les conditions actuelles de la livraison spéciale</b></span>';
					horaireLiv.innerHTML=str;
					return false;
				}
			} else if (locLiv=="3_4_10_13") {
				if (parseInt(hour)*100+parseInt(minutes)<1830) {
					if (parseInt(minutes)<30) {
						for (i=parseInt(hour); i<=18.5; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes+30).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+pad(minutes.toString(), '0');
							} else {
								var horaire_display=i.toString()+'h'+pad(minutes.toString(), '0')+'-'+(i+1).toString()+'h'+(minutes+30).toString();
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					} else {
						for (i=parseInt(hour)+0.5; i<=18.5; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+pad((minutes-30).toString(), '0');
							} else {
								var horaire_display=i.toString()+'h'+pad((minutes-30).toString(), '0')+'-'+(i+1).toString()+'h'+minutes.toString();
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					}
				} else {
					str="";
					mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui selon les conditions actuelles de la livraison spéciale</b></span>';
					horaireLiv.innerHTML=str;
					return false;
				}
			} else if (locLiv=="autres_Paris") {
				if (parseInt(hour)*100+parseInt(minutes)<1800) {
					if (parseInt(minutes)<30) {
						for (i=parseInt(hour); i<=18; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes+30).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+(minutes+30).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad(minutes.toString(), '0')+'-'+(i+2).toString()+'h'+pad(minutes.toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					} else {
						for (i=parseInt(hour)+0.5; i<=18; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+minutes.toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+minutes.toString();
							} else {
								var horaire_display=i.toString()+'h'+pad((minutes-30).toString(), '0')+'-'+(i+2).toString()+'h'+pad((minutes-30).toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					}
				} else {
					str="";
					mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui selon les conditions actuelles de la livraison spéciale</b></span>';
					horaireLiv.innerHTML=str;
					return false;
				}
			} else if (locLiv=="autres") {
				if (parseInt(hour)*100+parseInt(minutes)<1800) {
					if (parseInt(minutes)<30) {
						for (i=parseInt(hour); i<=18; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes+30).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+(minutes+30).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad(minutes.toString(), '0')+'-'+(i+2).toString()+'h'+pad(minutes.toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					} else {
						for (i=parseInt(hour)+0.5; i<=18; i+=0.5) {
							if (i.toString().indexOf('.')!=-1) {	
								var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h'+(minutes).toString()+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h'+(minutes).toString();
							} else {
								var horaire_display=i.toString()+'h'+pad((minutes-30).toString(), '0')+'-'+(i+2).toString()+'h'+pad((minutes-30).toString(), '0');
							}
							str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
						}
					}
				} else {
					str="";
					mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui selon les conditions actuelles de la livraison spéciale</b></span>';
					horaireLiv.innerHTML=str;
					return false;
				}
			}
		}
		str+='</select>';
	} else {
		str+='<select name="horaire_commande" id="horaire_commande" onchange="changeHoraire();"><option value="none" selected>tranche horaire</option>';
		if (typeLiv=="bistrot") {
			if (locLiv=="11_12_20") {
				for (i=10; i<=13.5; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30'+'-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+1)+'h30';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+1).toString()+'h00';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			} else if (locLiv=="3_4_10_13") {
				for (i=10; i<=13; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h00';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+1).toString()+'h30';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			} else if (locLiv=="autres_Paris") {
				for (i=10; i<=12.5; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h30';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+2).toString()+'h00';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			}	
		} else if (typeLiv=="traiteur") {
			if (locLiv=="11_12_20" || locLiv=="3_4_10_13") {
				for (i=10; i<=13; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h00';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+1).toString()+'h30';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			} else if (locLiv=="autres_Paris") {
				for (i=10; i<=12.5; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h30';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+2).toString()+'h00';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			}	
		} else if (typeLiv=="vs") {
			if (locLiv=="Paris") {
				for (i=10; i<=13.5; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+1)+'h30';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+1).toString()+'h00';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			} else if (locLiv=="hors_Paris") {
				str="";
				mentionHoraireLiv.innerHTML='<span class="arial12blanc"><b>impossible de vous livrer pour aujourd\'hui selon les conditions actuelles de la livraison voyages et séminaires</b></span>';
				horaireLiv.innerHTML=str;
				return false;
			}	
		} else if (typeLiv=="sp") {
			if (locLiv=="11_12_20") {
				for (i=10; i<=19; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+1)+'h30';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+1).toString()+'h00';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			} else if (locLiv=="3_4_10_13") {
				for (i=10; i<=18.5; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h00';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+1).toString()+'h30';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			} else if (locLiv=="autres_Paris") {
				for (i=10; i<=18; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h30';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+2).toString()+'h00';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			} else if (locLiv=="autres") {
				for (i=10; i<=18; i+=0.5) {
					if (i.toString().indexOf('.')!=-1) {	
						var horaire_display=i.toString().substr(0,i.toString().indexOf('.'))+'h30-'+(parseInt(i.toString().substr(0,i.toString().indexOf('.')))+2)+'h30';
					} else {
						var horaire_display=i.toString()+'h00-'+(i+2).toString()+'h00';
					}
					str+='<option value="'+horaire_display+'">'+horaire_display+'</option>';
				}
			}
		}
		str+='</select>';
	}
	horaireLiv.innerHTML=str;
}
function checkDateDej (d, m, Y) {
	cboxChecked=false;
	document.getElementById("cgvAcc").checked=false;
	document.getElementById("cgvAcc").style.visibility="hidden";
	document.getElementById("cgvMention").style.visibility="hidden";
	document.getElementById("boutonPaiement").style.visibility="hidden";
	heurePdej="non_testé";
	dateDej="non_testé";
	var dateLivDej=document.getElementById("dateLivDej");
	dateLivDej.innerHTML="";
	document.getElementById("horDej_1").style.visibility="hidden";
	document.getElementById("horDej_2").style.visibility="hidden";
	document.getElementById("paiementTxt").style.visibility="hidden";
	document.getElementById("paiement").style.visibility="hidden";
	document.getElementById("mentionPaiement").style.visibility="hidden";
	if (askforNumCommandeSNCF==true) {
		var numCommandeSNCF=document.getElementById("numCommandeSncf");
		var nSNCF=numCommandeSNCF.value;
		if (nSNCF.length!=10) {
			alert("le numéro de commande sncf que vous avez rentré est incorrect!");
			numCommandeSNCF.focus();
			return false;
		}
	}
	if (d.length==0 || parseInt(d)==0) {
		alert("le jour est incorrect");
		d.focus();
		return false;
	}
	if (m.length==0 || parseInt(m)==0) {
		alert("le mois est incorrect");
		m.focus();
		return false;
	}
	if (Y.length!=4 || parseInt(Y)==0) {
		alert("l'année est incorrecte");
		Y.focus();
		return false;
	}
	var daysArray=Array();
	if (parseInt(Y)%4==0) {
		daysArray=Array(31,29,31,30,31,30,31,31,30,31,30,31);
	} else {
		daysArray=Array(31,28,31,30,31,30,31,31,30,31,30,31);
	}
	if (parseInt(d)>parseInt(daysArray[parseInt(m)-1]) || parseInt(d)<1) {
		alert("le jour est incorrect");
		d.focus();
		return false;
	}
	if (parseInt(m)<1 || parseInt(m)>12) {
		alert("le mois est incorrect");
		m.focus();
		return false;
	}
	if (parseInt(Y)==parseInt(year)) {
		if (parseInt(m)<parseInt(month)) {
			alert("le mois est incorrect");
			m.focus();
			return false;
		} else if (parseInt(m)==parseInt(month)) {
			if (parseInt(d)<parseInt(day)) {
				alert("le jour est incorrect");
				d.focus();
				return false;
			}
		}
	} else if (parseInt(Y)<parseInt(year)) {
		alert("l'année est incorrecte");
		Y.focus();
		return false;
	}
	dDej=d;
	mDej=m;
	yDej=Y;
	var dateLivDej=document.getElementById("dateLivDej");
	dateLivDej.innerHTML="Date choisie : le "+d+"/"+m+"/"+Y;
	dateDej="ok";
	document.getElementById("horDej_1").style.visibility="visible";
	document.getElementById("horDej_2").style.visibility="visible";
	if (pdejLiv.length>0) {
		changeHoraireDej();
	}
}
function changeHoraireDej() {
	if (dateDej!='ok') {
		alert("veuillez d'abord choisir une date de livraison correcte!");
	} else {
		var mode_paiement=document.getElementsByClassName("mode_paiement");
		heurePdej="non_testé";
		var sel=document.getElementById("horaire_dej");
		var opts=sel.getElementsByTagName("option");
		for (i=0; i<opts.length; i++) {
			if (opts[i].selected) {
				if (parseInt(opts[i].value.substr(0,opts[i].value.indexOf('h')))*100+parseInt(opts[i].value.substr(opts[i].value.indexOf('h')+1))>=830) {
					if (dDej==day && mDej==month && yDej==year) {
						if (hour>parseInt(opts[i].value.substr(0, opts[i].value.indexOf('h')))) {
							alert("votre horaire doit être ultérieur à celui de la prise de commande!");
							return false;
						} else if (hour==parseInt(opts[i].value.substr(0, opts[i].value.indexOf('h'))) && minutes>parseInt(opts[i].value.substr(opts[i].value.indexOf('h')+1, opts[i].value.length-(opts[i].value.indexOf('h')+1)))) {
							alert("votre horaire doit être ultérieur à celui de la prise de commande!");
							return false;
						}
					}
					if (parseInt(pdej_liv)!=15 && bupo==false) {
						if (codeAuth==false) {
							setPdejLiv('15', opts[i].value);
						} else {
							setPdejLivAuth('25', opts[i].value);
						}
						pdejLiv=opts[i].value;
						heurePdej="ok";
						if (date=="non_dispo" || date=="ok") {
							document.getElementById("paiementTxt").style.visibility="visible";
							document.getElementById("paiement").style.visibility="visible";
							document.getElementById("fac_devis").style.visibility="visible";
							for (j=0; j<mode_paiement.length; j++) {
								mode_paiement[j].checked=false;
							}
							if (payliv=="present") {
								document.getElementById("mentionPaiement").style.visibility="visible";
							}
						}
					} else {
						pdejLiv=opts[i].value;
						heurePdej="ok";
						if (date=="non_dispo" || date=="ok") {
							document.getElementById("paiementTxt").style.visibility="visible";
							document.getElementById("paiement").style.visibility="visible";
							document.getElementById("fac_devis").style.visibility="visible";
							for (j=0; j<mode_paiement.length; j++) {
								mode_paiement[j].checked=false;
							}
							if (payliv=="present") {
								document.getElementById("mentionPaiement").style.visibility="visible";
							}
						}
					}
				} else {
					if (dDej==day && mDej==month && yDej==year) {
						if (hour>parseInt(opts[i].value.substr(0, opts[i].value.indexOf('h')))) {
							alert("votre horaire doit être ultérieur à celui de la prise de commande!");
							return false;
						} else if (hourDej==parseInt(opts[i].value.substr(0, opts[i].value.indexOf('h'))) && minutesDej>parseInt(opts[i].value.substr(opts[i].value.indexOf('h')+1, opts[i].value.length-(opts[i].value.indexOf('h')+1)))) {
							alert("votre horaire doit être ultérieur à celui de la prise de commande!");
							return false;
						}
					}
					if (parseInt(pdej_liv)!=20 && bupo==false) {
						if (codeAuth==false) {
							setPdejLiv('20', opts[i].value);
						} else {
							setPdejLivAuth('25', opts[i].value);
						}
						pdejLiv=opts[i].value;
						heurePdej="ok";
						if (date=="non_dispo" || date=="ok") {
							document.getElementById("paiementTxt").style.visibility="visible";
							document.getElementById("paiement").style.visibility="visible";
							document.getElementById("fac_devis").style.visibility="visible";
							for (j=0; j<mode_paiement.length; j++) {
								mode_paiement[j].checked=false;
							}
							if (payliv=="present") {
								document.getElementById("mentionPaiement").style.visibility="visible";
							}
						}
					} else {
						pdejLiv=opts[i].value;
						heurePdej="ok";
						if (date=="non_dispo" || date=="ok") {
							document.getElementById("paiementTxt").style.visibility="visible";
							document.getElementById("paiement").style.visibility="visible";
							document.getElementById("fac_devis").style.visibility="visible";
							for (j=0; j<mode_paiement.length; j++) {
								mode_paiement[j].checked=false;
							}
							if (payliv=="present") {
								document.getElementById("mentionPaiement").style.visibility="visible";
							}
						}
					}
				}
			}
		}
	}
}
function setPdejLiv(montant, horaire) {
	var str="montant="+encodeURIComponent(montant)+"&horaire="+encodeURIComponent(horaire);
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				var str=xhr.responseText;
				//alert(str);
				if (str.substr(0,2)=="ok") {
					window.location.reload();
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "set_pdej_liv.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function setPdejLivAuth(montant, horaire) {
	var str="montant="+encodeURIComponent(montant)+"&horaire="+encodeURIComponent(horaire);
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				var str=xhr.responseText;
				//alert(str);
				if (str.substr(0,2)=="ok") {
				} else {
					alert("Erreur, votre horaire n'a pas été enregistré");
				}
			} else { 
				alert("error: "+xhr.status+" "+xhr.statusText);
			}
		}
	};
	xhr.open("POST", "set_pdej_liv.php", true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function changeHoraire() {
	if (date!='ok') {
		alert("veuillez d'abord choisir une date de livraison correcte!");
	} else {
		heure="non_testé";
		var mode_paiement=document.getElementsByClassName("mode_paiement");
		var sel=document.getElementById("horaire_commande");
		var opts=sel.getElementsByTagName("option");
		var str="";
		for (i=0; i<opts.length; i++) {
			if (opts[i].selected) {
				if (parseInt(day)==parseInt(dCom) && parseInt(month)==parseInt(mCom) && parseInt(year)==parseInt(yCom)) {
					if (parseInt(hour)<10) {
						if (countPromos==0 && totalBistrot>0 && bupo==false && paiementDiff=="non") {
							str="code="+encodeURIComponent("8890")+"&deW="+encodeURIComponent("Promotion de "+promoBistrot+"% sur tout le bistrot avant 10h")+"&pHT="+encodeURIComponent(fix(-totalBistrot*promoBistrot*0.01/1.07))+"&pTT="+encodeURIComponent(fix(-totalBistrot*promoBistrot*0.01))+"&cat="+encodeURIComponent("Les promotions");
							ajaxPostSendWithEndFnAndAdditionnalArgs(str, "setPromo_Ajax.php", "postPromo", new Array("8890","Promotion de "+promoBistrot+"% sur tout le bistrot avant 10h",fix(-totalBistrot*promoBistrot*0.01/1.07),fix(-totalBistrot*promoBistrot*0.01)));
						}
					}
				} else {
					if (countPromos==0 && totalBistrot>0 && bupo==false && paiementDiff=="non") {
						str="code="+encodeURIComponent("8890")+"&deW="+encodeURIComponent("Promotion de "+promoBistrot+"% sur tout le bistrot avant 10h")+"&pHT="+encodeURIComponent(fix(-totalBistrot*promoBistrot*0.01/1.07))+"&pTT="+encodeURIComponent(fix(-totalBistrot*promoBistrot*0.01))+"&cat="+encodeURIComponent("Les promotions");
						ajaxPostSendWithEndFnAndAdditionnalArgs(str, "setPromo_Ajax.php", "postPromo", new Array("8890","Promotion de "+promoBistrot+"% sur tout le bistrot avant 10h",fix(-totalBistrot*promoBistrot*0.01/1.07),fix(-totalBistrot*promoBistrot*0.01)));
					}
				}
				commandeLiv=opts[i].value;
				heure="ok";
				if (dateDej=="non_dispo" || dateDej=="ok") {
					document.getElementById("paiementTxt").style.visibility="visible";
					document.getElementById("paiement").style.visibility="visible";
					document.getElementById("fac_devis").style.visibility="visible";
					for (j=0; j<mode_paiement.length; j++) {
						mode_paiement[j].checked=false;
					}
					if (payliv=="present") {
						document.getElementById("mentionPaiement").style.visibility="visible";
					}
				}
			}
		}
	}
}
function actionPromo() {
	if (PROMOTAB=="off") {
		expandPromo("promo");
	} else if (PROMOTAB=="on") {
		reducePromo("promo");
	}
}
function expandPromo(theId) {
	PROMOTAB="on";
	var theList=document.getElementById("__"+theId);
	theList.innerHTML="";
	for (i=0; i<listData.length; i++) {
		theList.innerHTML+=listData[i];
	}
	$("#"+theId).animate({
		height:document.getElementById('__'+theId).offsetHeight+25
	}, 500, function () {
		document.getElementById('img'+theId).src="media/fleche_reduce.png";
	});
}
function reducePromo(theId) {
	PROMOTAB="off";
	$("#"+theId).animate({
		height:25
	}, 500, function () {
		document.getElementById('img'+theId).src="media/fleche_expand.png";
	});
}
function choosePromo(code, theId) {
	var thePromo=document.getElementById('promo_'+code);
	var deW=document.getElementById('promoDeW_'+code);
	var cat=document.getElementById('promoCat_'+code);
	document.getElementById('_'+theId).style.opacity=1;
	document.getElementById('_'+theId).innerHTML="> "+deW.value;
	reducePromo(theId);
	setTimeout("doPromo('"+code+"', '"+thePromo.value+"', '"+deW.value+"', '"+cat.value+"');", 1000);
}
function doPromo(code, thePromo, deWpromo, cat) {
	if (code=="8885") {
		ajaxPostSend("code=8885", "setPromo.php", "retourPromo");
	} else {
		if (thePromo.substr(0,1)=="-") {
		str="code="+encodeURIComponent(code)+"&deW="+encodeURIComponent(deWpromo)+"&pHT="+encodeURIComponent(fix(parseFloat(thePromo)/1.07))+"&pTT="+encodeURIComponent(fix(parseFloat(thePromo)))+"&cat="+encodeURIComponent(cat);
		} else {
			str="code="+encodeURIComponent(code)+"&deW="+encodeURIComponent(thePromo)+"&pHT="+encodeURIComponent()+"&pTT="+encodeURIComponent("offert")+"&cat="+encodeURIComponent(cat);
		}
		ajaxPostSend(str, "setPromo.php", "retourPromo");
	}
}
function retourPromo(strRep) {
	if (strRep.substr(0,2)=="bo") {
		alert("vous allez être redirigé(e) sur la page boissons pour y faire votre choix");
		document.location="boissons.php";
	} else if (strRep.substr(0,2)=="ok") {
		document.location="panier.php";
	} else {
		alert("une erreur s'est produite lors de l'établissement de vos droits à cette promotion, nous sommes désolés");
	}
}
function postPromo(rep, implodedArr) {
	if (rep.substr(0,2)=="ok") {
		exploded=explode('|', implodedArr);
		var basket=document.getElementById("panier");
		basket.innerHTML+='<tr class="panier_lines"><td style="padding-left:10px; width:200px;">'+stripslashes(exploded[1])+'</td><td align="right">1</td><td align="right">'+exploded[2]+' €</td><td align="right">'+exploded[3]+' €</td><td align="center"><a href="panier.php?action=remove&identifiant='+rep.substr(3)+'" style="outline:none;"><img src="media/supp.png" border="0" style="outline:none;"/></a></td></tr>';
	}
}
function genereDocument(type, mail) {
	ajaxPostSend("type="+encodeURIComponent(type)+"&dates="+encodeURIComponent(dCom+"/"+mCom+"/"+yCom+"|"+dDej+"/"+mDej+"/"+yDej)+"&horaires="+encodeURIComponent(commandeLiv+"|"+pdejLiv)+"&mail="+encodeURIComponent(mail), 'genereDocumentPdf.php', "retourGenereDocument");
}
function retourGenereDocument(str) {
	var result_pdf=document.getElementById("result_pdf");
	result_pdf.innerHTML=str;
}
function ajaxPostSendWithEndFnAndAdditionnalArgs(str, url, endFunction, addArgs) {
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				var strRep=xhr.responseText;
				if (endFunction!="") { 
					eval(endFunction+"('"+addslashes(strRep)+"', '"+implode('|', addArgs)+"');");
				}
			} else { 
				if (endFunction!="") { 
					eval(endFunction+"('Une erreur s'est produite: Erreur AJAX. "+xhr.status+". "+xhr.statusText+"');");
				}
			}
		}
	};
	xhr.open("POST", url, true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function ajaxPostSend(str, url, endFunction) {
	var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l\'objet XMLHTTPRequest...");
		return;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200 || xhr.status == 0) {
				var strRep=xhr.responseText;
				if (endFunction!="") { 
					eval(endFunction+"('"+addslashes(strRep)+"');");
				}
			} else { 
				if (endFunction!="") { 
					eval(endFunction+"('Une erreur s'est produite: Erreur AJAX. "+xhr.status+". "+xhr.statusText+"');");
				}
			}
		}
	};
	xhr.open("POST", url, true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(str);
}
function checkCGVacc() {
	var cbox=document.getElementById("cgvAcc");
	if (cbox.checked==true) {
		cboxChecked=true;
	} else {
		cboxChecked=false;
	}
}
function pad(str, char) {
	while (str.length<2) {
		str=char+str;
	}
	return str;
}
function generePassword() {
	ajaxPostSend("key=getPassword", "generePassword.php", "postGenerePassword");
}
function postGenerePassword(str) {
	var passField=document.getElementById("passwd");
	passField.value=str;
	alert("nous avons généré le mot de passe suivant pour votre compte : "+str);
}
