﻿// JavaScript Document

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

	SWITCH ARTICLE
	
	###################################################################################
*/
function shop_switch_article(sel)
{
	try
	{
		var rep=confirm('Êtes-vous sûr de vouloir changer d\'article?\nToutes les modifications non enregistrées seront perdues!');
		if(rep)
		{
			document.location=BASE_HREF+'admin/index.php?id_site='+ID_SITE+'&id_module=3&url=edit_article&id_article='+sel.value;
		}
		else
		{
			return false;
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_switch_article\' dans shop.js :\n'+e.message);
	}
}

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

	RESET INDICE
	
	###################################################################################
*/
function shop_tarification_reset_indice()
{
	try
	{
		var ind=0;
		$$('table#shop-tarification-table tr.shop-tarification-tr').each(function(e) {
			e.removeClassName('pair');
			e.removeClassName('impair');
			if(ind%2==0)
			{
				e.addClassName('pair');
			}
			else
			{
				e.addClassName('impair');
			}
			ind++;
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_tarification_reset_indice\' dans shop.js :\n'+e.message);
	}
}

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

	AFFICHE OU MASQUE LE LOADER DES TARIFS
	
	###################################################################################
*/
function shop_tarification_mask_loader(txt)
{
	try
	{
		if(txt)
		{
			$('shop-load-txt').update(txt);
		}
		else
		{
			$('shop-load-txt').update();
		}
		var main=$('shop-fieldset-tarification');
		var mask=$('shop-tarification-mask-loader');
		var span=$('shop-loader-info');
		$('shop-img-loader').src=THEME_PROGRESS;
		if(mask.getStyle('display')=='none')
		{
			var dimensions = main.getDimensions();
			var dimTop=main.offsetTop;
			var dimLeft=main.offsetLeft;
			if(dimTop==null)
			{
				dimTop=0;
			}
			if(dimLeft==null)
			{
				dimLeft=0;
			}		
			mask.setStyle({width: dimensions.width+'px', height: dimensions.height+'px', left:dimLeft+'px', top:dimTop+'px', display:'block' });
			
			// ON POSITIONNE LE MESSAGE ET LE LOADER
			var dimensions_span = span.getDimensions();
			span.setStyle({left:(dimensions.width/2)-(dimensions_span.width/2)+'px', top:(dimensions.height/2)-(dimensions_span.height/2)+'px'});
		}
		else
		{
			$('shop-img-loader').src=THEME_ICONE_VALIDE;
			$('shop-load-txt').update('Terminée');
			setTimeout(function() { mask.setStyle({display:'none'}); }, 500);
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_tarification_mask_loader\' dans shop.js :\n'+e.message);
	}
}

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

	ENREGISTRE LES TARIFS
	
	###################################################################################
*/
function shop_tarification_save(id_article, id_combinaison, taxe, poids, stock) {
	try {
		shop_tarification_mask_loader('Enregistrement des tarifs, du poids et du stock en cours...');
		// LES PRIX
		var tab_prix=new Array();
		var ind=0;
		$$('input.shop-degressif-from').each(function(e) {
			var tmp=new RegExp('shop_from_(.*)');
			var res=tmp.exec(e.id);
			var indtmp=new Number(res[1]);
			tab_prix[ind]=new Array();
			tab_prix[ind][0]=$('shop-prix_ht-'+indtmp).value;
			tab_prix[ind][1]=$('shop-prix_pro_ht-'+indtmp).value;
			tab_prix[ind][2]=$('shop-prix_promo_ht-'+indtmp).value;
			tab_prix[ind][3]=$('shop-prix_promo_pro_ht-'+indtmp).value;
			tab_prix[ind][4]=$('shop-ecotaxe_ht-'+indtmp).value;
			tab_prix[ind][5]=e.value;
			ind++;
		});
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_tarification_save.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_combinaison: id_combinaison,
				id_site: ID_SITE,
				id_article: id_article,
				prix: Object.toJSON(tab_prix),
				taxe: taxe,
				poids: poids,
				stock: stock },
			onCreate: function() {
				//$('img_save_prix').src=THEME_PROGRESS_MINI;
				//$('img_save_prix').setStyle(visibility='hidden');
			},
			onComplete: function(retour) {
				shop_tarification_mask_loader();
				//alert(retour.responseText);
				/*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 \'shop_tarification_save\' dans shop.js :\n'+e.message);
	}
}

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

	SUPPRIME UNE PLAGE DE TARIF
	
	###################################################################################
*/
function shop_degressif_del(id_article, id_combinaison, quantite) {
	try
	{
		if($$('tr.shop-tarification-tr').length==1)
		{
			alert('Vous ne pouvez pas supprimer la dernière plage tarifaire.\nAu moins une plage est nécessaire.');
			return false;
		}
		
		var rep=confirm('Êtes-vous sûr de vouloir supprimer cette plage tarifaire?');
		if(rep)
		{
			var myAjax = new Ajax.Request( 
			BASE_HREF+'modules/shop/admin/ajax_tarification_del.php',
			{
				method: 'post',
				asynchronous: true,
				parameters: {
					id_site: ID_SITE,
					id_article: id_article,
					id_combinaison: id_combinaison,
					quantite: quantite
				},
				onCreate: function() {
					$('shop-icone-supprimer-'+quantite).src=THEME_PROGRESS_MINI;
				},
				onComplete: function(retour){
					try
					{						
						if(retour.status==200)
						{
							Effect.Fade('shop-tarification-tr-'+quantite, { duration: 0.3 });
							setTimeout(function() { $('shop-tarification-tr-'+quantite).remove(); shop_tarification_reset_indice(); }, 400);
						}
					}
					catch(e)
					{
						alert('Erreur dans la fonction \'shop_degressif_add\' retour ajax, dans shop.js :\n'+e.messagee.message);
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_degressif_del\' dans shop.js :\n'+e.message);
	}
}


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

	AJOUTE UNE PLAGE DE TARIF
	
	###################################################################################
*/
function shop_tarification_add(id_article, id_combinaison) {
	try
	{
		// RECHERCHE DE LA DERNIERE PLAGE
		var last=0;
		var tmp=new RegExp('shop_from_(.*)');
		var ind=0;
		$$('input.shop-degressif-from').each(function(e) {
			//alert('value: '+e.value+' - Last: '+last);
			if(parseInt(e.value)>last)
			{
				last=parseInt(e.value);
			}
			
			var res=tmp.exec(e.id);
			if(res[1]>ind)
			{
				ind=res[1];
			}

		});
		var myAjax = new Ajax.Request( 
		BASE_HREF+'modules/shop/admin/ajax_tarification_add.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				id_site: ID_SITE,
				id_article: id_article,
				id_combinaison: id_combinaison,
				last: last,
				ind: ind
			},
			onComplete: function(retour){
				try
				{	
				//	alert(retour.responseText);
					
					if(retour.status==200)
					{
						var reponse=retour.responseJSON;
						$('shop-tarification-table').insert(reponse['plage']);
						shop_tarification_reset_indice();
					}
				}
				catch(e)
				{
					alert('Erreur dans la fonction \'shop_degressif_add\' retour ajax, dans shop.js :\n'+e.messagee.message);
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_degressif_add\' dans shop.js :\n'+e.message);
	}
}


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

	RENVOIE LES PDFS ADMIN
	
	###################################################################################
*/
function shop_get_pdf_admin(id_commande, type)
{
	try
	{
		switch(type)
		{
			case 'FA'	: {
				var ref='';
				// RECUPERATION EN AJAX DE LA REF FACTURE
				var myAjax = new Ajax.Request(
				BASE_HREF+'modules/shop/admin/ajax_get_ref_facture.php',
				{
					method: 'post',
					asynchronous: true,
					parameters: {
						id_commande: id_commande,
						id_site: ID_SITE },
					onCreate: function() {
						$('shop-pdf-logo-'+id_commande).src=THEME_PROGRESS;
						$('shop-pdf-logo-'+id_commande).setStyle({marginBottom:'3px'});
					},
					onComplete: function(retour){
						$('shop-pdf-logo-'+id_commande).src='../images/pdf_logo.jpg';
						$('shop-pdf-logo-'+id_commande).setStyle({marginBottom:'0px'});
						ref=retour.responseText;
						var ref_facture=prompt('Veuillez saisir le numéro de la facture si besoin', ref);
						if(ref_facture)
						{
							// ENREGISTREMENT EN AJAX DE LA REF FACTURE
							var myAjax = new Ajax.Request(
							BASE_HREF+'modules/shop/admin/ajax_set_ref_facture.php',
							{
								method: 'post',
								asynchronous: true,
								parameters: {
									id_commande: id_commande,
									ref_facture: ref_facture,
									id_site: ID_SITE },
								onCreate: function() {
									$('shop-pdf-logo-'+id_commande).src=THEME_PROGRESS;
									$('shop-pdf-logo-'+id_commande).setStyle({marginBottom:'3px'});
								},
								onComplete: function(retour){
									var retour=retour.responseJSON;
									$('shop-pdf-logo-'+id_commande).src='../images/pdf_logo.jpg';
									$('shop-pdf-logo-'+id_commande).setStyle({marginBottom:'0px'});
									if(retour[0]=='1')
									{
										var lien_pdf='index.php?id_site='+ID_SITE+'&id_module=3&url=get_pdf_admin&id_commande='+id_commande+'&type='+type;
										window.open(lien_pdf, 'PDF_Commande', '');
									}
									else
									{
										alert(retour['msg']);
										shop_get_pdf_admin(id_commande, type);
									}
								}
							});
						}			
					}
				});
				break;
			}
			default : {
				var lien_pdf='index.php?id_site='+ID_SITE+'&id_module=3&url=get_pdf_admin&id_commande='+id_commande+'&type='+type;
				window.open(lien_pdf, 'PDF_Commande');
			}
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_get_pdf_admin\' dans shop.js :\n'+e.message);
	}
}



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


// CHARGE LES LIGNES DES COMBINAISONS
function shop_load_ligne_combinaison(id_article, start)
{
	try
	{
		$('img-loading').setStyle({visibility:'visible'});
		$('container-combinaisons').setStyle({opacity:'0.2'});
		var myAjax = new Ajax.Request( 
		BASE_HREF+'modules/shop/admin/ajax_get_ligne_combinaison.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_site: ID_SITE,
				id_article: id_article,
				start: start
			},
			onComplete: function(retour){
				try
				{	
				//alert(retour.responseText);
					if(retour.status==200)
					{
						$('img-loading').setStyle({visibility:'hidden'});
						$('container-combinaisons').setStyle({opacity:'1'});
						var ret=retour.responseJSON;
						if(start==0)
						{
							$('shop_lst_combinaisons').update(ret['lng']);
						}
						else
						{
							$('shop_lst_combinaisons').insert(ret['lng']);
						}
						if(ret['lng']!='')
						{
							shop_load_ligne_combinaison(id_article, ret['start']);
						}
						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 \'shop_load_ligne_combinaison\' retour ajax, dans shop.js :\n'+e.messagee.message);
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_load_ligne_combinaison\' dans shop.js :\n'+e.message);
	}
}


// 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: Object.toJSON(table),
				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: Object.toJSON(table),
								id_site: ID_SITE,
								id_article: id_article,
								file: 'ajax_search_prix_combi.php',
								sid: SESSION_ID,
								lng: LNG,
								module: 'shop' },
							onComplete: function(retour){
								//alert(retour.responseText);
								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')
				{
					shop_load_ligne_combinaison(id_article, 0);
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'del_combinaison\' dans shop.js :\n'+e.message);
	}
}


// Fonction qui enregistre une combinaison
function save_combinaison(id_combinaison, id_article, poids, prix, promo, libelle, ecotaxe, stock, quantite)
{
	try
	{
		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,
				quantite: quantite
			},
			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=='')
					{
						shop_load_ligne_combinaison(id_article, 0);
					}
				}
			}
		});
	}
	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){
				shop_load_ligne_combinaison(id_article, 0);
			}
		});
	}
	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){
				shop_load_ligne_combinaison(id_article, 0);
			}
		});
	}
	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) {	
				shop_load_ligne_combinaison(id_article, 0);
			}
		});
	}
	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 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: true,
				parameters: 'id_combinaison='+id_combinaison+'&id_site='+ID_SITE+'&id_article='+id_article,
				onCreate: function() {
					shop_tarification_mask_loader('Chargement des tarifs, du poids et du stock en cours...');
				},
				onComplete: function(retour){
					//alert(retour.responseText);
					if(retour.status==200)
					{
						try
						{
							var tab=retour.responseJSON;
					
							// ON VIRE LES LIGNES EXISTANTES
							$$('tr.shop-tarification-tr').each(function(e) {
								e.remove();
							});
							$('shop-tarification-table').insert(tab['detail']);
					
							
							// 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;
								}
							}
							
							$('container_prix').style.display='';
							$('container_livraisons').style.display='';
							
							
							// ON MET A JOUR LA TAILLE DU LOADER
							var main=$('shop-fieldset-tarification');
							var mask=$('shop-tarification-mask-loader');
							var dimensions = main.getDimensions();
							var dimTop=main.offsetTop;
							var dimLeft=main.offsetLeft;
							if(dimTop==null)
							{
								dimTop=0;
							}
							if(dimLeft==null)
							{
								dimLeft=0;
							}		
							mask.setStyle({width: dimensions.width+'px', height: dimensions.height+'px', left:dimLeft+'px', top:dimTop+'px', display:'block' });
							
							shop_tarification_mask_loader('Terminé');
						}
						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 ###################### */


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

	CALCUL UNE ESTIMATION DES FRAIS DE PORT
	
	###################################################################################
