// JavaScript Document
$(function(){
	// Changer l'apercu de l'image
	$("#js_photo li").find("a").click(function(){ 
		ImgA = $("#big_image");
		url = $(this).attr("href");
		reg = new RegExp("med_","g");
		urlReg = url.replace(reg,"big_");
		ImgA.attr({ href : urlReg });
		ImgA.find("img").attr({ src : url });
		return false;
	});
	
	$("#big_image").click(function(){
		img = $(this).attr("href");;
		PopupImage(img);
		return false;
	});
	
	$("#copyMe").click(function(){
		if($(this).attr("checked")){
			$("#b1").val($("#a1").val());
			$("#b2").val($("#a2").val());
			$("#b3").val($("#a3").val());
			document.getElementById('b4').selectedIndex = document.getElementById('a4').selectedIndex;
		}
	});
	
	$("#form_toile").submit(function(){
		if( $("#pas1").val() != $("#pas1").val() ){
			return false;
		}
	});
	
	// Chargement Formulaire Client // non terminé
	$("#info client").click(function(){
		id_client = $(this).val();
		
	});
	
	// Controle lors d'un ajout au panier
	var modele 	= $("[@name=modele]");
	var prix 	= $("[@name=prix]");
	var taille 	= $("[@name=taille]");
	var couleur = $("[@name=couleur]");
	var quantite= $("[@name=quantite]");
	var choice 	= false;
	var base	= $("base").attr("href");
	
	modele.change(function(){
		
		if( modele.val() != "no_selected" ){			
			// Changer les valeur par défaut
			tab = modele.val().split("|");
			prix.val(tab[3]);
			taille.val(tab[2]);
			couleur.val(tab[1]);
			choice = true;
			
			// Changer l'image
			ImgA = $("#big_image");
			url = base + "pictures/prod_couleur_details_prix/med_"+tab[0]+".jpg";
			urlB = base + "pictures/prod_couleur_details_prix/big_"+tab[0]+".jpg";
			ImgA.attr({ href : urlB });
			ImgA.find("img").attr({ src : url });
		}else{
			// Remettre à 0
			prix.val("");
			taille.val("");
			couleur.val("");
			choice = false;
		}
	});
	
	$("#achat").submit(function(){
		reponse = false;
		
		if( choice ){
			if( !isNaN( quantite.val() ) && quantite.val() > 0 ){
				reponse = true;
			}else{
				$("#error2").animate({ opacity : "show"}, 500).animate({ opacity : "hide"}, 1500);
			}
		}
		
		if(!choice){
			$("#error1").animate({ opacity : "show"}, 500).animate({ opacity : "hide"}, 1500);
		}
		
		return reponse;
	});
});
