function trim(s){
	return s.replace(/^\s+/g,'').replace(/\s+$/g,'')
} 	

function encodeJS(s) {
return (!/[\x00-\x19\'\\]/.test(s)) ? s : s.replace(/([\\'])/g, '\\$1').replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/[\x00-\x19]/g, '')
}
function toJSON(o) {
    var UNDEFINED
    switch (typeof o) {
      case 'string': return '\'' + encodeJS(o) + '\''
      case 'number': return String(o)
      case 'object': 
        if (o) {
          var a = []
          if (o.constructor == Array) {
            for (var i = 0; i < o.length; i++) {
              var json = toJSON(o[i])
              if (json != UNDEFINED) a[a.length] = json
            }
            return '[' + a.join(',') + ']'
          } else if (o.constructor == Date) {
            return 'new Date(' + o.getTime() + ')'
          } else {
            for (var p in o) {
              var json = toJSON(o[p])
              if (json != UNDEFINED) a[a.length] = (/^[A-Za-z_]\w*$/.test(p) ? (p + ':') : ('\'' + encodeJS(p) + '\':')) + json
            }
            return '{' + a.join(',') + '}'
          }
        }
        return 'null'
      case 'boolean'  : return String(o)
      case 'function' : return
      case 'undefined': return 'null'
    }
}
/******* CAttribut *******/
var CAttribut_validate = new Array;

function CAttItem (code_ean, option_id, majoration_prix, qte_stock){
	this.Datas = new Array;
	this.EAN = code_ean;
	this.OptID = option_id;
	this.Majoration = majoration_prix;
	this.Stock = qte_stock;
}
CAttItem.prototype.AddProperty = function (attribut_id, attribut_detail_id){
	newID = this.Datas.length;
	this.Datas[newID] = new Array;
	this.Datas[newID]["AttDetailID"] = attribut_detail_id;
	this.Datas[newID]["AttID"] = attribut_id;
}

function CAttribut (ObjectName, pagesURL, ProductsImagesPath, ProduitID, socNet){
	this.ObjectName = ObjectName;
	
	this.ProduitID = ProduitID;
	this.DelaiLivTag = "DelaiLivTag";
	this.StockTag = "StockTag";
	this.MajorationTag = "";
	this.AttSelectName = "sel_attrib";
	this.DefaultValue = "----------";
	this.HiddenOptID = "option_id";
	this.HiddenEAN = "code_ean";
	this.LinkedCheckBox = "";

	this.KitController = null;
	this.DisableSaving = false;
	
	this.PrixBase = 0;
	this.Devise = "EUR";
	this.Majoration = 0;
	this.pagesURL = pagesURL;
	this.ProductsImagesPath = ProductsImagesPath;
	this.SelectOK = false;
	this.socNet = socNet;
	
	this.s_DelaiLiv = 0;
	this.DelaiLiv = new Array;
	this.DelaiLiv[0] = new Array;
	this.DelaiLiv[1] = new Array;
	this.DelaiLiv[2] = new Array;
	this.DelaiLiv[3] = new Array;
	this.DelaiLiv[4] = new Array;
	this.DelaiLiv[5] = new Array;
	this.DelaiLiv[6] = new Array;
	this.DelaiLiv[0][0] = 1;
	this.DelaiLiv[1][0] = 2;
	this.DelaiLiv[2][0] = 3;
	this.DelaiLiv[3][0] = 4;
	this.DelaiLiv[4][0] = 5;
	this.DelaiLiv[5][0] = 6;
	this.DelaiLiv[6][0] = 7;
	
	this.EANList = new Array;
	this.AttArbo = new Array;
	this.AttArboDef = new Array;
	
	/* fabrication arbo */
	this.PrevEAN = "";
	this.cItem = 0;
	this.levelCount = 0;
	
	this.SelectedList = new Array;
	this.SelectedListImg = new Array;
	
	this.LevelZeroSelected = function() {};
	
	CAttribut_validate[CAttribut_validate.length] = ObjectName;

	/* recup des precedentes selections d'attributs */
	if(!socNet) {
		var cs = document.cookie.split(';');
		var found = false;
		this.PreviousSelections = new Array();
		for(var i=0; i<cs.length; i++){
			var cv = cs[i].split('=');
			if(trim(cv[0]) == "Attributs"){
				 this.PreviousSelections = eval('('+unescape(cv[1])+')')
			}
		}
	}
}

