/**
 * product.js
 * Contient les methodes d'initialisation et de traitement des donnees contenues
 * dans les specs de la maquette WonderBra
 *    
 * 
 */
// variable pour la gestion de la valeur de l'image zoom de la parure
var onload_img_zoom = "" ;
var onload_img_zoomB = "" ;
var mono = "" ;
var last_height = "" ;

// variable pour l'option voir de dos
var onload_img_back_zoom = "";
var onload_img_back_zoom_HD = "";
var backVisualEnabled;


// Fonction d'initialisation au chargement de la page
// parametre 'ismono'  de type boolean 
// ismono == true : il s'agit d'une page MonoParure
// ismono == false : il s'agit d'une page BiParure
function loadInfo(ismono){
	// Declaration des variables
	var color_id = new Array();
	var product_id = new Array();
	var artDist = new Array();
	var artDist1 = new Array();
	var artsplit = new Array();
	var tabColorByProduct = new Array();
	var tabSizeStr = new Array();
	var tabIdColorByProduct = new Array();
	var tabIdSizeStr = new Array();
	var all_dispo = 0;
	mono = ismono;
	
	product_id = dis_color(tabProduct, '0');// recuperation id produit distinct.
	
	// parcours de la liste des produits 
	// remplissage et initialisation des composants de la page avec les donnees de chaque produit
	for (var i = 0; i < product_id.length; i++) {
		var tabColorStr = new Array();
		artDist[i] = findProduct(product_id[i]);// chercher pour cet id produit les articles associï¿½s.
		artDist1 = artDist[i];
		
		for (var k = 0; k < artDist1.length; k++) { // on boucle sur le tableau des articles trouvï¿½s
			artsplit = artDist1[k].toString().split(",");
			tabColorStr[k] = colorInfo(artsplit[1])[0][0]; // on cherche pour chaque articles les donnÃ©es associÃ©s
		}
		tabColorByProduct = dis_color(tabColorStr, '1'); // on charge les couleurs distincts
		tabIdColorByProduct = dis_color(tabColorStr, '2'); // on charge les id_couleurs distincts
		tabSizeStr = dis_color(tabColorStr, '3'); // on charge les taille distincts
		tabIdSizeStr = dis_color(tabColorStr, '4'); // on charge les id_taille distincts
		var listeArticleByProduct = new Array();
		listeArticleByProduct = findArticle(product_id[i]);
		
		var liste_non_dispo = new Array();
		var i_non_dispo = 0;
		var compt_dispo = 0;
		var default_color_id = 0;
		all_dispo = 0;    // variable pour verifier qu'aucune couleur n'est dispo
		
		for (var t = 0; t < tabColorByProduct.length; t++) {
			var dispo = 0;
			for (var cmpt = 0; cmpt < listeArticleByProduct.length; cmpt++) {
				if (tabColorByProduct[t] == listeArticleByProduct[cmpt][1]) 
					dispo += parseInt(dispoInfo(listeArticleByProduct[cmpt][0]));
			}
			var no_dispo = "";
			if (dispo == '0') {// si la couleur n'est pas dispo on stocke son indice "t" dans le tableau :"liste_non_dispo"
				no_dispo = " / non dispo";
				liste_non_dispo[i_non_dispo] = t;
				i_non_dispo++;
			}
			else {// si la couleur est dispo on l'implemente directement dans la listbox couleur : ça permet le tri couleur  dispo/non dispo
				if (document.getElementById("color" + product_id[i]) != null) 
					document.getElementById("color" + product_id[i]).options[compt_dispo] = new Option(tabColorByProduct[t] + no_dispo, tabIdColorByProduct[t] + no_dispo);
				all_dispo = 1;
				if (compt_dispo == 0) 
					default_color_id = tabIdColorByProduct[t];
				compt_dispo++;
			}
		}
		// implementation du listbox couleur avec les valeur du tableau "liste_non_dispo" : ça permet le tri couleur  dispo/non dispo
		for (var t = 0; t < liste_non_dispo.length; t++) 
			if (document.getElementById("color" + product_id[i]) != null) {
				document.getElementById("color" + product_id[i]).options[compt_dispo] = new Option(tabColorByProduct[liste_non_dispo[t]] + " / non dispo", tabIdColorByProduct[liste_non_dispo[t]] + " / non dispo");
				compt_dispo++;
			}
			
	//	liste_non_dispo = new Array();
		i_non_dispo = 0;
		compt_dispo = 0;
		
		
		listeArticleByProduct = findArticleByColor(product_id[i], default_color_id);
		var compt = 0;
		for (var cmpt = 0; cmpt < listeArticleByProduct.length; cmpt++) 
		
			if (article_dispo(listeArticleByProduct[cmpt][0]) > 0) 
			
				if (document.getElementById("height" + product_id[i]) != null) {
					document.getElementById("height" + product_id[i]).options[compt] = new Option(listeArticleByProduct[cmpt][3], listeArticleByProduct[cmpt][4]);
					compt++;
				}
				
		// controle pour permettre de filtrer les tailles
		
		 	sortArray_taille("height" + product_id[i]);

		// afficher les details pour cet article
		detail_article(product_id[i],"load");
		
		// si aucune couleur n'est dispo pour ce produit desactiver les listbox taille && quantite / masdquer les prix/prixbarre boutons && composition
		if (all_dispo == 0) {
			document.getElementById("color" + product_id[i]).disabled = false;
			
			document.getElementById("quantity" + product_id[i]).disabled = true;
			document.getElementById("quantity" + product_id[i]).clear;
			
			document.getElementById("height" + product_id[i]).disabled = true;
			document.getElementById("height" + product_id[i]).clear;
			
			document.getElementById("bouton_wishlist" + product_id[i]).style.display = "none";
			document.getElementById("bouton_add" + product_id[i]).style.display = "none";
			document.getElementById("price_barre" + product_id[i]).style.display = "none";
			document.getElementById("price" + product_id[i]).style.display = "none";
			document.getElementById("comp" + product_id[i]).style.display = "none";
		}
	}
}


