// JavaScript Document
var tChoixLiv = 'Vous devez sélectionner votre mode d\'expédition pour la mise à jour du calendrier.';
var tReserv = 'Date valable sous réserve d\'encaissement de votre règlement avant le %s à %s.';

/******************************************
CODE POUR RECHERCHER UN OBJET
Example: obj = findObj("image1");
*/
function findObj(theObj, theDoc)
{
	var p, i, foundObj;
  
	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
		theDoc = parent.frames[theObj.substring(p+1)].document;
	theObj = theObj.substring(0,p);
	}
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++)
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
	window.alert(foundObj);
	return foundObj;
}

/******************************************
CODE LIRE ET ECRIRE DES COOKIES
*/
sDate = new Date;
sDate.setMonth(sDate.getMonth()+6);

function EcrireCookie(nom, valeur) {
	var argv = EcrireCookie.arguments;
	var argc = EcrireCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function LireCookie(nom) {
	var arg = nom + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i<clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}

/******************************************
CODE POUR AFFECTER UNE CLASSE
Example: obj = findObj("image1");

* Dependencies * 
this function requires the following snippet:
JavaScript/readable_MM_functions/findObj
*/
function setClasse(objName, classeName)
{
	obj = document.getElementById(objName);
	obj.className = classeName;
}


/******************************************
CODE POUR FAIRE UNE REQUETE AJAX
Example:
callAjax('page.php', '&param1=3&param2=f')";
*/
function callAjax(sUrl, sQuery) {
	
	if (sUrl!='') {
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			return;
		}
		
		xhr_object.open('POST', sUrl, true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}
		
		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xhr_object.send(sQuery);
	}
	return;
	
}

/******************************************
CODE POUR CHANGER L'APERCU D'UN ARTICLE
*/
function ChangeCouleurImageArticle(sArticleId, sArticleCouleurId, sVue) {
	sFonction = '1';
	callAjax('include/allquery.php', '&f='+sFonction+'&article_id='+sArticleId+'&article_couleur_id='+sArticleCouleurId+'&type_vue='+sVue);
	return;
}

function ControlePanier(sCommandeId) {
	sFonction = '3';
	callAjax('include/allquery.php', '&f='+sFonction+'&tcmd_commande_id='+sCommandeId);
	return;
}

function ApercuImage(sImageId) {
	sFonction = '4';
	callAjax('include/allquery.php', '&f='+sFonction+'&image_id='+sImageId);
	return;
}

function ControleCommande(sCommandeId) {
	sFonction = '8';
	callAjax('include/allquery.php', '&f='+sFonction+'&tcmd_commande_id='+sCommandeId);
	return;
}

var iDebuter = 60000;

function AfficherAide(sRel, sId, sRub) {
	/*
	sCacher = LireCookie('cacheraide');
	if(sCacher!='1')
		setTimeout("tb_show('Comment d&eacute;buter', 'comment-debuter.php?width=600&height=400', false)", iDebuter);
	return;
	*/
	if (sId!='')
		sUrl = sRel+'/aide.php?aid='+sId;
	else
		if (sRub!='')
			sUrl = sRel+'/aide.php?rub_id='+sRub;
		else
			sUrl = sRel+'/aide.php?aid=0';
	
	aide = window.open(sUrl, 'aide', 'menubar=no,status=yes,scrollbars=auto,menubar=no,width=720,height=580');
	aide.focus();
}

function switchImage(imgName, imgSrc) {
  if (document.images) {
    if (imgSrc != "none") {
      document.images[imgName].src = imgSrc;
    }
  }
}

function CommanderProduit(sCommandeId, sProduitId) {
	sFonction = '9';
	callAjax('../include/allquery.php', '&f='+sFonction+'&cmd_commande_id='+sCommandeId+'&cmd_produit_id='+sProduitId);
	return;
}

// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload() { 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++) {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