/*** 
	enregistrement d'un input checkbox ou radio lié au produit
	si cet input est déselectionné/décoché, 
	alors this.IsOk() renvoie TRUE dans tous les cas
***/
CAttribut.prototype.SetLinkedCheckBox = function (InputName){
	this.LinkedCheckBox = InputName
}

CAttribut.prototype.SetEANHiddenInput = function (InputName){
	this.HiddenEAN = InputName
}
CAttribut.prototype.SetOptionIDHiddenInput = function (InputName){
	this.HiddenOptID = InputName
}
CAttribut.prototype.SetAttSelectName = function (InputName){
	this.AttSelectName = InputName
}
CAttribut.prototype.SetMajorationTag = function (InputName){
	this.MajorationTag = InputName
}
CAttribut.prototype.SetDefaultOption = function (Libelle){
	this.DefaultValue = Libelle
}

CAttribut.prototype.SetDelaiLivText = function (DelaiID, DelaiText){
	for(i=0; i<this.DelaiLiv.length; i++){
		if(this.DelaiLiv[i][0] == DelaiID)
			this.DelaiLiv[i][1] = DelaiText;
	}
}

CAttribut.prototype.IsOk = function (){
	if(this.LinkedCheckBox != ""){
		chkbox = document.getElementById(this.LinkedCheckBox);
		if(chkbox){
			if(!chkbox.checked)	return true;
			else return this.SelectOK;
		}else{
			return this.SelectOK;
		}
	}else{
		return this.SelectOK;
	}
}

CAttribut.prototype.Add = function (libelle, attribut_id, libelle_opt, attribut_detail_id, majoration_prix, qte_stock, code_ean, tri, option_id, main_ean){
	
	if(this.PrevEAN != code_ean){
		//recherche si EAN existant
		var found = false;
		for(var i=0; i<this.EANList.length; i++){
			if(this.EANList[i].EAN == code_ean){
				found = true;
				this.cItem = i;
			}
		}
		if(!found){
			this.cItem = this.EANList.length;
			this.EANList[this.cItem] = new CAttItem(code_ean, option_id, majoration_prix, qte_stock);
		}
		this.PrevEAN = code_ean;
	}
	this.EANList[this.cItem].AddProperty(attribut_id, attribut_detail_id);
	
	ItemDatasCount = this.EANList[this.cItem].Datas.length-1;
	this.NewArboEntry(this.AttArbo, 0, ItemDatasCount, libelle_opt, attribut_detail_id, code_ean, libelle, attribut_id, main_ean);
}

CAttribut.prototype.NewArboEntry = function (Arbo, cLevel, ToLevel, eText, eID, EAN, eDef, eDefID, MainEAN){
	if(cLevel < ToLevel){
		this.NewArboEntry(Arbo[this.EANList[this.cItem].Datas[cLevel]["AttDetailID"]][0], cLevel+1, ToLevel, eText, eID, EAN, eDef, eDefID, MainEAN);
		return;
	}else{
		if(cLevel > this.levelCount) this.levelCount = cLevel;
	
		found = false;
		for(var i in Arbo){
			if(i == eID){
				found = true;
				break;
			}
		}
		
		if(found){
			Arbo[eID][2][Arbo[eID][2].length] = EAN;
		}else{
			Arbo[eID] = new Array;
			Arbo[eID][0] = new Array;
			Arbo[eID][1] = eText;
			Arbo[eID][2] = new Array;
			Arbo[eID][2][0] = EAN;
			Arbo[eID][3] = MainEAN;
			
			if(cLevel+1 > this.AttArboDef.length){
				this.AttArboDef[cLevel] = new Array;
				this.AttArboDef[cLevel][0] = eDefID;
				this.AttArboDef[cLevel][1] = eDef;
				this.AttArboDef[cLevel][2] = new Array;
			}
			//ajout des valeurs possible de chaque attribut
			if(eID){
				var toAdd = true;
				for(var j in this.AttArboDef[cLevel][2]){
					if(isNaN(j)) continue;
					if(this.AttArboDef[cLevel][2][j][0] == eID) toAdd = false;
				}
				if(toAdd){
					this.AttArboDef[cLevel][2][this.AttArboDef[cLevel][2].length] = new Array(eID, eText);
				}
			}
		}
	}
}