*/
function shop_simulport_calcul(id_article, id_combinaison, quantite, id_pays, id_livreur)
{
	try
	{
		var action=testdom('shop', 'ajax_simulport_calcul.php', '/appel_ajax.php');
		var myAjax = new Ajax.Request(
		action,
		{
			method: 'post',
			asynchronous: true,
			parameters: {
				id_site: ID_SITE,
				id_pays: id_pays,
				id_article: id_article,
				id_combinaison: id_combinaison,
				quantite: quantite,
				id_livreur: id_livreur,
				sid:SESSION_ID,
				file:'ajax_simulport_calcul.php',
				module:'shop'
			},
			onCreate: function() {
				$('shop-simulport-calcul-container').update();
				$('shop-simulajax').setStyle({visibility:'visible'});
			},
			onComplete: function(retour) {
				$('shop-simulport-calcul-container').update(retour.responseText);
				$('shop-simulajax').setStyle({visibility:'hidden'});
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_get_livreurs\' dans shop.js :\n'+e.message);
	}
}


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

	AFFICHE LES LIVREURS COMPATIBLES AVEC LE PAYS
	
	###################################################################################
*/
function shop_simulport_get_livreurs(id_article, id_combinaison, quantite, id_pays)
{
	try
	{
		if(id_pays=='#')
		{
			$('shop-simulport-livreurs-container').update();
		}
		else
		{
			var action=testdom('shop', 'ajax_simulport_get_livreurs.php', '/appel_ajax.php');
			var myAjax = new Ajax.Request(
			action,
			{
				method: 'post',
				asynchronous: true,
				parameters: {
					id_site: ID_SITE,
					id_pays: id_pays,
					id_article: id_article,
					id_combinaison: id_combinaison,
					quantite: quantite,
					sid:SESSION_ID,
					file:'ajax_simulport_get_livreurs.php',
					module:'shop'
				},
				onCreate: function() {
					$('shop-simulport-livreurs-container').update();
					$('shop-simulajax').setStyle({visibility:'visible'});
				},
				onComplete: function(retour) {
					var ret=retour.responseJSON;
					$('shop-simulport-livreurs-container').update(ret[1]);
					$('shop-simulajax').setStyle({visibility:'hidden'});
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_get_livreurs\' dans shop.js :\n'+e.message);
	}
}




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

	SUPPRIME LES UPLOADS FRONT
	
	###################################################################################
*/
function shop_del_upload_front(id_commande, id_client, id_article, id_combinaison, indice, fichier_complet)
{
	try
	{
		var rep=confirm('Êtes-vous sûr de vouloir supprimer ce fichier?');
		if(rep)
		{
			var action=testdom('shop', 'ajax_del_upload.php', '/appel_ajax.php');
			var myAjax = new Ajax.Request(
			action,
			{
				method: 'post',
				parameters: {
					id_site: ID_SITE,
					id_commande: id_commande,
					id_client: id_client,
					id_article: id_article,
					id_combinaison: id_combinaison,
					indice: indice,
					fichier: fichier_complet,
					sid:SESSION_ID,
					file:'ajax_del_upload.php',
					module:'shop'
				},
				onCreate: function() {
					$('shop-img-supprimer-fichier-client-'+id_article+'-'+id_combinaison+'-'+indice).src=THEME_PROGRESS_MINI;
					$('shop-del-upload-'+id_article+'-'+id_combinaison+'-'+indice).setStyle({visibility:'visible'});
				},
				onComplete: function(retour) {
					$('shop-file-upload-'+id_article+'-'+id_combinaison+'-'+indice).update();
					$('shop-file-poids-'+id_article+'-'+id_combinaison+'-'+indice).update();
					$('shop-del-upload-'+id_article+'-'+id_combinaison+'-'+indice).setStyle({visibility:'hidden'});
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_del_upload_front\' dans shop.js :\n'+e.message);
	}
}



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

	SUPPRIME LES UPLOADS ADMIN
	
	###################################################################################
*/
function shop_del_upload(id_commande, id_client, id_article, id_combinaison, indice, fichier_complet)
{
	try
	{
		var rep=confirm('Êtes-vous sûr de vouloir supprimer ce fichier?');
		if(rep)
		{			
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_upload.php',
			{
				method: 'post',
				parameters: {
					id_commande: id_commande,
					id_client: id_client,
					id_article: id_article,
					id_combinaison: id_combinaison,
					indice: indice,
					fichier: fichier_complet,
					id_site: ID_SITE
				},
				onCreate: function() {
					$('shop-img-supprimer-fichier-client-'+id_article+'-'+id_combinaison+'-'+indice).src=THEME_PROGRESS_MINI;
				},
				onComplete: function(retour) {
					Effect.SwitchOff('shop-li-upload-'+id_article+'-'+id_combinaison+'-'+indice);
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_del_upload\' dans shop.js :\n'+e.message);
	}
}



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

	Affecte les inputs files
	
	###################################################################################
*/
function shop_load_upload()
{
	try
	{
		var indice=1;
		var uploadbuttons=$$('div.shop_upload_button');
		for(var i=0; i<uploadbuttons.length; i++)
		{
			// ID DE L'ARTICLE
			var tmp=new RegExp('upload_button_(.*)_(.*)');
			var res=tmp.exec(uploadbuttons[i].id);
			var id_article=res[1];
			var id_combinaison=res[2];

			// ON CHERCHE L'INDICE
			/*$$('span.shop-files').each(function(e) {
				if(e.innerHTML=='')
				{
					var tmpb=new RegExp('shop\-file\-(.*)');
					var resb=tmpb.exec(e.id);
					indice=resb[1];
					throw $break;
				}
			});*/
			//alert(id_article+' --> '+indice);
			var action=testdom('shop', 'ajax_upload.php', '/appel_ajax.php');
			new AjaxUpload(uploadbuttons[i], {
				action: action,
				responseType: 'json',
				data: {
					id_site: ID_SITE,
					id_article: id_article,
					id_combinaison: id_combinaison,
					sid:SESSION_ID,
					file:'ajax_upload.php',
					module:'shop'
				},
				onSubmit: function(file, ext) {
					try
					{
					if(!(ext.toLowerCase() && /^(jpg|png|jpeg|gif|pdf|tiff|zip|psd)$/.test(ext.toLowerCase())))
					{
						// extension is not allowed
						alert('Format de fichier incorrect!');
						// cancel upload
						return false;
					}
					else
					{
						var nb_indice=0;
						// ON CHERCHE L'INDICE
						var tmpm=new RegExp('upload_button_(.*)_(.*)');
						var resm=tmpm.exec(this._button.id);
						id_article=resm[1];
						id_combinaison=resm[2];
						$$('span.shop-files-'+id_article+'-'+id_combinaison).each(function(e) {						
							if(e.innerHTML=='')
							{
								var tmpb=new RegExp('shop\-file\-upload\-(.*)\-(.*)\-(.*)');
								var resb=tmpb.exec(e.id);
								indice=resb[3];
								throw $break;
							}
							else
							{
								nb_indice++;
							}
						});
						//alert(nb_indice+' ---> '+indice);
						if(nb_indice>=indice)
						{
							alert('Vous ne pouvez plus télécharger de fichier pour cet article.');
							return false;
						}
						else
						{
							// allow only 1 upload
							this.disable();
							$('shop-file-upload-'+id_article+'-'+id_combinaison+'-'+indice).update(file);
							$('shop-file-poids-'+id_article+'-'+id_combinaison+'-'+indice).update();
							$('shop-img-supprimer-fichier-client-'+id_article+'-'+id_combinaison+'-'+indice).src=THEME_PROGRESS_MINI;
							$('shop-del-upload-'+id_article+'-'+id_combinaison+'-'+indice).setStyle({visibility:'visible'});
						}
					}
					}
					catch(e)
					{
						alert('onSubmit: '+e.message);
					}
				},
				onComplete: function(file, response) {
					try
					{
						//alert(response);
						if(response=='')
						{
							alert('Impossible d\'envoyer le fichier, il est trop volumineux.');
							$('shop-file-upload-'+id_article+'-'+id_combinaison+'-'+indice).update();
							$('shop-del-upload-'+id_article+'-'+id_combinaison+'-'+indice).setStyle({visibility:'hidden'});
							this.enable();
							return false;
						}
						else
						{
							//response=Object.evalJSON(response);
							//alert(response);
							if(response['status']=='1')
							{
								//$('apercu_image_'+id_photo).src=BASE_HREF+'bibliotheques/'+ID_SITE+'/etiquettes/photos_clients/'+tmp[1]+'?time='+alea;
							}
							else
							{
								if(typeof response['erreur']!='undefined')
								{
									var erreur=response['erreur'];
								}
								else
								{
									var erreur='Votre fichier est trop lourd et ne peux être téléchargé.';
								}
								alert('Erreur lors de l\'envoie de la photo:\n'+erreur);
								$('shop-file-upload-'+id_article+'-'+id_combinaison+'-'+indice).update();
								$('shop-del-upload-'+id_article+'-'+id_combinaison+'-'+indice).setStyle({visibility:'hidden'});
								this.enable();
								return false;
							}
						}
						this.enable();
						//alert(response['indice']);
						
						if(typeof response['width']!='undefined' && typeof response['height']!='undefined')
						{
							var dim=', '+response['width']+'x'+response['height'];
						}
						else
						{
							var dim='';
						}
						
						$('shop-file-poids-'+id_article+'-'+id_combinaison+'-'+indice).update('('+response['poids']+dim+')');
						$('shop-del-upload-'+response['id_article']+'-'+response['id_combinaison']+'-'+response['indice']).onclick=function() {
							shop_del_upload_front(response['id_commande'], response['id_client'], response['id_article'], response['id_combinaison'], response['indice'], response['fichier']);
						};
						$('shop-img-supprimer-fichier-client-'+response['id_article']+'-'+response['id_combinaison']+'-'+response['indice']).src=ICONE_SUPPRIMER;
					}
					catch(e)
					{
						alert('Onload ajaxupload: '+e.message);
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_load_upload\' dans shop.js :\n'+e.message);
	}
}




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

	ENVOIE LES MAILS DE NOTIFICATION
	
	###################################################################################
*/
function shop_admin_send_mails(id_site, id_commande, table, id)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_send_mails.php',
		{
			method: 'post',
			parameters: {
				id_commande: id_commande,
				table: table,
				id: id,
				id_site: id_site
			},
			onCreate: function() {
				//$('booking_icone_loading').src=THEME_PROGRESS_MINI;
			},
			onComplete: function(retour) {
				//alert(retour.responseText);
				var rep=retour.responseJSON;
				if(rep['status']=='1')
				{
					alert('L\'email de notification a bien \351t\351 envoy\351 \340 '+rep['destinataire']);
				}
				else
				{
					alert('Une erreur c\'est produite lors de l\'envoie:\n'+retour.responseText);
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_admin_send_mails\' dans shop.js :\n'+e.message);
	}
}


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

	Affiche la grande photo de l'album Apercu
	
	###################################################################################
*/
function shop_apercu_photo(id, photo)
{
	try
	{
		$('shop_album_apercu_lien').href=$('zoom_'+id).value;
		$('shop_album_apercu_lien').onclick=function () { Lightview.show('href_'+id); return false; };
		$('shop_grande_photo').src=photo;
		if($('titre_'+id).value!='' && $('description_'+id).value!='')
		{
			$('shop_infos').update('<span class="shop_titre_photo">'+$('titre_'+id).value+'</span><br />'+$('description_'+id).value);
		}
		else
		{
			$('shop_infos').update('<span class="shop_titre_photo"></span>');
		}
		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: Object.toJSON(tab_ordre),
				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: Object.toJSON(tab_ordre),
					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(mode, format, fichier)
{
	try
	{
		if(mode=='del')
		{
			var rep=confirm('\312tes-vous s\373r de vouloir supprimer le fichier :\n'+fichier);
			if(!rep)
			{
				return false;
			}
		}
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_export.php',
		{
			method: 'post',
			parameters: {
				id_site: ID_SITE,
				mode: mode,
				fichier: encodeURI(fichier),
				format: format },
			onCreate: function() {
				if(mode=='del')
				{
					$('icone_supprimer_'+fichier.replace('.', '')).src=THEME_PROGRESS_MINI;
				}
				else if(mode=='gen')
				{
					$('icone_generer_'+format).src=THEME_PROGRESS_MINI;
				}
			},
			onComplete: function(retour){
				if(mode=='del')
				{
					$('icone_supprimer_'+fichier.replace('.', '')).src=THEME_ICONE_SUPPRIMER;
				}
				else if(mode=='gen')
				{
					$('icone_generer_'+format).src=THEME_ICONE_AVANCE;
				}
				if(retour.responseText!="")
				{
					alert(retour.responseText);
				}
				document.location=BASE_HREF+'admin/index.php?id_site='+ID_SITE+'&id_module=3&url=import_export';
			}
		});
	}
	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 UN MOYEN DE PAIEMENT
function shop_show_hide_paiement(class_paiement)
{
	try
	{
		// ON MASQUE LES AUTRES
		$$('div.shop_paiement_container').each(function(o){ 
			if(o.id!='shop_bloc_paiement_'+class_paiement)
			{
				if(o.getStyle('display')=='block')
				{
					Effect.BlindUp(o, { queue: 'end', limit: 3, duration:0.1 });
				}
			}
		});				
		var bloc=$('shop_bloc_paiement_'+class_paiement);
		if(bloc.getStyle('display')=='none')
		{
			Effect.BlindDown('shop_bloc_paiement_'+class_paiement, { queue: 'end', limit: 2, duration:0.3 });
		}
		else
		{
			Effect.BlindUp('shop_bloc_paiement_'+class_paiement, { queue: 'end', limit: 2, duration:0.3 });
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'shop_show_hide_paiement\' 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);
	}
}


function show_hide_nb_upload(mode)
{
	try
	{
		var bloc=$('shop-upload-fichier');
		if(mode)
		{
			bloc.setStyle({display:'block'});
		}
		else
		{
			bloc.setStyle({display:'none'})
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'show_hide_nb_upload\' 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: Object.toJSON(filtres),
				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);
	}
}


// ENREGISTRE LE COMMENTAIRE PERSONNEL DE LA COMMANDE
function shop_save_commentaire(id_site, id_commande, commentaire)
{
	if($('img_save_commentaire'))
	{
		$('img_save_commentaire').src=THEME_PROGRESS_MINI;
		$('img_save_commentaire').setStyle({visibility:'visible'});
	}
	var myAjax = new Ajax.Request(
	BASE_HREF+'modules/shop/admin/ajax_save_commentaire.php',
	{
		method: 'post',
		asynchronous: true,
		parameters: {
			id_site: id_site,
			id_commande: id_commande,
			commentaire: commentaire
		},
		onComplete: function(retour) {
			if($('img_save_commentaire'))
			{
				$('img_save_commentaire').src=THEME_ICONE_SUCCES;
			}
		}
	});
}


// ENREGISTRE LES NUMEROS DE TRACKING
function shop_save_tracking(id_site, id_commande, tracking)
{
	if($('img_save_tracking'))
	{
		$('img_save_tracking').src=THEME_PROGRESS_MINI;
		$('img_save_tracking').setStyle({visibility:'visible'});
	}
	var myAjax = new Ajax.Request(
	BASE_HREF+'modules/shop/admin/ajax_save_tracking.php',
	{
		method: 'post',
		asynchronous: false,
		parameters: {
			id_site: id_site,
			id_commande: id_commande,
			tracking: tracking
		},
		onComplete: function() {
			if($('img_save_tracking'))
			{
				$('img_save_tracking').src=THEME_ICONE_SUCCES;
			}
		}
	});
}


// Fonction qui met à jour le status d'une commande admin
function set_paiement_commande_admin(id_commande, paiement)
{
	try
	{
		$('img_save_paiement_'+id_commande).style.visibility='hidden';
		
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_save_paiement.php',
		{
			method: 'post',
			asynchronous: true,
			parameters: 'id_site='+ID_SITE+'&id_commande='+id_commande+'&paiement='+paiement,
			onCreate: function() {
				$('img_save_paiement_'+id_commande).src=THEME_PROGRESS_MINI;
				$('img_save_paiement_'+id_commande).style.visibility='visible';
			},
			onComplete: function(retour){
				var rep=retour.responseJSON;
				if(rep[0]=='1')
				{
					$('img_save_paiement_'+id_commande).src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('img_save_paiement_'+id_commande).src=THEME_ICONE_ERREUR;
				}
				$('img_save_paiement_'+id_commande).style.visibility='visible';
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'set_paiement_commande_admin\' 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_'+id_commande).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,
			onCreate: function() {
				$('img_save_status_'+id_commande).src=THEME_PROGRESS_MINI;
				$('img_save_status_'+id_commande).style.visibility='visible';
			},
			onComplete: function(retour){
				var rep=retour.responseJSON;
				if(rep[0]=='1')
				{
					if(rep[1]=='3') // CAS SPE POUR LE MAIL D'EXPEDITION
					{
						if(!$('shop_tracking'))
						{
							switch(status)
							{
								case '3'	:
								{
									var myAjax = new Ajax.Request(
									BASE_HREF+'modules/shop/admin/ajax_get_tracking.php',
									{
										method: 'post',
										asynchronous: false,
										parameters: 'id_site='+ID_SITE+'&id_commande='+id_commande,
										onComplete: function(retour){
											var tracking=prompt('Veuillez entrer le/les num\351ro(s) de suivi, s\351par\351 par des virgules', retour.responseText);
											shop_save_tracking(ID_SITE, id_commande, tracking);
										}
									});
									break;
								}
							}
						}
						var send_mail=confirm('Voulez-vous envoyer le mail de notification au client?');
						if(send_mail)
						{
							shop_admin_send_mails(ID_SITE, id_commande, 'status', status);
						}
					}
					else if(rep[1]!='0') // LIVRAISON RETARDEE
					{
						var send_mail=confirm('Voulez-vous envoyer le mail de notification au client?');
						if(send_mail)
						{
							shop_admin_send_mails(ID_SITE, id_commande, 'status', status);
						}
					}
					$('img_save_status_'+id_commande).src=THEME_ICONE_SUCCES;
				}
				else
				{
					$('img_save_status_'+id_commande).src=THEME_ICONE_ERREUR;
				}
				$('img_save_status_'+id_commande).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);
	}
}


// POUR LES TIMER
var launch=false;
var timerID=null;
var timerRunning=false;
var delay=1000;


// 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--;
			}
		}
		if(launch)
    {
			clearTimeout(timerID);
			timerRunning=false;
			launch=false;
			panier_update_quantite(id_article,id_combinaison, $('lngart_'+id_article+'_'+id_combinaison).value);
		}
    else
    {
			if(timerRunning)
			{
				clearTimeout(timerID);
			}
			timerRunning = true;
			timerID = self.setTimeout(function () {
				launch=false;
				panier_update_quantite(id_article,id_combinaison, $('lngart_'+id_article+'_'+id_combinaison).value);
			}, delay);
    }
	}
	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){
				//alert(retour.responseText);
				var ret=retour.responseJSON;
				// On refresh les paniers
				update_panier('modif');
				update_bloc_panier();
				if(ret['quantite']!=quantite)
				{
					alert(html_entity_decode(ret['message']));
				}
			}
		});
	}
	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(ETES_VOUS_SUR_VIDER_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();
					document.location=retour.responseText;
				}
			});
		}
	}
	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);
				try
				 {
				if(retour.responseText!="")
				{
					$('panier_container').update(retour.responseText);
					$('img_panier_loader').setStyle({visibility:'hidden'});
				}
				 }
				 catch(e)
				 {
					 alert(e.message);
				 }
			}
		});
	}
	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
		];
		}
		alert(position);
		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)
			{
				try
				{
				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();
				//alert(div.height+' -- '+dimensions.height+' -- '+top+' -- '+scrollpos[1]+' -- '+(top+scrollpos[1]));
				$('shop-splash').setStyle({left: (left)+'px', top: (top)+'px'}); //$('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);
				}
			}
		});
		
	}
	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);
	}
}


