<!--
// ----------------------------------------------------------------------------- RollOver();
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document;if(d.images){if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;if(!d) d=document;if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];}
}
// ----------------------------------------------------------------------------- trim();
function trim(string)
{
return string.replace(/(^\s*)|(\s*$)/g,'');
}
// ----------------------------------------------------------------------------- fDomOffset();
function fDomOffset(oObj,sProp)
{
 // oObj : [Object] - Objet dont on désire le positionnement
 // sProp : [String] - Propriété désirée : offsetLeft - offsetTop
 var iVal = 0;
 // On boucle tant que l'on n'est pas à la racine du document
 while (oObj && oObj.tagName != 'body') {
  eval('iVal += oObj.' + sProp + ';');
  oObj = oObj.offsetParent;
 }
 return iVal;
}
// ---------------------------------------------------------------------------- Dessinez
function dessinez() {
	window.location.href='feriad-dessin-libre.html';
}
// ----------------------------------------------------------------------------- smenu();
function smenu(id) {
	if(document.getElementById("smenu-"+id) && document.getElementById("smenu-"+id).style.display=="none") {
		/*if(document.getElementById("menu_actif") && document.getElementById("menu_actif").value!="") {
			menu_actif=document.getElementById("menu_actif").value;
			document.getElementById("smenu-"+menu_actif).style.display="none";
			}*/
		document.getElementById("smenu-"+id).style.display="";
		document.getElementById("menu_actif").value=id;
		}
	else if(document.getElementById("smenu-"+id) && document.getElementById("smenu-"+id).style.display!="none") {
		document.getElementById("smenu-"+id).style.display="none";
		document.getElementById("menu_actif").value="";
	}
}
// ----------------------------------------------------------------------------- active_smenu();
function active_smenu() {
	var menuActif = document.getElementById("menu_actif").value;
	if(menuActif != "" && document.getElementById("smenu-"+menuActif) && document.getElementById("smenu-"+menuActif).style.display=="none") {
		document.getElementById("smenu-"+menuActif).style.display="";
		document.getElementById("smenu-"+menuActif).parentNode.getElementsByTagName('a')[0].className="menuActif";
	}
}
// ----------------------------------------------------------------------------- active_smenu();
function rechargeLP(page) {
	if(document.getElementById("lp_page")) {
		document.getElementById("lp_page").value=page;
		if(document.getElementById("rechargelp")) {
			document.getElementById("rechargelp").submit();
			}
		}
}
function detail(id) {
var client_active = document.getElementById("client_active").value;
if(client_active != "" && client_active != id)
	{
	document.getElementById("client"+client_active).style.display="none";
	}
else if(client_active != "" && client_active == id)
	{
	document.getElementById("client"+client_active).style.display="none";
	document.getElementById("client_active").value="";
	}
if(client_active != id)
	{
	document.getElementById("client"+id).style.display="";
	document.getElementById("client_active").value=id;
	}
}