//       affichage   des boutons Wishlist/ ajout panier
//       affichage   des prix et prix barre
//       activation/desactivation   des listbox : quantite couleur et taille
//       displayBlock( id_Product, height    , color , quantity   , price_barre    , price    , B.wishlist  , B.add) 
function displayBlock( id_Product, aff_height, aff_color, aff_quantity, aff_price_barre, aff_price, aff_wishlist, aff_add){
        
		if(aff_height != 'none')
			document.getElementById("height" + id_Product).disabled = aff_height;
		
		if(aff_color != 'none')		
			document.getElementById("color" + id_Product).disabled = aff_color;	
								
		if(aff_quantity != 'none')		
			document.getElementById("quantity" + id_Product).disabled = aff_quantity;						
			
		if(aff_price_barre!=0)		
			document.getElementById("price_barre" + id_Product).style.display = aff_price_barre;
			
		if(aff_price!=0)		
			document.getElementById("price" + id_Product).style.display = aff_price;
			
		if(aff_wishlist!=0)    	
			document.getElementById("bouton_wishlist" + id_Product).style.display = aff_wishlist;
			
		if(aff_add!=0)		
			document.getElementById("bouton_add" + id_Product).style.display = aff_add;
		
   }

// OnChange de la couleur
function select_color(id_Product){

    var select_opt = document.getElementById('color'+id_Product).value;

    last_height = document.getElementById('height'+id_Product).value;

	affiche_info(select_opt,id_Product);

	detail_article(id_Product,"color");
	sortArray_taille('height'+id_Product);
	set_last_height(id_Product);
}

// OnChange de la taille
function select_taille(id_Product){

	  detail_article(id_Product,"taille");
	  
}

// info
function affiche_info(id_color, id_Product){
    
        var tab1 = new Array();
		
		if (id_color.indexOf("/") != -1) {
			id_color = id_color.split(" / non dispo");
			id_color = id_color[0];
			displayBlock(id_Product,true, false, true, 'none', 'none', 'none', 'none');
		}
		else {
			tab1 = colorInfo1(id_color, id_Product);
			document.getElementById("height" + id_Product).options.length = 0;
			//remplissage liste taille selon couleur selectionnÃ©e
			var i_select = 0;
			for (var i = 0; i < tab1.length; i++) {
				var tabCol_sp = tab1[i].toString();
				var tabCol_str = new Array();
				tabCol_str = tabCol_sp.split(",");
				if (dispoInfo(tabCol_str[0]) > 0) {
					document.getElementById("height" + id_Product).options[i_select] = new Option(tabCol_str[3], tabCol_str[4]);
					if ( mono == false )
					document.getElementById("comp" + id_Product).innerHTML = "Composition : " + tabCol_str[7];
					i_select++;
				}
			}
		 }
}