// POUR LES TIMER
var launchRecalc=false;
var timerIDRecalc=null;
var timerRunningRecalc=false;
var delayRecalc=800;

// Fonction qui recalcule les champs TTC
function recalc_montants(id_article, id_combinaison, mode, ind, obj)
{
	try
	{
		if(launchRecalc)
    {
			clearTimeout(timerIDRecalc);
			timerRunningRecalc=false;
			launchRecalc=false;
			
			var tab_prix=Array();
			if(ind)
			{
				if(obj)
				{
					tab_prix[0]=Array(obj.id, obj.value);
				}
				else
				{
					tab_prix[0]=Array('shop-prix_'+mode+'-'+ind, $('shop-prix_'+mode+'-'+ind).value);
					tab_prix[1]=Array('shop-prix_pro_'+mode+'-'+ind, $('shop-prix_pro_'+mode+'-'+ind).value);
					tab_prix[2]=Array('shop-prix_promo_'+mode+'-'+ind, $('shop-prix_promo_'+mode+'-'+ind).value);
					tab_prix[3]=Array('shop-prix_promo_pro_'+mode+'-'+ind, $('shop-prix_promo_pro_'+mode+'-'+ind).value);
					tab_prix[4]=Array('shop-ecotaxe_'+mode+'-'+ind, $('shop-ecotaxe_'+mode+'-'+ind).value);
				}
			}
			else
			{
				shop_tarification_mask_loader('Cacul des prix en cours...');
				var reg=new RegExp('shop_from_(.*)');
				$$('input.shop-degressif-from').each(function(p) {
					var res=reg.exec(p.id);
					var indb=new Number(res[1]);
					
					tab_prix[indb]=Array();
					
					tab_prix[indb][0]=Array('shop-prix_ht-'+indb, $('shop-prix_ht-'+indb).value);
					tab_prix[indb][1]=Array('shop-prix_pro_ht-'+indb, $('shop-prix_pro_ht-'+indb).value);
					tab_prix[indb][2]=Array('shop-prix_promo_ht-'+indb, $('shop-prix_promo_ht-'+indb).value);
					tab_prix[indb][3]=Array('shop-prix_promo_pro_ht-'+indb, $('shop-prix_promo_pro_ht-'+indb).value);
					tab_prix[indb][4]=Array('shop-ecotaxe_ht-'+indb, $('shop-ecotaxe_ht-'+indb).value);
					
					//recalc_montants(id_article, id_combinaison, 'ht', ind);
				});
				//return false;
			}
			var taxe=$('shop_taxe').value;
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_calc_tva_prix.php',
			{
				method: 'post',
				asynchronous: true,
				parameters: {
					mode: mode,
					prix: Object.toJSON(tab_prix),
					taxe: taxe,
					id_article: id_article,
					id_combinaison: id_combinaison,
					id_site: ID_SITE
				},
				onComplete: function(retour){
					//alert(retour.responseText);
					if(retour.status==200)
					{
						var tab=retour.responseJSON;
						for(id in tab)
						{
							if(tab[id]=='')
							{
								$('shop-'+id).value='';
							}
							else
							{
								$('shop-'+id).value=Number(tab[id]).toFixed(5);
							}
						}
					}
					if(!ind)
					{
						shop_tarification_mask_loader();
					}
				}
			});
		}
    else
    {
			if(timerRunningRecalc)
			{
				clearTimeout(timerIDRecalc);
			}
			timerRunningRecalc = true;
			timerIDRecalc = self.setTimeout(function () {
				launchRecalc=true;
				recalc_montants(id_article, id_combinaison, mode, ind, obj);
			}, delayRecalc);
    }
	}
	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 fabriquant
