//src=listbox
//num=indexname of composant (ex: "" = main page, "2" popup page)

/**
 * Dynamic behavior of elements of product page in function of the selected variant
 * num = 2 in case of call from the popup "size - quantity"
 * hideButtonAddToCart : used for countries - the add to cart button is not clickable after	page load if there are several variants
 * numberOfvariants : given only in countries - else it ias calculated from combo box
 * index : index of selected variant - same thing, it is given only in countries
 */
function displayPrice(src,num, hideButtonAddToCart, numberOfvariants, index) {
	var indexStore = index;
	
	if (numberOfvariants==undefined || index==undefined) {
		//get index 
		index = 0; 
		numberOfvariants = 1;
	    try {
	       if (src.length!=undefined) numberOfvariants = src.length;
	    } catch (e) {
	       numberOfvariants=1;
	    }

	    if (numberOfvariants==undefined) {
	    	numberOfvariants = 1;
	    }
	    
		if(numberOfvariants == 1){
			index = 1;
		} else {
			index = src.selectedIndex;
		}
		indexStore = index;
	}

	// flags to determine if we have to displays some elements on the page
	var displayPrice = true;
	var displayAvailability = false;
	var displayNonAvailability = false;
	var displayPartiallyAvailable = false;
	var displayItemButton = false;	
	var displayPromoFromThru = false;	
	var displayFromPrice = false;	
	var displayFromPricePromo = false;
	var selectedIndex = index;
	var displayEbookingButton = false;	
	
	// there is one single variant or one variant has been selected on the list
	if(numberOfvariants == 1 || index != 0){
	
		// one variant : no choose of the variant - set the index to 1 to display values.
		if (numberOfvariants == 1) {
			index = 1;
		}
		
		displayPrice = true;
		displayFromPrice = false;
		displayFromPricePromo = false;
		// availability
		maxDelay = MAXDELAY[index];
		if (maxDelay != 0 && maxDelay != undefined) {
			displayAvailability = true;
			displayItemButton = true;
		}
		else {
			displayNonAvailability = true;
			displayItemButton = false;
		}
		hideButtonAddToCart = false;
		indexStore = index;
	}
	// several variants and no one has been selected : 
	// displays price if all variants prices are equals
	// displays availability if all variants availabilities are equals
	else {
        // set the index to 1 to display values from 1st variant
        // the code below will determine if we have to display the data or not
        index = INDEXMINPRICE;
        indexStore = INDEXMINPRICESTORE;
        displayFromPrice = !ALLPRICESEQUALS;
		displayFromPricePromo = !ALLPROMOEQUALS;
        
        displayPrice = true;
        maxDelay = MAXDELAY[0];
        if (num==2) {
            displayItemButton = false;
        } else {    
            displayItemButton = true;
        }
        
        // model is not available
        if (modelAvailability == "U") {
       		displayNonAvailability = true;
        	displayItemButton = false;
        }
        
        else {
        	if (num=="") displayItemButton=true;
        	// model available
        	if (modelAvailability == "A") {
        		displayAvailability = true;
        	}
        	// model partially available
        	else {
        		displayPartiallyAvailable = true;
        	}
        }
   	}
	
	// Undefined taille
	if (document.getElementById('TsMemoTaille2') != undefined && document.getElementById('TsMemoTaille2').value == '...') {
		displayItemButton = false;
	}
	
	// -----------
	// init values
	// -----------
		
	// displays the product price
	if (displayPrice) {
		if (PROMOPRICES[index]) {
			// PROMO
			var oldPrice = PRICES[index];
			var newPrice = PROMOPRICES[index];
			var promoPercentage = PROMOPERCENTAGE[index];	
			var promoPercentageRaw = PROMOPERCENTAGERAW[index];		
			var promoFromDate = PROMOFROMDATES[index];
			var promoThruDate = PROMOTHRUDATES[index];
			var promoType  = PROMOTYPE[index]
			var deee = DEEE[index];
						
			//set values
			document.getElementById('old_price'+num).innerHTML = oldPrice;
			if (document.getElementById('old_price_insert_price_old'+num) != undefined)
				document.getElementById('old_price_insert_price_old'+num).innerHTML = oldPrice;
			document.getElementById('new_price'+num).innerHTML = newPrice;
			document.getElementById('price'+num).innerHTML = newPrice;
			if (document.getElementById('price_insert_price_old'+num) != undefined)
				document.getElementById('price_insert_price_old'+num).innerHTML = newPrice;
			document.getElementById('promo_percentage'+num).innerHTML = promoPercentage;
			if (document.getElementById('promo_percentage_raw'+num) != undefined)
				document.getElementById('promo_percentage_raw'+num).innerHTML = promoPercentageRaw;
			if(deee != undefined && deee != "&nbsp;"){
				document.getElementById('deee_promo'+num).innerHTML = deee;
				document.getElementById('deee_prix'+num).innerHTML = deee;
				if (document.getElementById('deee_prix_insert_price_old'+num) != undefined)
					document.getElementById('deee_prix_insert_price_old'+num).innerHTML = deee;
			}

			//set display
			document.getElementById('produit_prix'+num).style.display = "none";
			document.getElementById('produit_promo'+num).style.display = "block";
			if (document.getElementById('produit_promo_insert_price_old'+num) != undefined)
				document.getElementById('produit_promo_insert_price_old'+num).style.display = "block";
			if (promoThruDate != "noEndDate"){
				document.getElementById('promo_from_date'+num).innerHTML = promoFromDate;
				if (document.getElementById('promo_from_date_insert_price_old'+num) != undefined)
					document.getElementById('promo_from_date_insert_price_old'+num).innerHTML = promoFromDate;
				document.getElementById('promo_thru_date'+num).innerHTML = promoThruDate;
				if (document.getElementById('promo_thru_date_insert_price_old'+num) != undefined)
					document.getElementById('promo_thru_date_insert_price_old'+num).innerHTML = promoThruDate;
				document.getElementById('price_delay'+num).style.display = "block";
				if (document.getElementById('produit_promo_date_internet'+num)) document.getElementById('produit_promo_date_internet'+num).style.display = "block";
			} else {
				//hide the display of the start date/end Date
				document.getElementById('price_delay'+num).style.display = "none";
				if (document.getElementById('produit_promo_date_internet'+num)) document.getElementById('produit_promo_date_internet'+num).style.display = "none";
			}
		}
		else {
			// NOT PROMO			
			var displayPrice = PRICES[index];
			var deee = DEEE[index];
			
			//set values
			if(displayPrice != undefined){
				document.getElementById('price'+num).innerHTML = displayPrice;
				if (document.getElementById('price_insert_price_old'+num) != undefined)
					document.getElementById('price_insert_price_old'+num).innerHTML = displayPrice;
			 }
			
			if(deee != undefined && deee != "&nbsp;"){
				document.getElementById('deee_prix'+num).innerHTML = deee; 
				if (document.getElementById('deee_prix_insert_price_old'+num) != undefined)
					document.getElementById('deee_prix_insert_price_old'+num).innerHTML = deee; 
			}
			
			//set display
			document.getElementById('produit_promo'+num).style.display = "none";
			if (document.getElementById('produit_promo_insert_price_old'+num) != undefined)
				document.getElementById('produit_promo_insert_price_old'+num).style.display = "none";
			document.getElementById('produit_prix'+num).style.display = "block";
		}
		
		// display the high store price
		var highStorePrice = STOREPRICES[index];
		if(highStorePrice != undefined){
			var storePriceElement = document.getElementById('price_magasin');
			if (storePriceElement != undefined){
				storePriceElement.innerHTML = highStorePrice+"*";
			}
		}

		if (document.getElementById('price_from'+num)) {
			if (displayFromPrice == false && displayFromPricePromo == false){
				document.getElementById('price_from'+num).style.display = "none";
			} else {
				document.getElementById('price_from'+num).style.display = "block";
			}
		}
		
		if (document.getElementById('price_from_insert_price_old'+num)) {
			if (displayFromPrice == false && displayFromPricePromo == false){
				document.getElementById('price_from_insert_price_old'+num).style.display = "none";
			} else {
				document.getElementById('price_from_insert_price_old'+num).style.display = "block";
			}
		}
		
		// display the price per unit (15EUR / Kg...)
		if (PERUNITPRICES[index]) {
			if( document.getElementById('unit_price') ) document.getElementById('unit_price').style.display = "block";
			if( document.getElementById('unit_price_insert_price_old') ) document.getElementById('unit_price_insert_price_old').style.display = "block";
			if( document.getElementById('unit_price_promo') ) document.getElementById('unit_price_promo').style.display = "block";
			if( document.getElementById('unit_price') ) document.getElementById('unit_price').innerHTML = PERUNITPRICES[index];
			if( document.getElementById('unit_price_insert_price_old') ) document.getElementById('unit_price_insert_price_old').innerHTML = PERUNITPRICES[index];
			if( document.getElementById('unit_price_promo') ) document.getElementById('unit_price_promo').innerHTML = PERUNITPRICES[index];
		}
		else {
			if( document.getElementById('unit_price') ) document.getElementById('unit_price').style.display = "none";
			if( document.getElementById('unit_price_insert_price_old') ) document.getElementById('unit_price_insert_price_old').style.display = "none";
			if( document.getElementById('unit_price_promo') ) document.getElementById('unit_price_promo').style.display = "none";
		}
		
		/* CORE-2283 begin */
		var localStoreSellPrice = LOCAL_STORE_SELL_PRICE[indexStore];
		var localStoreSellPriceStart = LOCAL_STORE_SELL_PRICE_START[indexStore]; 
		var localStoreSellPriceEnd = LOCAL_STORE_SELL_PRICE_END[indexStore]; 
		var localStoreStrikePrice = LOCAL_STORE_STRIKE_PRICE[indexStore];
		var localStorePercent = LOCAL_STORE_PERCENT[indexStore]; 
		var localStoreDeee = LOCAL_STORE_DEEE[indexStore]; 
		var localStoreCentral = LOCAL_STORE_CENTRAL[indexStore]; 
		var localStoreAvailable = LOCAL_STORE_AVAILABLE[indexStore];
		var localStoreDiscount = LOCAL_STORE_DISCOUNT[indexStore]; 
		var localStorePricePerUnit = LOCAL_STORE_PERUNITPRICES[indexStore];
		var localStoreHomogeneous = LOCAL_STORE_HOMOGENEOUS[indexStore]; 
		var localStoreSales = LOCAL_STORE_SALES[indexStore]; 
		var displayDiscountDate = false;
		
		/* CORE-2822 / CORE-2873 begin */
		if(localStoreSellPrice == undefined && (!ISSTORE || DISABLE_EREP)) {
			localStoreSellPrice = STOREPRICES[index];
		}
		/* CORE-2822 / CORE-2873 end */
		
		//set values
		if (document.getElementById('local_store_sell_price'+num) && localStoreSellPrice != undefined) {
			document.getElementById('local_store_sell_price'+num).innerHTML = localStoreSellPrice;
		}else{
			if (document.getElementById('price_mention_magasin'+num)) document.getElementById('price_mention_magasin'+num).style.display = "none";
		}
		if(localStoreDiscount == "true"){
			if (document.getElementById('local_store_strike_price'+num) && localStoreStrikePrice != undefined) {
				document.getElementById('local_store_strike_price'+num).innerHTML = localStoreStrikePrice;
			}
			if (document.getElementById('local_store_sell_price_start'+num) && localStoreSellPriceStart != undefined
				&& document.getElementById('local_store_sell_price_end'+num) && localStoreSellPriceEnd != undefined) {
				document.getElementById('local_store_sell_price_start'+num).innerHTML = localStoreSellPriceStart;
				document.getElementById('local_store_sell_price_end'+num).innerHTML = localStoreSellPriceEnd;
				displayDiscountDate = true;
			}
			if (document.getElementById('local_store_percent'+num) && localStorePercent != undefined) {
				document.getElementById('local_store_percent'+num).innerHTML = localStorePercent;
			}
		}
		if (document.getElementById('local_store_deee'+num) && localStoreDeee != undefined) {
			document.getElementById('local_store_deee'+num).innerHTML = localStoreDeee;
		}
		if (document.getElementById('unit_price_magasin'+num) && localStorePricePerUnit != undefined) {
			document.getElementById('unit_price_magasin'+num).innerHTML = localStorePricePerUnit;
		}
		
		//set display
		if(localStoreDiscount == "true"){
			if (document.getElementById('produit_promo_magasin'+num)) document.getElementById('produit_promo_magasin'+num).style.display = "block";
			if(localStoreSales == "true"){
				if (document.getElementById('local_store_sales_mention'+num)) document.getElementById('local_store_sales_mention'+num).style.display = "block";
			}else{
				if (document.getElementById('local_store_sales_mention'+num)) document.getElementById('local_store_sales_mention'+num).style.display = "none";
				if(displayDiscountDate){
					if (document.getElementById('produit_promo_date_magasin'+num)) document.getElementById('produit_promo_date_magasin'+num).style.display = "block";
				}else{
					if (document.getElementById('produit_promo_date_magasin'+num)) document.getElementById('produit_promo_date_magasin'+num).style.display = "none";
				}				
			}
		}else{
			if (document.getElementById('produit_promo_date_magasin'+num)) document.getElementById('produit_promo_date_magasin'+num).style.display = "none";
			if (document.getElementById('produit_promo_magasin'+num)) document.getElementById('produit_promo_magasin'+num).style.display = "none";
			if (document.getElementById('local_store_sales_mention'+num)) document.getElementById('local_store_sales_mention'+num).style.display = "none";
		}

		if((localStoreAvailable == undefined || localStoreAvailable != "true") && ISSTORE){
			displayEbookingButton = false;
			if (document.getElementById('no_available_magasin'+num)) {
				document.getElementById('no_available_magasin'+num).style.display = "block";
				setClass("no_available no_available_active",document.getElementById('no_available_magasin'+num));
			}
		}else{			
			displayEbookingButton = true;
			if (document.getElementById('no_available_magasin'+num)) { 
				document.getElementById('no_available_magasin'+num).style.display = "none";
				setClass("no_available no_available_inactive",document.getElementById('no_available_magasin'+num));
			}
		}
		
		if(localStoreHomogeneous == "false"){
			if (document.getElementById('price_from_magasin'+num)) document.getElementById('price_from_magasin'+num).style.display = "block";
		}else{			
			if (document.getElementById('price_from_magasin'+num)) document.getElementById('price_from_magasin'+num).style.display = "none";
		}
		/* CORE-2283 end */
	}
	else {
		//set values
		document.getElementById('price'+num).innerHTML = "";
		if (document.getElementById('price_insert_price_old'+num) != undefined)
			document.getElementById('price_insert_price_old'+num).innerHTML = "";
		//set display
		document.getElementById('produit_promo'+num).style.display = "none";
		if (document.getElementById('produit_promo_insert_price_old'+num) != undefined)
			document.getElementById('produit_promo_insert_price_old'+num).style.display = "none";
		document.getElementById('produit_prix'+num).style.display = "block";
		document.getElementById('deee'+num).style.display = "none";
		if (document.getElementById('price_from'+num)) {
			document.getElementById('price_from'+num).style.display = "none";
		}
		if (document.getElementById('price_from_insert_price_old'+num)) {
			document.getElementById('price_from_insert_price_old'+num).style.display = "none";
		}
	}

	// ----------------------------------
	// displays or not availability label
	// ----------------------------------
	
	// displays the product availability
	if (displayAvailability) {
		if (document.getElementById('itemAvailable'+num)) {
			document.getElementById('itemAvailable'+num).style.display='block';
		}
		if (document.getElementById('livraison_content'+num)) {
		var maxDelaySpan = document.getElementById('livraison_content'+num);
		maxDelaySpan.innerHTML=maxDelay;
		}
		if (document.getElementById('livraison_content_insert_price_old'+num)) {
			var maxDelaySpan_insert_price_old = document.getElementById('livraison_content_insert_price_old'+num);
			maxDelaySpan_insert_price_old.innerHTML=maxDelay;
		}
		if (document.getElementById('infosLivraison'+num)) document.getElementById('infosLivraison'+num).style.display='block';
		if (document.getElementById('infosLivraison_insert_price_old'+num) != undefined)
			document.getElementById('infosLivraison_insert_price_old'+num).style.display='block';
		if (document.getElementById('info_livraison_internet'+num) != undefined)
			document.getElementById('info_livraison_internet'+num).style.display='block';
		if (selectedIndex == 0 && numberOfvariants > 1) {
			if (document.getElementById('infosLivraison'+num))
			setClass("livraison no-selection",document.getElementById('infosLivraison'+num));
			if (document.getElementById('infosLivraison_insert_price_old'+num) != undefined)
				setClass("livraison no-selection",document.getElementById('infosLivraison_insert_price_old'+num));
		}
		else {
			if (document.getElementById('infosLivraison'+num))
			setClass("livraison",document.getElementById('infosLivraison'+num));
			if (document.getElementById('infosLivraison_insert_price_old'+num) != undefined)
				setClass("livraison",document.getElementById('infosLivraison_insert_price_old'+num));
		}
	}
	else {
		if (document.getElementById('itemAvailable'+num)) {
			document.getElementById('itemAvailable'+num).style.display='none';
		}
	}

	// displays the product non-availability
	if (displayNonAvailability) {
		if (document.getElementById('dispo-main')) {
			document.getElementById('dispo-main').style.display='block';
		}
		if (document.getElementById('itemNotAvailable'+num)) {
			document.getElementById('itemNotAvailable'+num).style.display='block';
		}
		if (document.getElementById('infosLivraison'+num)) {
		document.getElementById('infosLivraison'+num).style.display='block';
		setClass("livraison-nondispo",document.getElementById('infosLivraison'+num));
		}
		if (document.getElementById('infosLivraison_insert_price_old'+num) != undefined) {
			document.getElementById('infosLivraison_insert_price_old'+num).style.display='block';
			setClass("livraison-nondispo",document.getElementById('infosLivraison_insert_price_old'+num));
		}
		if (document.getElementById('info_livraison_internet'+num) != undefined)
			document.getElementById('info_livraison_internet'+num).style.display='none';
		if (document.getElementById('no_available_internet'+num) != undefined)
			document.getElementById('no_available_internet'+num).style.display = "block";	
		setClass("no_available_link active_link", document.getElementById('no_available_link'+num));
	}
	else {
		if (document.getElementById('itemNotAvailable'+num)) {
			document.getElementById('itemNotAvailable'+num).style.display='none';
		}
		if (document.getElementById('no_available_internet'+num) != undefined)
			document.getElementById('no_available_internet'+num).style.display = "none";	
		setClass("no_available_link inactive_link", document.getElementById('no_available_link'+num));
	}
	
	// displays the product Partially Available
	if (displayPartiallyAvailable) {
		if (document.getElementById('itemPartiallyAvailable'+num)) {
			document.getElementById('itemPartiallyAvailable'+num).style.display='block';
		}
		if (document.getElementById('infosLivraison'+num)) document.getElementById('infosLivraison'+num).style.display='block';
		if (document.getElementById('infosLivraison_insert_price_old'+num))
			document.getElementById('infosLivraison_insert_price_old'+num).style.display='block';
		if (document.getElementById('info_livraison_internet'+num) != undefined)
			document.getElementById('info_livraison_internet'+num).style.display='block';
		if (document.getElementById('infosLivraison'+num)) setClass("livraison-nondispo",document.getElementById('infosLivraison'+num));
		if (document.getElementById('infosLivraison_insert_price_old'+num) != undefined)
			setClass("livraison-nondispo",document.getElementById('infosLivraison_insert_price_old'+num));
	}
	else {
		if (document.getElementById('itemPartiallyAvailable'+num)) {
			document.getElementById('itemPartiallyAvailable'+num).style.display='none';
		}
	}	
	
	if (!displayAvailability && !displayNonAvailability ){
		if (document.getElementById('infosLivraison'+num)) document.getElementById('infosLivraison'+num).style.display='none';
		if (document.getElementById('infosLivraison_insert_price_old'+num) != undefined)
			document.getElementById('infosLivraison_insert_price_old'+num).style.display='none';
		if (document.getElementById('info_livraison_internet'+num) != undefined)
			document.getElementById('info_livraison_internet'+num).style.display='none';
	}
			
	// ------------------------------------------------
	// display or not the add item button (add to cart)
	// ------------------------------------------------	
	var addToCartDiv = document.getElementById("addItemButton"+num);
	
	if (addToCartDiv) {
		
		if (displayItemButton && ISSELLABLE!=false && ONLINEBUYABLE!=false && !hideButtonAddToCart) {
		    setClass("ajoutPanier", addToCartDiv);
				
		    var addToCartLink = addToCartDiv.getElementsByTagName('A')[0];
		    if (!_notAddInCartTips) {
		      
		      try {
		          if (document.getElementById("tooltip-addcart-text"+num)) document.getElementById("tooltip-addcart-text"+num).innerHTML=_messageAddToCart;
		      } catch(e){
		          addToCartLink.title = _messageAddToCart;
		      };
		    } else {
		      	setClass("ajoutPanier inactive not-add-incart", addToCartDiv);
		    }
		}
		else {
			setClass("ajoutPanier inactive", addToCartDiv);
			
	        var addToCartLink = addToCartDiv.getElementsByTagName('A')[0];
	        if (!_notAddInCartTips) {
	           try {
	               if (document.getElementById("tooltip-addcart-text"+num)) document.getElementById("tooltip-addcart-text"+num).innerHTML=_messageChooseSize;
	           } catch(e){
	               addToCartLink.title = _messageChooseSize;
	           };
	        }
		}
	}

	// ------------------------------------------------
	// display or not the add eBooking button (add to ebooking cart)
	// ------------------------------------------------	
	var addToEbookingCartDiv = document.getElementById("addEbookingButton"+num);
	if (addToEbookingCartDiv) {	
		// JIRA CORE-2798 
		if (((!DISABLE_EREP || (DISABLE_EREP && localStoreAvailable))) && ((displayEbookingButton && ISEBOOKABLE!=false && !hideButtonAddToCart) || (ISSTORE!=true && ISEBOOKABLE!=false && !hideButtonAddToCart))) {
		    setClass("addEbookingCart", addToEbookingCartDiv);
		} else {
			//if(ISSTORE!=false){
				setClass("addEbookingCart eBookingInactive", addToEbookingCartDiv);
				if(!DISABLE_EREP){
					var addToEbookingCartLink = addToEbookingCartDiv.getElementsByTagName('A')[0];
					try {
		                document.getElementById("tooltip-addebookingcart-text"+num).innerHTML=_messageChooseSize;
		            } catch(e){
		                addToEbookingCartLink.title = _messageChooseSize;
		            };
	            }
			//}
		}
	}

	// Change css if the integer part is greater or equals than 4
	if(priceIsGreaterThan(document.getElementById('price'+num).innerHTML, 3)){
		setClass("smallPrice",document.getElementById('price'+num));
	}
	if(document.getElementById('local_store_sell_price'+num) != undefined && priceIsGreaterThan(document.getElementById('local_store_sell_price'+num).innerHTML, 3)){
		setClass("smallPrice",document.getElementById('local_store_sell_price'+num));
	}
	manageFinalDiscountPrice(promoType,promoFromDate,promoThruDate);
}