CAttribut.prototype.HasStock = function(Arbo){
	var hasStock = false;
	if(!Arbo) return false;
	for(var k=0; k<Arbo[2].length; k++){
		for(var j=0; j<this.EANList.length; j++){
			if(this.EANList[j].EAN == Arbo[2][k]){
				if(this.EANList[j].Stock > 0){
					hasStock = true;
					break;
				}
			}
		}
		if(hasStock) break;
	}
	return hasStock;
}

CAttribut.prototype.SaveSelection = function (Level, Value){
	if(!this.socNet) {
		if(this.DisableSaving) return;

		var f = false;
		for(var i=0; i<this.PreviousSelections.length; i++){
			if(this.PreviousSelections[i].p == this.ProduitID){
				this.PreviousSelections[i].a[Level] = Value;
				this.PreviousSelections[i].a.length = Level+1;
				f = true;
				break;
			}
		}
		if(!f){
			var o = new Object();
			o.p = this.ProduitID;
			o.a = new Array();
			o.a[Level] = Value;
			this.PreviousSelections.push(o);
		}
		
		var today = new Date();
		today.setTime( today.getTime() );
		var expire = 1000 * 60 * 60 * 24;
		var expires_date = new Date( today.getTime() + (expire) );
		
		document.cookie = "Attributs=" +escape(toJSON(this.PreviousSelections)) +
			"; expires=" + expires_date.toGMTString() +
			"; path=/";
		}
}

CAttribut.prototype.SelectFromSave = function (){
	if(!this.socNet) {
		this.DisableSaving = true;
		for(var i=0; i<this.PreviousSelections.length; i++){
			if(this.PreviousSelections[i].p == this.ProduitID){
				for(var j=0; j<this.PreviousSelections[i].a.length; j++){
					this.RefreshCombo(j, this.PreviousSelections[i].a[j]);
				}
				break;
			}
		}
		this.DisableSaving = false;
	}
}

