﻿// JavaScript Document



/* FONCTIONS DES MODELES DES ARTICLES ########################## */


// Fonction qui remet les listes des modèles à vide coté FRONT
function raz_modeles(id_article)
{
	try
	{
		var tbl_modeles=$$('select.select_modeles'); 
		for(var i=0; i<tbl_modeles.length; i++)
		{
			tbl_modeles[i].selectedIndex=0;
		}
		update_modeles('', '', id_article);
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'raz_modeles\' dans shop.js :\n'+e.message);
	}
}


// Fonctions qui met à jour les selects des modèles côté Front
function update_modeles(id_attribut, id_modele, id_article)
{
	try
	{
		var nb_value=0;
		var tableau='';
		var table=new Array();
		var tab_chk=new Array();
		var tab=new Array();
		var tbl_modeles=$$('select.select_modeles'); 
		for(var i=0; i<tbl_modeles.length; i++)
		{
			var tmp=tbl_modeles[i].id.split('_');
			var indice=new Number(tmp[1]);
			if(tbl_modeles[i].value!='')
			{
				nb_value++;
			}
			var valeur=new Number(tbl_modeles[i].value);
			table[tmp[1]]=Array(indice, valeur);
			tab_chk[indice]=valeur;
		}
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_update_modeles.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				tab: table.toJSON(),
				id_site: ID_SITE,
				id_attribut: id_attribut,
				id_modele: id_modele,
				id_article: id_article,
				file: 'ajax_update_modeles.php',
				sid: SESSION_ID,
				lng: LNG,
				module:'shop' },
			onCreate: function() {
				$('shop-img-modele-raz').src=PROGRESS_MINI;
			},
			onComplete: function(retour){
				//alert(retour.responseText);
				if(retour.status==200)
				{
					$('shop-lst-modeles').update(retour.responseText);
					$('shop-img-modele-raz').src=ICONE_REFRESH;
					
					if(nb_value==tbl_modeles.length)
					{
						// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
						var action=testdom('shop', 'ajax_search_prix_combi.php', '/appel_ajax.php');
						// On renvoie le prix de la combi
						var myAjax = new Ajax.Request(
						action,
						{
							method: 'post',
							asynchronous: false,
							parameters: {
								tab: table.toJSON(),
								id_site: ID_SITE,
								id_article: id_article,
								file: 'ajax_search_prix_combi.php',
								sid: SESSION_ID,
								lng: LNG,
								module: 'shop' },
							onComplete: function(retour){
								if(retour.status==200)
								{
									var tt=retour.responseText.split('|');
									if($('label_apartirde'))
									{
										$('label_apartirde').style.display='none';
									}
									$('label_prix').update(tt[0]);
									$('label_prix_barre').update(tt[4]);
									$('prix_ecotaxe').update(tt[3]);
									$('label_combinaison').update(html_entity_decode(tt[1], 'ENT_COMPAT'));
									$('id_combinaison').value=tt[2];
								}
							}
						});
					}
				}
				else
				{
					// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
					var action=testdom('shop', 'ajax_search_prix.php', '/appel_ajax.php');
					// On renvoie le prix normal
					var myAjax = new Ajax.Request(
					action,
					{
						method: 'post',
						asynchronous: false,
						parameters: {
							id_site: ID_SITE,
							id_article: id_article,
							file: 'ajax_search_prix.php',
							sid: SESSION_ID,
							lng: LNG,
							module: 'shop' },
						onComplete: function(retour){
							if(retour.status==200)
							{
								if(retour.responseText!='')
								{
									var tt=retour.responseText.split('|');
									if($('label_apartirde'))
									{
										$('label_apartirde').style.display='';
									}
									$('label_prix').update(tt[0]);
									$('label_prix_barre').update(tt[3]);
									$('prix_ecotaxe').update(tt[2]);
									$('label_combinaison').update(html_entity_decode(tt[1], 'ENT_COMPAT'));
									$('id_combinaison').value='';
								}
							}
						}
					});
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'update_modeles\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui enregistre l'attribut d'un modèle sur une combinaison d'un article
function save_attribut_article(id_attribut, id_modele, id_article, id_combinaison)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_attribut_article.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				id_site: ID_SITE,
				id_combinaison: id_combinaison,
				id_attribut: id_attribut,
				id_modele: id_modele,
				id_article: id_article
				
			},
			onCreate: function() {
				$('ajax_combi_save_'+id_combinaison).src=THEME_PROGRESS_MINI;
				$('ajax_combi_save_'+id_combinaison).setStyle({visibility:'visible'});
			},
			onSuccess: function() {
				$('ajax_combi_save_'+id_combinaison).src=THEME_ICONE_SUCCES;
			},
			onFailure: function() {
				$('ajax_combi_save_'+id_combinaison).src=THEME_ICONE_ECHEC;
			},
			onComplete: function(retour){
				if(retour.responseText!='1')
				{
					var tmp=retour.responseText.split('|');
					alert('Cette combinaison existe d\351j\340:\n'+tmp[1]);
					var slt=$('slt_'+id_article+'_'+id_combinaison+'_'+id_modele);
					var opt=slt.select("option");
					for(var i=0; i<opt.length; i++)
					{
						if(opt[i].value==tmp[0])
						{
							opt[i].selected='true';
						}
					}
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_attribut_article\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre une combinaison
function del_combinaison(id_combinaison, id_article)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_del_combinaison.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: 'id_site='+ID_SITE+'&id_combinaison='+id_combinaison,
			onComplete: function(retour){
				if(retour.responseText!='0')
				{
					tbl_combinaisons(id_article);
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_combinaison\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui renvoie le tableau complet des combinaisons
function tbl_combinaisons(id_article)
{
	try
	{		
		// Appel ajax pour boucler sur les modèles cochés
		var myAjaxMod = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_get_tableau_combinaison.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: 'id_site='+ID_SITE+'&id_article='+id_article,
			onComplete: function(retour){
				if(retour.responseText!='0')
				{
					$('tableau_combinaisons').innerHTML=retour.responseText;
					var section_modele=['shop_lst_combinaisons'];
					Sortable.create('shop_lst_combinaisons', {tree:false,scroll:window,constraint:'vertical',dropOnEmpty:true,handle:'handle',containment:section_modele,onUpdate:function go() {save_ordre_combinaison('shop_lst_combinaisons'); } });
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'tbl_combinaisons\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre une combinaison
function save_combinaison(id_combinaison, id_article, poids, prix, promo, libelle, ecotaxe, stock)
{
	try
	{
		libelle=encodeURIComponent(libelle);
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_combinaison.php',
		{
			method: 'post',
			parameters: 'id_site='+ID_SITE+'&id_article='+id_article+'&id_combinaison='+id_combinaison+'&prix='+prix+'&promo='+promo+'&poids='+poids+'&libelle='+libelle+'&ecotaxe='+ecotaxe+'&stock='+stock,
			onCreate: function() {
				if($('ajax_combi_save_'+id_combinaison))
				{
					$('ajax_combi_save_'+id_combinaison).src=THEME_PROGRESS_MINI;
					$('ajax_combi_save_'+id_combinaison).setStyle({visibility:'visible'});
				}
			},
			onSuccess: function() {
				$('ajax_combi_save_'+id_combinaison).src=THEME_ICONE_SUCCES;
			},
			onFailure: function() {
				$('ajax_combi_save_'+id_combinaison).src=THEME_ICONE_ECHEC;
			},
			onComplete: function(retour){
				if(retour.responseText!='0')
				{
					if(id_combinaison=='')
					{
						tbl_combinaisons(id_article);
					}
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_combinaison\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre l'ordre des combinaisons d'un article
function save_ordre_combinaison(tab)
{
	try
	{
		var ordre=new Array();
		var id_article=$('id_article').value;
		// On traite les LI
		li=$('shop_lst_combinaisons').select("li");
		for(l=0; l<li.length; l++)
		{	
			var tmp=li[l].id.split('_');
			
			ordre[l]=tmp[1];
		}
	
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_ordre_combinaison.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: 'ordre='+ordre+'&id_site='+ID_SITE+'&id_article='+id_article,
			onComplete: function(retour){
				tbl_combinaisons(id_article);
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_ordre_modele\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre l'ordre des modèles d'un article
function save_ordre_modele(tab)
{
	try
	{
		var ordre=new Array();
		var id_article=$('id_article').value;
		// On traite les LI
		li=$('lst_modeles').select("li");
		for(l=0; l<li.length; l++)
		{	
			var tmp=li[l].id.split('_');
			
			ordre[l]=tmp[1];
		}
	
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_ordre_modele.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: 'ordre='+ordre+'&id_site='+ID_SITE+'&id_article='+id_article,
			onComplete: function(retour){
				tbl_combinaisons(id_article);
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_ordre_modele\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui ajoute un modèle à l'article
function add_mod_art(id_modele, id_article)
{
	try
	{
		if($('checkbox_modele_'+id_modele).checked)
		{
			var action="add";
		}
		else
		{
			var rep=confirm("\312tes-vous s\373r de vouloir supprimer le mod\350le de cet article?");
			if(!rep)
			{
				$('checkbox_modele_'+id_modele).checked=true;
				return false;
			}
			var action="del";
		}
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_mod_art.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: 'id_modele='+id_modele+'&id_site='+ID_SITE+'&id_article='+id_article+'&action='+action,
			onComplete: function(retour) {	
				tbl_combinaisons(id_article);
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'add_mod_art\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui supprime un attribut
function del_attribut(id_attribut)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_del_attribut.php',
		{
			method: 'post',
			parameters: 'id_attribut='+id_attribut+'&id_site='+ID_SITE,
			onComplete: function(retour) {
				if(retour.responseText=='1')
				{
					var ul=$('lst_attributs');
					var li = ul.select('li');

					
					for(k=0; k<li.length; k++)
					{
						if(li[k].id=='attribut_'+id_attribut)
						{
							$(li[k]).remove();
							break;
						}
					}
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_attribut\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui supprime une zone
function del_zone_pays(id_zone, id_pays)
{
	try
	{		
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_edit_zone_pays.php',
		{
			method: 'post',
			parameters: 'id_zone='+id_zone+'&id_pays='+id_pays+'&id_site='+ID_SITE+'&del=1',
			onComplete: function(retour) {
				if(retour.responseText!='0')
				{				
					$('zones_pays_container').innerHTML=retour.responseText;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'add_zone\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui ajoute une zone
function add_zone_pays(id_zone, id_pays)
{
	try
	{		
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_edit_zone_pays.php',
		{
			method: 'post',
			parameters: 'id_zone='+id_zone+'&id_pays='+id_pays+'&id_site='+ID_SITE,
			onComplete: function(retour) {
				if(retour.responseText!='0')
				{				
					$('zones_pays_container').innerHTML=retour.responseText;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'add_zone\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui ajoute un attribut
function add_attribut(id_modele)
{
	try
	{		
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_add_attribut.php',
		{
			method: 'post',
			parameters: 'id_modele='+id_modele+'&id_site='+ID_SITE,
			onComplete: function(retour) {
				if(retour.responseText!='0')
				{	
					$('attribut_container').innerHTML=retour.responseText;
				}
				else
				{
					$('attribut_container').innerHTML='Impossible d\'ajouter un attribut.';
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'add_attribut\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui supprime une classe fiscale
function del_taux(id)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer ce taux fiscal?");
		
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_taux.php',
			{
				method: 'post',
				parameters: 'id='+id+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						var ul=$('lst_taux');
						var li = ul.select('li');
	
						for(k=0; k<li.length; k++)
						{
							if(li[k].id=='taux_'+id)
							{
								$(li[k]).remove();
								break;
							}
						}
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_classe\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre un taux
function shop_save_taux(id, taux)
{
	try
	{
		var tmp=id.split('_');
		var zone=tmp[0];
		var classe=tmp[1];
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_taux.php',
		{
			method: 'post',
			parameters: {
				zone: zone,
				classe: classe,
				taux: taux,
				id_site: ID_SITE
			},
			onComplete: function(retour) {
				
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_save_taux\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui supprime une classe fiscale
function del_classe(id_classe)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer cette classe fiscale?");
		
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_classe.php',
			{
				method: 'post',
				parameters: 'id_classe='+id_classe+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						var ul=$('lst_classes');
						var li = ul.select('li');
	
						for(k=0; k<li.length; k++)
						{
							if(li[k].id=='classe_'+id_classe)
							{
								$(li[k]).remove();
								break;
							}
						}
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_classe\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui supprime un moyen de livraison
function del_remise(id_remise)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer ce module de remise?");
		
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_remise.php',
			{
				method: 'post',
				parameters: 'id_remise='+id_remise+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						$('remise_'+id_remise).remove();				
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_remise\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui supprime un moyen de livraison
function del_livraison(id_livraison)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer ce moyen de livraison?");
		
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_livraison.php',
			{
				method: 'post',
				parameters: 'id_livraison='+id_livraison+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						$('livraison_'+id_livraison).remove();				
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_livraison\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui supprime un moyen de paiement
function del_paiement(id_paiement)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer ce moyen de paiement?");
		
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_paiement.php',
			{
				method: 'post',
				parameters: 'id_paiement='+id_paiement+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						$('paiement_'+id_paiement).remove();				
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_paiement\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui supprime une zone
function del_zone(id_zone)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer la zone?");
		
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_zone.php',
			{
				method: 'post',
				parameters: 'id_zone='+id_zone+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						$('zone_'+id_zone).remove();				
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_zone\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui supprime un modèle
function del_modele(id_modele)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer le mod\350le ainsi que tous ces attributs?");
		
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_modele.php',
			{
				method: 'post',
				parameters: 'id_modele='+id_modele+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					//alert(retour.responseText);
					if(retour.responseText=='1')
					{
						$('modele_'+id_modele).remove();
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_modele\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre les prix d'une combinaison pour l'admin uniquement
function save_prix_admin(id_article, id_combinaison, tva, poids, stock)
{
	try
	{
		// LES PRIX
		var tab_prix=Array();
		var prix=$$('input.shop_prix_ht');
		for(var i=0; i<prix.length; i++)
		{
			tab_prix[i]=Array(prix[i].id, prix[i].value);
		}
		// LA TAXE
		var taxe=$('shop_taxe').value;
		// LE POIDS
		var poids=$('poids').value;
		// LE STOCK
		var stock=$('stock').value;
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_prix_admin.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				id_combinaison: id_combinaison,
				id_site: ID_SITE,
				id_article: id_article,
				prix: tab_prix.toJSON(),
				taxe: taxe,
				poids: poids,
				stock: stock },
			onCreate: function() {
				$('img_save_prix').src=THEME_PROGRESS_MINI;
				$('img_save_prix').setStyle(visibility='hidden');
			},
			onComplete: function(retour){
				if(retour.status==200)
				{
					if(retour.responseText!="1")
					{
						$('img_save_prix').src=THEME_ICONE_ERREUR;
						$('img_save_prix').style.visibility='visible';
						alert('Erreur d\'enregistrement des prix!\n'+retour.responseText);
					}
					else
					{
						$('img_save_prix').src=THEME_ICONE_SUCCES;
						$('img_save_prix').style.visibility='visible';
					}
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_prix_admin\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui récupère les prix d'une combinaison pour l'admin uniquement
function get_prix_admin(id_combinaison, id_article)
{
	try
	{
		if(id_combinaison!='')
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_get_prix_admin.php',
			{
				method: 'post',
				asynchronous: false,
				parameters: 'id_combinaison='+id_combinaison+'&id_site='+ID_SITE+'&id_article='+id_article,
				onCreate: function() {
					$('container_prix').style.display='';
					$('container_livraisons').style.display='';
				},
				onComplete: function(retour){
					if(retour.status==200)
					{
						try
						{
							// LES PRIX
							var tab=retour.responseJSON;
							for(x in tab['prix'])
							{
								if($(x+'_ht'))
								{
									if(tab['prix'][x]['ht']=='' && tab['prix'][x]['ttc']=='')
									{
										$(x+'_ht').value='';
										$(x+'_ttc').value='';
									}
									else
									{
										$(x+'_ht').value=Number(tab['prix'][x]['ht']).toFixed(5);
										$(x+'_ttc').value=Number(tab['prix'][x]['ttc']).toFixed(5);
									}
								}
							}
							
							// LE POIDS
							$('poids').value=tab['poids'];
							
							// LE STOCK
							if(tab['stock']==null)
							{
								tab['stock']='';
							}
							$('stock').value=tab['stock'];
							
							// LES LIVRAISONS
							var tab_livraisons=$$('input.chk_livraisons');
							for(var k=0; k<tab_livraisons.length; k++)
							{
								if(in_array(tab_livraisons[k].value, tab['livraisons']))
								{
									tab_livraisons[k].checked=true;
								}
								else
								{
									tab_livraisons[k].checked=false;
								}
							}
						}
						catch(e)
						{
							alert('Erreur dans la fonction \'get_prix_admin\', retour ajax dans shop.js :\n'+e.message);
						}
					}
				}
			});
		}
		else
		{
			$('container_prix').style.display='none';
			$('container_livraisons').style.display='none';
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'get_prix_admin\' dans shop.js :\n'+e.message);
	}
}


/* FIN FONCTIONS DES MODELES DES ARTICLES ###################### */




/*
	###################################################################################

	Affiche la grande photo de l'album Apercu
	
	###################################################################################
*/
function shop_apercu_photo(id, photo)
{
	try
	{
		$('shop_album_apercu_lien').href=$('zoom_'+id).value;
		$('shop_grande_photo').src=photo;
		$('shop_infos').update('<span class="shop_titre_photo">'+$('titre_'+id).value+'</span><br />'+$('description_'+id).value);
		Lightview.updateViews();
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_apercu_photo\' dans shop.js :\n'+e.message);
	}
}





/*
	###################################################################################

	Enregistre les infos des photos
	
	###################################################################################
*/
function shop_save_infos_photo(mode, id_photo, info)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_infos_photo.php',
		{
			method: 'post',
			parameters: {
				mode: mode,
				id_photo: id_photo,
				info: info,
				id_site: ID_SITE
			},
			onCreate: function() {
				//$('booking_icone_loading').src=THEME_PROGRESS_MINI;
			},
			onComplete: function(retour) {
				//$('booking_container_photos').update(retour.responseText);
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_save_infos_photo\' dans shop.js :\n'+e.message);
	}
}


/*
	###################################################################################

	Enregistre l'ordre des photos
	
	###################################################################################
*/
function shop_save_ordre_photos()
{
	try
	{
		// ORDRE
		var tab_ordre=Array();
		var ordre=$$('ul#ul_photos_article li');
		for(var i=0; i<ordre.length; i++)
		{
			if(ordre[i].id!='')
			{
				tab_ordre[i]=ordre[i].id;
			}
		}
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_ordre_photos.php',
		{
			method: 'post',
			parameters: {
				ordre: tab_ordre.toJSON(),
				id_site: ID_SITE
			},
			onCreate: function() {
				//$('booking_icone_loading').src=THEME_PROGRESS_MINI;
			},
			onComplete: function(retour) {
				//$('booking_container_photos').update(retour.responseText);
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_save_ordre_photos\' dans shop.js :\n'+e.message);
	}
}


/*
	###################################################################################

	Renvoie les photos de l'article
	
	###################################################################################
*/
function shop_admin_load_photos(id_article)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_load_photos.php',
		{
			method: 'post',
			parameters: {
				id_article: id_article,
				id_site: ID_SITE
			},
			onCreate: function() {
				//$('booking_icone_loading').src=THEME_PROGRESS_MINI;
			},
			onComplete: function(retour) {
				$('shop_container_photos').update(retour.responseText);
				Sortable.create('ul_photos_article', {scroll:window,constraint:'vertical',onUpdate:shop_save_ordre_photos,dropOnEmpty:true,handle:'handle'});
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_admin_load_photos\' dans shop.js :\n'+e.message);
	}
}


/*
	###################################################################################

	Enregistre une photo pour un article
	
	###################################################################################
*/
function shop_admin_manage_photo(id_article, id_photo, fichier, mode)
{
	try
	{
		var rep=true;
		if(mode=='del')
		{
			rep=confirm('\312tes-vous s\373r de vouloir supprimer cette photo?\nNote: elle ne sera pas supprim\351e de votre biblioth\350que de documents.');
		}
		if(rep)
		{
			// ORDRE
			var tab_ordre=Array();
			var ordre=$$('ul#ul_photos_article li');
			for(var i=0; i<ordre.length; i++)
			{
				if(ordre[i].id!='')
				{
					tab_ordre[i]=ordre[i].id;
				}
			}
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_manage_photo.php',
			{
				method: 'post',
				parameters: {
					mode: mode,
					ordre: tab_ordre.toJSON(),
					id_article: id_article,
					id_photo: id_photo,
					fichier: fichier,
					id_site: ID_SITE
				},
				onCreate: function() {
					//$('booking_icone_loading').src=THEME_PROGRESS_MINI;
				},
				onComplete: function(retour) {
					shop_admin_load_photos(id_article);
					if(retour.responseText!='')
					{
						alert(retour.responseText);
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_admin_manage_photo\' dans shop.js :\n'+e.message);
	}
}



// LANCE L'UPLOAD DU FICHIER A DL
function shop_upload_dl_fichier()
{
	try
	{
		// ON CREE LE DOSSIER TEMP POUR L'UPLOAD DANS LA BIBLIOTHEQUE
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_mkdir_tmp_upload.php',
		{
			method: 'post',
			parameters: {
				id_site: ID_SITE
			},
			onCreate: function() {
				//$('shop_img_associes').setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				if(retour.status==200)
				{
					// ON LANCE L'UPLOAD
					mcFileManager.upload({
						path : '{0}/shop/fichiers_telecharger/',
						onupload : function(res) {
							$('id_fichier').value=res.files[0].name;
							$('shop_nom_fichier_telecharger').update(res.files[0].name);
							shop_load_type_fichier('oui');
						}
					});
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_upload_dl_fichier\' dans shop.js :\n'+e.message);
	}
}


// AFFICHE LE NOM ET L'ICONE DU TYPE DE FICHIER SELECTIONNE POUR LE DL
function shop_load_type_fichier(mode)
{
	try
	{
		if(mode=='oui')
		{
			$('rad_dl_fichier_oui').checked='checked';
			var tmp=$('id_fichier').value.split('.');
			var ext=tmp[tmp.length-1];
			var picto=ext+'_logo.jpg';
			switch(ext)
			{
				case 'jpeg'	: var picto='jpg_logo.jpg'; break;
				case 'xlsx'	: var picto='xls_logo.jpg'; break;
				case 'docx'	: var picto='doc_logo.jpg'; break;
			}
			$('shop_id_logo_type').src=BASE_HREF+'modules/shop/images/'+picto;
			$('shop_id_logo_type').setStyle({visibility:'visible'});
			Effect.BlindDown('shop_dl_fichier_container', { duration: 0.5 });
		}
		else
		{
			$('shop_id_logo_type').setStyle({visibility:'hidden'});
			$('id_fichier').value='';
			Effect.BlindUp('shop_dl_fichier_container', { duration: 0.1 });
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_load_type_fichier\' dans shop.js :\n'+e.message);
	}
}



// COCHE OU DECOCHE UN ARTICLE ASSOCIE
function shop_chk_article_associe(id_parent, id_enfant, mode)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_chk_article_associe.php',
		{
			method: 'post',
			parameters: {
				id_site: ID_SITE,
				mode: mode,
				id_parent: id_parent,
				id_enfant: id_enfant },
			onCreate: function() {
				$('shop_img_associes').setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				if(retour.status==200)
				{
					//$('shop_articles_associes_container').update(retour.responseText);
				}
				$('shop_img_associes').setStyle({visibility:'hidden'});
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_chk_article_associe\' dans shop.js :\n'+e.message);
	}
}



// LISTE DES PRODUITS ASSOCIES
function shop_admin_load_articles_associes(id_article, id_categorie)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_load_articles_associes.php',
		{
			method: 'post',
			parameters: {
				id_site: ID_SITE,
				id_categorie: id_categorie,
				id_article: id_article },
			onCreate: function() {
				$('shop_img_associes').setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				if(retour.status==200)
				{
					$('shop_articles_associes_container').update(retour.responseText);
				}
				$('shop_img_associes').setStyle({visibility:'hidden'});
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_admin_load_articles_associes\' dans shop.js :\n'+e.message);
	}
}



// Vérifie que les CGV sont acceptées
function shop_chk_cgv(mode)
{
	try
	{
		if(mode==true)
		{
			Effect.BlindDown('shop_paiements_container', { duration: 0.5 });
			Effect.ScrollTo('shop_ancre_paiements');
		}
		else
		{
			Effect.BlindUp('shop_paiements_container', { duration: 0.1 });
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_chk_cgv\' dans shop.js :\n'+e.message);
	}
}



// Renvoie la prévisualisation d'un avis
function shop_get_previsu_avis()
{
	try
	{
		var note=$('note_article').value;
		var nom=$('shop_avis_nom').value;
		var email=$('shop_avis_email').value;
		var titre=$('shop_avis_titre').value;
		var contenu=$('shop_avis_contenu').value;
		if($('shop_chk_visible_email').checked==true)
		{
			var visible_email=0;
		}
		else
		{
			var visible_email=1;
		}
		var action=testdom('shop', 'ajax_avis_previsu.php', '/appel_ajax.php');
		Lightview.show({
			href: action,
			rel: 'ajax',
			options: {
				width: 650,
				height: 300,
				ajax: {
					method: 'post',
					parameters: {
						id_site: ID_SITE,
						note_avis: note,
						nom_avis: nom,
						email_avis: email,
						titre_avis: titre,
						contenu_avis: contenu,
						visible_email_avis: visible_email,
						sid:SESSION_ID,
						file:'ajax_avis_previsu.php',
						module:'shop'
					},
					evalScripts: true
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_get_previsu_avis\' dans shop.js :\n'+e.message);
	}
}

// Coche les étoiles des avis
function shop_chk_etoiles(etoile)
{
	try
	{
		var nb_etoile=$$('div.shop_fond_etoile').length;
		var tmp=etoile.id.split('_');
		var nb=tmp[tmp.length-1];
		for(var i=1; i<=nb_etoile; i++)
		{
			if(i<=nb)
			{
				$('shop_avis_etoile_'+i).checked=true;
			}
			else
			{
				$('shop_avis_etoile_'+i).checked=false;
			}
		}
		$('note_article').value=nb;
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_chk_etoiles\' dans shop.js :\n'+e.message);
	}
}



// Charge une adresse
function clients_load_adresse(id_client, id_adresse, suffixe)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('clients', 'ajax_load_adresse.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			parameters: {
				id_site: ID_SITE,
				id_client: id_client,
				id_adresse: id_adresse,
				suffixe: suffixe,
				sid:SESSION_ID,
				file:'ajax_load_adresse.php',
				module:'clients'
			},
			onCreate: function() {
				$('adresse_loading').setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				$('clients_adresse_container').update(retour.responseText);
				$('adresse_loading').setStyle({visibility:'hidden'});
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'clients_load_adresse\' dans shop.js :\n'+e.message);
	}
}




// Fonction qui recharge au panier une commande passée
function load_commande(id_commande)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_load_commande.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				id_site: ID_SITE,
				id_commande: id_commande,
				sid: SESSION_ID,
				lng: LNG,
				file: 'ajax_load_commande.php',
				module: 'shop' },
			onComplete: function(retour){
				document.location=retour.responseText;
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'check_code_promo\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui export les articles
function shop_export(format)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_export.php',
		{
			method: 'post',
			parameters: {
				id_site: ID_SITE,
				format: format },
			onCreate: function() {
				$('img_export').src=THEME_PROGRESS_MINI;
				$('img_export').setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				if(retour.responseText=="")
				{
					$('img_export').src=THEME_ICONE_SUCCES;
					$('td_'+format).setStyle({visibility:'visible'});
				}
				else
				{
					$('img_export').src=THEME_ICONE_ERREUR;
					$('td_'+format).setStyle({visibility:'hidden'});
					alert(retour.responseText);
				}
				$('img_export').setStyle({visibility:'visible'});
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_export\' dans shop.js :\n'+e.message);
	}
}



// Fonction qi envoie les mails d'une commande en ajax
function send_mails_commande(id_commande, dest)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_send_mails_commande.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				id_site: ID_SITE,
				dest: dest,
				id_commande: id_commande },
			onCreate: function() {
				$('img_send_mails').src=THEME_PROGRESS_MINI;
				$('img_send_mails').setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				if(retour.responseText=="")
				{
					$('img_send_mails').src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('img_send_mails').src=THEME_ICONE_ERREUR;
					alert(retour.responseText);
				}
				$('img_send_mails').setStyle({visibility:'visible'});
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'send_mails_commande\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui vérifie un code promo
function check_code_promo(code)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_check_code_promo.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				id_site: ID_SITE,
				code: code,
				sid: SESSION_ID,
				lng: LNG,
				file: 'ajax_check_code_promo.php',
				module: 'shop' },
			onComplete: function(retour){
				//alert(retour.responseText);
				var tmp=retour.responseText.split('|');
				alert(html_entity_decode(tmp[2], 'ENT_COMPAT'));
				update_panier('modif');
				update_bloc_panier();
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'check_code_promo\' dans shop.js :\n'+e.message);
	}
}


// VERIFIE SIL Y A DES ARTICLES DANS LA CAT
function shop_check_art_cat(id_categorie)
{
	try
	{
		var ret='';
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_check_art_cat.php',
		{
			asynchronous: false,
			method: 'post',
			parameters: {
				id_site: ID_SITE,
				id_categorie: id_categorie },
			onComplete: function(retour) {
				ret=retour.responseText;
			}
		});
		return ret;
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_check_art_cat\' dans shop.js :\n'+e.message);
	}
}


// AFFICHE OU MASQUE LA CREATION D'UN NOUVEAU COMPTE
function shop_show_hide_creer_compte(bloc)
{
	try
	{
		if(bloc=='creation')
		{
			$('shop_area_log_compte').setStyle({display:'none'});
			Effect.BlindDown('shop_area_creer_compte', { duration: 0.5 });
			//Effect.ScrollTo('shop_ancre_creer_compte');
		}
		else
		{
			$('shop_area_creer_compte').setStyle({display:'none'});
			Effect.BlindDown('shop_area_log_compte', { duration: 0.5 });
			//Effect.ScrollTo('shop_ancre_log_compte');
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_show_hide_creer_compte\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui affiche ou cache les articles du catalogue admin
function show_hide_catalogue_admin(id_categorie, dsp_art)
{
	try
	{
		if($('ul_'+id_categorie).style.display=='none')
		{
			
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_load_catalogue.php',
			{
				method: 'post',
				parameters: {
					id_site: ID_SITE,
					dsp_art: dsp_art,
					id_categorie: id_categorie },
				onCreate: function() {
					$('img-open-close_'+id_categorie).src=THEME_PROGRESS_MINI;
				},
				onComplete: function(retour) {
					//alert(retour.responseText);
					$('ul_'+id_categorie).update(retour.responseText);
					Effect.BlindDown('ul_'+id_categorie,{ duration: 0.3 });
					$('img-open-close_'+id_categorie).src=THEME_DIR_OPEN;
					if(dsp_art=='true')
					{
						Sortable.destroy('catalogue');
						Sortable.create('catalogue', {format:'^(.*)$',tree:true,scroll:window,constraint:false,dropOnEmpty:true,handle:'handle',containment:sections,onUpdate:function go() {action_fin_drag('catalogue'); } });
					}
					else
					{
						Sortable.destroy('categories');
						Sortable.create('categories', {format:'^(.*)$',tree:true,scroll:window,constraint:false,dropOnEmpty:true,handle:'handle',containment:sections,onUpdate:function go() {action_fin_drag('categories'); } });
					}
				}
			});
			
		}
		else
		{
			Effect.BlindUp('ul_'+id_categorie,{ duration: 0.3 });
			var nb_art=shop_check_art_cat(id_categorie);
			if(nb_art!='' && nb_art>0)
			{
				$('img-open-close_'+id_categorie).src=THEME_DIR_CLOSE_REMPLI;
			}
			else
			{
				$('img-open-close_'+id_categorie).src=THEME_DIR_CLOSE;
			}
			$('ul_'+id_categorie).update();		
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'show_hide_catalogue_admin\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui filtre les articles côté front
function filtre_articles(niveau)
{
	try
	{
		// On parcours tous les filtres
		var selects=$$('select.shop-select-filtres');
		var filtres=Array();
		var prixmin='';
		var prixmax='';
		for(var i=0; i<selects.length; i++)
		{
			var tmp=selects[i].name.split('_');
			//alert("Modele : "+tmp[1]+" -- Value : "+selects[i].value);
			if(selects[i].value!='')
			{
				filtres[i]=Array(tmp[1], selects[i].value);
			}
		}
		// Prix min et max
		if($('box-prix-min'))
		{
			prixmin=$('box-prix-min').innerHTML;
		}
		if($('box-prix-max'))
		{
			prixmax=$('box-prix-max').innerHTML;
		}
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_filtre_articles.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_site: ID_SITE,
				filtres: filtres.toJSON(),
				prixmin: prixmin,
				prixmax: prixmax,
				niveau: niveau,
				sic: SESSION_ID,
				lng: LNG,
				file: 'ajax_filtre_articles.php',
				module: 'shop' },
			onCreate: function() {
				if($('shop-img-filtre-loading'))
				{
					$('shop-img-filtre-loading').setStyle({display:'block'});
				}
			},
			onComplete: function(retour){
				if($('shop-container-articles'))
				{
					$('shop-container-articles').innerHTML=retour.responseText;
				}
				if($('shop-img-filtre-loading'))
				{
					$('shop-img-filtre-loading').setStyle({display:'none'});
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'filtre_articles\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui demande une confirmation de changer de module
function shop_go_form()
{
	try
	{
		var rep=confirm('Si vous changez de module, vous perdrez les modifications en cours.\n\312tes-vous s\373r de vouloir quitter?');
		if(rep)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_go_form\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui rajoute l'id combinaison au lien de contact d'un article
function add_query_contact(id_combinaison)
{
	try
	{
		if($('id-href-addpanier'))
		{
			var origine=$('id-href-addpanier').href;
			var tmp=origine.split('?');
			var query=tmp[1].toQueryParams();
			var base='?id_site='+query['id_site']+'&id_article='+query['id_article']+'&lng='+query['lng'];
			$('id-href-addpanier').href=tmp[0]+base; // par défaut on remet à vide
			if(query['id_combinaison'])
			{
				if(id_combinaison!='')
				{
					query['id_combinaison']=id_combinaison;
					$('id-href-addpanier').href=tmp[0]+base+'&id_combinaison='+query['id_combinaison'];
				}
			}
			else
			{
				if(id_combinaison!='')
				{
					$('id-href-addpanier').href=origine+'&id_combinaison='+id_combinaison;
				}
			}
			Lightview.updateViews();
			return false;
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'add_query_contact\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui paye on non une commande
function ajax_paye_commande(id_commande, valeur)
{
	try
	{
		$('img_save_paye').style.visibility='hidden';
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_paye_commande.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: 'id_site='+ID_SITE+'&id_commande='+id_commande+'&valeur='+valeur,
			onComplete: function(retour) {
				if(retour.responseText=="1")
				{
					$('img_save_paye').src=THEME_ICONE_SUCCES;
					if(valeur=='1')
					{
						var rep=confirm('Voulez-vous envoyer le mail de confirmation au client?');
						if(rep)
						{
							send_mails_commande(id_commande, 'all');
						}
					}
				}
				else
				{
					$('img_save_paye').src=THEME_ICONE_ERREUR;
				}
				$('img_save_paye').style.visibility='visible';
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'paye_commande\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui supprime un code promo
function del_code_promo(id_code_promo)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer ce code promo?");
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_code_promo.php',
			{
				method: 'post',
				asynchronous: true,
				parameters: {
					id_site: ID_SITE,
					id_code_promo: id_code_promo },
				onComplete: function(retour) {
					if(retour.responseText=="1")
					{
						$('shop-tr-code-promo-'+id_code_promo).remove();
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_code_promo\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui supprime un client
function del_client(id_client)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir supprimer ce client ainsi que ces commandes?");
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/clients/admin/ajax_del_client.php',
			{
				method: 'post',
				asynchronous: true,
				parameters: 'id_site='+ID_SITE+'&id_client='+id_client,
				onComplete: function(retour) {
					if(retour.responseText=="1")
					{
						$('shop-tr-client-'+id_client).remove();
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_client\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui supprime une commande
function del_commande(id_commande)
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de supprimer cette commande?");
		if(rep)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_commande.php',
			{
				method: 'post',
				asynchronous: true,
				parameters: 'id_site='+ID_SITE+'&id_commande='+id_commande,
				onComplete: function(retour) {
					if(retour.responseText=="1")
					{
						$('shop-tr-commande-'+id_commande).remove();
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_commande\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre les paramètres perso d'une livraison
function save_paiement_perso(field, value, id)
{
	try
	{
		var allpic=$$('img.picto_ajax');
		for(var i=0; i<allpic.length; i++)
		{
			allpic[i].setStyle({visibility:'hidden'});
		}
		$('img_save_'+field+'_'+id).src=THEME_PROGRESS_MINI;
		$('img_save_'+field+'_'+id).setStyle({visibility:'visible'});
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_paiement_perso.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				id_site: ID_SITE,
				id_paiement: id,
				value: value,
				field: field },
			onComplete: function(retour) {
				if(retour.responseText=="1")
				{
					$('img_save_'+field+'_'+id).src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('img_save_'+field+'_'+id).src=THEME_ICONE_ERREUR;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_paiement_perso\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre les paramètres perso d'une livraison
function save_remise_perso(field, value, id)
{
	try
	{
		$('img_save_'+field).style.visibility='hidden';
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_remise_perso.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: 'id_site='+ID_SITE+'&id_remise='+id+'&value='+encodeURIComponent(value)+'&field='+field,
			onComplete: function(retour) {
				if(retour.responseText=="1")
				{
					$('img_save_'+field).src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('img_save_'+field).src=THEME_ICONE_ERREUR;
				}
				$('img_save_'+field).style.visibility='visible';
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_remise_perso\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui enregistre les paramètres perso d'une livraison
function save_livraison_perso(field, value, id)
{
	try
	{
		var allpic=$$('img.picto_ajax');
		for(var i=0; i<allpic.length; i++)
		{
			allpic[i].setStyle({visibility:'hidden'});
		}
		$('img_save_'+field+'_'+id).src=THEME_PROGRESS_MINI;
		$('img_save_'+field+'_'+id).setStyle({visibility:'visible'});
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_livraison_perso.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_site: ID_SITE,
				id_livraison: id,
				value: value,
				field: field },
			onComplete: function(retour) {
				if(retour.responseText=="1")
				{
					$('img_save_'+field+'_'+id).src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('img_save_'+field+'_'+id).src=THEME_ICONE_ERREUR;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_livraison_perso\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui active ou désactive un module de remise
function active_remise(id_remise)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_active_remise.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: 'id_site='+ID_SITE+'&id_remise='+id_remise,
			onComplete: function(retour) {
				if(retour.responseText=="1")
				{
					$('icone_visible_'+id_remise).src=THEME_ICONE_VISIBLE_OVER;
				}
				else
				{
					$('icone_visible_'+id_remise).src=THEME_ICONE_INVISIBLE_OVER;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'active_remise\' dans shop.js :\n'+e.message);
	}
}	



// Fonction qui active ou désactive un moyen de paiement
function active_paiement(id_paiement)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_active_paiement.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: 'id_site='+ID_SITE+'&id_paiement='+id_paiement,
			onComplete: function(retour) {
				if(retour.responseText=="1")
				{
					$('icone_visible_'+id_paiement).src=THEME_ICONE_VISIBLE_OVER;
				}
				else
				{
					$('icone_visible_'+id_paiement).src=THEME_ICONE_INVISIBLE_OVER;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'active_paiement\' dans shop.js :\n'+e.message);
	}
}	




// Fonction qui active ou désactive un moyen de livraison
function active_livraison(id_livraison)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_active_livraison.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: 'id_site='+ID_SITE+'&id_livraison='+id_livraison,
			onComplete: function(retour) {
				if(retour.responseText=="1")
				{
					$('icone_visible_'+id_livraison).src=THEME_ICONE_VISIBLE_OVER;
				}
				else
				{
					$('icone_visible_'+id_livraison).src=THEME_ICONE_INVISIBLE_OVER;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'active_livraison\' dans shop.js :\n'+e.message);
	}
}	




// Fonction qui affecte/desaffecte un moyen de livraison à un article
function save_livraison_article(id_article, id_livraison, id_combinaison, id_site, mode)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_livraison_article.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: 'id_site='+ID_SITE+'&id_article='+id_article+'&id_livraison='+id_livraison+'&id_combinaison='+id_combinaison+'&mode='+mode
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_livraison_article\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui met à jour le status d'une commande admin
function set_status_commande_admin(id_commande, status)
{
	try
	{
		$('img_save_status').style.visibility='hidden';
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_status.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: 'id_site='+ID_SITE+'&id_commande='+id_commande+'&status='+status,
			onComplete: function(retour){
				if(retour.responseText=="1")
				{
					$('img_save_status').src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('img_save_status').src=THEME_ICONE_ERREUR;
				}
				$('img_save_status').style.visibility='visible';
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'set_status_commande_admin\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui met à jour le status d'une commande
function set_status_commande(id_site, id_commande, id_paiement, paiement_force, status_force, redirect)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_action_paiement.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_site: ID_SITE,
				id_commande: id_commande,
				id_paiement: id_paiement,
				paiement_force: paiement_force,
				status_force: status_force,
				sic: SESSION_ID,
				file: 'ajax_action_paiement.php',
				lng: LNG,
				module: 'shop' },
			onComplete: function(retour){
				if(retour.responseText!="" && redirect)
				{
					document.location=retour.responseText;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'set_status_commande\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui affecte une livraison
function select_livraison(id_livraison)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_select_livraison.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_site: ID_SITE,
				id_livraison: id_livraison,
				sid: SESSION_ID,
				lng: LNG,
				file: 'ajax_select_livraison.php',
				module: 'shop' },
			onComplete: function(retour){
				if(retour.responseText=="")
				{
					// On refresh les paniers
					update_panier('read');
					update_bloc_panier();
				}
				else
				{
					alert(retour.responseText);
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'select_livraison\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui enregistre les infos du client
function update_info_client(id_client, field, value)
{
	try
	{
		var allico=$$('img.icones_ajax');
		for(var i=0; i<allico.length; i++)
		{
			allico[i].style.visibility='hidden';
		}
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_save_infos_client.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_site: ID_SITE,
				id_client: id_client,
				field: field,
				value: value,
				lng: LNG,
				sid: SESSION_ID,
				file: 'ajax_save_infos_client.php',
				module: 'shop' },
			onComplete: function(retour){
				if(retour.responseText=="1")
				{
					$('icone_'+field).src=ICONE_SUCCES;
					$('icone_'+field).style.visibility='visible';
				}
				else
				{
					$('icone_'+field).src=ICONE_ERREUR;
					$('icone_'+field).style.visibility='visible';
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'update_info_client\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui charge une adresse
function load_adresse(id_adresse)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_load_adresse.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_site: ID_SITE,
				id_adresse: id_adresse,
				sid: SESSION_ID,
				lng: LNG,
				file: 'ajax_load_adresse.php',
				module: 'shop' },
			onComplete: function(retour){
				if(retour.responseText!="")
				{
					var tab=PHP_Unserialize(retour.responseText);
					$('input_nom_livraison').value=html_entity_decode(tab["nom_adresse"], 'ENT_COMPAT');
					$('input_prenom_livraison').value=html_entity_decode(tab["prenom_adresse"], 'ENT_COMPAT');
					$('input_raison_sociale_livraison').value=html_entity_decode(tab["raison_sociale_adresse"], 'ENT_COMPAT');
					$('input_adresse_livraison').value=html_entity_decode(tab["adresse_adresse"], 'ENT_COMPAT');
					$('input_code_postal_livraison').value=html_entity_decode(tab["code_postal_adresse"], 'ENT_COMPAT');
					$('input_ville_livraison').value=html_entity_decode(tab["ville_adresse"], 'ENT_COMPAT');
					switch(tab["civilite_adresse"])
					{
						case "M."		: m="true"; mme=""; mlle=""; break;
						case "Mme"	: m=""; mme="true"; mlle=""; break;
						case "Mlle"	: m=""; mme=""; mlle="true"; break;
					}
					$('radio_m_livraison').checked=m;
					$('radio_mme_livraison').checked=mme;
					$('radio_mlle_livraison').checked=mlle;
					var slt=$('select_pays_livraison');
					var opt=slt.select("option");
					for(var i=0; i<opt.length; i++)
					{
						if(opt[i].value==tab["pays_adresse"])
						{
							opt[i].selected='true';
						}
					}
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'load_adresse\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui augmente ou diminue la quantité d'un article dans le panoer
function less_more_panier(id_article, id_combinaison, mode)
{
	try
	{
		if(mode=='+')
		{
			$('lngart_'+id_article+'_'+id_combinaison).value++;
		}
		else
		{
			if($('lngart_'+id_article+'_'+id_combinaison).value-1<=0)
			{
				return false;
			}
			else
			{
				$('lngart_'+id_article+'_'+id_combinaison).value--;
			}
		}
		panier_update_quantite(id_article,id_combinaison, $('lngart_'+id_article+'_'+id_combinaison).value);
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'less_more_panier\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui met à jour la quantité d'un article dans le panier
function panier_update_quantite(id_article, id_combinaison, quantite)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_update_quantite_panier.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				id_site: ID_SITE,
				id_article: id_article,
				id_combinaison: id_combinaison,
				quantite: quantite,
				file: 'ajax_update_quantite_panier.php',
				lng: LNG,
				sid: SESSION_ID,
				module: 'shop' },
			onComplete: function(retour){
				if(retour.responseText!="")
				{
					alert(html_entity_decode(retour.responseText));
				}
				// On refresh les paniers
				update_panier('modif');
				update_bloc_panier();
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'update_panier\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui vide le panier
function clear_panier()
{
	try
	{
		var rep=confirm("\312tes-vous s\373r de vouloir vider votre panier?");
		
		if(rep)
		{
			// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
			var action=testdom('shop', 'ajax_clear_panier.php', '/appel_ajax.php');
			var myAjax = new Ajax.Request(
			action,
			{
				method: 'post',
				asynchronous: true,
				parameters: { 
					id_site: ID_SITE,
					sid: SESSION_ID,
					file: 'ajax_clear_panier.php',
					lng: LNG,
					module: 'shop' },
				onCreate: function() {
					// Affichage du loader
					$('panier_container').style.display='none';
					$('img_panier_loader').style.display='block';
				},
				onComplete: function(retour){
					// On refresh les paniers
					update_panier('modif');
					update_bloc_panier();
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'clear_panier\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui actualise le panier
function update_panier(mode)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_update_panier.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: true,
			parameters: 'lng='+LNG+'&id_site='+ID_SITE+'&mode='+mode+'&file=ajax_update_panier.php&sid='+SESSION_ID+'&module=shop',
			onCreate: function() {
				// Affichage du loader
				$('img_panier_loader').setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				//alert(retour.responseText);
				if(retour.responseText!="")
				{
					$('panier_container').update(retour.responseText);
					$('img_panier_loader').setStyle({visibility:'hidden'});
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'update_panier\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui supprime un article du panier
function panier_del_article(id_article, id_combinaison)
{
	try
	{
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_del_article_panier.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: true,
			parameters: 'lng='+LNG+'&id_site='+ID_SITE+'&id_article='+id_article+'&id_combinaison='+id_combinaison+'&file=ajax_del_article_panier.php&sid='+SESSION_ID+'&module=shop',
			onComplete: function(retour){
				if(retour.responseText!="")
				{
					alert(retour.responseText);
				}
				else
				{
					// On refresh les paniers
					update_panier('modif');
					update_bloc_panier();
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'panier_del_article\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui met à jour le bloc panier
function update_bloc_panier()
{
	try
	{
		if($('shop_bloc_panier'))
		{
			// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
			var action=testdom('shop', 'ajax_update_bloc_panier.php', '/appel_ajax.php');
			var myAjax = new Ajax.Request(
			action,
			{
				method: 'post',
				asynchronous: true,
				parameters: 'lng='+LNG+'&id_site='+ID_SITE+'&file=ajax_update_bloc_panier.php&sid='+SESSION_ID+'&module=shop',
				onCreate: function() {
					$('bloc_panier_loader').setStyle({visibility:'visible'});
				},
				onComplete: function(retour){
					if(retour.responseText!="")
					{
						if($('lst_articles_bloc_panier'))
						{
							$('lst_articles_bloc_panier').update(retour.responseText);
						}
					}
					else
					{
						$('lst_articles_bloc_panier').update();
					}
					$('bloc_panier_loader').setStyle({visibility:'hidden'});
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'update_bloc_panier\' dans shop.js :\n'+e.message);
	}
}

// RENVOIE LA POSITION DU SCROLL
function shop_getScrollingPosition()
{
	try
	{
		var position = [0, 0];
		if (typeof window.pageYOffset != 'undefined')
		{
		position = [
		window.pageXOffset,
		window.pageYOffset
		];
		}
		else if (typeof document.documentElement.scrollTop
		!= 'undefined' && document.documentElement.scrollTop > 0)
		{
		position = [
		document.documentElement.scrollLeft,
		document.documentElement.scrollTop
		];
		}
		else if (typeof document.body.scrollTop != 'undefined')
		{
		position = [
		document.body.scrollLeft,
		document.body.scrollTop
		];
		}
		return position;
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'getScrollingPosition\' dans etiquette.js :\n'+e.message);
	}
}

// Fonction qui affiche le splash après l'ajout au panier
function splash_panier(id_article, id_combinaison, quantite)
{
	try
	{
		if($('shop-splash'))
		{
			$('shop-splash').remove();
		}
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action=testdom('shop', 'ajax_get_splash.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			parameters:
			{
				lng: LNG, 
				id_combinaison: id_combinaison, 
				id_article: id_article, 
				quantite: quantite, 
				id_site: ID_SITE, 
				file: 'ajax_get_splash.php', 
				sid: SESSION_ID, 
				module:'shop'
			},
			onComplete: function(retour)
			{
				document.body.insert({bottom: retour.responseText});
				var div = $('shop-splash').getDimensions();
				var dimensions = document.viewport.getDimensions();
				var left=((dimensions.width/2)-(div.width/2));
				var top=((dimensions.height/2)-(div.height/2));
				if(left<0)
				{
					left=left*-1;
				}
				if(top<0)
				{
					top=top*-1;
				}
				var scrollpos=shop_getScrollingPosition();
				$('shop-splash').setStyle({left: (left+scrollpos[0])+'px', top: (top+scrollpos[1])+'px'}); 
				$('shop-splash').appear({duration:0.2});
			}
		});
		
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'splash_panier\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui ajoute un article dans le panier
function add_panier(id_article, id_combinaison)
{
	try
	{
		var quantite=1; // par défaut la quantité est à 1

		// SI QTE ARTICLE NORMAL
		if($('quantite_article_'+id_article))
		{
			var tmp_quantite=$('quantite_article_'+id_article).value;
			
			if(tmp_quantite>0)
			{
				quantite=tmp_quantite;
			}
		}
		
		// SI QTE ARTICLE ASSOCIE
		if($('quantite_article_associe_'+id_article))
		{
			var tmp_quantite=$('quantite_article_associe_'+id_article).value;
			
			if(tmp_quantite>0)
			{
				quantite=tmp_quantite;
			}
		}
		
		// SI MODELE EN TABLEAU
		if($('quantite_article_'+id_article+'_'+id_combinaison))
		{
			var tmp_quantite=$('quantite_article_'+id_article+'_'+id_combinaison).value;
			
			if(tmp_quantite>0)
			{
				quantite=tmp_quantite;
			}
		}
		
		// On test si on est sur webagoo ou sur le domaine pour l'appel ajax
		var action = testdom('shop', 'ajax_add_panier.php', '/appel_ajax.php');
		
		var myAjax = new Ajax.Request(
		action,
		{
			parameters:
			{
				lng: LNG, 
				id_combinaison: id_combinaison, 
				id_article: id_article, 
				quantite: quantite, 
				id_site:ID_SITE, 
				file: 'ajax_add_panier.php', 
				sid:SESSION_ID, 
				module:'shop'
			},
			onComplete: function(retour)
			{
				try
				{
				var tmp = retour.responseText.split('|');
				if (tmp[0] != "0")
				{
					// ON RESET LES MODELES
					raz_modeles(id_article);
					if(tmp[1] && tmp[1]!="")
					{
						quantite=tmp[1];
						// SI MODELE EN TABLEAU
						if($('quantite_article_'+id_article+'_'+id_combinaison))
						{
							$('quantite_article_'+id_article+'_'+id_combinaison).value=quantite;
						}
						else if($('quantite_article_'+id_article))
						{
							$('quantite_article_'+id_article).value=quantite;
						}
						else if($('quantite_article_associe_'+id_article))
						{
							$('quantite_article_associe_'+id_article).value=quantite;
						}
					}
					
					if(tmp[2])
					{
						alert(html_entity_decode(tmp[2]));
					}
					
					splash_panier(id_article, id_combinaison, quantite);
					update_bloc_panier();
				}
				else
				{
					alert(html_entity_decode(tmp[1]));
					return false;
				}
				}
				catch(e)
				{
					alert(e.message);
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'add_panier\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui recalcule les champs TTC
function recalc_montants(id_article, id_combinaison, mode)
{
	try
	{
		var prix=$$('input.shop_prix_'+mode);
		var tab_prix=Array();
		for(var i=0; i<prix.length; i++)
		{
			tab_prix[i]=Array(prix[i].id, prix[i].value);
		}
		var taxe=$('shop_taxe').value;
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_calc_tva_prix.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				mode: mode,
				prix: tab_prix.toJSON(),
				taxe: taxe,
				id_article: id_article,
				id_combinaison: id_combinaison,
				id_site: ID_SITE
			},
			onComplete: function(retour){
				if(retour.status==200)
				{
					var tab=retour.responseJSON;
					for(x in tab)
					{
						if(tab[x]['ht']=='' && tab[x]['ttc']=='')
						{
							$(x+'_ht').value='';
							$(x+'_ttc').value='';
						}
						else
						{
							$(x+'_ht').value=Number(tab[x]['ht']).toFixed(5);
							$(x+'_ttc').value=Number(tab[x]['ttc']).toFixed(5);
						}
					}
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'recalc_montants\' dans shop.js :\n'+e.message);
	}
}




// Fonction qui gère les affectations des catégories dans la page
function affect_option(idpage, id_site)
{
	var myAjax = new Ajax.Request(
	'../../shop/admin/ajax_choix_cat.php',
	{
		method: 'post',
		parameters: 'id_page='+idpage+'&id_site='+id_site,
		onComplete: function(retour){
			$('fin_module').innerHTML=retour.responseText;
		}
	});
}




// Fonction qui supprime un article
function delarticle(id)
{
	try
	{
		var rep=confirm('\312tes-vous sur de vouloir supprimer cet article?');
		if(rep===true)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_article.php',
			{
				method: 'post',
				parameters: 'id_art='+id+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					//alert(retour.responseText);
					if(retour.responseText=='1')
					{
						var ul=$('catalogue');
						var li = ul.select('li');
						for(k=0; k<li.length; k++)
						{
							if(li[k].id=='art_'+id)
							{
								$(li[k]).remove();
								break;
							}
						}
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'delcat\' dans shop.js :\n'+e.message);
	}
}


// Supprime un avis
function shop_admin_delete_avis(id)
{
	try
	{
		var rep=confirm('\312tes-vous sur de vouloir supprimer cet avis?');
		if(rep===true)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_avis.php',
			{
				method: 'post',
				parameters: 'id='+id+'&id_site='+ID_SITE,
				onCreate: function() {
					$('picto_supprimer_avis_'+id).src=THEME_PROGRESS_MINI;
				},
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						Effect.BlindUp('shop_ligne_avis_'+id, { duration: 0.3});
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_admin_delete_avis\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui supprime un référent
function delreferent(id)
{
	try
	{
		var rep=confirm('\312tes-vous sur de vouloir supprimer ce r\351f\351rent?\nToutes les statistiques seront d\351finitivement supprim\351es.');
		if(rep===true)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_referent.php',
			{
				method: 'post',
				parameters: {
					id_referent: id,
					id_site: ID_SITE
				},
				onCreate: function() {
					$('icone_supprimer_'+id).src=THEME_PROGRESS_MINI;
				},
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						Effect.BlindUp('referent_'+id, { duration: 0.5 });
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'delreferent\' dans shop.js :\n'+e.message);
	}
}




// Fonction qui supprime une catégorie
function delcat(id)
{
	try
	{
		var rep=confirm('\312tes-vous sur de vouloir supprimer cette cat\351gorie?\nToutes les sous-cat\351gories et tous les articles de cette cat\351gorie seront d\351finitivement supprim\351es.');
		if(rep===true)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_categorie.php',
			{
				method: 'post',
				parameters: 'id_cat='+id+'&id_site='+ID_SITE,
				onComplete: function(retour) {
					//alert(retour.responseText);
					if(retour.responseText=='1')
					{
						var ul=$('categories');
						var li = ul.select('li');
						for(k=0; k<li.length; k++)
						{
							if(li[k].id=='cat_'+id)
							{
								$(li[k]).remove();
								break;
							}
						}
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'delcat\' dans shop.js :\n'+e.message);
	}
}






function action_fin_drag(arbre)
{
	try
	{
		var tableau=Sortable.serialize(arbre);
		// La on lance l'ajax
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_ordre.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: tableau+'&arbre='+arbre+'&id_site='+ID_SITE
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'action_fin_drag\' dans shop.js :\n'+e.message);
	}
}


// Enregistre le titre d'un avis
function shop_admin_save_titre_avis(id, titre)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_titre_avis.php',
		{
			method: 'post',
			parameters: {
				id: id,
				id_site: ID_SITE,
				titre: titre
			},
			onCreate: function() {
				$('shop_avis_loading_'+id).src=THEME_PROGRESS_MINI;
				$('shop_avis_loading_'+id).setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				if(retour.responseText=="1")
				{
					$('shop_avis_loading_'+id).src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('shop_avis_loading_'+id).src=THEME_ICONE_ECHEC;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_admin_save_titre_avis\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui enregistre les libelles des catégories et des articles
function save_libelle(id, libelle, table)
{
	libelle=encodeURIComponent(libelle);

	var myAjax = new Ajax.Request(
	BASE_HREF+'modules/shop/admin/ajax_save_libelle.php',
	{
		method: 'post',
		parameters: 'id='+id+'&libelle='+libelle+'&id_site='+ID_SITE+'&table='+table
	});
}



// Fonction qui affiche ou non une catégorie ou un article dans le catalogue
function shop_avis_valide(id)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_valide_avis.php',
		{
			method: 'post',
			parameters: 'id='+id+'&id_site='+ID_SITE,
			onCreate: function() {
				$('invisible_picto_'+id).src=THEME_PROGRESS_MINI;
			},
			onComplete: function(retour){
				if(retour.responseText=="1")
				{
					$('invisible_picto_'+id).src=THEME_ICONE_VISIBLE_OVER;
				}
				else
				{
					$('invisible_picto_'+id).src=THEME_ICONE_INVISIBLE_OVER;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_avis_valide\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui affiche ou non une catégorie ou un article dans le catalogue
function cache_montre(id, table)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_invisible.php',
		{
			method: 'post',
			parameters: {
				id: id,
				id_site: ID_SITE,
				table: table
			},
			onCreate: function() {
				$('invisible_picto_'+id).src=THEME_PROGRESS_MINI;
			},
			onComplete: function(retour){
				if(retour.responseText=="1")
				{
					$('invisible_picto_'+id).src=THEME_ICONE_VISIBLE_OVER;
				}
				else
				{
					$('invisible_picto_'+id).src=THEME_ICONE_INVISIBLE_OVER;
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'cache_montre\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui redimensionne UNE image
function resize_pic(type,size,id)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_resize_pics.php',
		{
			method: 'post',
			parameters: 'type='+type+'&id_site='+ID_SITE+'&size='+size+'&id='+id
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'resize_pic\' dans shop.js :\n'+e.message);
	}
}



// Fonction qui redimensionne les images
function resize_pics(type,size,mode)
{
	try
	{
		//alert('type : '+type+' -- size : '+size+' -- mode : '+mode);
		$('img_save_'+type).src=THEME_PROGRESS;
		$('img_save_'+type).style.visibility='visible';
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_resize_pics.php',
		{
			method: 'post',
			parameters: 'type='+type+'&id_site='+ID_SITE+'&size='+size+'&mode='+mode,
			onComplete: function(retour){
				if(retour.responseText=='')
				{
					$('img_save_'+type).src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('img_save_'+type).src=THEME_ICONE_ERREUR;
					alert(retour.responseText);
				}
				$('img_save_'+type).style.visibility='visible';
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'resize_pics\' dans shop.js :\n'+e.message);
	}
}

// Fonction qui affiche les options du bloc catégorie
function affiche_opt_bloc_categories(mode)
{
	try
	{
		if(mode)
		{
			Effect.BlindDown('label-optbloc_categories', { duration: 0.5 });
			Effect.BlindDown('tbl-optbloc_categories', { duration: 0.5 });
		}
		else
		{
			Effect.BlindUp('label-optbloc_categories', { duration: 0.5 });
			Effect.BlindUp('tbl-optbloc_categories', { duration: 0.5 });
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'affiche_opt_bloc_categories\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui affiche les options RSS
function affiche_optrss(mode)
{
	try
	{
		if(mode)
		{
			Effect.BlindDown('label-optrss', { duration: 0.5 });
			Effect.BlindDown('tbl-optrss', { duration: 0.5 });
		}
		else
		{
			Effect.BlindUp('label-optrss', { duration: 0.5 });
			Effect.BlindUp('tbl-optrss', { duration: 0.5 });
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'affiche_optrss\' dans shop.js :\n'+e.message);
	}
}


// Function qui enregistre les paramètres de la boutique
function save_param(libelle, value, callback)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_param.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				libelle: libelle,
				value: value,
				id_site: ID_SITE },
			onCreate: function() {
				$('img_save_'+libelle).src=THEME_PROGRESS_MINI;
				$('img_save_'+libelle).setStyle({visibility:'visible'});
			},
			onComplete: function(retour){
				if(retour.responseText!="" && retour.responseText!="0")
				{
					if(callback!='')
					{
						eval(callback);
						$('img_save_'+libelle).setStyle({visibility:'hidden'});
					}
					else
					{
						$('img_save_'+libelle).src=THEME_ICONE_SUCCES;
						$('img_save_'+libelle).setStyle({visibility:'visible'});
					}
				}
				else
				{
					$('img_save_'+libelle).src=THEME_ICONE_ERREUR;
					$('img_save_'+libelle).setStyle({visibility:'visible'});
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'save_param\' dans shop.js :\n'+e.message);
	}
}