//Modify quantity add value(pQuantity) in textbox
//ex : ModifyQuantity(pId, -1) to decrement the value
//Value min in the textbox = 0
function ModifyTheQuantity(pId, pQuantity) {
	if (document.getElementById(pId).value == parseInt(document.getElementById(pId).value)){
		var _qty=parseInt(document.getElementById(pId).value)+pQuantity;
		if (_qty<0) {
			document.getElementById(pId).value = 0;
			
		} else {
			document.getElementById(pId).value = _qty;
		}
	}
}

//Modify quantity set value(pQuantity) in textbox
//ex : ModifySetQuantity(pId, 18) to set the value
//Value min in the textbox = 0
function ModifySetQuantity(pId, pQuantity) {
	if (pQuantity<0) {
		document.getElementById(pId).value = 0;
	} else {
		document.getElementById(pId).value = pQuantity;
	}
}

// validate the list quantity in the listbox
// if ok -> submit
function validateListQtyProductModel() {
	if (document.getElementById('popupquantity').value == parseInt(document.getElementById('popupquantity').value)){
		if ((document.getElementById('TsMemoTaille2').value != '...') && (parseInt(document.getElementById('popupquantity').value) > 0)){
			var _name_input_quantity= '_' + document.getElementById('TsMemoTaille2').value + '_quantity';
			
			//in product page: more 1 same id then get all by name 
			var liste = document.getElementsByName(_name_input_quantity);
			for(i=0;i<liste.length;i++){
				liste[i].value=parseInt(document.getElementById('popupquantity').value);
			}
			//$HidePopup(); 
			document.popupaddform.submit();
		}
	}
}