// Fonction des traitements onchange des listbox couleur des produits parure
function select_color_promo(id_CurrentProduct){
    var liste_article_current = new Array();
    var liste_article_productB = new Array();
    var liste_size_current = new Array();
    var liste_size_productB = new Array();
    var liste_color_current = new Array();
    var liste_color_productB = new Array();
    var liste_info_product = new Array();
    var img_color_selected = -1;
    var color_selected;
	var id_ProductB;
	
	last_height = document.getElementById('height'+id_CurrentProduct).value;
	
	if (produit_parure(id_CurrentProduct)==1)
				id_ProductB = tabParure[0][1];
			else 
				id_ProductB = tabParure[0][0];
		
	liste_article_current = findArticle(id_CurrentProduct); // recuperation liste des articles pour produit-parure A (en cours) 
    liste_article_productB = findArticle(id_ProductB);      // recuperation liste des articles pour produit-parure B 
    
    liste_size_current = dis_color(liste_article_current, '4'); // distincter les tailles de select courant
    liste_size_productB = dis_color(liste_article_productB, '4'); // distincter les tailles de select de l'autre produit
    
    liste_color_current = dis_color(liste_article_current, '2');
    liste_color_productB = dis_color(liste_article_productB, '2');

	//recuperation de la couleur selectionnee du produit en cours
	color_selected = document.getElementById("color" + id_CurrentProduct).value;   
   
   // Changement de l'image Parure + picto parure
   	if (color_selected.indexOf("/") != -1) {
		if (produit_parure(id_CurrentProduct) == 1) {
			img_color_selected = color_selected.split(" / non dispo");
			img_color_selected = img_color_selected[0];
			
		}
		else 
			img_color_selected = -1;
	}
	else {
				if (produit_parure(id_CurrentProduct) == 1)
					   img_color_selected = color_selected;
					   else{
						   	for(var ind=0 ; ind < liste_color_productB.length; ind++)
								     if(color_selected == liste_color_productB[ind]){
									 	var dispo_color_selected=0;
										var liste_temp_article = findArticleByColor(id_ProductB,color_selected);
    										for (var indB=0 ; indB < liste_temp_article.length;indB++ )
												dispo_color_selected += dispoInfo(liste_temp_article[indB][0]);
											 	if (dispo_color_selected > 0) {
	   												img_color_selected = color_selected;
		        										break;
												}
				 							 }
					   				}
	}	
			
	if (img_color_selected != -1) {
				var new_article = findArticleByColor(tabParure[0][0], img_color_selected);
				if (new_article.length > 0) {
							// inclure les images flash de dos classique et HD
							var liste_img = new_article[0][5] + "," + new_article[0][6] + "," + new_article[0][11] + "," + new_article[0][12];
						
							ChangeZoom(liste_img, new_article[0][13]);		
							
		        			document.getElementById("im_parure").className = new_article[0][10];			
        			}
			}
    
    
	
	// Remplissage du selectB avec les valeurs distinctes des couleur produit B
       if(color_dispo(id_ProductB,color_selected)>0)
    if (color_selected.indexOf("/") == -1) {
		var indice_colorB = -1;
		for (var k = 0; k < liste_color_productB.length; k++) {
			if (liste_color_productB[k] == color_selected) {
				indice_colorB = k
				break;
			}
		}
		
		var liste_col_indispo = new Array();
		var ind_select = 0;
		var l = 0;
		if (indice_colorB > -1) 
			if (liste_color_productB[indice_colorB].indexOf("/") == -1) {
			
				for (var i = 0; i < liste_color_productB.length; i++) {
					var dispo = 0;
					var color_found = 0;
					var color_value;
					var color_value_id;
					
					
					for (var j = 0; j < liste_article_productB.length; j++) 
						if (liste_article_productB[j][2] == liste_color_productB[i]) {
							dispo += parseInt(dispoInfo(liste_article_productB[j][0]));
							color_value = liste_article_productB[j][1];
							color_value_id = liste_article_productB[j][2];
							color_found++;
						}
					if (color_found > 0) {
						if (dispo > 0) {
							document.getElementById('color' + id_ProductB).options[ind_select] = new Option(color_value, color_value_id);
							ind_select++;
						}
						else {
							var col_tempo = new Array();
							col_tempo[0] = color_value + " / non dispo";
							col_tempo[1] = color_value_id + " / non dispo";
							liste_col_indispo[l] = col_tempo;
							l++;
						}
					}
				}
		for (var j = 0; j < liste_col_indispo.length; j++) {
		document.getElementById('color' + id_ProductB).options[ind_select] = new Option(liste_col_indispo[j][0] , liste_col_indispo[j][1]);
		ind_select ++;
		}
		
		
							// Verifier que  la color_selected est disponible
						var tmp_color = -1;       
						var liste_info_productB ;
						for (var indice = 0; indice < document.getElementById('color' + id_ProductB).options.length; indice++) {
							if (document.getElementById('color' + id_ProductB).options[indice].value.indexOf("/") == -1) {
								if (document.getElementById('color' + id_ProductB).options[indice].value == color_selected) {
									tmp_color = color_selected;
									document.getElementById('color' + id_ProductB).options[indice].selected = true;
									// Filtrer les tailles selon la couleur selectionnee
									document.getElementById("height" + id_ProductB).options.length = 0;
									liste_info_productB = findArticleByColor(id_ProductB, tmp_color);
									var cmp_heightB = 0;
									for (var j = 0; j < liste_info_productB.length; j++) {
										if (article_dispo(liste_info_productB[j][0]) > 0) {
											document.getElementById("height" + id_ProductB).options[cmp_heightB] = new Option(liste_info_productB[j][3], liste_info_productB[j][4]);
											cmp_heightB++;
										}
									}
									
									if(document.getElementById("height" + id_ProductB).options[0] != null)
											document.getElementById("height" + id_ProductB).options[0].selected = true;	
									sortArray_taille("height" + id_ProductB);
									
									var id_itemB = fill_quantity(id_ProductB);
									var articleB = getArticleData(id_itemB);
									document.getElementById("price" + id_ProductB).className = articleB[8];
									document.getElementById("price_barre" + id_ProductB).className = articleB[9];
										
								}	  
							}
						}
	
	}
		
	}	 

	//	Initialisation Remplissage de la liste des tailles pour le produit en cours
    document.getElementById("height" + id_CurrentProduct).options.length = 0;
	liste_info_product = findArticleByColor(id_CurrentProduct, color_selected);
    
    var cmp_height = 0;
    for (var j = 0; j < liste_info_product.length; j++) {
        if (article_dispo(liste_info_product[j][0]) > 0) {
			document.getElementById("height" + id_CurrentProduct).options[cmp_height] = new Option(liste_info_product[j][3], liste_info_product[j][4]);
			cmp_height++;
		}
    }
  
		sortArray_taille("height" + id_CurrentProduct);
			
	// Remplissage Liste des Quantites & des details de l'article
	detail_article(id_CurrentProduct,"color_promo");	
	set_last_height(id_CurrentProduct);
}