simplePreload('/img/v2/promo/picto_article_on.gif', '/img/v2/promo/picto_100p_on.gif', '/img/v2/promo/picto_image_on.gif');

// estimation-livraison.php
function MajListeMode() {
	
	var oForm = document.FormEstim;
	var sCodePostal = oForm.code_postal.value;
	var sPaysCode = oForm.pays_code.value;
	var sSessionId = oForm.sid.value;
	
	var xhr_object = null;
	
	if(window.XMLHttpRequest) // Firefox
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
	else { // XMLHttpRequest non supporté par le navigateur
		window.alert('Une erreur est survenue.');
		return;
	}
	
	xhr_object.open('POST', 'include/allquery.php', true);
	
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
			//window.alert(xhr_object.responseText);
			eval(xhr_object.responseText);
		}
	}
	
	xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	var data = 'f=2&code_postal='+escape(sCodePostal)+'&pays_code='+escape(sPaysCode)+'&sid='+escape(sSessionId);
	xhr_object.send(data);
	
	return;
}

function EnregistrerLivraison() {
	var oForm = document.FormEstim;
	var sCodePostal = oForm.code_postal.value;
	var sPaysCode = oForm.pays_code.value;
	var sLivraisonModeId = oForm.livraison_mode_id.value;
	
	EcrireCookie('d_code_postal', sCodePostal, sDate);
	EcrireCookie('d_pays_code', sPaysCode, sDate);
	EcrireCookie('d_livraison_mode_id', sLivraisonModeId, sDate);
	
	location.href='panier.php';
}

// reduction.php
function CalculerReduction() {
	
	oForm = document.FormReduc;
	sValeurCode = oForm.valeur_code.value;
	sSessionId = oForm.sid.value;
	//window.alert('Calcul...\nCode : '+sValeurCode+'\nSession : '+sSessionId);
	
	if ((sValeurCode!='')&&(sSessionId!='')) {
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			window.alert('Une erreur est survenue.');
			return;
		}
		
		xhr_object.open('POST', 'include/update_panier.php', true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}
		
		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		var data = 'act=reduc&valeur_code='+escape(sValeurCode)+'&sid='+escape(sSessionId);
		xhr_object.send(data);
		
		oForm.valeur_code.value = '';
	}
	else
		window.alert('Vous n\'avez saisi aucun code.');
	return;
}

function EnregistrerReduction(sValeurCode, sSessionId) {
	
	//window.alert('Ajout...\nCode : '+sValeurCode+'\nSession : '+sSessionId);
	if ((sValeurCode!='')&&(sSessionId!='')) {
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			window.alert('Une erreur est survenue.');
			return;
		}
		
		xhr_object.open('POST', 'include/update_panier.php', true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}
		
		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		var data = 'act=ajouterreduc&valeur_code='+escape(sValeurCode)+'&sid='+escape(sSessionId);
		xhr_object.send(data);
	}
	return;
}

function ConserverReduction() {
	tb_remove();
	return;
}

// cheque-cadeau.php
function AjouterChequeCadeau() {
	
	oForm = document.FormCheque;
	sValeurCode = oForm.code_cheque.value;
	sSessionId = oForm.sid.value;
	
	if ((sValeurCode!='')&&(sSessionId!='')) {
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			window.alert('Une erreur est survenue.');
			return;
		}
		
		xhr_object.open('POST', 'include/query_client.php', true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}
		
		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		var data = 'act=chqcado&code_cheque='+escape(sValeurCode)+'&sid='+escape(sSessionId);
		xhr_object.send(data);
	}
	return;
}

function SupprimerChequeCadeau(sValeurCode, sSessionId) {
	
	if ((sValeurCode!='')&&(sSessionId!='')) {
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			window.alert('Une erreur est survenue.');
			return;
		}
		
		xhr_object.open('POST', 'include/query_client.php', true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}
		
		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		var data = 'act=supprchqcado&code_cheque='+escape(sValeurCode)+'&sid='+escape(sSessionId);
		xhr_object.send(data);
	}
	return;
}