function multiClass(eltId) {
	arrLinkId = new Array('onglet-0','onglet-1','onglet-2','onglet-3');
	intNbLinkElt = new Number(arrLinkId.length);
	arrClassLink = new Array('selected','normal');
	strContent = new String()
	for (i=0; i<intNbLinkElt; i++) {
		strContent = "bloc-"+arrLinkId[i];
		if ( arrLinkId[i] == eltId ) {
			document.getElementById(arrLinkId[i]).className = arrClassLink[0];
			document.getElementById(strContent).className = 'tableau-details-contenu on';
		} else {
			if (document.getElementById(arrLinkId[i])!=null && document.getElementById(strContent)!=null){
			document.getElementById(arrLinkId[i]).className = arrClassLink[1];
			document.getElementById(strContent).className = 'tableau-details-contenu off';
			}
		}
	}
}


// Redefinition of functions since this script is called on page load
function $n(o) {
    return (typeof o=='string') ? o=document.getElementById(o) : o;
}
function setVisible(elt)
{
  if( !$n(elt) ) {return false};
  
  $n(elt).style.display = 'block';
  $n(elt).style.visibility = 'visible';
}
function setInvisible(elt)
{
  if(!$n(elt)) {return false};
  
  $n(elt).style.display = 'none';
  $n(elt).style.visibility = 'hidden';
}
function setClass(className, element)
{
    var elt = $n(element);
    if(!elt) {return false;}
    elt.className = className;
}

