var busy=false;

function AddD2ShopCartWithConfirmation(form, n, catentryIdList, productId, nbrArtPan, destockCatgroupId, destockFfmcenterId){	
	var executeCmd=false;
	if (!busy) {
		busy=true;
		var storeId=form.storeId.value;
		var langId=form.langId.value;
		var catalogId=form.catalogId.value; 
		var justAddedItems = '-';
		var ahref='/webapp/wcs/stores/servlet/OrderItemAdd?calculateOrder=1&storeId='+storeId+'&langId='+langId+'&catalogId='+catalogId+'&URL=AddToBagView&productId='+productId+'&limitedCart=false';
		for(var i=0;i<n;i++) {		
			if(document.getElementById("quantity")){
				var quant=document.getElementById("quantity").value;
				if(quant > 0){
					ahref += '&catEntryId_' + i + '='+catentryIdList[i] + '&quantity_' + i + '=' + quant+ '&field2_' + i + '=' + destockCatgroupId;

					if(destockFfmcenterId) {
						ahref += '&field1_' + i + '=' + destockFfmcenterId ;
					}
					executeCmd=true;
					justAddedItems += catentryIdList[i]+'-';
				}
				else
					return;	
			} else if(document.getElementById('qty_'+i)) {
				var quant=document.getElementById('qty_'+i).value;
				if(quant > 0){
					ahref+='&catEntryId_'+i+'='+catentryIdList[i]+'&quantity_'+i+'='+quant+ '&field2_' + i + '=' + destockCatgroupId;
					
					if(destockFfmcenterId) {
						ahref += '&field1_' + i + '=' + destockFfmcenterId ;
					}
					executeCmd=true;
					justAddedItems += catentryIdList[i]+'-';
				}
			}
		}
		ahref += '&justAddedItems='+justAddedItems;

		var justAddedServices = '-';
		/*// [ATTENTION : BUG ?]
		for(var j=0;j<5;j++){
			for(var i=0;i<n;i++){
				if(document.getElementById('service_'+i+'_'+j) && document.getElementById('service_'+i+'_'+j).checked){
					var services=document.getElementById('service_'+i+'_'+j).value;
					ahref+='&services_'+i+'_'+j+'='+services;
					executeCmd=true;
					justAddedServices += services+'-';
				} 
			}
		}*/
		$("#product_form input.xSellServiceProposal:checked").each(function() {
			var service = $(this).val();
			ahref+='&'+ $(this).attr('id') + '='+ service;
			executeCmd=true;
			justAddedServices += service + '-';
		});
		
		
		if(!executeCmd){
			// ahref='ProductDisplayView?storeId='+storeId+'&langId='+langId+'&catalogId='+catalogId+'&catentryId='+productId;
			ahref='/webapp/wcs/stores/servlet/AddToBagView?storeId='+storeId+'&langId='+langId+'&catalogId='+catalogId+'&productId='+productId+'&limitedCart=false';
		}	  
		ahref += '&justAddedServices='+justAddedServices;
		
		if(destockFfmcenterId) {
			ahref += '&isDestock=1&destockFfmcenterId='+destockFfmcenterId;
		}
		//alert(ahref); return;
		
		masqueShow();
		initPopin();//dans scripts/popin.js
		showPopin();//dans scripts/popin.js

		var maCss="/webapp/wcs/stores/servlet/Conforama/css/general/neutre/color.css";
		var maLangCss="/webapp/wcs/stores/servlet/Conforama/css/fr_FR/neutre/color.css";
		$("#cssColorTemp").attr("href", maCss);
		$("#cssColorLangTemp").attr("href", maLangCss);
		window.location="#header";	
		$("#layerPopin").load(ahref, function(){$("#loading").hide();loadAll2();});

		busy=false;
	} 
}

function popupWindow(url) {
	newwindow=window.open(url,'name','height=600,width=800,resizable=yes,scrollbars=yes');
	if (window.focus)
		newwindow.focus();
}