CAttribut.prototype.RefreshCombo = function (Level, Value){
	//if(Value == 0) return true;

	var ArboNode = new Array;
	ArboNode[0] = this.AttArbo;
	
	//selection de l'arborescence filtrée en fonction des choix deja fait
	var Pastille = null;
	for(var i=0; i<this.SelectedList.length && i<Level; i++){
		ArboNode = ArboNode[0][this.SelectedList[i]];
		Pastille = this.SelectedListImg[i];
	}
	ArboNode = ArboNode[0][Value];
	
	//check du stock de l'attribut, empeche la selection si = 0
	var hasStock = this.HasStock(ArboNode);	
	if(!hasStock){
		return;
	}
	
	//stockage des choix choisi, donc l'ordre, fonctionnement stack
	if(this.SelectedList.length > Level)
		while(this.SelectedList.length > Level){
			this.SelectedList.pop();
			if(this.SelectedListImg[this.SelectedListImg.length-1]) {
				if(this.SelectedListImg[this.SelectedListImg.length-1]){
					if(this.SelectedListImg[this.SelectedListImg.length-1].getElementsByTagName("img")[0])
						this.SelectedListImg[this.SelectedListImg.length-1].getElementsByTagName("img")[0].src = pageURL + "/ximg/shim.gif";
					this.SelectedListImg[this.SelectedListImg.length-1].className = "attrib_link";
				}
			}
			this.SelectedListImg.pop();
		}
	this.SelectedList.push(Value);
	this.SelectedListImg.push(document.getElementById("pastille_"+Level+"_"+Value));
	Pastille = this.SelectedListImg[this.SelectedListImg.length-1];
	
	switch(Level){
		case 0:
			if(!this.socNet) this.SaveSelection(Level, Value);
		
			//selection de la couleur, mise a jour des tailles

			for(var z in this.AttArboDef[Level+1][2]){
				var Img = document.getElementById("cross_"+(Level+1)+"_"+z);
				if(Img == null) continue;
				Img.className = "attrib_size_cross";
				Img.style.display = 'block';
			}
			
			//parcours les tailles et met a jour les img attributs
			for(var i in ArboNode[0]){
				var Img = document.getElementById("cross_"+(Level+1)+"_"+i);
				
				var hasStock = this.HasStock(ArboNode[0][i]);
				
				if(Img) {
					if(hasStock) Img.style.display = 'none';
					else {
						Img.className = "attrib_size_cross";
						Img.style.display = 'block';
					}
				}
				
			}
			
			//affichage de la pastille de selection
			Pastille.getElementsByTagName("img")[0].src = pageURL + "/ximg/selected.gif";
			Pastille.className = "attrib_link selected";
			
			//changement de l'image principale du produit
			var ImgProd = document.getElementById("main_img");
			var imgSocNet = document.getElementById("socNet_img");
			if(ImgProd){
				var ProduitID = ArboNode[3];//recup MainEAN pour le parser
				ProduitID = ProduitID.substr(1, 8);
				ProduitID = parseInt(ProduitID, 10);
				
				ImgProd.src = this.ProductsImagesPath + "/prod_" + ProduitID + "/C_" + ArboNode[3] + "_1_" + Value + ".jpg";
				imgSocNet.href = this.ProductsImagesPath + "/prod_" + ProduitID + "/B_" + ArboNode[3] + "_1_" + Value + ".jpg";
				
				
				
				//changement des images gallerie
				tab_gal_fiche_color_id = Value;
				
				build_gal_thumbnail(ProduitID);
				
			}
			
			this.LevelZeroSelected(Value);

		break;
		case 1:
			if(!this.socNet) this.SaveSelection(Level, Value);
		
			//affichage de la pastille de selection
			Pastille.getElementsByTagName("img")[0].src = pageURL + "/ximg/selected.gif";
			Pastille.className = "attrib_link selected";
			
			
			//si on a un troisieme attribut, la longueur donc...
			if(Level != this.levelCount){
				//affichage des longueurs en combo DEV
				var ISelect = document.getElementById(this.AttSelectName + "l" + (Level+1));
				if(ISelect){
					ISelect.options.length = 1;
					//on ajoute au select seulement les produits avec du stock
					for(var i in ArboNode[0]){
						if(this.HasStock(ArboNode[0][i]))
							ISelect.options[ISelect.options.length] = new Option(ArboNode[0][i][1], i);
					}			
				}

				//affichage des longueurs en pastille PROD
				for(var i in ArboNode[0]){
					var Img = document.getElementById("cross_"+(Level+1)+"_"+i);
					
					var hasStock = this.HasStock(ArboNode[0][i]);
					
					if(hasStock) Img.style.display = 'none';
					else {
						Img.className = "attrib_size_cross";
						Img.style.display = 'block';
					}
					//Img.src = this.ProductsImagesPath + "/attribut/" + ((hasStock)? "nocross.png" : "cross.png");
					//Img.className = ((hasStock)? "attrib_size_link" : "attrib_size_link selected");
					//Img.style.border = "1px solid red !important";
				}
			
			}
		
		break;
		case 2:
			
			//affichage de la pastille de selection
			/*Pastille.getElementsByTagName("img")[0].src = pageURL + "/ximg/selected.gif";
			Pastille.className = "attrib_link selected";

			if(ArboNode[2].length == 1){
				var ISelect = document.getElementById(this.AttSelectName + "l" + (Level));
				if(ISelect) ISelect.selectedIndex = 1;
			}*/
			
		break;
	}
	
	
	if(Level == this.levelCount){

		if(Value != 0){
			var SelectedEAN = ArboNode[2][0];
			for(i=0; i<this.EANList.length; i++){
				if(this.EANList[i].EAN == SelectedEAN){
					var divMajor = document.getElementById(this.MajorationTag);
					if(divMajor)divMajor.innerHTML = this.EANList[i].Majoration + " " + this.Devise;
					
					var divMajor = document.getElementById("s" + this.MajorationTag);
					if(divMajor)divMajor.innerHTML = this.EANList[i].Stock;
					
					this.Majoration = this.EANList[i].Majoration;
					
					UpdateTotal(this.Majoration);
					
					eval("document.productform."+this.HiddenOptID+".value = '" + this.EANList[i].OptID + "'");
					eval("document.productform."+this.HiddenEAN+".value = '" + this.EANList[i].EAN + "'");
					this.SelectOK = true;
					
					if(this.KitController){
						this.KitController.CalcValue();
					}		
					else
					{
						if(typeof layer_major != "undefined"){
							layer_major.innerHTML = '<b>Majoration :</b> +' + this.EANList[i].Majoration + " &euro;";
						}
					}			
					break;
				}
			}
		}
		return true;
	}else{
		eval("document.productform."+this.HiddenEAN+".value = ''");
		eval("document.productform."+this.HiddenOptID+".value = 0");
		//var divMajor = document.getElementById(this.MajorationTag);
		//divMajor.innerHTML = "NC";
		this.Majoration = 0;
		if(this.KitController){
			this.KitController.CalcValue();
		}
	}
	this.SelectOK = false;
	
	
	/*var ISelect = document.getElementById(this.AttSelectName + "l" + (Level+1));
	ISelect.options.length = 1;
	if(Value == 0) return true;*/

	
	/*for(var i in ArboNode[0]){
		ISelect.options[ISelect.options.length] = new Option(ArboNode[0][i][1], i);
	}*/

	//auto select des prochains combo, si plus qu'un choix dispo
	if(ArboNode[2].length == 1){
		var NextAttID = 0;
		for(NextAttID in ArboNode[0]){}
		//ISelect.selectedIndex = 1;
		this.RefreshCombo(Level+1, NextAttID);
	}


	return true;
}