function select_color_promo_mono(id_CurrentProduct){
	var img_color_selected = -1;
	var color_selected = document.getElementById("color" + id_CurrentProduct).value;   
    last_height = document.getElementById('height'+id_CurrentProduct).value;
   // Changement de l'image Parure + picto parure
   	if (color_selected.indexOf("/") == -1) {
		affiche_info(color_selected,id_CurrentProduct);
		detail_article(id_CurrentProduct,"color");
		sortArray_taille('height'+id_CurrentProduct);
		set_last_height(id_CurrentProduct);
		img_color_selected = color_selected;
	}		
	else {
				document.getElementById("height" + id_CurrentProduct).options.length = 0;
				document.getElementById("quantity" + id_CurrentProduct).options.length = 0;
				displayBlock( id_CurrentProduct, true, 'none', true, 'none', 'none', 'none', 'none');
	}
	if(img_color_selected == -1){
		img_color_selected = color_selected.split(" / non dispo");
		img_color_selected = img_color_selected[0];
	}
		
				var new_article = findArticleByColor(tabParure[0], img_color_selected);
				if (new_article.length > 0) {
					var liste_img = new_article[0][5] + "," + new_article[0][6] + "," + new_article[0][11] + "," + new_article[0][12];
					ChangeZoom(liste_img, new_article[0][13]);
					document.getElementById("im_parure").className = new_article[0][10];
				}
}



// Fonction des traitements onchange des listbox taille des produits parure
function select_size_promo(id_Product){
   
    detail_article(id_Product,"taille");
	
}

/**
 *
 * Methodes Diverses
 */

function color_by_id(id_color){
    var i = 0;
    while (i < tabInfo.length && id_color != tabInfo[i][4]) 
        i++;
    
    if (id_color == tabInfo[i][4]) 
        return tabInfo[i][3];
    
    return null;
}

// Chercher pour chaque id_Product tous les articles associes
function findProduct(id_Product){
    var searchItem = new Array();
    var j = 0;
    for (var i = 0; i < tabProduct.length; i++) {
        if (tabProduct[i][0] == id_Product) {
            searchItem[j] = new Array(tabProduct[i]);
            j++;
        }
    }
    return searchItem;
}

// Chercher l'URL produit pour chaque id_Product de la page BestSellers   
function getProductUrl(id_item){
	var i = 0;
				for(var i = 0; i < tabURL.length; i++){
						if(tabURL[i][0] == id_item){
							return tabURL[i][1];
						}	
				}
	return null;			
}

// fonction qui retourne l'id_article si la taille et couleur correspond a un article sinon null
function fill_quantity(id_Product){
    var bool = false;
    var rep_Art = new Array();
    var fill = new Array();
    var sp_fill = new Array();
	var height = -1;
	var color = -1;
    
	if(document.getElementById("height" + id_Product).selectedIndex == -1)
		height = -1;	
			else
		height = document.getElementById("height" + id_Product).options[document.getElementById("height" + id_Product).selectedIndex].value;	
			
	if(document.getElementById("color" + id_Product).selectedIndex == -1)
		color =	-1;
			else		
  		color =document.getElementById("color" + id_Product).options[document.getElementById("color" + id_Product).selectedIndex].value;
		
	if(height == -1 || color == -1 )	
    		return null;
	
        rep_Art = findProduct(id_Product);
		for (var i = 0; i < rep_Art.length; i++) {
            var sp_tab = rep_Art[i].toString().split(",");
            fill[i] = colorInfo(sp_tab[1])[0][0];
            sp_fill = fill[i].toString().split(",");
            if (sp_fill[2] == color && sp_fill[4] == height) 
                return sp_fill[0];
        }
    
    return null;
}

// Chercher la disponibilitï¿½ d'article
function dispoInfo(id_Art){
    for (var i = 0; i < tabDispo.length; i++) {
        if (tabInfo[i][0] == id_Art) {
            return tabDispo[i][1];
        }
    }
}

function color_dispo(id_product,id_color){
	
	 var dispo_couleur=0;
     var liste_article= findArticleByColor(id_product,id_color);
	
	
	 for (var i = 0; i < liste_article.length; i++)
	      dispo_couleur += dispoInfo(liste_article[i][0]);
		  
		  return dispo_couleur;
	}