// mot-de-passe.php
function DemandeMotDePasse() {
	
	oForm = document.FormPass;
	sEmail = oForm.email_login.value;
	
	var xhr_object = null;
	
	if(window.XMLHttpRequest) // Firefox
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
	else { // XMLHttpRequest non supporté par le navigateur
		window.alert('Une erreur est survenue.');
		return;
	}
	
	xhr_object.open('POST', '../include/query_client.php', true);
	
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
			//window.alert(xhr_object.responseText);
			eval(xhr_object.responseText);
		}
	}
	
	xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	var data = 'act=demandepass&email_login='+escape(sEmail);
	xhr_object.send(data);
	
	return;
}

// Affichage de l'enquete
function AfficherEnquete(sEnqueteId, sNom, sScroll, sWidth, sHeight) {
	sCacher = LireCookie('cacherenquete'+sEnqueteId);
	if(sCacher!='1') {
		enquete = window.open(sNom+'.php', 'enquete', 'menubar=no,status=no,scrollbars='+sScroll+',menubar=no,width='+sWidth+',height='+sHeight);
		window.focus();
		enquete.blur();
	}
	return;
}

function ChangerCouleurRecherche(oThis, sEvt, sDefaut) {
	switch (sEvt) {
	case 'focus':
		if (oThis.value==sDefaut) {
			oThis.value='';
			oThis.style.color='#6C5B66';
		}
		else {
			oThis.value=sDefaut;
			oThis.style.color='#DDDDDD';
		}
		break;
	case 'blur':
		if (oThis.value=='') {
			oThis.value=sDefaut;
			oThis.style.color='#DDDDDD';
		}
		break;
	}
	return;
}

function ShowHideRayon(sId) {
	
	if (document.getElementById(sId).style.display=='')
		document.getElementById(sId).style.display = 'none';
	else
		document.getElementById(sId).style.display = '';
}

// modifier-article.php

function ChoixArticle() {
	oForm = document.FormModifierArticle;
	l2 = oForm.elements['couleur_id'];
	l3 = oForm.elements['taille_id'];
	sCouleurId = l2.options[l2.selectedIndex].value;
	sTailleId = l3.options[l3.selectedIndex].value;
	sArticleId = oForm.article_id.value;
	sProduitId = oForm.tcmd_produit_id.value;
	sSessionId = oForm.sid.value;
	
	if ((sCouleurId=='')||(sTailleId=='')) {
		window.alert('Vous devez choisir une couleur et une taille.');
		return;
	}
	else {
		if ((sArticleId=='')||(sProduitId=='')||(sSessionId=='')) {
			window.alert('Une erreur est survenue.\nNous ne pouvons pas modifier le contenu de votre panier.');
			location.href='panier.php';
		}
		else {
			var sData = 'f=7&article_id='+sArticleId+'&couleur_id='+sCouleurId+'&taille_id='+sTailleId+'&tcmd_produit_id='+sProduitId+'&sid='+sSessionId;
			callAjax('include/allquery.php', sData);
		}
	}
	return;
}

function ListeTaille() {
	
	var l2 = document.FormModifierArticle.elements['couleur_id'];
	var l3 = document.FormModifierArticle.elements['taille_id'];
	var iIndex2 = l2.selectedIndex;
	var iIndex3 = l3.selectedIndex;
	if (iIndex2 < 1) {
		l3.options.length = 0;
		l3.options[0] = new Option('Aucune','');
		document.getElementById('ItemPriceHtml').innerHTML = '-';
	}
	else {
	
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			window.alert(tError);
			return;
		}
		
		xhr_object.open('POST', 'include/allquery.php', true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}

		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		var sData = 'f=5&article_id='+escape(document.FormModifierArticle.article_id.value)+'&couleur_id='+escape(l2.options[iIndex2].value)+'&image_id='+escape(document.FormModifierArticle.image_id.value);
		xhr_object.send(sData);
	}   
}