CAttribut.prototype.AutoSelect = function (AttributID){
	for(i=0; i<this.AttArboDef.length; i++){
		if(AttributID == this.AttArboDef[i][0]){
			document.getElementById(this.AttSelectName+"l"+i).selectedIndex=1;
			for(var z in this.AttArbo){
				if(isNaN(z)) continue;
				this.RefreshCombo(i, z);
				break;
			}
			break;
		}
	}
}

CAttribut.prototype.Select = function (CodeEAN){
	var EanObj = null;
	for(var i=0; i<this.EANList.length; i++){
		if(this.EANList[i].EAN == CodeEAN){
			EanObj = this.EANList[i];
		}
	}
	if(!EanObj) return;

	for(var i=0; i<EanObj.Datas.length; i++){
		//alert("RefreshCombo("+i+", "+EanObj.Datas[i]["AttDetailID"]+");")
		this.RefreshCombo(i, EanObj.Datas[i]["AttDetailID"]);
	}
}


CAttribut.prototype.DisplayCombo = function (AttributID) {
	var Opts = ""
	
	for(i=0; i<this.AttArboDef.length; i++){
		if(AttributID == this.AttArboDef[i][0]){

			document.write("<select id='"+this.AttSelectName+"l"+i+"' name='"+this.AttSelectName+this.AttArboDef[i][0]+"' onchange='"+this.ObjectName+".RefreshCombo("+i+", this.value)'>");
			document.write("<option value='0'>"+this.DefaultValue+"</option>");
			if(i == 0)
				for(var z in this.AttArbo){
					if(isNaN(z)) continue;
					document.write("<option value='"+z+"'>"+this.AttArbo[z][1]+"</option>");
				}
			document.write("</select>");
		}
	}
}