// Chercher le prix d'article
function priceInfo(id_Art){
    for (var i = 0; i < tabPrice.length; i++) {
        if (tabPrice[i][0] == id_Art) {
            return tabPrice[i][1] + ";" + tabPrice[i][2];
        }
    }
}

// Chercher les articles ayant la même couleur en passant un parametre (id article)
function colorInfo(id_article){
    var searchColor = new Array();
    j = 0;
    for (var i = 0; i < tabInfo.length; i++) {
        if (tabInfo[i][0] == id_article) {
            searchColor[j] = new Array(tabInfo[i]);
            j++;
        }
    }
    return searchColor;
}

// Chercher les articles en passant  id couleur + id produit
function colorInfo1(id_color, product_id){
    var searchColor1 = new Array();
    var j = 0;
    var tab2 = new Array();
    tab2 = findProduct(product_id);
    
    for (var i = 0; i < tab2.length; i++) {
        var stou = colorInfo(tab2[i][0][1].toString())[0][0];
        if (stou[2] == id_color) {
            searchColor1[j] = stou;
            j++;
        }
    }
    return searchColor1;
    
}

// Fonction qui retourne la liste des articles d'un produit donne
function findArticle(id_Product){
    var searchItem = new Array();
    var j = 0;
    for (var i = 0; i < tabProduct.length; i++) {
        if (tabProduct[i][0] == id_Product) {
            for (var k = 0; k < tabInfo.length; k++) 
                if (tabInfo[k][0] == tabProduct[i][1]) {
                    searchItem[j] = tabInfo[k];
                    j++;
                }
        }
    }
    return searchItem;
}

// Fonction qui retourne la liste des articles d'un produit et d'une couleur donnes
function findArticleByColor(id_Product,idcolor){
    var searchItem = new Array();
    var j = 0;
    for (var i = 0; i < tabProduct.length; i++) {
        if (tabProduct[i][0] == id_Product) {
            for (var k = 0; k < tabInfo.length; k++) 
                if (tabInfo[k][0] == tabProduct[i][1]) 
				if (tabInfo[k][2]== idcolor)
				{
                    searchItem[j] = tabInfo[k];
                    j++;
                }
        }
    }
    return searchItem;
}

// Fonction qui retourne les donnees d'un article connu par son id_item
function getArticleData(id_article){
    var searchItem =new Array();
    var j = 0;
    for (var i = 0; i < tabInfo.length; i++)
        if (tabInfo[i][0] == id_article) {
          searchItem = tabInfo[i];
		  break;
		}
    return searchItem;
}

// Chercher les articles ayant la meme taille
function sizeInfo(id_taille, id_Product){
    var searchSize = new Array();
    var liste_article = findArticle(id_Product);
    
    j = 0;
    for (var i = 0; i < liste_article.length; i++) {
        if (liste_article[i][4] == id_taille) {
            if (article_dispo(liste_article[i][0]) > 0) {
				searchSize[j] = getArticleData(liste_article[i][0]);
				j++;
			}
        }
    }
    return searchSize;
}

// Chercher toutes les couleurs distinctes d'un tableau donne
function dis_color(tab, id){
    var tabColorDis = new Array();
    var exist = false;
    for (var i = 0; i < tab.length; i++) {
        exist = false;
        if (tabColorDis.length == 0) {
            tabColorDis[0] = tab[i][id];
        }
        else {
            for (var j = 0; j < tabColorDis.length; j++) {
                if (tabColorDis[j] == tab[i][id]) {
                    exist = true;
                    break;
                }
            }
            if (!exist) {
                tabColorDis[tabColorDis.length] = tab[i][id];
            }
        }
    }
    return tabColorDis;
}

// Fonction qui retourne si un produit est de type parure ou non ()
// produit non parure retourne 0
// produit parure partie du haut retourne 1
// produit parure partie du bas retourne 2
function produit_parure(id_product){
   var liste_parure = tabParure;
	
	if(liste_parure[0][0] == 'plusvendus' ) return 0;
	if(mono == true ) return 0;
	else
	for(var i=0; i<liste_parure.length;i++)
	 if(liste_parure[i][0]==id_product)
	   return 1;
	 else 
	 	if( liste_parure[i][1]==id_product )
			return 2;
	     		else return 0;
}

// Fonction qui retourne la disponibilite d'un article 
function article_dispo(id_article){
	
	for(var i=0;i<tabDispo.length;i++)
	if(tabDispo[i][0]==id_article) return tabDispo[i][1];

}

// Fonction de tri d'une lisbox selon les critere (Tour de poitrine / Bonnet)
function sortArray_taille(id_select){
	var Liste = new Array();
	Obj = document.getElementById(id_select);
	
	for (i = 0; i < Obj.options.length; i++) {
		Liste[i] = new Array();
		Liste[i][0] = Obj.options[i].text;
		Liste[i][1] = Obj.options[i].value;
	}
	
	if (Liste.length > 0) {
		if (Liste[0][0].length > 2) 
			Liste = tri_num_alpha(Liste);
		else 
			if (Liste[0][0].length <= 2) 
				Liste.sort();
		
		for (i = 0; i < Obj.options.length; i++) {
			Obj.options[i].text = Liste[i][0];
			Obj.options[i].value = Liste[i][1];
		}
	}
}

