
//global variables
var combinations = new Array();
var selectedCombination = new Array();
var globalQuantity = new Number;
var colors = new Array();

var interdictionCommande = false;
var messageInetrdiction = "Vous avez déjà sélectionné l'option montage à domicile pour un autre produit , le forfait montage est valable pour une demi-journée d'intervention";

function lanceAjaxVerifMontage(element){
	if(element.checked){
		$.ajax({
		   type: "POST",
		   url: "/tools/ajax/verificationMontageSelect.php",
		   success: function(msg){
				if(msg == 'oui'){
					interdictionCommande = true;
                    $('.bg_btn_radio').children(".btn_radio").fadeOut(500);
                    $('.bg_btn_radio').children("input[type='radio']").attr('checked',false);
					alert(messageInetrdiction);
				} else {
					interdictionCommande = false;
                    changeSelectPietement(document.getElementById('btn_radio_montage'),'group_17');
				} 
		   }
		 });
	}else{
		interdictionCommande = false;
        changeSelectPietement(document.getElementById('btn_radio_montage'),'group_17');
	}
}

//check if a function exists
function function_exists(function_name)
{
	if (typeof function_name == 'string')
		return (typeof window[function_name] == 'function');
	return (function_name instanceof Function);
}

//execute oosHook js code
function oosHookJsCode()
{
	for (var i = 0; i < oosHookJsCodeFunctions.length; i++)
	{
		if (function_exists(oosHookJsCodeFunctions[i]))
		setTimeout(oosHookJsCodeFunctions[i]+'()', 0);
	}	
}

//add a combination of attributes in the global JS sytem
function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference)
{
	globalQuantity += quantity;
		
		var combi = new Array();
		combi['idCombination'] = idCombination;
		combi['quantity'] = quantity;
		combi['idsAttributes'] = arrayOfIdAttributes;
		combi['price'] = price;
		combi['ecotax'] = ecotax;
		combi['image'] = id_image;
		combi['reference'] = reference;
		
		combinations.push(combi);
	
		
	
}

// search the combinations' case of attributes and update displaying of availability, prices, ecotax, and image
function findCombination(firstTime)
{
	//create a temporary 'choice' array containing the choices of the customer
	var choice = new Array();
	$('div#attributes select').each(function(){
		choice.push($(this).val());
	});
	var nbAttributesEquals = 0;
	//testing every combination to find the conbination's attributes' case of the user
	
	for (combination in combinations)
	{
		//verify if this combinaison is the same that the user's choice
		nbAttributesEquals = 0;
		for (idAttribute in combinations[combination]['idsAttributes'])
		{
			//ie6 bug fix
			if (idAttribute != 'indexOf'){
				//if this attribute has been choose by user
				if (in_array(combinations[combination]['idsAttributes'][idAttribute], choice))
				{
					//we are in a good way to find the good combination !
					nbAttributesEquals++;
				}
			}
		}

		if (nbAttributesEquals == choice.length)
		{
			
			//combination of the user has been found in our specifications of combinations (created in back office)
			selectedCombination['unavailable'] = false;
			selectedCombination['reference'] = combinations[combination]['reference'];
			$('#idCombination').val(combinations[combination]['idCombination']);

			//get the data of product with these attributes
			quantityAvailable = combinations[combination]['quantity'];
			
			selectedCombination['price'] = combinations[combination]['price'];
			if (combinations[combination]['ecotax'])
				selectedCombination['ecotax'] = combinations[combination]['ecotax'];
			else
				selectedCombination['ecotax'] = default_eco_tax;
			
			//show the large image in relation to the selected combination
			if (combinations[combination]['image'] && combinations[combination]['image'] != -1)
				displayImage( $('#thumb_'+combinations[combination]['image']).parent() );
			
			
			//update the display
			updateDisplay();

			if(typeof(firstTime) != 'undefined' && firstTime)
				refreshProductImages(0);
			else
				refreshProductImages(combinations[combination]['idCombination']);
			//leave the function because combination has been found
			return;
		}
	}
	//this combination doesn't exist (not created in back office)
	selectedCombination['unavailable'] = true;
	updateDisplay();
}