function AffichePrix() {
	
	var l2 = document.FormModifierArticle.elements['couleur_id'];
	var l3 = document.FormModifierArticle.elements['taille_id'];
	var iIndex2 = l2.selectedIndex;
	var iIndex3 = l3.selectedIndex;
	if ((iIndex2<1)||(iIndex3<1)) {
		document.getElementById('ItemPriceHtml').innerHTML = '-';
	}
	else {
	
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			window.alert(tError);
			return;
		}
		
		xhr_object.open('POST', 'include/allquery.php', true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}

		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		var sData = 'f=6&article_id='+escape(document.FormModifierArticle.article_id.value)+'&couleur_id='+escape(l2.options[iIndex2].value)+'&taille_id='+escape(l3.options[iIndex3].value)+'&image_id='+escape(document.FormModifierArticle.image_id.value);
		xhr_object.send(sData);
	}   
}

function Fermer() {
	tb_remove();
	return;
}

// remise-devis.php
function CalculerRemise() {
	
	oForm = document.FormRemise;
	sDevisId = oForm.devis_id.value;
	sSessionId = oForm.sid.value;
	
	if ((sDevisId!='')&&(sSessionId!='')) {
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			window.alert('Une erreur est survenue.');
			return;
		}
		
		xhr_object.open('POST', 'include/update_panier.php', true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}
		
		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		var data = 'act=remdevis&devis_id='+escape(sDevisId)+'&sid='+escape(sSessionId);
		xhr_object.send(data);
		
		oForm.devis_id.value = '';
	}
	return;
}

function FermerRemise() {
	tb_remove();
	return;
}

// dupliquer-compte.php
function DupliquerCompte() {
	
	oForm = document.FormDup;
	sEmail = oForm.email_login.value;
	sPwd = oForm.client_pwd.value;
	sFrom = oForm.from.value;
	
	var xhr_object = null;
	
	if(window.XMLHttpRequest) // Firefox
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
		xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
	else { // XMLHttpRequest non supporté par le navigateur
		window.alert('Une erreur est survenue.');
		return;
	}
	
	xhr_object.open('POST', '../include/query_client.php', true);
	
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
			//window.alert(xhr_object.responseText);
			eval(xhr_object.responseText);
		}
	}
	
	xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	var data = 'act=dupliquercompte&email_login='+escape(sEmail)+'&client_pwd='+escape(sPwd)+'&from='+escape(sFrom);
	xhr_object.send(data);
	
	return;
}

// recapitulatif.php
function ChangerUneAdresse(sAdresseType, sSessionId) {
	location.href = 'adresse.php?adresse_type='+sAdresseType;
}