// fonction de tri alphanumerique
function tri_num_alpha(liste_taille){
	var liste_resultat = new Array();
	
	var liste_taille3 = new Array();
	var liste_taille2 = new Array();
	
for(var i=0 ; i < liste_taille.length ; i++){
		liste_resultat[i] = new Array();
			if (liste_taille[i][0].indexOf("/") != -1) {
			liste_taille[i][0] = liste_taille[i][0].substring(0,liste_taille[i][0].indexOf("/"));
			}
		liste_resultat[i][0] = liste_taille[i][0].substring(0,liste_taille[i][0].length-1);
		liste_resultat[i][1] = liste_taille[i][0].substring(liste_taille[i][0].length-1);
		liste_resultat[i][2] = liste_taille[i][1];
	}
		var j=0;
		var k=0;
	for(var i=0 ; i<liste_resultat.length ; i++){
		if (liste_resultat[i][0].length == 2) {
			liste_taille2[j] = liste_resultat[i];
			j++;
		}
		if(liste_resultat[i][0].length == 3){
		     liste_taille3[k] = liste_resultat[i];			 
			k++; 
		}
	}	
	liste_taille2.sort();
	liste_taille3.sort();	
	liste_taille = liste_taille2.concat(liste_taille3);
	
	liste_resultat = new Array();
	for (var i = 0; i < liste_taille.length; i++) {
		liste_resultat[i] = new Array();
		liste_resultat[i][0] = liste_taille[i][0]+ liste_taille[i][1];
		liste_resultat[i][1] = liste_taille[i][2];
		
		if (liste_taille[i][2].indexOf("/") != -1){
		liste_resultat[i][0] += " / non dispo ";
		liste_resultat[i][1] += " / non dispo ";
		}
		
	}
	
	
	return liste_resultat;
}