var pg_carousel=0;
var bloc_click=0;
var time_message;
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({scroll: 5, visible: 5});
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_square', overlay_gallery: false});
	$("#img_produit").live("click", function() {
		$("#premier_details").click();
	});
	$(".img_galerie").click(function() {
		if (bloc_click == 0) {
			$("#selecteur").remove();
			$(this).prepend("<div id=\"selecteur\"><img src=\"images/interface/spacer.jpg\" height=\"1\" width=\"1\" /></div>");
			bloc_click = 1
			$.ajax({
				type: "GET",
				url: "boutiques/ajax.php",
				data: "mod=1&id=" + this.id,
				success: function(msg){
					$("#img_produit_temp").remove();
					var dec = msg.split('[#]');
					var html_details = "";
					var dimg = dec[1].split("|");
					for(var i=0;i<dimg.length-1;i++) {
						
						html_details=html_details+ "<a href=\"images/photos_produits/"+dimg[i];
						html_details=html_details+"\" rel=\"prettyPhoto[mixed]\" ";
						if (i==0) {
							html_details=html_details+"id=\"premier_details\"";
						}  
						html_details=html_details+"><img style=\"margin-right:5px;margin-bottom:5px;\" src=\"images/photos_produits/small/"+dimg[i]+"\" width=\"40\" height=\"53\" alt=\"\" /></a>";
					}
					//$("#desc_produit").fadeOut("slow",function() {
						$("#desc_produit").html(dec[2]);
					//});
					$("#zone_details").fadeOut("slow", function() {
						$("#zone_details").fadeIn().html(html_details);
						$(".dark_square").remove();
						$(".pp_overlay").remove();
						$(".ppt").remove();
						$("a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_square', overlay_gallery: false});
					});
					$("#loader").animate({opacity:0.5});
					$("<img width=\"485\" height=\"689\" alt=\"\" src=\"images/photos_produits/"+dec[0]+"\" id=\"img_produit_temp\" style=\"position: absolute; display: none;\">").insertBefore("#rendezvous");
					//$("#img_produit_temp").attr('src', "images/photos_produits/" + dec[0]);
					$("#img_produit_temp").load(function() {
						$("#loader").animate({opacity:0});
						$("#img_produit_temp").fadeIn("slow", function(){
							$("#img_produit").remove();
							//$("#img_produit").attr('src', "images/photos_produits/" + dec[0]);
							$("<img width=\"485\" height=\"689\" alt=\"\" src=\"images/photos_produits/"+dec[0]+"\" id=\"img_produit\" style=\"position: absolute;\">").insertBefore("#img_produit_temp");
							$("#img_produit").load(function() {
								if (html_details!="") {
									$("#img_produit").css("cursor", "pointer");
								}
								else {
									$("#img_produit").css("cursor", "auto");
								}
								$("#img_produit_temp").hide();
								bloc_click=0;
							});
						});
					})
					if (dec[3]=="oui") {
						$("#ajouter_selection").hide();
						$("#retirer_selection").show();
					}
					else {
						$("#ajouter_selection").show();
						$("#retirer_selection").hide();
					}
				}
			});
		}
	});
	$("#ajouter_selection").click(function() {
		$.ajax({
			type: "GET",
			url: "selection.php",
			data: {id:$("#selecteur").parent().attr("id"),mod:1},
			success:function(msg) {
				$("#message_retrait").fadeOut("fast",function() {
					clearTimeout(time_message);
					$("#message_ajout").fadeIn("fast");
					time_message = setTimeout(hide_message,3000);
				});
				$("#ajouter_selection").hide();
				$("#retirer_selection").show();
				$(".selection_count").each(function() {
					if ($(this).hasClass("nb_seul")) {
						$(this).html(msg);
					}
					else {
						$(this).html("("+msg+")");
					}
				});
			}
		});
		return false;
	});
	$("#retirer_selection").click(function() {
		$.ajax({
			type: "GET",
			url: "selection.php",
			data: {id:$("#selecteur").parent().attr("id"),mod:2},
			success:function(msg) {
				$("#message_ajout").fadeOut("fast",function() {
					clearTimeout(time_message);
					$("#message_retrait").fadeIn("fast");
					time_message = setTimeout(hide_message,3000);
				});
				$("#ajouter_selection").show();
				$("#retirer_selection").hide();
				$(".selection_count").each(function() {
					if ($(this).hasClass("nb_seul")) {
						$(this).html(msg);
					}
					else {
						$(this).html("("+msg+")");
					}
				});
				if ($("#menu_ma_selection").children("#puce").length>0) {
					location.href="ma_selection.html";
				}
			}
		});
		return false;
	});
	$(".jcarousel-next-horizontal").click(function() {
		pg_carousel=pg_carousel+1;
		$.ajax({
			type: "GET",
			url: "boutiques/ajax.php",
			data: "mod=2&id=3&pg="+pg_carousel,
			success: function(msg){
				$("#precharge_image").html(msg);		
			}
		});
	});
	$(".jcarousel-prev-horizontal").click(function() {
		pg_carousel=pg_carousel-1;
		$.ajax({
			type: "GET",
			url: "boutiques/ajax.php",
			data: "mod=2&id=3&pg="+pg_carousel,
			success: function(msg){
				$("#precharge_image").html(msg);
			}
		});
	});
	$(".magasin").click(function() {
		if ($("#info_" + $(this).attr("id")).css("display") == "none") {
			$("#info_" + $(this).attr("id")).slideDown();
		}
		else {
			$("#info_" + $(this).attr("id")).slideUp();
		}
	});
	
	$(".lien_client").click(function() {
		var id = $(this).attr("id");
		$(".details_carte").hide();
		$("#client"+id).show();
	});
	$("#rdv_selection").click(function() {
		$("#rendezvous").fadeIn();
		return false;
	})
	$("#pdf_selection").click(function() {
		if ($(this).attr("href")!="") {
			window.open("pdf.html?"+$(this).attr("href"));
		}
		else {
			if ($(this).parent().parent().find(".selection_count").html()=="(0)") {
				alert("Vous devez faire une selection pour pouvoir imprimer.");
			}
			else if ($("#nom_magasin").length>0 && $("#nom_magasin").html()=="") {
				var chemin = $("#choisissez_magasin").attr("href");
				$.prettyPhoto.open(chemin.replace("choix_magasins", "choix_magasins2"));
			}
			else {
				window.open("pdf.html");
			}
		}
		return false;
	})
	$("#ch_annuler").click(function() {
		$("#rendezvous").fadeOut();
	})
	$("#form_rdv").submit(function() {
		var msg="";
		if ($("#ch_nom").val()=="" || $("#ch_nom").val().length<3) {
			msg = msg +"- Nom\n";
		}
		if ($("#ch_prenom").val()=="" || $("#ch_prenom").val().length<3) {
			msg = msg +"- Prénom\n";
		}
		if ($("#ch_email").val()=="" && $("#ch_tel").val()=="") {
			msg = msg +"- Email ou Téléphone\n";
		}
		if ($("#nom_magasin").length>0 && $("#nom_magasin").html()=="") {
			msg = msg +"- Magasin\n";
		}
		var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
		if ($("#ch_email").val()!="" && reg.test($("#ch_email").val())==false) {
			msg = msg +"- L'email n'est pas dans un format valide\n";
		}
		if (msg!="" && $("#form_rdv").is(":visible")) {
			alert("Les champs suivant n'ont pas été renseigné correctement :\n"+msg);
			return false
		}
		else {
			return true;
		}
	});
});

function hide_message() {
	$("#message_ajout").fadeOut("fast");
	$("#message_retrait").fadeOut("fast");
}