/**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************NEWQUEST FONCTION ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/



function addProductNuancierOnAjax(){

	var idProduct = id_product_nauncier;
	var idCombination = null;
	var addedFromProductPage = true;
	var callerElement = $("#detail_panneau_achat_nuancier");
	var quantity = 1 ;
	var whishlist = null;
	
	
	
	$.ajax({
			type: 'GET',
			url: baseDir + 'cart.php',
			async: true,
			cache: false,
			dataType : "json",
			data: 'ajax=true',
			success: function(jsonData)
			{
				var control = false;
				for(var i = 0 ; i < jsonData.products.length ; i++){
					if(jsonData.products[i].id == id_product_nauncier){
						control = true;
					}
				}
				
				if(control){
					alert(nuancier_already_add);
					
				}else{
				
						$.ajax({
							type: 'GET',
							url: baseDir + 'cart.php',
							async: true,
							cache: false,
							dataType : "json",
							data: 'add&ajax=true&qty=' + ( (quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''),
							success: function(jsonData)
							{
				
								//apply 'transfert' effect
								var elementToTransfert = callerElement;
				
								//alert('jsonData.updateCart : '+typeof(jsonData.updateCart));
								elementToTransfert.TransferTo({
											to: $('.information_panier').get(0),
											className:'transferProduct',
											duration: 800,
											complete: function () {
												//ajaxCart.updateCart(jsonData);
												$(".ajax_cart_quantity").html(jsonData.nbTotalProducts);
											}
								});
							},
							error: function(XMLHttpRequest, textStatus, errorThrown) {
								alert("TECHNICAL ERROR: unable to add the product.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
								//reactive the button when adding has finished
								if (addedFromProductPage)
									$('body#product p#add_to_cart input').removeAttr('disabled').addClass('exclusive').removeClass('exclusive_disabled');
								else
									$('.ajax_add_to_cart_button').removeAttr('disabled');
							}
						});
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("TECHNICAL ERROR: unable to add the product.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
				//reactive the button when adding has finished
				if (addedFromProductPage)
					$('body#product p#add_to_cart input').removeAttr('disabled').addClass('exclusive').removeClass('exclusive_disabled');
				else
					$('.ajax_add_to_cart_button').removeAttr('disabled');
			}
		});	
		
}


function findCombinationNQ(id_product,nombreInputForProduit)
{
	
	//create a temporary 'choice' array containing the choices of the customer
	var choice = new Array();
	$('div#attributes select').each(function(){
		 
		 var temp = $(this).attr('name').split('_');
		 if($(this).val() != 0 && temp[0] == 'id')
		 {
			choice.push($(this).val());
		 }
	});

			var compteurAjax = 0;
			$('div#attributes input').each(function(){
				var temp = $(this).attr('name').split('_');
				
				if($(this).val() != '' && this.type == 'text' && temp[0] == 'id')
				{
					choice.push($(this).val());
					compteurAjax++;
				}
			});
			
			
			//compteur ajax s il y a 2 ou 1 champs input => soit largeur et hauteur (2) et soit juste diametre
			if(compteurAjax==nombreInputForProduit)
			{
				
						if(id_product == 14 || id_product == 13 || id_product == 10)
						{
							var temp1 = choice[choice.length-2];
							var temp2 = choice[choice.length-1];
							choice[choice.length-1] = temp1;
							choice[choice.length-2] = temp2;
						}
						
						var param = '';
						for(var i=0; i<choice.length;i++)
						{
							param+=choice[i];
							if(i != choice.length-1)
							{
								param+=',';
							}
						}
						
						$.ajax({
						   type: "POST",
						   url: "/tools/ajax/checkCombi.php",
						   data: "combi="+param+"&produit="+id_product,
						   success: function(msg){
							   
							   if(msg != 'dipin' && msg != 'dipin;')
							   {
								   try{
										eval(msg);
								   }
								   catch(error)
								   {
										//alert('probleme'); 
								   }
								   if(typeof(objCombi) != "undefined"){
								   	retourVerifCombiNQ(true,objCombi);
								   }
							   }
							   else
							   {
									retourVerifCombiNQ(false,'');
							   }
							  
						   }
						 });
			}
	
}


//ma function prend en param une ligne de la base de donnée qui correspond  a la combi select par l'utilisateur
function retourVerifCombiNQ(combiTrouve,contenu)
{
	
	if(combiTrouve)
	{
		
		
		
		selectedCombination['unavailable'] = false;
		selectedCombination['reference'] = contenu.reference;
		$('#idCombination').val(contenu.id_product_attribute);
		quantityAvailable == parseInt(contenu.quantity);
		selectedCombination['price'] = parseFloat(contenu.price);
		if (contenu.ecotax)
					selectedCombination['ecotax'] = contenu.ecotax;
				else
					selectedCombination['ecotax'] = default_eco_tax;
		
		updateDisplay();
		
		
		
		gestionCommandeMin(parseFloat(contenu.price));
	}
	else
	{
		
		selectedCombination['unavailable'] = true;
		updateDisplay();	
	}

}



function gestionCommandeMin(price){
	
	var quantity;
	if($('#quantitReel').length) {
		quantity = parseInt($('#quantitReel').attr('value'));
	}
	else {
		quantity = parseInt($('#quantity_wanted').attr('value'));
	}
	
	price *=quantity;
	
	$("#commande_min_decoupe").css("display", "none");
	$("#ajoutPanier1").css("display", "block");
	$("#ajoutPanier2").css("display", "block");
	
	var panneau_select = $("#select_panneau_onchange option:selected").text();
	
	if(panneau_select == "MDF plaqué bois véritable" || panneau_select == "MDF laqué"){
		if(price < 71.43 && typeof(no_min_price) != "undefined" && no_min_price == 0){
			$("#commande_min_decoupe").css("display", "block");
			$("#ajoutPanier1").css("display", "none");
			$("#ajoutPanier2").css("display", "none");
		}
	}	
}


//**************************************SELECT*********************************************
//**************************************SELECT*********************************************
//**************************************SELECT*********************************************


function miseAjourSelect()
{
	
	var valeurSelect = '';
	var numSelect = '';
	
	var str_opt = '';
	$('div#attributes select').each(function(){
											 
		 str_opt+= $(this).val()+'#';
	});
	
	
	
	$.ajax({
	   type: "POST",
	   url: "/tools/ajax/configSelect.php",
	   data: "str_opt="+str_opt+"&produit="+id_product,
	   success: function(msg){
			
			eval(msg);
			
			if(typeof(largeur_min_val)!='undefined') {
				$("#largeur_min_val").html(largeur_min_val);
				$("#largeur_max_val").html(largeur_max_val);
			}
			if(typeof(hauteur_min_val)!='undefined') {
				$("#hauteur_min_val").html(hauteur_min_val);
				$("#hauteur_max_val").html(hauteur_max_val);
			}
			if(typeof(diametre_min_val)!='undefined') {
				$("#diametre_min_val").html(diametre_min_val);
				$("#diametre_max_val").html(diametre_max_val);
			}
			
			var tabSelec = responseConfigSelect.split('#');
			
			
			var selecteur = '';
			if(tabSelec[tabSelec.length-1] == 1)
			{
				
				$('#select_traitement_options > div > span').each(function(){
					for(p = 0; p<(tabSelec.length-1);p++)
					{
						
						if($(this).html() == tabSelec[p])
						{
							$(this).parent("div").css('display','block');
							break;
						}
						else
						{
							$(this).parent("div").css('display','none');
						}
					}	
				});
				
				if(tabSelec.length-1==1) {
					// on selectionne la seule option disponible et on passe à l'étape suivante
					$('#select_traitement_options > div > span').each(function(){
						if($(this).html() == tabSelec[0]) {
							$(this).parent("div").trigger('click');
						}
					});
				}
				
			}
			else if (tabSelec[tabSelec.length-1] == 2) 
			{
				$('#select_epaisseur_options > div > span').each(function(){
					for(p = 0; p<(tabSelec.length-1);p++)
					{
						
						if($(this).html() == tabSelec[p]+'mm')
						{
							$(this).parent("div").css('display','block');
							break;
						}
						else
						{
							$(this).parent("div").css('display','none');
						}
					}	
				});
				
				if(tabSelec.length-1==1) {
					// on selectionne la seule option disponible et on passe à l'étape suivante
					$('#select_epaisseur_options > div > span').each(function(){
						if($(this).html() == tabSelec[0]+'mm') {
							$(this).parent("div").trigger('click');
						}
					});
				}
				
			}
			
			
				
			
			
	   }
	 });
	 
	 
	 
	 
	
	
}


//mise a jourdes text et select si c'est laqué

function changementEnFctDuPanneau(){
	
	var panneau_select = $("#select_panneau_onchange option:selected").text();
	
	
	
	var control = false;
	if(panneau_select == "MDF laqué"){
		control = true;
		
		
		$("#indicationMela").css("display", "none");
		
		$("#etape_6").children("div").children(".titre_etape").html("Laquage des chants");
		$(".placage_chant").children("span.txt_champ1").html("Chants laqués : 1, 2, 3 ou 4 côtés");
		$(".placage_chant").children("span.txt_champ2").html("Sélectionner les côtés à laquer ...");	
		
		if(!$("#check2face").attr("checked")){
			$("#check1face_btn_contener").trigger("click");
		}
		
		selectionCouleurChampsAuto();
		
		
		$("#placageFaceContener").children("span.txt_14px_808080").html("Face à laquer");
		$("#placageFaceContener").children("span.txt_12px_808080").html("Sélectionner le nombre de face à laquer...");
		
		$("#placage_img_mela").css("display", "none");
		$("#placage_img_laque").css("display", "block");
		$("#detail_panneau_achat_nuancier").css("display", "block");
		
		
	}
	if(panneau_select == "MDF plaqué bois véritable"){
		control = true;
		$("#indicationMela").css("display", "none");
		
		$("#etape_6").children("div").children(".titre_etape").html("Placage des chants");
		$(".placage_chant").children("span.txt_champ1").html("Chants plaqués : 1, 2, 3 ou 4 côtés");
		$(".placage_chant").children("span.txt_champ2").html("Sélectionner les côtés à plaquer ...");
		
		if(!$("#check2face").attr("checked")){
			$("#check1face_btn_contener").trigger("click");
		}
		selectionCouleurChampsAuto();
		
		$("#placageFaceContener").children("span.txt_14px_808080").html("Face à plaquer");
		$("#placageFaceContener").children("span.txt_12px_808080").html("Sélectionner le nombre de face à plaquer...");
		
		$("#placage_img_mela").css("display", "block");
		$("#placage_img_laque").css("display", "none");
		
			$("#detail_panneau_achat_nuancier").css("display", "none");
		
		
		
	}
	
	if(!control){
		$("#indicationMela").css("display", "block");
		
		$("#etape_6").children("div").children(".titre_etape").html("Placage des chants");
		$(".placage_chant").children("span.txt_champ1").html("Chants plaqués : 1, 2, 3 ou 4 côtés");
		$(".placage_chant").children(".txt_champ2").html("Sélectionner les côtés à plaquer ...");
		
		$("#colorPlaquageChoix").css("display", "block");
		var tab=document.getElementById("group_24").options;
		for(var b=0;b<tab.length;b++)
		{
			if($(tab[b]).val() == 0)
			{
				tab[b].selected = 'selected';
			}
		}
		
		$("#placage_img_mela").css("display", "block");
		$("#placage_img_laque").css("display", "none");
		$("#detail_panneau_achat_nuancier").css("display", "none");
		
	}
	
}



function selectionCouleurChampsAuto(){
		var couleur_panneau_text = $("#group_7 option:selected").text();
		var couleur_panneau_val = $("#group_7 option:selected").val();
		$("#colorPlaquageChoix").css("display", "none");
		if(couleur_panneau_val != 0){
			
			var tab=document.getElementById("group_16").options;
			for(var b=0;b<tab.length;b++)
			{
				if($(tab[b]).text() == couleur_panneau_text)
				{
					tab[b].selected = 'selected';
				}
			}
			
		}else{
			var tab=document.getElementById("group_16").options;
			for(var b=0;b<tab.length;b++)
			{
				if($(tab[b]).text() == 0)
				{
					tab[b].selected = 'selected';
				}
			}
		}
}

function initAllSelectRetourAchat()
{
	
	
		var str_opt = '';
	$('div#attributes select').each(function(){
											 
		 str_opt+= $(this).val()+'#';
	});
	
	
	
	$.ajax({
	   type: "POST",
	   url: "/tools/ajax/configSelectRetourAchat.php",
	   data: "str_opt="+str_opt+"&produit="+id_product,
	   success: function(msg){
		  // alert(msg);
		   
		   var t_infos = msg.split('[#]');
		   
		   
			   $('#select_epaisseur_options > div > span').each(function(){
						var t_info_solo = t_infos[1].split('#');	
						
						for(p = 0; p<(t_info_solo.length);p++)
						{
							if(t_info_solo[p] != '')
							{
								if($(this).html() == t_info_solo[p]+'mm')
								{
									$(this).parent("div").css('display','block');
									break;
								}
								else
								{
									$(this).parent("div").css('display','none');
								}
							}
						}	
					});
		   
		   
		   $('#select_traitement_options > div > span').each(function(){
					var t_info_solo = t_infos[0].split('#');
					
					for(p = 0; p<t_info_solo.length;p++)
					{
						if(t_info_solo[p] != '')
						{
							if($(this).html() == t_info_solo[p])
							{
								$(this).parent("div").css('display','block');
								break;
							}
							else
							{
								$(this).parent("div").css('display','none');
							}
						}
					}	
				});
			
	   }
	 });
}


function initSelect(numSelect)
{
	for(var i =2; i <=6 ; i++)
	{
		//if(i<=numSelect) {	
		if(i==numSelect && i!=4 && i!=6) {	
			$('#etape_'+i).addClass("etape_visible").removeClass("etape_hidden");
			
		}
		else if(i>numSelect){
			$('#etape_'+i).addClass("etape_hidden").removeClass("etape_visible");
			$('#infoRecap'+i).html('');
		}
	}
	
	
	for(var i =1; i <9; i++)
	{
		
		if(i>=numSelect)
		{	
			$('#infoRecap'+i).html('');
		}
	}
	
	
	if(numSelect<5){
		// on masque l'aper_u de la couleur
		document.getElementById('div_coloris_panneau_resume').style.display = 'none';
		document.getElementById('div_coloris_champs_resume').style.display = 'none';
	}
	
	
	var tabSelec = ['','select_traitement_onchange','select_epaisseur_onchange','group_7','group_8','group_16'];

	for(var y =numSelect-1; y <7 ; y++)
	{
		if(document.getElementById(tabSelec[y]))
		{
			var tab=document.getElementById(tabSelec[y]).options;
			for(var b=0;b<tab.length;b++)
			{
				if($(tab[b]).val() == 0)
				{
					tab[b].selected = 'selected';
				}
			}
		}
	}
	
	if(numSelect == 2)
	{
		$('#select_traitement_iconselect').html('Choisir le traitement');
		$('#select_epaisseur_iconselect').html('Choisir l\'epaisseur');
	}
	
	if(numSelect == 3)
	{
		$('#select_epaisseur_iconselect').html('Choisir l\'epaisseur');
		
		
	}
	
	if(numSelect == 4)
	{
		$('#nomCouleur').html('');
		$('#apercu_couleur_planche').attr('src','/themes/prestashop/img/decors/small/empty.png');
	}
	
	if(numSelect == 5)
	{
		/*$('#group_10').val(0);
		$('#group_9').val(0);*/
		$('#group_10').trigger('onblur');
		$('#group_9').trigger('onblur');
	
		var temp = 'type_panneau=';
		var tab=document.getElementById('select_panneau_onchange').options;
		for(var b=0;b<tab.length;b++)
		{
			if(tab[b].selected == true)
			{
				temp += $(tab[b]).html();
			}
		}
		temp+='&type_traitement=';
		var tab=document.getElementById('select_traitement_onchange').options;
		for(var b=0;b<tab.length;b++)
		{
			if(tab[b].selected == true)
			{
				temp += $(tab[b]).html();
			}
		}
		temp+='&epaisseur=';
		var tab=document.getElementById('select_epaisseur_onchange').options;
		for(var b=0;b<tab.length;b++)
		{
			if(tab[b].selected == true)
			{
				temp += $(tab[b]).html();
			}
		}
		
		$.ajax({
	   type: "POST",
	   url: "/tools/ajax/champPossible.php",
	   data: temp,
	   success: function(msg){
			if(msg == 'non')
			{
				$('#etape_6').addClass("etape_hidden").removeClass("etape_visible");
			}
			else
			{
				$('#etape_6').addClass("etape_visible").removeClass("etape_hidden");
			}
		 }
	   });
	}
	
	if(numSelect == 6)
	{
		$('#check1').attr('checked',false);
		$('#check2').attr('checked',false);
		$('#check3').attr('checked',false);
		$('#check4').attr('checked',false);
		
		$('#check1_btn').css('display','none') ;
		$('#check2_btn').css('display','none');
		$('#check3_btn').css('display','none');
		$('#check4_btn').css('display','none');
		
		$('#nomCouleurChamps').html('');
		$('#apercu_couleur_champs').attr('src','/themes/prestashop/img/decors/small/empty.png');
		
		
		var temp = 'type_panneau=';
		var tab=document.getElementById('select_panneau_onchange').options;
		for(var b=0;b<tab.length;b++)
		{
			if(tab[b].selected == true)
			{
				temp += $(tab[b]).html();
			}
		}
		temp+='&type_traitement=';
		var tab=document.getElementById('select_traitement_onchange').options;
		for(var b=0;b<tab.length;b++)
		{
			if(tab[b].selected == true)
			{
				temp += $(tab[b]).html();
			}
		}
		temp+='&epaisseur=';
		var tab=document.getElementById('select_epaisseur_onchange').options;
		for(var b=0;b<tab.length;b++)
		{
			if(tab[b].selected == true)
			{
				temp += $(tab[b]).html();
			}
		}
		
		$.ajax({
	   type: "POST",
	   url: "/tools/ajax/champPossible.php",
	   data: temp,
	   success: function(msg){
			if(msg == 'non')
			{
				$('#etape_6').addClass("etape_hidden").removeClass("etape_visible");
			}
			else
			{
				$('#etape_6').addClass("etape_visible").removeClass("etape_hidden");
			}
		 }
	   });
	}
}





 
 function isNumeric(sText)
 {
		var ValidChars = "0123456789";
		var IsNumber=true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++)
		{
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1)
			{
				IsNumber = false;
			}
		}
		return IsNumber;
 } 

 
 

 
 
 function miseAjourLinkBox(idLinkBox, selectType1, selectType2, selectType3)
 {
	
	 if($(selectType1).val() != 0 && $(selectType2).val() != 0 && $(selectType3).val() != 0)
	 {
		
	 	document.getElementById(idLinkBox).onclick = function(){showBox('http://www.woodeos.com/lightbox_nuancier_light.php','panneau='+$(selectType1).val()+'&traitement='+$(selectType2).val()+'&epaisseur='+$(selectType3).val(),400,700)};
		
		document.getElementById("couleur_champs_link").onclick = function(){showBox('http://www.woodeos.com/lightbox_nuancier_light_champs.php','panneau='+$(selectType1).val()+'&traitement='+$(selectType2).val()+'&epaisseur='+$(selectType3).val(),400,700)};
		
		voirSiPlusDuneCouleur('panneau='+$(selectType1).val()+'&traitement='+$(selectType2).val()+'&epaisseur='+$(selectType3).val());
		
		
		checkIsFacePlaquer('panneau='+$(selectType1).val()+'&traitement='+$(selectType2).val()+'&epaisseur='+$(selectType3).val());
	 }
	 else
	 {
		// document.getElementById(idLinkBox).title = '';
		 document.getElementById(idLinkBox).onclick = function(){showBox('http://www.woodeos.com/lightbox_nuancier_light.php','',400,700)};
	 }
 }
 
 
 
 function checkIsFacePlaquer(param){
	 
	 $.ajax({
	   type: "POST",
	   url: "/tools/ajax/isPossiblePlaquageFace.php",
	   data: param,
	   success: function(msg){
			if(msg == "oui"){
				$("#placageFaceContener").css("display", "block");
			}else{
				$("#placageFaceContener").css("display", "none");
				
				var tab=$('#group_24').attr('options');
				for(var b=0;b<tab.length;b++)
				{
					
					if($(tab[b]).html() == 0)
					{
						tab[b].selected = 'selected';
					}
				}
				$("#group_24").trigger('onchange');
			}
		 }
	   });
	   
 }
 
