function majPanier(){
  $.ajax({
    type: "POST",
	url: "inc/infos_panier.php",
	success:function(msg){
	  $("#page_right_panier").html(msg) ;
	}
  }) ;
}

function ajoutPanierListe(id){
  var id_bonbon = id ;
  var qte = $("#qte_"+id).val() ;
  if(qte==0 || isNaN(qte)){
    alert("La quantite saisie n'est pas valide...") ;
	$("#qte_"+id).focus() ;
  }
  else{
    $.ajax({
	  type: "POST",
	  url: "php/ajout_panier.php",
	  data: "id_bonbon="+id_bonbon+"&qte="+qte,
	  success:function(){
		majPanier() ;
	    detailAjoutPanier(id_bonbon,qte) ;
	  }
	}) ;
  }
}

function changeRef(id_ref){
  $.ajax({
    type: "POST",
	url: "inc/ajout_panier.php",
	data: "id_bonbon="+$("id_bonbon").val()+"&id_ref_bonbon="+id_ref,
	success:function(msg){
	  $("#div_ajout_panier").html(msg) ;
	}
  }) ;
}

function ajoutPanier(){
  var id_bonbon = $("#id_bonbon").val() ;
  var qte = $("#qte").val() ;
  if(qte==0 || isNaN(qte)){
    alert("La quantite saisie n'est pas valide...") ;
	$("#qte").focus() ;
  }
  else{
    $.ajax({
	  type: "POST",
	  url: "php/ajout_panier.php",
	  data: "id_bonbon="+id_bonbon+"&qte="+qte,
	  success:function(){
		majPanier() ;
	    detailAjoutPanier(id_bonbon,qte) ;
	  }
	}) ;
  }
}



// affiche le detail de ce qui vient d'être ajouté au panier
function detailAjoutPanier(id_bonbon,qte){
  $("<div id=\"msg_detail_ajout_panier\" class=\"msg_user\"></div>").appendTo($("body")) ;
  $("<div id=\"light_detail_ajout_panier\" class=\"light_user\"></div>").appendTo($("body")) ;
  
  
  /*
  var pos = $("#msg_detail_ajout_panier").position() ;
  var top = pos.top ;
  var height = $("#light_detail_ajout_panier").height() ;
  var scroll = $(document).scrollTop() ;
  $("#light_detail_ajout_panier").css("height",(height+scroll)+"px") ;
  if(scroll>0) $("#msg_detail_ajout_panier").css("top",(top+scroll)) ;
  */

  $("#light_detail_ajout_panier").click(function(){
    closeDetail() ;
  }) ;

  $.ajax({
    type: "POST",
	url: "inc/detail_ajout_panier.php",
	data: "id_bonbon="+id_bonbon+"&qte="+qte,
	success:function(msg){
	  $("#msg_detail_ajout_panier").html(msg) ;
	  $("#light_detail_ajout_panier").show("fast") ;
	  $("#msg_detail_ajout_panier").show("fast") ;
	}
  }) ;
}

function closeDetail(){
  $("#msg_detail_ajout_panier").remove() ;
  $("#light_detail_ajout_panier").remove() ;
}



function goRecherche(){
  rech_mc = $("#rech_mc").val().replace("&","-ecom-") ;
  var rech_mc = encodeURIComponent(rech_mc) ;
  
  var type_rech = $("input[type=radio][name=type_rech]:checked").attr("value");
  if(!type_rech) type_rech = "tout" ;
  window.location = "http://localhost/wsp/cdhv.com/q="+rech_mc+"&tr="+type_rech ;
}


// recupere l'url direct d'un produit en html et envoit sur cette page
function rechercheRef(ref){
  $.ajax({
    type:"POST",
	url:"php/ref2url.php",
	data:"ref="+ref,
	success:function(msg){
	  window.location = msg ;
	}
  });
}

// recupere l'url direct d'un produit en html et envoit sur cette page
function rechercheNom(id){
  $.ajax({
    type:"POST",
	url:"php/id2url.php",
	data:"id="+id,
	success:function(msg){
	  window.location = msg ;
	}
  });
}
