
	//	-------------------------------------------------------------------------------------------------------------------
	/**
	 *		Fonction de gestion des échanges avec le panier d'achat
	 */
	var oldcontenu;
	function addComp(obj){
		var obj=findDOM("page",0);
		oldcontenu=obj.innerHTML;
		ecranattente("");
		var value="-1",qte=1,objqte=findDOM("panier_add_qte",0);
		if(objqte)qte=objqte.value;
		var url="AjaxEvenement.html?noos=ELCOADDCOMP" ;
		var request=initRequest(url,PLATEFORM);
		request.onreadystatechange=function(){if(request.readyState==4 && request.status==200)panierAlert(request.responseText);}
		request.open("POST",url,true);
		request.send(null);
	}

	function addArt(event,idofmodele,idofarticle,pagepanier,obj){
		var obj=findDOM("page",0);
		var panierqte=findDOM("panierqte",0);
		var qte;
		if(panierqte)qte=panierqte.value;
		if(!qte | qte==0)qte=1;
		oldcontenu=obj.innerHTML;
		//ecranattente("");
		var url="AjaxEvenement.html?noos=ELCOADDART&idofmodele="+idofmodele+"&idofarticle="+idofarticle+"&qteofarticle="+qte;
		var request=initRequest(url,PLATEFORM);
		request.onreadystatechange=function(){if(request.readyState==4 && request.status==200)panierAlert(event,request.responseText);}
		request.open("POST",url,true);
		request.send(null);
	}

	function panierAlert(e,msg){
		var pos=msg.indexOf("$qte:",0);
		var end=msg.indexOf(";",pos);
		var qte=msg.substring(pos+5,end);
		var obj=findDOM("page",0);
		var themsg=msg.substring(0,pos);

		//var thehtml="<h1 class=\"panierpoursuivre\">panier d'achat</h1><br>";
		//thehtml+="<div style=\"width:90%;height:90%;border:1px solid #eaeaea\">";
		var thehtml="<p class=\"panierpoursuivre\">"+themsg+"</p>";
		thehtml+="<h3 class=\"panierpoursuivreqte\">Votre panier contient "+qte+" article(s)</h3>";
		//thehtml+="</div>"; //<br><br>";
		//thehtml+="<a class=\"panierpoursuivre\" href=\"#\" onclick=\"javascript:restoreAlert("+qte+");\">poursuivre vos achats</a><br><br>";

		obj=findDOM("panier_quantite",0);
		if(obj)obj.innerHTML=qte;

		//alert("ajout au panier");
		var x, y;
		if(e){
			x=e.pageX+(document.body.scrollLeft || document.documentElement.scrollLeft)-500,
			y=e.pageY+(document.body.scrollTop || document.documentElement.scrollTop)-200;
		}else{
			x=event.clientX+(document.body.scrollLeft || document.documentElement.scrollLeft)-500,
			y=event.clientY+(document.body.scrollTop || document.documentElement.scrollTop)-200;
		}

		/*
		var x=event.clientX+(document.body.scrollLeft || document.documentElement.scrollLeft)-500,
				y=event.clientY+(document.body.scrollTop || document.documentElement.scrollTop)-200;
				*/
		var $dialog_panier=$("<div class=\"modal\"></div>");
		$dialog_panier
			.html(thehtml)
			.dialog({
				width:500,
				height:200,
				modal:true,
				autoOpen:false,
				position:[x,y],
				title:"l'article à été ajouté à votre panier",
				buttons:{"poursuivre vos achats": function(){$(this).dialog("close");}}
			});
		$dialog_panier.dialog("open");
		
		/*

		contenu=oldcontenu;
		var x=event.clientX,y=event.clientY+(document.body.scrollTop || document.documentElement.scrollTop);
		contenu+="<div style=\"position:absolute;top:-20px;left:0;width:100%;height:200%;z-index:2000\">";
    contenu+="<div style=\"position:absolute;top:0;left:0;width:100%;height:100%;background-color:#312e1d;filter:alpha(opacity=80);-moz-opacity:0.80;opacity:0.80\">&nbsp;</div>";
		contenu+="<center style=\"position:absolute;top:"+y+"px;left:25%;width:50%;height:auto;background-color:#fff\"><br>";
		contenu+="<h1 class=\"panierpoursuivre\">panier d'achat</h1><br>";
		contenu+="<div style=\"width:90%;height:90%;border:1px solid #eaeaea\">";
		contenu+="<h3 class=\"panierpoursuivre\">y:"+y+" | "+themsg+"</h3>";
		contenu+="<h3 class=\"panierpoursuivreqte\">Votre panier contient "+qte+" article(s)</h3>";
		contenu+="</div><br><br>";
		contenu+="<a class=\"panierpoursuivre\" href=\"#\" onclick=\"javascript:restoreAlert("+qte+");\">poursuivre vos achats</a><br><br>";
		contenu+="</center>";
		contenu+="</div>";
		obj.innerHTML=contenu;
		obj=findDOM("panier_quantite",0);
		if(obj)obj.innerHTML=qte;*/
	}

	function panierEnd(msg){
		var obj=findDOM("page",0);
		oldcontenu=obj.innerHTML;
		contenu+="<div style=\"position:absolute;top:-20px;left:0;width:100%;height:200%;z-index:2000\">";
    contenu+="<div style=\"position:absolute;top:0;left:0;width:100%;height:100%;background-color:#312e1d;filter:alpha(opacity=80);-moz-opacity:0.80;opacity:0.80\">&nbsp;</div>";
		contenu+="<center style=\"position:absolute;top:200px;left:25%;width:50%;height:auto;background-color:#fff\"><br>";
		contenu+="<div style=\"width:90%;height:90%;border:1px solid #eaeaea\">";
		contenu+="<h3 style=\"color:#383838;background-color:#ccc;filter:alpha(opacity=80);-moz-opacity:0.80;opacity:0.80;padding:10px;margin:0\">"+msg+"</h3>";
		contenu+="</div><br><br>";
		contenu+="<a href=\"#\" class=\"panierend\" onclick=\"javascript:restoreAlert(0);\">poursuivre</a><br><br>";
		contenu+="</center>";
		contenu+="</div>";
		obj.innerHTML=contenu;
	}
	function restoreAlert(qte){
		var obj=findDOM("page",0);
		obj.innerHTML=oldcontenu;
		if(qte!=0){
			obj=findDOM("panier_quantite",0)
			if(obj)obj.innerHTML=qte;
		}
	}

	function panierport(action,obj,val){
		var id=null,v=null;
		if(action=="panierport_select_pays") id=obj.value;
		else if(action=="panierport_select_paiement") id=obj.value;
		else if(action=="panierport_select_conditionvente") id=(obj.value=='conditionvente'?1:0);
		else if(action=="panierport_change_qte"){id=obj;v=val.value;}
		else if(action=="panierport_supp_row"){id=obj;v=val.value;}
		else id=obj;
		var url="gauvain/PanierportIO.html?action="+action+"&id="+id+"&val="+escape(v);
		var request=initRequest(url,PLATEFORM);
		request.onreadystatechange=function(){
			if(request.readyState==4){
				if(request.status==200){
					var reponse=request.responseText;
					if(reponse.indexOf("RELOAD")!=-1){
						window.location.reload ( true ) ;
					}else{
						var tranche=getHtmlForZone(reponse,"[tranche]");
						if(tranche){
							$("#panierport_tranche span").html(tranche);
							$("#panierport_tranche").css("display","block");
						}
						var paiement=getHtmlForZone(reponse,"[paiement]");
						if(paiement){
							$("#panierport_paiement span").html(paiement);
							$("#panierport_paiement").css("display","block");
						}
						var conditionvente=getHtmlForZone(reponse,"[conditionvente]");
						if(conditionvente){
							$("#panierport_conditionvente span").html(conditionvente);
							$("#panierport_conditionvente").css("display","block");
						}
						var totaux=getHtmlForZone(reponse,"[totaux]");
						if(totaux)$("div.totaux").html(totaux);
						/*
						var totalht=getHtmlForZone(reponse,"[totalht]");
						if(totalht)	$("div.panier_totalht").html(totalht);
						var totalttc=getHtmlForZone(reponse,"[totalttc]");
						if(totalttc)	$("div.panier_totalttc").html(totalttc);
						var poids=getHtmlForZone(reponse,"[poids]");
						if(poids)	$("div.panier_poids").html(poids);
						var totalhtfp=getHtmlForZone(reponse,"[totalhtfp]");
						if(totalhtfp)	$("div.panier_totalhtfraisport").html(totalhtfp);
						var totalttcfp=getHtmlForZone(reponse,"[totalttcfp]");
						if(totalttcfp)	$("div.panier_totalttcfraisport").html(totalttcfp);
						var tvafp=getHtmlForZone(reponse,"[tvafp]");
						if(tvafp)	$("div.panier_tvafraisport").html(tvafp);
						var row=getHtmlForZone(reponse,"[row]");
						if(row){
							var id=getChamp(row,"id=");
							var ht=getChamp(row,"ht=");
							var ttc=getChamp(row,"ttc=");
							$("#"+id+".ht").html(ht);
							$("#"+id+".ttc").html(ttc);
						}

						if(reponse.indexOf("EXONERATION_TVA")!=1){
							$(".ht" ).css("display","none");
							$(".tva" ).css("display","none");
						} else {
							$(".ht" ).css("display","block");
							$(".tva" ).css("display","block");
						}*/

						if(reponse.indexOf("AFFICHAGE")!=-1) $(".panierport_suite").css("display","block");
						else $(".panierport_suite").css("display","none");
					}
				}
			}
		}
		request.open("POST",url,true);
		request.send(null);
	}

	function getChamp(src,champ){
		var pos=src.indexOf(champ);
		if(pos!=-1){
			var end=src.indexOf(";",pos);
			return src.substring(pos+champ.length,end);
		}
		return "";
	}

	function getHtmlForZone(src,zone){
		var pos=src.indexOf(zone);
		if(pos!=-1) return src.substring(pos+zone.length,src.indexOf(zone,pos+zone.length));
		return "";
	}

	function actionPanier(action,id,obj){
		var value="-1",qte=1;
		if(action=="changeqte"){
		  panier=id;
			value=obj.value;
		}else if(action=="changecommentaire"){
			panier=id;
			value=obj.value;
		}else if(action=="selectpays"){
			id=obj.value ;
		}else if(action=="selecttransport"){
			id=obj.value;
		}else if(action=="selectpaiement"){
			id=obj.value;
		}else if(action=="changeconditionvente"){
			id=obj.value;
		}else if(action=="controlpanier"){
			document.location.reload() ;
			return ;
		}
		
		var url="AjaxEvenement.html?noos=ELCO&id="+id+"&cmde=-1&value="+value+"&action="+action;
		var request=initRequest(url,PLATEFORM);
		request.onreadystatechange=function(){
			if ( request.readyState == 4 ) {
				if ( request.status == 200 ) {
					var reponse = request.responseText ;

					//	Si nous sommes dans un cas de NOMESSAGE, on rafraichit la page courante
					if				( reponse == 'NOMESSAGE' ) {
						window.location.reload ( true ) ;

					//	Si la réponse contient OPEN: alors if faut ouvrir en modification une ligne du panier
					} else if ( reponse.indexOf ( "ID_MS" ) != -1 ) {
						document.location.href = reponse  ;

					//	Est ce que la réponse contient un tableau de valeur. Début {, fin } valeur séparée par des
					} else if ( reponse.indexOf ( "paysselect" ) != -1 | reponse.indexOf ( "transportselect" ) != -1 | reponse.indexOf ( "paiementselect" ) != -1 | reponse.indexOf ( "conditionventeselect" ) != -1 ) {
						document.location.reload() ;

					} else if ( reponse.indexOf ( "paniervalider" ) != -1 ) {
						alert ( "Merci de votre confiance, votre panier de commande vient d'être validé ! " ) ;
						document.location.reload() ;

					//	Sinon, on affiche le dialogue d'alerte contenant la réponse
					} else {
						alert ( reponse ) ;
						if ( action == "facturation" | action == "livraison" | action == "entreprise" | action == "destinataire" ) document.location.reload ( true ) ;
					}
				}
			}
		}
		request.open("POST",url,true);
		request.send(null);
	}