//**************************************COULEUR*********************************************
//**************************************COULEUR*********************************************
//**************************************COULEUR*********************************************

function voirSiPlusDuneCouleur(param)
{
	$.ajax({
	   type: "POST",
	   url: "/tools/ajax/gestionCouleur.php",
	   data: param,
	   success: function(msg){
			var tabInfo = msg.split('#');
			
			// si on a qu'une seule couleur on la sélectionne et on désactive l'option
			if(tabInfo.length>1){
				chooseColor(tabInfo[0],tabInfo[2]);
				$('#etape_4').addClass("etape_hidden").removeClass("etape_visible");
				$('#infoRecap4').html('');
			}
			else {
				$('#etape_4').addClass("etape_visible").removeClass("etape_hidden");
			}
		 }
	   });
}




function chooseColor(nom,new_image_source)
{

	var tab= $('#group_7').attr('options');
	
		var selection_ok = false;
		for(var b=0;b<tab.length;b++)
		{
			if($(tab[b]).html() == nom)
			{
				selection_ok = true;
				tab[b].selected = 'selected';
				
				$('#apercu_couleur_planche').attr('src',new_image_source);
				$('#coloris_panneau_resume').attr('src',new_image_source.replace(/small/,'resume'));
				
				var t_nom_couleur_temp = nom.split(' - ');
				
				// si une couleur avec un code alors on affiche dans le résumé
				if(t_nom_couleur_temp.length>1) {
					$('#texte_coloris_panneau_resume').attr('innerHTML',nom);
					$('#div_coloris_panneau_resume').css('display','block');
				}
				else {
					$('#div_coloris_panneau_resume').css('display','none');
				}
				
				
				$('#nomCouleur').attr('innerHTML',nom);
			}
		}
		
		if(!selection_ok){
			$('#div_coloris_panneau_resume').css('display','none');
		}
		
		$("#group_7").trigger('onchange');
	
	// on masque l'aperçu des couleurs
	window.setTimeout("$('.qtip-active').hide();",500);
	
	changeColorMeuble(nom);
	
	

}