CAttribut.prototype.DisplayCombo2 = function (AttributID) {
	var Opts = ""
	
	for(i=0; i<this.AttArboDef.length; i++){
		if(AttributID == this.AttArboDef[i][0]){

			document.write("<select id='"+this.AttSelectName+"l"+i+"' name='"+this.AttSelectName+this.AttArboDef[i][0]+"' onchange='"+this.ObjectName+".RefreshCombo("+i+", this.value)'>");
			document.write("<option value='0'>"+this.DefaultValue+"</option>");
			for(var z in this.AttArboDef[i][2]){
				document.write("<option value='"+this.AttArboDef[i][2][z][0]+"'>"+this.AttArboDef[i][2][z][1]+"</option>");
			}
			document.write("</select>");
		}
	}
}

CAttribut.prototype.DisplayImages = function (AttributID) {
	var Opts = "";
	/*
	for(i=0; i<this.AttArboDef.length; i++){
		if(AttributID == this.AttArboDef[i][0]){
			var j=0;
			for(var z in this.AttArboDef[i][2]){
				if(isNaN(z)) continue;
				if(j == 6){
					j = 0;
					document.write("<br>");
				}
				var imgname = this.AttArboDef[i][2][z][0];
				
				document.write("<div class='att_color'>");
				document.write("<img class='png' src='"+this.ProductsImagesPath+"/attribut/02/02_"+imgname+".gif' ");
				document.write("alt='"+i+"_"+this.AttArboDef[i][2][z][0]+" "+this.AttArboDef[i][2][z][1]+"'>");
				document.write("<a class='attrib_link' id='pastille_"+i+"_"+this.AttArboDef[i][2][z][0]+"' href='javascript:"+this.ObjectName+".RefreshCombo("+i+", \""+this.AttArboDef[i][2][z][0]+"\");void(0);'><img src='/e_commerce/ximg/shim.gif'></a>");
				document.write("</div>");
				j++;
			}
		}
	}
	*/
	
	for(i=0; i<this.AttArboDef.length; i++){
		if(AttributID == this.AttArboDef[i][0]){

			if(i == 0){
				var j=0;
				for(var z in this.AttArbo){
					if(isNaN(z)) continue;
					if(j == 6){
						j = 0;
						document.write("<br>");
					}
					var imgname = z;
					
					var hasStock = this.HasStock(this.AttArbo[z]);
					
					document.write("<div class='att_color'>");
					document.write("<img src='"+this.ProductsImagesPath+"/attribut/02/02_"+imgname+".gif' ");
					document.write("alt='"+i+"_"+z+" "+this.AttArbo[z][1]+"'>");
					if(hasStock){
						document.write("<a class='attrib_link' id='pastille_"+i+"_"+z+"' href='javascript:socNet_URL = base_URL + "+z+" + \"&socNet=1\";"+this.ObjectName+".RefreshCombo("+i+", \""+z+"\");document.productform.att_prod_coul.value="+z+";void(0);' title='"+this.AttArbo[z][1]+"'>");
						document.write("<img src='/e_commerce/ximg/shim.gif' alt='"+this.AttArbo[z][1]+"'>");
						document.write("</a>");
					}else{
						// Rajouter le png transparent de non dispo
						//document.write("<img src='/e_commerce/ximg/shim.gif'>");
						document.write("<div class='attrib_size_cross'>&nbsp;</div>");
					}
					document.write("</div>");
					j++;
				}
			}
		}
	}
}