// Methode qui affiche les donnees des articles
function detail_article(id_Product, selection){
	var choice = "quantity";
	var visible = 'none';
	var disabled = false;
	var id_item = fill_quantity(id_Product);// recuperer id article	
	var itemURL = "#";
	
	if ( typeof(window['tabURL']) != 'undefined'){
		var hurle = getProductUrl(id_item); 
		if( hurle != null){
			itemURL = hurle;
		}	
	}	
	

	if (id_item == null) {
		
		if (produit_parure(id_Product) == 0) {
			displayBlock(id_Product, 'none', 'none', 'none', 'none', 'none', 'none', 'none');			
			
			var idcolor = document.getElementById("color" + id_Product).value;
			if (idcolor.indexOf("/") != -1) {
				idcolor = idcolor.split(" / non dispo");
				idcolor = idcolor[0];
			}
			var liste_article = findArticleByColor(id_Product, idcolor);
			var item = liste_article[0];
			
			if(document.getElementById("front" + id_Product) != null){
				document.getElementById("front" + id_Product).style.backgroundImage = "url(" + item[5] + ")";
				document.getElementById("cadrepicFront" + id_Product).innerHTML = 	"<a href=\""+itemURL+"\" title=\"\"><img src=\""+ item[5] +"\" alt=\"\" class=\"hide4screen\" /></a>";
				
				
			}
			
			if(document.getElementById("back" + id_Product) != null){
				document.getElementById("back" + id_Product).style.backgroundImage = "url(" + item[6] + ")";
				document.getElementById("cadrepicBack" + id_Product).innerHTML = 	"<a href=\""+itemURL+"\" title=\"\"><img src=\""+ item[6] +"\" alt=\"\" class=\"hide4screen\" /></a>";
			}
			
			if(document.getElementById("im_picto" + id_Product) != null){
				document.getElementById("im_picto" + id_Product).className = item[10];
			}
		}
		else {
			document.getElementById("height" + id_Product).disabled = false;
			// control : Si la couleur selectionnee n'est pas disponible desactiver : Selects-taille-quantite + Boutons-ajout-wishlist
			// control : Si la taille selectionnee n'est pas disponible desactiver : Selects-quantite + Boutons-ajout-wishlist
			var select_opt_color = document.getElementById('color' + id_Product).value;
			var select_opt = document.getElementById('height' + id_Product).value;
			
			if (select_opt_color.indexOf("non dispo") != -1) {
				displayBlock(id_Product, true, "none", true, "none", "none", "none", "none")
				document.getElementById("im_parure").className = "";
			}
			else 
				if (select_opt.indexOf("non dispo") != -1) {
					displayBlock(id_Product, true, "none", true, "none", "none", "none");
					document.getElementById("im_parure").className = "";
				}
		// Fin  // control couleur/taille  selectionnee non disponible
		}
	}
	else {
	
		displayBlock(id_Product, false, false, false, 'block', 'block', 'block', 'block')
		
		var price_str = priceInfo(id_item);// recuperation de prix et prix barrï¿½
		var price_sp = new Array();
		price_sp = price_str.split(";");// distincter entre prix et prix barrï¿½
		
		if (document.getElementById("price_barre" + id_Product) != null){
		    var unite="&euro;";
		    if(price_sp[1] == "") unite="";
			document.getElementById("price_barre" + id_Product).innerHTML = price_sp[1] + unite +"<span class=\"bar\"></span>";
		}
		
		if ((price_sp[0] !== "") && (document.getElementById("price" + id_Product) != null)) // si le prix != null ou il n'est y a pas d'id prix
			document.getElementById("price" + id_Product).innerHTML = price_sp[0] + "&euro;";
		
		var article = getArticleData(id_item);
		document.getElementById("price" + id_Product).className = article[8];
		document.getElementById("price_barre" + id_Product).className = article[9];
		document.getElementById("comp" + id_Product).innerHTML = "Composition : " + article[7];
		// Si ce n'est pas un produit parure afficher la composition + image + picto correspondante article		
		if (produit_parure(id_Product) == 0) {
			if (mono == false || ((mono == true) && (id_Product != tabParure[0]))) {
			
				document.getElementById("front" + id_Product).style.backgroundImage = "url(" + article[5] + ")";
				document.getElementById("cadrepicFront" + id_Product).innerHTML = 	"<a href=\""+itemURL+"\" title=\"\"><img src=\""+article[5]+"\" alt=\"\" class=\"hide4screen\" /></a>";
				document.getElementById("front" + id_Product).style.display = "block";
				document.getElementById("back" + id_Product).style.backgroundImage = "url(" + article[6] + ")";
				document.getElementById("cadrepicBack" + id_Product).innerHTML = 	"<a href=\""+itemURL+"\" title=\"\"><img src=\""+article[6]+"\" alt=\"\" class=\"hide4screen\" /></a>";
				document.getElementById("back" + id_Product).style.display = "none";
				document.getElementById("im_picto" + id_Product).className = article[10];
				
		}
		}
		if (mono == false) {
		
			if (produit_parure(id_Product) > 0) {
				var id_ProductB = 0;
				price_str = null;
				
				
				if (produit_parure(id_Product) == 1) {
					id_ProductB = tabParure[0][1];
					document.getElementById("im_parure").className = article[10];
				}
				else 
					if (produit_parure(id_Product) == 2) 
						id_ProductB = tabParure[0][0];
				
				var id_itemB = getItem(id_ProductB); //fill_quantity(id_ProductB);
				if (id_itemB != null) 
					price_str = priceInfo(id_itemB);
				if (price_str != null) {
					price_sp = price_str.split(";");
					if ((price_sp[1] !== "") && (document.getElementById("price_barre" + id_ProductB) != null)) 
						document.getElementById("price_barre" + id_ProductB).innerHTML = price_sp[1] + "&euro;<span class=\"bar\"></span>";
					if ((price_sp[0] !== "") && (document.getElementById("price" + id_ProductB) != null)) 
						document.getElementById("price" + id_ProductB).innerHTML = price_sp[0] + "&euro;";
				}

				// remplir le select quantite pour le produitB
				if (id_itemB != null) 
					fill_select_quantity(id_itemB, id_ProductB);
			}
		}
		else{
			if(id_Product == tabParure[0]){
			document.getElementById("im_parure").className = article[10];
		}
	    }
	}
	
	// remplir le select quantite pour le produit en cours
	fill_select_quantity(id_item , id_Product );
}


// Fonction qui permet de remplir le select quantite  produit selon les dispo d'un article donne
function fill_select_quantity(id_item , id_Product ){
	
	
	var proDispo = dispoInfo(id_item); // recherche la disponiblite d'article
		if (proDispo > 5) {
			document.getElementById("quantity" + id_Product).options.length = 5;
			displayBlock( id_Product, false, false, false, "block" , "block", "block", "block");
		}
		else 
			if (proDispo > 0) {
				document.getElementById("quantity" + id_Product).options.length = proDispo;
				displayBlock( id_Product, false, false, false, "block" , "block", "block", "block");
			}
			else {
				document.getElementById("height" + id_Product).options.length = 0;
				document.getElementById("quantity" + id_Product).options.length = 0;
				displayBlock( id_Product, 'none', 'none', true, 'none', 'none', 'none', 'none');
			}
		
		// remplissage de select quantity du produit
		for (var ii = 0; ii < document.getElementById("quantity" + id_Product).options.length; ii++) { 
			document.getElementById("quantity" + id_Product).options[ii] = new Option(ii + 1, ii + 1);
		}
		
}


// Fonction qui permet de passer en parametre le nom de l'image parure au chargement de la page
function get_flash_img(){
	return onload_img_zoom;
}

// Fonction qui permet de passer en parametre le nom de l'image parure au chargement de la page
function get_flash_img_zoom_url(){
	return onload_img_zoomB;
}