function chooseColor2(nom,new_image_source)
{
	
	var selection_ok = false;
	var tab=document.getElementById('group_16').options;
	for(var b=0;b<tab.length;b++)
	{
		if($(tab[b]).html() == nom)
		{
			selection_ok = true;
			tab[b].selected = 'selected';
			$('#apercu_couleur_champs').attr('src',new_image_source);
			$('#coloris_champs_resume').attr('src',new_image_source.replace(/small/,'resume'));
			
			$('#nomCouleurChamps').html(nom);
			$('#texte_coloris_champs_resume').html(nom);
			$('#div_coloris_champs_resume').css('display','block');
		}
	}

	if(!selection_ok){
		$('#div_coloris_champs_resume').css('display','none');
	}

	// on masque l'aperçu des couleurs
	window.setTimeout("$('.qtip-active').hide();",500);
	
	$("#group_16").trigger('onchange');

}



//**************************************CHECKBOX*********************************************
//**************************************CHECKBOX*********************************************
//**************************************CHECKBOX*********************************************


$(document).ready(function(){
	
	var val = "";
		var tab=$('#group_24').attr('options');
		if(typeof(tab) == "undefined"){
			return;
		}
		
		for(var b=0;b<tab.length;b++)
		{
			
			if($(tab[b]).val() == $('#group_24').val())
			{
				val = $(tab[b]).html();
			}
		}
		
		if(val == 1){
			$("#check2face_btn").css("display", "none");
			$("#check2face").attr("checked", false);
			$("#check1face_btn").css("display", "block");
			$("#check1face").attr("checked", true);
		}
		if(val == 2){
			$("#check2face_btn").css("display", "block");
			$("#check2face").attr("checked", true);
			$("#check1face_btn").css("display", "none");
			$("#check1face").attr("checked", false);
		}
		
		
	
});