function ChoixModeLivraison() {
	sLivraisonModeId = $('#livraison_mode_id').val();
	sD = $('#d').val();
	sSessionId = LireCookie('PHPSESSID');
	
	$('#DateLivraison').text('--/--/----');
	$('#CondReglement').text(tChoixLiv);
	
	$.ajax({
		type: "POST",
		url: "include/query_client.php",
		data: "act=choixmodelivraison&livraison_mode_id="+sLivraisonModeId+"&sid="+sSessionId+"&d="+sD,
		dataType: "json",
		success: function(tab_json){
			if (tab_json.erreur==true) {
				tb_show('Information', 'alerte.php?p='+tab_json.alerte_type+'&width=490&height=250', null);
			}
			else {
				$('#PrixFabrication').text(tab_json.total.prix_fabrication);
				$('#TotalProduit').text(tab_json.total.total_produit);
				$('#PrixLivraison').text(tab_json.total.prix_livraison);
				$('#PrixTotal').text(tab_json.total.prix_total);
				$('#TotalTva').text(tab_json.total.total_tva);
				$('#GrandTotalTTC').text(tab_json.total.grand_total_ttc);
				
				$('#delai_fabrication_id').val(tab_json.delai_fabrication_id);
				$('#DateLivraison')
					.text(tab_json.date_livraison)
					.datePicker({
						startDate: tab_json.date_min,
						endDate: tab_json.date_max,
						renderCallback:function($td, thisDate, month, year) {
							
							if (tab_json.date_livraison!='--/--/----') {
								
								// Creation de la date en cours au format aaaammjj
								m = thisDate.getMonth() + 1;
								(m > 9) ? m = m.toString() : m = '0'+m.toString();
								(thisDate.getDate() > 9) ? d = thisDate.getDate().toString() : d = '0'+thisDate.getDate().toString();
								id_date_tab = thisDate.getFullYear().toString()+m+d;
								
								// Creation de la date min au format aaaammjj
								tm = tab_json.date_min.split('/');
								dmin = tm[2]+tm[1]+tm[0];
								// Creation de la date min au format aaaammjj
								tm = tab_json.date_max.split('/');
								dmax = tm[2]+tm[1]+tm[0];
								
								if (id_date_tab>=dmin && id_date_tab<=dmax)
									if (thisDate.isWeekDay())
										$td.removeClass('disabled');
									else
										if (thisDate.isSaturday())
											if (tab_json.liv_sam==false)
												$td.addClass('disabled');
											else
												$td.removeClass('disabled');
								
								if (tab_json.prix_jour[id_date_tab]==undefined)
									$td.html(thisDate.getDate()+'<br/>&nbsp;');
								else
									$td.html(thisDate.getDate()+'<br/>'+tab_json.prix_jour[id_date_tab]+'&euro;');
								/*
								if (tab_json.condition.sans_choix==false) {
									s = tReserv;
									p1 = s.indexOf('%s');
									p2 = s.lastIndexOf('%s');
									s = s.substring(0, p1)+tab_json.condition.date+s.substring(p1+2, p2)+tab_json.condition.heure+s.substr(p2+2);
									$('#CondReglement').text(s);
								}
								else
									$('#CondReglement').text(tChoixLiv);
								*/
								$.each(tab_json.jour_ferie, function(i, n) {
									if (id_date_tab==n)
										$td.addClass('disabled'); 
								});
							}
							else {
								$td.addClass('disabled');
								$td.html(thisDate.getDate()+'<br/>&nbsp;');
								$('#CondReglement').text(tChoixLiv);
							}
						}
					})
					.dpSetSelected(tab_json.date_livraison);
					
			}
			if (tab_json.alerte==true)
				tb_show('Information', 'alerte.php?date_livraison='+tab_json.date_livraison+'&p='+tab_json.alerte_type+'&width=490&height=250', null);
		},
		error: function() {
			tb_show('Information', 'alerte.php?p=asynch_error&width=490&height=250', null);
		}
	});

	return;
}