function goToShop(ahref){
	busy=false;	
	var maCss="/webapp/wcs/stores/servlet/Conforama/css/general/neutre/color.css";
	var maLangCss="/webapp/wcs/stores/servlet/Conforama/css/fr_FR/neutre/color.css";
	$("#cssColorTemp").attr("href", maCss);
	$("#cssColorLangTemp").attr("href", maLangCss);		
	$("#contentPopin").hide();
	$("#loading").show();
	busy=false;
}

function showLoadingAndSubmitForm(){ 
   busy=true;
   masqueShow();
   initPopin();//dans scripts/popin.js
   showPopin();//dans scripts/popin.js
   var maCss="/webapp/wcs/stores/servlet/Conforama/css/general/neutre/color.css";
   var maLangCss="/webapp/wcs/stores/servlet/Conforama/css/fr_FR/neutre/color.css";
   $("#cssColorTemp").attr("href", maCss);
   $("#cssColorLangTemp").attr("href", maLangCss);
   window.location="#header";	
   $("#loading").show();
   busy=false;
}

function submitForm(formName) {
	document.forms[formName].submit();
}

var busyPopin=false;
function AddD2ShopCartWithConfirmationPopin(storeId, langId, catalogId, n, catentryIdList, productId, nbrArtPan, destockCatgroupId, destockFfmcenterId){
	var executeCmd=false;
	if (!busyPopin) {
		busyPopin=true;
		var ahref='/webapp/wcs/stores/servlet/OrderItemAdd?calculateOrder=1&storeId='+storeId+'&langId='+langId+'&catalogId='+catalogId+'&URL=AddToBagView&productId='+productId+'&limitedCart=false';
		for(var i=0;i<n;i++) {		
			if(document.getElementById("quantity")){
				var quant=document.getElementById("quantity").value;
				if(quant > 0){
					ahref+='&catEntryId_'+i+'='+catentryIdList[i]+'&quantity_'+i+'='+quant+ '&field2_' + i + '=' + destockCatgroupId;
					
					if(destockFfmcenterId) {
						ahref += '&field1_' + i + '=' + destockFfmcenterId ;
					}
					
					executeCmd=true;
				}
				else
					return;	
			} else if(document.getElementById('qty_'+i)) {
				var quant=document.getElementById('qty_'+i).value;
				if(quant > 0){
					ahref+='&catEntryId_'+i+'='+catentryIdList[i]+'&quantity_'+i+'='+quant+ '&field2_' + i + '=' + destockCatgroupId;
					
					if(destockFfmcenterId) {
						ahref += '&field1_' + i + '=' + destockFfmcenterId ;
					}
					
					executeCmd=true;
				}
			} 
		}

		var justAddedServices = '-';
		// [ATTENTION : BUG ?]
		for(var j=0;j<5;j++){
			for(var i=0;i<n;i++){
				if(document.getElementById('popinservice_'+i+'_'+j) && document.getElementById('popinservice_'+i+'_'+j).checked){
					var services=document.getElementById('popinservice_'+i+'_'+j).value;
					ahref+='&services_'+i+'_'+j+'='+services;
					executeCmd=true;
					justAddedServices += services+'-';
				} 
			}
		}
		if(!executeCmd){
			ahref='/webapp/wcs/stores/servlet/AddToBagView?storeId='+storeId+'&langId='+langId+'&catalogId='+catalogId+'&productId='+productId+'&limitedCart=false';
		}	  
		ahref += '&justAddedServices='+justAddedServices;
		
		if(destockFfmcenterId) {
			ahref += '&isDestock=1&destockFfmcenterId='+destockFfmcenterId;
		}
		
		var maCss="/webapp/wcs/stores/servlet/Conforama/css/general/neutre/color.css";
		var maLangCss="/webapp/wcs/stores/servlet/Conforama/css/fr_FR/neutre/color.css";
		$("#cssColorTemp").attr("href", maCss);
		$("#cssColorLangTemp").attr("href", maLangCss);
		window.location="#header";	
		$("div.popin").hide();
		$("#layerPopin").load(ahref, function(){$("div.popin").show();$("#loading").hide();loadAll2();});
		busyPopin=false;
	} 
	//}
}