function delfabriquant(id)
{
	try
	{
		var rep=confirm('\312tes-vous sur de vouloir supprimer ce fabriquant?');
		if(rep===true)
		{
			var myAjax = new Ajax.Request(
			BASE_HREF+'modules/shop/admin/ajax_del_fabriquant.php',
			{
				method: 'post',
				parameters: {
					id_fabriquant: id,
					id_site: ID_SITE
				},
				onCreate: function() {
					$('icone_supprimer_'+id).src=THEME_PROGRESS_MINI;
				},
				onComplete: function(retour) {
					if(retour.responseText=='1')
					{
						Effect.BlindUp('fabriquant_'+id, { duration: 0.5 });
					}
				}
			});
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'delfabriquant\' 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(bloc, mode)
{
	try
	{
		if(mode)
		{
			Effect.BlindDown('label-optbloc_'+bloc, { duration: 0.5 });
			Effect.BlindDown('tbl-optbloc_'+bloc, { duration: 0.5 });
		}
		else
		{
			Effect.BlindUp('label-optbloc_'+bloc, { duration: 0.5 });
			Effect.BlindUp('tbl-optbloc_'+bloc, { duration: 0.5 });
		}
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'affiche_opt_bloc\' 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);
	}
}


// Fonction exécuté après sélection d'une image pour un article
function update_photo_article(image)
{
	try
	{
		var myAjax = new Ajax.Request(
		BASE_HREF+'modules/shop/admin/ajax_chk_dbl_image.php',
		{
			method: 'post',
			asynchronous: false,
			parameters: {
				image: image,
				id_site: ID_SITE },
			onCreate: function() {
			},
			onComplete: function(retour){
				var rep=retour.responseJSON;
				if(rep[0]=='0')
				{
					rep[0]=confirm(rep[1]);
				}
				else
				{
					rep[0]=true;
				}
				
				if(rep[0])
				{
					$('apercu_image').src=image;
					$('apercu_image').style.display='block';
					$('radio_fichier').checked='checked';
				}
				else
				{
					$('apercu_image').src='';
					$('apercu_image').style.display='none';
					$('radio_fichier').checked='';
				}
			}
		});
	}
	catch(e)
	{
		alert('Erreur dans la fonction \'update_photo_article\' 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);
	}
}


function showField(){

  new Effect.toggle('p_fb_message','slide', { duration: 0.5 });

}