function affectCheckboxTraitementFace(element){
		
		
		$(element).children(".bg_btn_checkbox2").children(".btn_checkbox").css("display", "block");
		$(element).children(".bg_btn_checkbox2").children("input").attr("checked", true);
		
		
		if($(element).attr("id") == "check1face_btn_contener"){
			$("#check2face_btn").css("display", "none");
			$("#check2face").attr("checked", false);
		}else{
			$("#check1face_btn").css("display", "none");
			$("#check1face").attr("checked", false);
		}
		
		var val = 0;
		if($('#check1face').attr('checked') == true)
		{
			val = 1;
		}
	
		if($('#check2face').attr('checked') == true)
		{
				val = 2;
		}
		
		var tab=$('#group_24').attr('options');
		for(var b=0;b<tab.length;b++)
		{
			
			if($(tab[b]).html() == val)
			{
				tab[b].selected = 'selected';
			}
		}
		$("#group_24").trigger('onchange');
		if($("#apercu_couleur_champs").attr("src").indexOf("empty.png") > 0 ){
			window.setTimeout("chooseColor2($('#nomCouleur').html(),$('#apercu_couleur_planche').attr('src'))",300);
		}
}



function affectCheckboxOuiNon(valeur)
{
	var do_not_trigger = false;
	var val = '';
	
		if($('#checkOui').attr('checked') == false)
		{
			val = 'oui';
		}
		

		if($('#checkOui').attr('checked') == true)
		{
			val = 'non';
			
		}
	
	
	if(val != '')
	{
		var tab=$('#group_8').attr('options');
		for(var b=0;b<tab.length;b++)
		{
			if(val != 'non')
			{
				if($(tab[b]).html() == val)
				{
					tab[b].selected = 'selected';
				}
				
				if($('#nomCouleurChamps').html()=='') {
					do_not_trigger = true;
					window.setTimeout("chooseColor2($('#nomCouleur').html(),$('#apercu_couleur_planche').attr('src'))",300);
				}
			}
			else
			{
				$('#div_coloris_champs_resume').css('display','none');
				$('#apercu_couleur_champs').attr('src', '/themes/prestashop/img/decors/small/empty.png'); 
				$('#coloris_champs_resume').attr('src', '');
				$('#nomCouleurChamps').html('');
				$('#texte_coloris_champs_resume').html('');
				
				if($(tab[b]).val() == 0)
				{
					tab[b].selected = 'selected';
					$('#nomCouleurChamps').html('');
					var tab=$('#group_16').attr('options');
					for(var b=0;b<tab.length;b++)
					{
						if($(tab[b]).val() == 0)
						{
							tab[b].selected = 'selected';
						}
					}
				}
			}
		}	
	}
	
	if(!do_not_trigger) {
		$("#group_8").trigger('onchange');
	}
}

function affectCheckbox()
{
	var compteurL = 0;
	var do_not_trigger = false;
	
	if($('#check1').attr('checked') == true)
	{
		compteurL++;
	}
	if($('#check4').attr('checked') == true)
	{
		compteurL++;
	}
	
	var compteurl = 0;
	if($('#check2').attr('checked') == true)
	{
		compteurl++;
	}
	if($('#check3').attr('checked') == true)
	{
		compteurl++;
	}
	
	if(compteurl == 0 && compteurL == 0)
	{
		
		var tab=$('#group_8').attr('options');
		for(var b=0;b<tab.length;b++)
		{
			if($(tab[b]).val() == 0)
			{
				tab[b].selected = 'selected';
			}
		}
		
		var tab=$('#group_16').attr('options');
		for(var b=0;b<tab.length;b++)
		{
			if($(tab[b]).val() == 0)
			{
				tab[b].selected = 'selected';
				$('#div_coloris_champs_resume').css('display','none');
				
				$('#apercu_couleur_champs').attr('src','/themes/prestashop/img/decors/small/empty.png');
				$('#coloris_champs_resume').attr('src','');
				
				$('#nomCouleurChamps').html('');
				$('#texte_coloris_champs_resume').html('');
			}
		}
	}
	
	var reponse = '';
	if(compteurl == 1 && compteurL == 0)
	{
		reponse ='l';
	}
	else if(compteurl == 2 && compteurL == 0)
	{
		reponse ='2l';
	}
	else if(compteurl == 0 && compteurL == 1)
	{
		reponse ='L';
	}
	else if(compteurl == 0 && compteurL == 2)
	{
		reponse ='2L';
	}
	else if(compteurl == 1 && compteurL == 1)
	{
		reponse ='lL';
	}
	else if(compteurl == 2 && compteurL == 1)
	{
		reponse ='2lL';
	}
	else if(compteurl == 1 && compteurL == 2)
	{
		reponse ='2Ll';
	}
	else if(compteurl == 2 && compteurL == 2)
	{
		reponse ='2L2l';
	}
	
	
	if(reponse != '')
	{
		var tab=$('#group_8').attr('options');
		
		for(var b=0;b<tab.length;b++)
		{
			
			if($(tab[b]).html() == reponse)
			{
				tab[b].selected = 'selected';
			}
		}
		if($('#nomCouleurChamps').html()=='') {
			do_not_trigger = true;
			window.setTimeout("chooseColor2($('#nomCouleur').html(),$('#apercu_couleur_planche').attr('src'))",300);
		}
		
	}
	
	if(!do_not_trigger) {
		$('#group_8').trigger('onchange');
	}
	
}


function ecrireRecap(selectElement,ID_info_recap,type)
{
	
	if(type == 1)
	{
		
		var tab= selectElement.options;
		for(var b=0;b<tab.length;b++)
		{
			if(tab[b].selected == true)
			{
				$('#'+ID_info_recap).html($(tab[b]).html());
			}
		}
	}
	
	if(type == 2)
	{
		var tab=selectElement.options;
		for(var b=0;b<tab.length;b++)
		{
			if(tab[b].selected == true)
			{
				
				var result = 0;
				if($(tab[b]).html() =='l' || $(tab[b]).html() =='L')
				{
					result = 1 ;
				}
				else if($(tab[b]).html() =='2L' || $(tab[b]).html() =='lL' || $(tab[b]).html() =='2l')
				{
					result = 2 ;
				}
				else if($(tab[b]).html() =='2lL' || $(tab[b]).html() =='2Ll')
				{
					result = 3 ;
				}
				else if($(tab[b]).html() =='2L2l')
				{
					result = 4 ;
				}
				
				$('#'+ID_info_recap).html(result);
			}
		}
	}
	
	if(type == 3)
	{
		$('#'+ID_info_recap).html(selectElement.value);
	}

	window.setTimeout(function(){	changementEnFctDuPanneau();}, 2000);
	window.setTimeout(function(){findCombinationNQ(prod_id_for_productJS,nbr_input_for_productJS);}, 3000);
}





 