CAttribut.prototype.DisplayText = function (AttributID) {
	var Opts = "";
	
	for(i=0; i<this.AttArboDef.length; i++){
		if(AttributID == this.AttArboDef[i][0]){
			var j=0;
			
			document.write("<ul id='size_filter_list'>");
			for(var z in this.AttArboDef[i][2]){
				if(isNaN(z)) continue;
				var s = "";
				if(j == 6){
					j = 0;
					s = "clear:left";
				}
				document.write("<li style='"+s+"'>");
				//document.write("<a class='main_link' href='javascript:"+this.ObjectName+".RefreshCombo("+i+", \""+this.AttArboDef[i][2][z][0]+"\");void(0);'>");
				//document.write("<img class='png' id='cross_"+i+"_"+this.AttArboDef[i][2][z][0]+"' src='"+this.ProductsImagesPath+"/attribut/cross.png' style='position:absolute;left:0;top:0;z-index:500'>");
				//document.write("<img class='png' id='pastille_"+i+"_"+this.AttArboDef[i][2][z][0]+"' src='"+this.ProductsImagesPath+"/attribut/nocross.png' style='position:absolute;left:0;top:0;z-index:501'>");
				
				//document.write();
				
				document.write("<div class='attrib_size_cross' id='cross_"+i+"_"+this.AttArboDef[i][2][z][0]+"'></div>");
				document.write("<a class='attrib_link' style='top: 0 !important;' id='pastille_"+i+"_"+this.AttArboDef[i][2][z][0]+"' href='javascript:"+this.ObjectName+".RefreshCombo("+i+", \""+this.AttArboDef[i][2][z][0]+"\");void(0);'>"+this.AttArboDef[i][2][z][1]);
				document.write("<img src='/e_commerce/ximg/shim.gif' style='top: 2px !important;'>");
				document.write("</a>");
				document.write("</li>");
				
				j++;
			}
			document.write("</ul>");
		}
	}
}

CAttribut.prototype.DisplayText2 = function (AttributID) {
	var Opts = ""
	
	for(i=0; i<this.AttArboDef.length; i++){
		if(AttributID == this.AttArboDef[i][0]){
			var j=0;
			
			document.write("<ul id='length_filter_list' style='display: none;'>");
			for(var z in this.AttArboDef[i][2]){
				if(isNaN(z)) continue;
				var s = "";
				if(j == 1){
					j = 0;
					s = "clear:left";
				}
				document.write("<li style='"+s+"'>");
				//document.write("<a href='javascript:"+this.ObjectName+".RefreshCombo("+i+", \""+this.AttArboDef[i][2][z][0]+"\");void(0);'>");
				
				//document.write("<img class='png' id='cross_"+i+"_"+this.AttArboDef[i][2][z][0]+"' src='"+this.ProductsImagesPath+"/attribut/cross.png' style='position:absolute;left:0;top:0;z-index:500'>");
				//document.write("<img class='png' id='pastille_"+i+"_"+this.AttArboDef[i][2][z][0]+"' src='"+this.ProductsImagesPath+"/attribut/nocross.png' style='position:absolute;left:0;top:0;z-index:501'>");
				
				//document.write("<a class='attrib_length_link' id='cross_"+i+"_"+this.AttArboDef[i][2][z][0]+"'><img src='/e_commerce/ximg/shm.gif'></a>");
				
				//document.write(this.AttArboDef[i][2][z][1]);
				//document.write("</a>");
					document.write("<div class='attrib_size_cross' id='cross_"+i+"_"+this.AttArboDef[i][2][z][0]+"'></div>");
					document.write("<a class='attrib_link' id='pastille_"+i+"_"+this.AttArboDef[i][2][z][0]+"' href='javascript:"+this.ObjectName+".RefreshCombo("+i+", \""+this.AttArboDef[i][2][z][0]+"\");void(0);'>"+this.AttArboDef[i][2][z][1]+"</a>");
				document.write("</li>");
				
				j++;
			}
			document.write("</ul>");
		}
	}
}

/* debug function */
function DumpArbo(Arbo, level){
	var s_level = "---";
	for(i=0; i<level; i++) s_level += "---";
	for(var i in Arbo){
		document.write(s_level + " " + Arbo[i][1] + " ("+ i +")<br>");
		//for(var j in Arbo[i][2])
			//document.write(s_level + " > " + Arbo[i][2][j] + "<br>");
		if(Arbo[i][0].length) DumpArbo(Arbo[i][0], level+1);
	}
}
//DumpArbo(C.AttArbo, 0)