function ChoixDateLivraison(sLivraisonModeId, sDatelivraison) {
	
	sLivraisonModeId = $('#livraison_mode_id').val();
	sDateLivraison = $('#DateLivraison').text();
	sD = $('#d').val();
	sSessionId = LireCookie('PHPSESSID');
	
	if (sLivraisonModeId!='' && sDateLivraison!='') {
		
		$.ajax({
			type: "POST",
			url: "include/query_client.php",
			data: 'act=choixdatelivraison&livraison_mode_id='+sLivraisonModeId+'&date_livraison='+sDateLivraison+'&sid='+sSessionId+'&d='+sD,
			dataType: "json",
			success: function(tab_json){
				if (tab_json.erreur==true) {
					tb_show('Information', 'alerte.php?p='+tab_json.alerte_type+'&width=490&height=250', null);
				}
				else {
					$('#PrixFabrication').text(tab_json.total.prix_fabrication);
					$('#TotalProduit').text(tab_json.total.total_produit);
					$('#PrixLivraison').text(tab_json.total.prix_livraison);
					$('#PrixTotal').text(tab_json.total.prix_total);
					$('#TotalTva').text(tab_json.total.total_tva);
					$('#GrandTotalTTC').text(tab_json.total.grand_total_ttc);
					
					$('#delai_fabrication_id').val(tab_json.delai_fabrication_id);
					
					if (tab_json.condition.sans_choix==false) {
						s = tReserv;
						p1 = s.indexOf('%s');
						p2 = s.lastIndexOf('%s');
						s = s.substring(0, p1)+tab_json.condition.date+s.substring(p1+2, p2)+tab_json.condition.heure+s.substr(p2+2);
						$('#CondReglement').text(s);
					}
					else
						$('#CondReglement').text(tChoixLiv);
				}
				if (tab_json.alerte==true)
					tb_show('Information', 'alerte.php?date_livraison='+tab_json.date_livraison+'&p='+tab_json.alerte_type+'&width=490&height=375', null);
			},
			error: function() {
				tb_show('Information', 'alerte.php?p=asynch_error&width=490&height=250', null);
			}
		});
		
	}
	else
		window.alert('Vous devez sélectionner un mode de livraison et une date de livraison pour votre commande.');

	return;
}

function Paiement(sSessionId) {
	
	sLivraisonModeId = $('#livraison_mode_id').val();
	sDateLivraison = $('#DateLivraison').text();
	sD = $('#d').val();
	sSessionId = LireCookie('PHPSESSID');
	sTexteCadeau = $('#texte_cadeau').val();
	sCommandeCadeau = 0;
	
	if (sLivraisonModeId!='') {
		
		/*
		sCommandeCadeau = 0;
		sTexteCadeau = document.FormRecap.texte_cadeau.value;
		sDateLivraison = $('#DateLivraison').text();
		var xhr_object = null;
		
		if(window.XMLHttpRequest) // Firefox
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject('Microsoft.XMLHTTP');
		else { // XMLHttpRequest non supporté par le navigateur
			//window.alert('Une erreur est survenue.');
			return;
		}
		
		xhr_object.open('POST', 'include/query_client.php', true);
		
		xhr_object.onreadystatechange = function() {
			if(xhr_object.readyState == 4) {
				//window.alert(xhr_object.responseText);
				eval(xhr_object.responseText);
			}
		}
		
		xhr_object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		var data = 'act=gopaiement&livraison_mode_id='+sLivraisonModeId+'&commande_cadeau='+sCommandeCadeau+'&texte_cadeau='+escape(sTexteCadeau)+'&date_livraison='+sDateLivraison+'&sid='+sSessionId;
		xhr_object.send(data);
		*/
		
		$.ajax({
			type: "POST",
			url: "include/query_client.php",
			data: 'act=gopaiement&livraison_mode_id='+sLivraisonModeId+'&commande_cadeau='+sCommandeCadeau+'&texte_cadeau='+escape(sTexteCadeau)+'&date_livraison='+sDateLivraison+'&sid='+sSessionId,
			dateType: "json",
			success: function(tab_json){
				if (tab_json.erreur==true || tab_json.alerte==true) {
					tb_show('Information', 'alerte.php?p='+tab_json.alerte_type+'&width=490&height=250', null);
				}
					location.href='paiement.php';
			},
			error: function() {
				tb_show('Information', 'alerte.php?p=asynch_error&width=490&height=250', null);
			}
		});

	}
	else
		window.alert('Vous devez sélectionner un mode de livraison pour votre commande.');
	return;
}

function Cadeau() {
	sDisp = document.getElementById('ChampsCadeau').style.display;
	if (sDisp=='none')
		document.getElementById('ChampsCadeau').style.display = '';
	else {
		document.FormRecap.date_livraison.value = 'Aucune';
		document.FormRecap.texte_cadeau.value = '';
		document.getElementById('ChampsCadeau').style.display = 'none';
	}
	return;
}