//**************************************MEUBLE*********************************************
//**************************************MEUBLE*********************************************
//**************************************MEUBLE*********************************************


function initFlashMeuble(id_pro)
{	
	
	if(id_pro == 15)
	{
		swfobject.embedSWF("/swf/meubleEta.swf", "flashDecouverte", "605", "515", "9.0.0","expressInstall.swf", {}, {wmode:"transparent", quality:"high"}, {id:"flashMeuble3D"});
	}
	else if(id_pro == 18)
	{
		swfobject.embedSWF("/swf/meuble1Porte.swf", "flashDecouverte", "605", "515", "9.0.0","expressInstall.swf", {}, {wmode:"transparent", quality:"high"}, {id:"flashMeuble3D"});
	}
	else
	{
		swfobject.embedSWF("/swf/meuble2Porte.swf", "flashDecouverte", "605", "515", "9.0.0","expressInstall.swf", {}, {wmode:"transparent", quality:"high"}, {id:"flashMeuble3D"});
	}
		
	
}


function initFlashMeubleConf(hauteur,largeur,profondeur,etagere,id_pro)
{	
	
	if(id_pro == 15)
	{
		swfobject.embedSWF("/swf/meubleEta.swf?hauteur="+hauteur+"&largeur="+largeur+"&profondeur="+profondeur+"&etagere="+etagere, "flashDecouverte", "605", "515", "9.0.0","expressInstall.swf", {}, {wmode:"transparent", quality:"high"}, {id:"flashMeuble3D"});
	}
	else if(id_pro == 18)
	{
		swfobject.embedSWF("/swf/meuble1Porte.swf?hauteur="+hauteur+"&largeur="+largeur+"&profondeur="+profondeur+"&etagere="+etagere, "flashDecouverte", "605", "515", "9.0.0","expressInstall.swf", {}, {wmode:"transparent", quality:"high"}, {id:"flashMeuble3D"});
	}
	else
	{
		swfobject.embedSWF("/swf/meuble2Porte.swf?hauteur="+hauteur+"&largeur="+largeur+"&profondeur="+profondeur+"&etagere="+etagere, "flashDecouverte", "605", "515", "9.0.0","expressInstall.swf", {}, {wmode:"transparent", quality:"high"}, {id:"flashMeuble3D"});
	}
		
	
}




 function changeDimMeuble( value ) 
 {
	
	if(document.getElementById("flashMeuble3D")){
		if(typeof(document.getElementById("flashMeuble3D").updateMeuble)=='undefined') {
			window.setTimeout('document.getElementById("flashMeuble3D").updateMeuble('+value+');',1000);
		}
		else {
			document.getElementById("flashMeuble3D").updateMeuble(value);
		}
	}
 } 
 
 
function changeEtaMeuble(value)
{
	if(value == '' || value > 8 || value <0)
	{
		value = 1 ;
	}
	
	if(document.getElementById("flashMeuble3D")){
		 if(typeof(document.getElementById("flashMeuble3D").updateMeubleEta)=='undefined') {
			window.setTimeout('document.getElementById("flashMeuble3D").updateMeubleEta('+value+');',1000);
		}
		else {
			document.getElementById("flashMeuble3D").updateMeubleEta(value);
		}
	}
}
 
 function reInitMeuble()
 {
	

	var value = varReInit;
	if(document.getElementById("flashMeuble3D")){
		 if(typeof(document.getElementById("flashMeuble3D").initMeuble)=='undefined') {
			window.setTimeout('document.getElementById("flashMeuble3D").initMeuble('+value+');',1000);
		}
		else {
			document.getElementById("flashMeuble3D").initMeuble(value);
		}
	} 
 }
 
 
 function gestionPlinthe(value)
 {
	
	if(document.getElementById("flashMeuble3D")){
		 if(typeof(document.getElementById("flashMeuble3D").misePlinthe)=='undefined') {
			
			window.setTimeout('document.getElementById("flashMeuble3D").misePlinthe("'+value+'");',1000);
		}
		else {
			
			document.getElementById("flashMeuble3D").misePlinthe(value);
		}
	}
	
	if(value=='oui') {
		alert("Information : \n\nEn ajoutant un piétement de plinthe, votre meuble sera réhaussé de 10cm.");
	}
	
 }
 
 function gestionBarre(value)
 {
	
	if(document.getElementById("flashMeuble3D")){
		 if(typeof(document.getElementById("flashMeuble3D").miseBarre)=='undefined') {
			window.setTimeout('document.getElementById("flashMeuble3D").miseBarre('+value+');',1000);
		}
		else {
			document.getElementById("flashMeuble3D").miseBarre(value);
		}
	}  
 }
 
 function changeColorMeuble(value)
 {
	
	if(document.getElementById("flashMeuble3D")){
		 if(typeof(document.getElementById("flashMeuble3D").initTextu)=='undefined') {
			window.setTimeout('document.getElementById("flashMeuble3D").initTextu("'+value+'");',1000);
		}
		else {
			document.getElementById("flashMeuble3D").initTextu(value);
		}
	}  
 }
 
 
 var compteurTextu = 0;
 function changeTextu()
 {
	 if(compteurTextu<3)
	 {
	 	compteurTextu++;
	 }
	 else
	 {
		 compteurTextu = 0;
	 }
	
	if(document.getElementById("flashMeuble3D")){
		 if(typeof(document.getElementById("flashMeuble3D").initTextu)=='undefined') {
			window.setTimeout('document.getElementById("flashMeuble3D").initTextu('+compteurTextu+');',1000);
		}
		else {
			document.getElementById("flashMeuble3D").initTextu(compteurTextu);
		}
	} 
 }
 
 function verifTailleMax(valeur,max_valu,nameChamp, element)
 {
	 var control = true;
		if(valeur > max_valu || valeur < 0)
		{
			alert('La '+nameChamp+' maximum a été atteinte ( Valeur compris entre 0 et '+max_valu+')');
			element.value = max_valu;
			control = false;
		}
		
		if(control)
		{
			if(!isNumeric(valeur))
			{
				alert('La valeur doit être une valeur entère (sans virgule)');
				element.value = Math.ceil(valeur);
			}
		}
 }
 
 
	function verifTaille(valeur,min_valu,max_valu,nameChamp, element) {
		var control = true;
		if(valeur > max_valu || valeur < min_valu) {
			if(valeur!='') {
				if(element.name=='id_8'){
					alert('Le nombre d\'étagère doit être compris entre '+min_valu+' et '+max_valu+'.');
				}
				else {
					alert('La '+nameChamp+' doit être comprise entre '+min_valu+'cm et '+max_valu+'cm.');
				}
			}
			control = false;
		}
		
		if(control)
		{
			element.value = Math.round(valeur*10)/10;
		}
		
		return control;
 }
 
 
 function changeValueInput(id_el,type,maxi)
 {
	 //alert('coucou '+type+' valu '+document.getElementById(id_el).value);
	 if(type=='up')
	 {
		 if(document.getElementById(id_el).value < maxi )
		 {
			 var new_value = parseInt(document.getElementById(id_el).value);
			 new_value++;
			document.getElementById(id_el).value = new_value;
		 }
	}
	else
	{
		if(document.getElementById(id_el).value > 0 )
		 {
			 var new_value = parseInt(document.getElementById(id_el).value);
			 new_value--;
			document.getElementById(id_el).value = new_value;
		 }
	}
 }
 
 function changeSelectProf(valu,selectC)
 {
	   var tab=document.getElementById(selectC).options;
		for(var b=0;b<tab.length;b++)
		{
			if($(tab[b]).html() == valu)
			{
				tab[b].selected = 'selected';
			}
		}
 }
 
 function changeSelectPietement(radio,selectC)
 {
	
	 var valu = 'oui';
	 if(radio.checked == false)
	 {
		 valu = 'non';
	 }
	 var tab=document.getElementById(selectC).options;
		for(var b=0;b<tab.length;b++)
		{
			if($(tab[b]).html() == valu)
			{
				tab[b].selected = 'selected';
			}
		}
		
	 $('#'+selectC).trigger('onchange');
	 
	 if(radio.id == 'btn_radio_pietement')
	 {
		 gestionPlinthe(valu);
	 }
	 
	 if(radio.id == 'btn_radio_penderie')
	 {
		 gestionBarre(valu);
	 }
 }
 
 