function displayPriceLine(src,num, withprice) {
	document.getElementById('availableList'+num).selectedIndex = src.selectedIndex;
	document.getElementById('available'+num).innerHTML = document.getElementById('availableList'+num).options[src.selectedIndex].text;
	
	if (displayPriceLine.arguments.length==3 && withprice) {
		document.getElementById('priceList'+num).selectedIndex = src.selectedIndex;
		document.getElementById('price'+num).innerHTML = document.getElementById('priceList'+num).value;
	}
	displayAddItemButtonPopup();
}

function displayAddItemButtonPopup() {
	nbLine = document.getElementById('nbProductLine').value;
	
	var showButton = true; 
	
	for (i=1; i<=nbLine; i++) {
		if (document.getElementById('availableList'+i).value != "A") {
			showButton = false;
		}
	}
	if (showButton == true ) {
		setVisible("addItemButtonPopup");
	} else {
		setInvisible("addItemButtonPopup");
	}	
}

function priceIsGreaterThan(displayPrice, integerLimit){
	var result = false;
	if(displayPrice != undefined){
		var temp0 = new Array();	
		temp0 = displayPrice.split('</span>');
		var temp = new Array();	
		if(temp0.length > 1 ){
			temp = temp0[1].split(',');
		}else{
			temp = temp0[0].split(',');
		}
		if(temp.length > 0 && temp[0].length > integerLimit){
			result = true;
		}
	}
	return result;
}