function KitController (ObjectName, pagesURL){
	this.ObjectName = ObjectName;
	this.elems = new Array;
	this.BaseValue = 0;
	this.Value = 0;	
	this.PriceTag = "";
	this.Devise = "EUR";
}
KitController.TypeMandatory = 1;
KitController.TypeAlternative = 2;
KitController.TypeOption = 3;

KitController.prototype.AddMandatory = function (value, AttObject){
	var nid = this.elems.length;
	this.elems[nid] = new Array;
	this.elems[nid][0] = KitController.TypeMandatory;
	this.elems[nid][1] = value;
	this.elems[nid][2] = AttObject;
	
	this.BaseValue += value;
}

KitController.prototype.AddElem = function (value, AttObject, CheckInput, Type, Groupe){
	var nid = this.elems.length;
	this.elems[nid] = new Array;
	this.elems[nid][0] = Type;
	this.elems[nid][1] = value;
	this.elems[nid][2] = AttObject;
	this.elems[nid][3] = CheckInput;	
	this.elems[nid][4] = Groupe;
	this.elems[nid][5] = document.getElementById(CheckInput).checked;
	
	/*** add handler on the product's checkbox ***/
	/*var FnName = (Type == KitController.TypeAlternative)? "AlternativeCheck" : "OptionCheck" ;
	eval("document.getElementById('"+CheckInput+"').onclick = " + this.ObjectName + "." + FnName);*/
}

KitController.prototype.AddAlternative = function (value, AttObject, CheckInput, Groupe){
	this.AddElem(value, AttObject, CheckInput, KitController.TypeAlternative, Groupe)
}

KitController.prototype.AddOption = function (value, AttObject, CheckInput){
	this.AddElem(value, AttObject, CheckInput, KitController.TypeOption, 0)
}

KitController.prototype.CalcValue = function(e){
	/*** locate elem ***/
	var elem = null;
	if(e){
		for(i=0; i<this.elems.length; i++){
			if(this.elems[i][0] == KitController.TypeMandatory) continue;
			if(this.elems[i][3] == e.id){
				elem = this.elems[i];
				break;
			}
		}
	}

	/*** calc total value ***/
	this.Value = this.BaseValue;
	for(i=0; i<this.elems.length; i++){
		if(this.elems[i][0] == KitController.TypeAlternative){//if good elem type
			if(elem != null && elem[0] == KitController.TypeAlternative && elem[4] == this.elems[i][4]){
				/*** if elem is alternative and same group
					 adding elem value, and check it. uncheck other group elem
				***/
				if(elem[3] == this.elems[i][3]){//if good elem
					this.elems[i][5] = true;
				}else{
					this.elems[i][5] = false;
				}
			}
			if(this.elems[i][5]){
				this.Value += this.elems[i][1];
				this.Value += this.elems[i][2].Majoration;
			}

		}else if(this.elems[i][0] == KitController.TypeOption){
			if(elem != null && elem[0] == KitController.TypeOption && elem[3] == this.elems[i][3]){
				if(e.checked){
					this.elems[i][5] = true;
				}else{
					this.elems[i][5] = false;
				}
			}
			if(this.elems[i][5]){
				this.Value += this.elems[i][1];
				this.Value += this.elems[i][2].Majoration;
			}
		}
	}
	
	this.Value = Math.round(this.Value*100)/100;

	document.getElementById(this.PriceTag).innerHTML = this.Value + " " + this.Devise;
}

KitController.prototype.AlternativeCheck = function (e){
	//if (!e){e = window.event;e = e.srcElement;}else{e = e.target;}
	this.CalcValue(e);
}

KitController.prototype.OptionCheck = function (e){
	//if (!e){e = window.event;e = e.srcElement;}else{e = e.target;}
	this.CalcValue(e);
}