// Fonction qui permet de passer en parametre le nom de l'image parure de dos au chargement de la page
function get_flash_back_img_zoom(){
	return onload_img_back_zoom;
}

// Fonction qui permet de passer en parametre le nom de l'image parure de dos HD au chargement de la page
function get_flash_back_img_zoom_HD(){
	return onload_img_back_zoom_HD;
}

// Fonction qui permet de savoir si la fonction "voir de dos" est disponible
function isBackVisualEnabled(){
	return backVisualEnabled;
}

// Fonction qui definnit la valeur de l'image parure selon le produit du haut 
//  qui s'affiche par defaut au chargement de la page
function Init_onload_img(ismono){
	var id_produit = -1;
	
	
	if(ismono == true ) id_produit= tabParure [0];
	else 
	id_produit= tabParure [0][0];
	
	var liste_article = findProduct(id_produit);// chercher pour cet id produit les articles associes.
    var tabColorStr = new Array();		

		for (var k = 0; k < liste_article.length; k++) { // on boucle sur le tableau des articles trouves
			var artsplit = liste_article[k].toString().split(",");
			tabColorStr[k] = colorInfo(artsplit[1])[0][0]; // on cherche pour chaque articles les donnÃ©es associÃ©s
		}
    var tabColorByProduct = dis_color(tabColorStr, '1'); // on charge les couleurs distincts
	var tabIdColorByProduct = dis_color(tabColorStr, '2'); // on charge les id_couleurs distincts
	
	var dispo = 0;
	var cmpt;	
	var found = false;
	
	for (var t = 0; t < tabColorByProduct.length && !found; t++) {
			for (cmpt = 0; cmpt < tabColorStr.length && !found; cmpt++) {
				if (tabColorByProduct[t] == tabColorStr[cmpt][1]){ 
					dispo += parseInt(dispoInfo(tabColorStr[cmpt][0]));
					if (dispo > 0) {
						dispo=cmpt;
						found = true;
					}
				}
			}			
	}
	
	var article=tabColorStr[dispo];
	onload_img_zoom = article[5];
	onload_img_zoomB = article[6];
	
	// images flash de dos
	onload_img_back_zoom = article[11];
	onload_img_back_zoom_HD = article[12];
	backVisualEnabled = article[13];	
}

// Fonction qui permet de changer l'image parureau quand on change la couleur selectionnee
function changeSWF(path, file, width, height, wmode, bgcolor, id, productLabel){
var EmbedSWF = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" id=\""+id+"\" width=\""+width+"\" height=\""+height+"\"><param name=\"movie\" value=\""+path+file+"\" /><param name=\"quality\" value=\"high\" /><param name=\"menu\" value=\"false\" /><param name=\"wmode\" value=\""+wmode+"\" /><param name=\"bgcolor\" value=\""+bgcolor+"\" /><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"FlashVars\" value=\"labelproduct="+productLabel+"\" /><embed src=\""+path+file+"\" bgcolor=\""+bgcolor+"\" wmode=\""+wmode+"\" menu=\"false\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" name=\""+id+"\" allowScriptAccess=\"always\" FlashVars=\"labelproduct="+productLabel+"\" swLiveConnect=\"true\" width=\""+width+"\" height=\""+height+"\"></embed></object>";
document.getElementById("change_SWF").innerHTML=EmbedSWF;
}

// Fonction 

function set_last_height(product_id){

	if (document.getElementById("height" + product_id) != null) 
	
			for(var i=0 ; i < document.getElementById("height" + product_id).options.length ; i++){
				if(document.getElementById("height" + product_id).options[i].value == last_height){
								document.getElementById('height' + product_id).options[i].selected = true;	
								break;
				}
			}
}

// Fonction qui retourne la quantite choisie par l'utilisateur pour un article
// parametres : id_Product
//    dans le cas d'une erreur la valeur du retour est '-1'
function getQuantity(id_Product){
	
	if (document.getElementById("quantity" + id_Product) != null) 
		if (document.getElementById("quantity" + id_Product).value != null) 
			return document.getElementById("quantity" + id_Product).value;

	return - 1;
}

// Fonction qui retourne l' id_item choisitpar l'utilisateur pour chaque produit
// parametres : product_id
//    dans le cas d'une erreur la valeur du retour est '-1'
function getItem(product_id){
	
	var taille_selected = null;
	var color_selected = null ;
	
		
	if (document.getElementById("height" + product_id) != null) 
		if (document.getElementById("height" + product_id).value != null) 
			taille_selected =  document.getElementById("height" + product_id).value;

	if (document.getElementById("color" + product_id) != null) 
		if (document.getElementById("color" + product_id).value != null) 
			color_selected =  document.getElementById("color" + product_id).value;
	
	if (taille_selected != null && color_selected != null) {
	var liste_article = findArticleByColor(product_id,color_selected);
	
			for(var i=0 ; i < liste_article.length ; i++){
				if (liste_article[i][4] == taille_selected)
				     return liste_article[i][0]
			}
	}
	return -1;
}