function manageFinalDiscountPrice(promoType,promoFromDate,promoThruDate) {
	if (document.getElementById('finalDiscountPrice')) {		
		document.getElementById('finalDiscountPrice').style.display = "none";
	}
	if (document.getElementById('finalSalesPrice')) {
		document.getElementById('finalSalesPrice').style.display = "none";
	}
	if (document.getElementById('finalPromoPrice')) {
		document.getElementById('finalPromoPrice').style.display = "none";
	}
	if (promoType == "PURCHASE_PRICE_DISC") {
		if (promoFromDate != undefined) {		
			document.getElementById('finalDiscountPrice').style.display = "block"; 
			document.getElementById('finalDiscountPriceFromDate').innerHTML = promoFromDate;
		}		
	} else if (promoType == "PURCHASE_PRICE_PROMO") {
		if (promoFromDate != undefined && promoThruDate != "noEndDate") {		
			document.getElementById('finalPromoPrice').style.display = "block";
			document.getElementById('finalPromoPriceFromDate').innerHTML = promoFromDate;
			document.getElementById('finalPromoPriceThruDate').innerHTML = promoThruDate;
		}		
	} else if (promoType == "PURCHASE_PRICE_SALES") {
		if (promoFromDate != undefined && promoThruDate != "noEndDate") {
			document.getElementById('finalSalesPrice').style.display = "block";
			document.getElementById('finalSalesPriceFromDate').innerHTML = promoFromDate;
			document.getElementById('finalSalesPriceThruDate').innerHTML = promoThruDate;
		}
	}
}