//------------------------------------------------------------------------------

function upQuantity(elementMoteur, elementFake, elementFake2)
{
	var quant = 	elementFake.value;
	elementMoteur.value = parseInt(quant)+1;
	elementFake.value = parseInt(quant)+1;
	elementFake2.value = parseInt(quant)+1;
	
	updateDisplay();
}

function downQuantity(elementMoteur, elementFake, elementFake2)
{
	var quant = elementFake.value;
	if(quant > 0)
	{
		elementMoteur.value = parseInt(quant)-1;
		elementFake.value = parseInt(quant)-1;
		elementFake2.value= parseInt(quant)-1;
	}
	
	updateDisplay();
}


var nq_timeout=null;

function keyEventManager(e, element) {
	var event = e || window.event;
	
	if(nq_timeout) {
		window.clearTimeout(nq_timeout);
	}
	
	var key = window.event ? e.keyCode : e.which;
	if(key==13) {
		if (event.stopPropagation) {
			event.stopPropagation();
		} else {
			event.cancelBubble = true;
		} 
		
		element.blur();
		return false;
	}
	else {
		var temp = element.value;
		if(temp) {
			element.value = temp.replace(/,/,".");
		}
		nq_timeout = window.setTimeout('document.getElementById("'+element.id+'").blur();document.getElementById("'+element.id+'").focus();',800);
	}
}
/**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************NEWQUEST FONCTION ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
















function updateColorSelect(id_attribute)
{
	if (id_attribute == 0)
	{
		refreshProductImages(0);
		return ;
	}
	// Visual effect
	$('#color_'+id_attribute).fadeTo('fast', 1, function(){	$(this).fadeTo('slow', 0, function(){ $(this).fadeTo('slow', 1, function(){}); }); });
	// Attribute selection
	$('#group_'+id_color_default+' option[value='+id_attribute+']').attr('selected', 'selected');
	$('#group_'+id_color_default+' option[value!='+id_attribute+']').removeAttr('selected');
	findCombination();
}

//update display of the availability of the product AND the prices of the product
function updateDisplay()
{
	if (!selectedCombination['unavailable'] && quantityAvailable > 0)
	{
		//show the choice of quantities
		$('#quantity_wanted_p:hidden').show('slow');
		
		//show the "add to cart" button ONLY if it was hidden
		$('#add_to_cart:hidden').fadeIn(600);
		$('#fakeAjoutPanier:hidden').fadeIn(600);
		$('#fake_bouton_commande:hidden').fadeIn(600);
		
		
		//hide the hook out of stock
		$('#oosHook').hide();
		
		//availability value management
		if (availableNowValue != '')
		{
			//update the availability statut of the product
			$('#availability_value').removeClass('warning-inline');
			$('#availability_value').html(availableNowValue);
			$('#availability_statut:hidden').show();
		}
		else
		{
			//hide the availability value
			$('#availability_statut:visible').hide();
		}
		
		//'last quantities' message management
		if (quantityAvailable <= maxQuantityToAllowDisplayOfLastQuantityMessage && !allowBuyWhenOutOfStock)
		{
			//display the 'last quantities' message
			$('#last_quantities').show('slow');
		}
		else
		{
			//hide the 'last quantities' message
			$('#last_quantities').hide('slow');
		}
	
		//display the quantities of pieces (only if allowed)
		if (quantitiesDisplayAllowed)
		{
			$('#pQuantityAvailable:hidden').show('slow');
			$('#quantityAvailable').text(quantityAvailable); 
			if(quantityAvailable < 2)
			{
				$('#quantityAvailableTxt').show();
				$('#quantityAvailableTxtMultiple').hide();
			}
			else
			{
				$('#quantityAvailableTxt').hide();
				$('#quantityAvailableTxtMultiple').show();
			}
		}
	}
	else
	{
		//show the hook out of stock
		$('#oosHook').show();
		if ($('#oosHook').length > 0 && function_exists('oosHookJsCode'))
			oosHookJsCode();
		
		//hide 'last quantities' message if it was previously visible
		$('#last_quantities:visible').hide('slow');

		//hide the quantity of pieces if it was previously visible
		$('#pQuantityAvailable:visible').hide('slow');
		
		//hide the choice of quantities
		if (!allowBuyWhenOutOfStock)
			$('#quantity_wanted_p:visible').hide('slow');
		
		//display that the product is unavailable with theses attributes
		if (!selectedCombination['unavailable'])
			$('#availability_value').text(doesntExistNoMore + (globalQuantity > 0 ? ' ' + doesntExistNoMoreBut : '')).addClass('warning-inline');
		else
			$('#availability_value').text(doesntExist).addClass('warning-inline');
		$('#availability_statut:hidden').show();

		
		//show the 'add to cart' button ONLY IF it's possible to buy when out of stock AND if it was previously invisible
		if (allowBuyWhenOutOfStock && !selectedCombination['unavailable'])
		{
			$('#add_to_cart:hidden').fadeIn(600);
			$('#fakeAjoutPanier:hidden').fadeIn(600);
			$('#fake_bouton_commande:hidden').fadeIn(600);
			if (availableLaterValue != '')
			{
				$('#availability_value').html(availableLaterValue);
				$('p#availability_statut:hidden').show('slow');
			}
			else
				$('p#availability_statut:visible').hide('slow');			
		}
		else
		{
			$('#add_to_cart:visible').fadeOut(600);
			$('#fakeAjoutPanier:visible').fadeOut(600);
			$('#fake_bouton_commande:visible').fadeOut(600);
			$('p#availability_statut:hidden').show('slow');
		}
	}
	
	//update display of the the prices in relation to tax, discount, ecotax, and currency criteria
	if (!selectedCombination['unavailable'])
	{
		var attribut_price_tmp = selectedCombination['price'];

		var tax = noTaxForThisProduct ? 1 : ((taxRate / 100) + 1);

		if (noTaxForThisProduct)
			attribut_price_tmp /= tax;

		if (selectedCombination['reference'])
		{
			$('#product_reference span').text(selectedCombination['reference']);
			$('#product_reference:hidden').show();
		}
		else
			$('#product_reference:visible').hide('slow');

		var productPriceWithoutReduction2 = (attribut_price_tmp + productPriceWithoutReduction) * currencyRate;
		
		if (reduction_from != reduction_to && (currentDate > reduction_to || currentDate < reduction_from))
			var priceReduct = 0;
		else
			var priceReduct = productPriceWithoutReduction2 / 100 * parseFloat(reduction_percent) + (reduction_price * currencyRate);
		var priceProduct = productPriceWithoutReduction2 - priceReduct;
		var productPricePretaxed = (productPriceWithoutReduction2 - priceReduct) / tax;

		if (displayPrice == 1)
		{
			priceProduct = productPricePretaxed;
			productPriceWithoutReduction2 /= tax;
		}

		if (group_reduction)
			priceProduct *= group_reduction;
		
		if($('#quantitReel').length) {
			var quantity = parseInt($('#quantitReel').attr('value'));
		}
		else {
			var quantity = parseInt($('#quantity_wanted').attr('value'));
		}
		
		$('#our_price_display').text(formatCurrency(priceProduct*quantity, currencyFormat, currencySign, currencyBlank));
		$('#our_price_display2').text(formatCurrency(priceProduct*quantity, currencyFormat, currencySign, currencyBlank));
		$('#pretaxe_price_display').text(formatCurrency(productPricePretaxed*quantity, currencyFormat, currencySign, currencyBlank));
		$('#old_price_display').text(formatCurrency(productPriceWithoutReduction2*quantity, currencyFormat, currencySign, currencyBlank));
		$('#ecotax_price_display').text(formatCurrency(selectedCombination['ecotax']*quantity, currencyFormat, currencySign, currencyBlank));
		
		gestionCommandeMin(parseFloat(priceProduct));
	}
}

//update display of the large image
function displayImage(domAAroundImgThumb)
{
    if (domAAroundImgThumb.attr('href'))
    {
        var newSrc = domAAroundImgThumb.attr('href').replace('thickbox','large');
        if ($('#bigpic').attr('src') != newSrc)
		{ 
            $('#bigpic').fadeOut('fast', function(){
                $(this).attr('src', newSrc).show();
                if (typeof(jqZoomEnabled) != 'undefined' && jqZoomEnabled)
	                $(this).attr('alt', domAAroundImgThumb.attr('href'));
            });
        }
        $('#views_block li a').removeClass('shown');
        $(domAAroundImgThumb).addClass('shown');
    }
}

// Serialscroll exclude option bug ?
function serialScrollFixLock(event, targeted, scrolled, items, position)
{
	serialScrollNbImages = $('#thumbs_list li:visible').length;
	serialScrollNbImagesDisplayed = 3;
	
	var leftArrow = position == 0 ? true : false;
	var rightArrow = position + serialScrollNbImagesDisplayed >= serialScrollNbImages ? true : false;
	
	$('a#view_scroll_left').css('cursor', leftArrow ? 'default' : 'pointer').css('display', leftArrow ? 'none' : 'block').fadeTo(0, leftArrow ? 0 : 1);		
	$('a#view_scroll_right').css('cursor', rightArrow ? 'default' : 'pointer').fadeTo(0, rightArrow ? 0 : 1).css('display', rightArrow ? 'none' : 'block');
	return true;
}

// Change the current product images regarding the combination selected
function refreshProductImages(id_product_attribute)
{
	$('#thumbs_list_frame').scrollTo('li:eq(0)', 700, {axis:'x'});
	$('#thumbs_list li').hide();
	id_product_attribute = parseInt(id_product_attribute);

	if (typeof(combinationImages) != 'undefined' && typeof(combinationImages[id_product_attribute]) != 'undefined')
	{
		for (var i = 0; i < combinationImages[id_product_attribute].length; i++)
			$('#thumbnail_' + parseInt(combinationImages[id_product_attribute][i])).show();
	}
	$('#thumbs_list_frame').width((parseInt(($('#thumbs_list_frame >li').width())* i) + 3) + 'px'); //  Bug IE6, needs 3 pixels more ?
	$('#thumbs_list').trigger('goto', 0);
	serialScrollFixLock('', '', '', '', 0);// SerialScroll Bug on goto 0 ?
}

//To do after loading HTML
$(document).ready(function()
{
	//init the serialScroll for thumbs
	$('#thumbs_list').serialScroll({
		items:'li:visible',
		prev:'a#view_scroll_left',
		next:'a#view_scroll_right',
		axis:'x',
		offset:0,
		start:0,
		stop:true,
		onBefore:serialScrollFixLock,
		duration:700,
		step: 2,
		lazy: true,
		lock: false,
		force:false,
		cycle:false
	});
	
	$('#thumbs_list').trigger('goto', 1);// SerialScroll Bug on goto 0 ?
	$('#thumbs_list').trigger('goto', 0);

	//hover 'other views' images management
	$('#views_block li a').hover(
		function(){displayImage($(this));},
		function(){}
	);
	
	//set jqZoom parameters if needed
	if (typeof(jqZoomEnabled) != 'undefined' && jqZoomEnabled)
	{
		$('img.jqzoom').jqueryzoom({
			xzoom: 200, //zooming div default width(default width value is 200)
			yzoom: 200, //zooming div default width(default height value is 200)
			offset: 21 //zooming div default offset(default offset value is 10)
			//position: "right" //zooming div position(default position value is "right")
		});
	}

	//add a link on the span 'view full size' and on the big image
	$('span#view_full_size, div#image-block img').click(function(){
		$('#views_block li a.shown').click();
	});

	//catch the click on the "more infos" button at the top of the page
	$('div#short_description_block p a.button').click(function(){
		$('#more_info_tab_more_info').click();
		$.scrollTo( '#more_info_tabs', 1200 );
	});

	// Hide the customization submit button and display some message
	$('p#customizedDatas input').click(function() {
		$('p#customizedDatas input').hide();
		$('p#customizedDatas').append('<img src="' + img_ps_dir + 'loader.gif" alt="loader" /> ' + uploading_in_progress);
	});

	//init the price in relation of the selected attributes
	if (typeof productHasAttributes != 'undefined' && productHasAttributes)
		findCombination(true);

	//
	$('a#resetImages').click(function() {
		updateColorSelect(0);
	});
});

function saveCustomization()
{
	$('#quantityBackup').val($('#quantity_wanted').val());
	$('body select[@id^="group_"]').each(function() {
		$('#customizationForm').attr('action', $('#customizationForm').attr('action') + '&' + this.id + '=' + parseInt(this.value));
	});
	$('#customizationForm').submit();
}


function add_product() {
	if(!$('#etape_6').hasClass('etape_visible') || $('#check1').attr('checked')==true || $('#check2').attr('checked')==true || $('#check3').attr('checked')==true || $('#check4').attr('checked')==true || $('#checkOui').attr('checked')==true || confirm("Etes-vous sûr de ne pas vouloir plaquer les chants de votre découpe ?")) {
		$('#ajoutPanierReel').trigger('click');	
	}
}

