// JavaScript Document

function aggiungiListenerMenu() {
  $("#tabMenuVert").click(function(e) {
   e.preventDefault();
  $("#divMenuTabMobile").toggleClass("visibileLeft");
  if ($("#statusBoxMobile").hasClass("visibileRight")) {
    $("#statusBoxMobile").toggleClass("visibileRight");
  }
 });
 
 $("#showStatusBox").click(function(e) {
   e.preventDefault();
   $("#statusBoxMobile").toggleClass("visibileRight");
   if ($("#divMenuTabMobile").hasClass("visibileLeft")) {
    $("#divMenuTabMobile").removeClass("visibileLeft");
  }
 });
 
 $("#imgloggato").click(function(e) {
   e.preventDefault();
   CatalogoFiltriWidget.reloadCatalogo();
 });
 
 $("#lenteRicercaNew").click(function(e) {
   e.preventDefault();
   closeAllItemList(e);
   execFilter();
 }); 
 
 $(".lenteRicercaNewMob").click(function(e) {
   e.preventDefault();
   closeAllItemList(e);
   execFilter();
 });

 /*
 $(".scannerBarcode").click(function (e) {
     e.preventDefault();
     closeAllItemList(e);
     showScanner();
 });
*/
 
 $("#mrkSelector").change(function(e) {
   e.preventDefault();
   CatalogoFiltriWidget.ricercaXMarchioDaSelector();
 });
 
 $("#levelSelector").change(function(e) {
   e.preventDefault();
   CatalogoFiltriWidget.ricercaXLivelloDaSelector();
 });
 
}

function aggiungiListenerTabellaClienti() {
 
  $(".recordCliente").each(function(i) {
    
    $(this).click(function(e) { 
      if ($(this).attr("cliBlk") == 0 || $(this).attr("mandBlkEn") == 0){ 
		  e.preventDefault();
		  settaCliente($(this).attr("codCliente"));
	  }
  });
 });
 
 }

function aggiungiListenerTabellaClientiSconti() {
 
  $(".recordCliente").each(function(i) {
    
    $(this).click(function(e) { 
      e.preventDefault();
      copiaSconti($(this).attr("codCliente"));
  });
 });
 
 $(".btnCloseCliSconti").click(function(a) {
   a.preventDefault();
   closeDiv($(this).attr("divname"));
 });
 }
 
function aggiungiListenerBigImage() {
 
 $("#prevImageDiv").click(function(e) {
   e.preventDefault();
   showPrevImg();
 });
 
 $("#nextImageDiv").click(function(e) {
   e.preventDefault();
   showNextImg();
 });
 
 $("#bigImageDiv").click(function(e) {
   e.preventDefault();
   closeDiv("bigImageDiv");
 });
 
}

function aggiungiListenerRicercaLivelloMarchio() {

   $(".level2").each(function(i) {
     $(this).click(function(e) {
       e.preventDefault();
       if ($(this).val() != ""){
		CatalogoFiltriWidget.ricercaXLivello2($(this));
	   }
     }); 
   });
   
   $(".level1").each(function(i) {
     $(this).click(function(e) {
       //e.preventDefault();
       //CatalogoFiltriWidget.ricercaXLivello1($(this));
     }); 
   });
   $(".checkMrk").each(function(i) {
     $(this).click(function(e) {
       e.preventDefault();
       CatalogoFiltriWidget.ricercaXMarchio($(this).val());
     }); 
   });
    $(".checkLevel2").each(function (i) {
        $(this).click(function (e) {
            e.preventDefault();
            CatalogoFiltriWidget.ricercaXLivello2($(this));
        });
    });
   
}
 
function aggiungiListenerRimuoviRicerca() {
 
  $(".annullaFiltroParola").each(function(i) {
    
    $(this).click(function(e) { 
      e.preventDefault();
      var idx = CatalogoFiltriWidget.getRicercheFatte().indexOf($(this).attr("ricerca"));
      // Se annullo il primo elemento, restto anche la creazione dei filtri
      if (idx == 0) {
         CatalogoFiltriWidget.setCreaElencoFiltri(true);
         CatalogoFiltriWidget.setPrimaRicerca(true); 
         CatalogoFiltriWidget.setDescrizioneDaFiltrare("");
         // Ripulisco i marchi
         var checkMarchi = document.getElementsByName("mrkChk");
         var checkMarchiGrid = document.getElementsByName("mrkChkGrid");
         for (var i = 0; i < checkMarchiGrid.length; i++) {
           checkMarchi.push(checkMarchiGrid[i]);
         }
         for (var i = 0; i < checkMarchi.length; i++) {
           checkMarchi[i].checked = false;
         } 
         // Elimino filtri che non siano descrizioni
         do {
           for (var i = 1; i < CatalogoFiltriWidget.getRicercheFatte().length; i++) {
             if (CatalogoFiltriWidget.getRicercheFatte()[i].split(":")[0] != "D") {
               CatalogoFiltriWidget.getRicercheFatte().splice(i, 1);
               break;
             }
           }
           var esci = true;
           for (var i = 1; i < CatalogoFiltriWidget.getRicercheFatte().length; i++) {
             if (CatalogoFiltriWidget.getRicercheFatte()[i].split(":")[0] != "D") {
               esci = false;
               break;
             }
           }
         } while (!esci); 
      }
      
      var checkMarchi = document.getElementsByName("mrkChk");
      var capofilaResponse = CatalogoWidget.getCapofilaResponse(); 
      if (CatalogoFiltriWidget.getRicercheFatte().length == 0) {
        CatalogoFiltriWidget.reloadCatalogo();
      } else if (CatalogoFiltriWidget.getRicercheFatte()[idx].split(":")[0] == "D") {
        capofilaResponse.capofila = CatalogoWidget.getCapofilaPrimaRicerca();
        CatalogoWidget.setCapofilaResponse(capofilaResponse);  
        var idx2 = CatalogoFiltriWidget.getDescrizioneDaFiltrare().indexOf(CatalogoFiltriWidget.getRicercheFatte()[idx].split(":")[1]);
        CatalogoFiltriWidget.getDescrizioneDaFiltrare().splice(idx2, 1);
      } else if (CatalogoFiltriWidget.getRicercheFatte()[idx].split(":")[0] == "F") {
        capofilaResponse.capofila = CatalogoWidget.getCapofilaPrimaRicerca();
        CatalogoFiltriWidget.setLivello1($("#levelSelector").val("all"));
        CatalogoFiltriWidget.setLivello1("");
      } else if (CatalogoFiltriWidget.getRicercheFatte()[idx].split(":")[0] == "M") {
        capofilaResponse.capofila = CatalogoWidget.getCapofilaPrimaRicerca();
        var idx2 = CatalogoFiltriWidget.getArrayMarchiXRicerca().indexOf(CatalogoFiltriWidget.getRicercheFatte()[idx].split(":")[1]); 
        CatalogoFiltriWidget.getArrayMarchiXRicerca().splice(idx2, 1);
        var mrk = CatalogoFiltriWidget.getRicercheFatte()[idx].split(":")[1];
         for (var i = 0; i < checkMarchi.length; i++) {
           if ($(checkMarchi[i]).val() == mrk) {
             checkMarchi[i].checked = false;
             break;
           }
         }
      } 
      CatalogoFiltriWidget.getRicercheFatte().splice(idx, 1);
      CatalogoFiltriWidget.setRemoveRicerca(true);
      if (CatalogoFiltriWidget.getRicercheFatte().length == 0) {
        CatalogoFiltriWidget.reloadCatalogo();
      } else {
        CatalogoWidget.lanciaRicercaCapofila("");
      }
  });
 });
 
 } 
 
function aggiungiListenersShowcase() {

  $("#vetrinaImg").click(function(e) {
     e.preventDefault();
     var action = $(this).attr("action");
     if (action != "?") {
       CatalogoWidget.showArticoloVetrina();
     }
   });
   
    $("#bigImageButton").click(function(e) {
     e.preventDefault();
     closeDiv("showCaseMaster");
   }); 
   
   $("#offerteImg").click(function(e) {
     e.preventDefault();
     CatalogoWidget.vaiAOfferte();
   });
 }

 
function rimuoviListenerPromo() {
	
	$(".addCarrelloDirettoPromo").off("click");
	$(".selCkPromo").off("change");
	$(".promoSelectAll").off("click");
	$(".addCarrelloPromo").off("click");
	$(".addCarrelloDirettoPromoMobile").off("click");
	$(".tornaAPromo").off("click");
	$("#showPromoFilterMobile").off("click");
	$(".imgDetailArticoloStart").off("click");
	$(".promoImagePiccola").off("click");
	$(".btnRemovePromo").off("click");
	$(".promoTrashCan").off("click");
	$(".lenteRicercaPromo").off("click");
	$(".arrowDwPromo").off("click");
	$(".arrowUpPromo").off("click");
	$(".arrowDwPromoMobile").off("click");
	$(".arrowUpPromoMobile").off("click");
	$(".inputQtaPromo").off("click");
	$(".inputQtaPromoMobile").off("click");
	$(".btnGridPromo").off("click");
	$(".btnGridPromoMrk").off("click");
	$(".btnMostraArticoliCapofilaPromo").off("click");
  $(".tabDivisioniPromo ").off("click");
  $(".radioElencoPromo ").off("click");	
  $(".catalogoImagePromo ").off("click");	
	
}
 
function aggiungiListenersPromo() {
	
	rimuoviListenerPromo();
  $(".tabDivisioniPromo ").click(function(e) {
     e.preventDefault();
     eraseCookie("divisioneAttiva");
     createCookie("divisioneAttiva", $(this).attr("divisione"));
     if (readCookie("modoElencoPromo") != null) {
       eraseCookie("modoElencoPromo");
     }
     createCookie("modoElencoPromo", $(this).attr("modoelenco"));
     getPromo();
  });
     
  	$(".catalogoImagePromo").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		if(!CommonApis.isMobile()) {
			var immagine = $(this).attr("immagine");
			mouseOverImage(immagine);
		}
    });
  });
     
  $(".addCarrelloDirettoPromo").click(function(e) {
     e.preventDefault();
     var isMobile = false
     addPromoDirect(this, isMobile);
  });
   
  $(".selCkPromo").each(function(i) {
    $(this).change(function(e) { 
     e.preventDefault();
     setArticoloPromo(this);
     });
  });

  $(".promoSelectAll").click(function(e) {
     e.preventDefault();
     setAllArticoliCapofilaPromo(this);
  });
   
      
   $(".addCarrelloPromo").click(function(e) {
     e.preventDefault();
     var isMobile = false
     addCarrelloPromoTabella(isMobile);
   });
         
   $(".addCarrelloDirettoPromoMobile").click(function(e) {
     e.preventDefault();
     var isMobile = true
     addPromoDirect(this, isMobile);
   });
   
   //if (PromoApis.isAddListeners()) {
   $(".tornaAPromo").click(function(e) {
        e.preventDefault();
        tornaAPromo(this);
   });
   
   $("#showPromoFilterMobile").click(function(e) {
        PromoApis.setAddListeners(false);
        e.preventDefault();
        $("#optionPromoPanelFilter").toggleClass("visibileLeft");
          if ($("#optionPromoPanelFilter").position().left == 0){
	          $(".toggleViewPromoOpt").removeClass("fa-angle-double-left");
	          $(".toggleViewPromoOpt").addClass("fa-angle-double-right");
            $("#optionPromoPanelFilter").removeClass("ov-auto");  
          } else {
	          $(".toggleViewPromoOpt").removeClass("fa-angle-double-right");
            $(".toggleViewPromoOpt").addClass("fa-angle-double-left");
            $("#optionPromoPanelFilter").addClass("ov-auto");
          }
   });
  // }
   
   $(".imgDetailArticoloStart").click(function(e) {
     e.preventDefault();
     CatalogoWidget.viewCatalogoArtDetail(this);
   });
   
   
   $(".promoImagePiccola").click(function(e) {
    e.preventDefault();
    if ($("#optionPromoPanelFilter").hasClass("visibileLeft") ) {
      $("#optionPromoPanelFilter").toggleClass("visibileLeft");
    }
    viewLastPromo($(this).attr("codpromo"));
   });
   
   $(".radioElencoPromo").each(function(i) {
    $(this).click(function(e) {
      e.preventDefault();
      if (readCookie("modoElencoPromo") != null) {
        eraseCookie("modoElencoPromo");
      } 
      createCookie("modoElencoPromo", $(this).val()); 
      reloadElencoPromo(); 
    });
   });
   
   $(".btnRemovePromo").click(function(e) {
     e.preventDefault();
     var delPromo = $(this).attr("delpromo");
     var codPromo = $(this).attr("codpromo");
	 var reloadCarello = $(this).attr("reloadCarello");
     removePromo(delPromo ,codPromo, reloadCarello);
   });
    
   
   $(".promoTrashCan").click(function(e) {
     e.preventDefault();
     var codArt = $(this).attr("codpromo");
     removeArticoloPromo(codArt, false);
   });
      
   $(".lenteRicercaPromo").click(function(e) {
     e.preventDefault();
     closeAllItemList(e);
     ricercaArticoliInPromo();
   });
   
   $(".arrowDwPromo").click(function(e) {
     e.preventDefault();
     var isMobile = false
     manageQtaPromo(this, "-", isMobile);
   });
   
   $(".arrowUpPromo").click(function(e) {
     e.preventDefault();
     var isMobile = false;
     manageQtaPromo(this, "+", isMobile);
     CommonApis.setMobile(isMobile);
   });
   
   $(".arrowDwPromoMobile").click(function(e) {
     e.preventDefault();
     var isMobile = true;
     manageQtaPromo(this, "-", isMobile);
   });
   
   $(".arrowUpPromoMobile").click(function(e) {
     e.preventDefault();
     var isMobile = true
     manageQtaPromo(this, "+", isMobile);
   });
    
   $(".inputQtaPromo").click(function(e) {
     e.preventDefault();
     this.select();
   });
   
   $(".inputQtaPromoMobile").click(function(e) {
     e.preventDefault();
     this.select();
   }); 
   
   $(".btnGridPromo").each(function(a) {
     $(this).click(function(e) {
       e.preventDefault();
       var codPromo = $(this).attr("codpromo");
       var tipoElenco = $(this).attr("elencopromo");
       $(this).attr("attivo", "1");
       if ($(this).hasClass("btnElencoPromoCategoria")) {
        $(this).text('Nascondi Promo');
       } else {
        $(this).text('Nascondi Articoli');
       }
       if (tipoElenco == "E") {
         viewArticoliPromoDaGriglia(codPromo);
       } else if (tipoElenco == "C") { 
         viewPromoForLivello(codPromo);
       } else if (tipoElenco == "M") {
         viewPromoForMarca(codPromo);
       }
     });
  });

   $(".promoImage").each(function(a) {
     $(this).click(function(e) {
       e.preventDefault();
       var codPromo = $(this).attr("levelPromo");
       var tipoElenco = $(this).attr("elencopromo");
       $(this).attr("attivo", "1");
       if (tipoElenco == "E") {
         viewArticoliPromoDaGriglia(codPromo);
       } else if (tipoElenco == "C") { 
         viewPromoForLivello(codPromo);
       } else if (tipoElenco == "M") {
         viewPromoForMarca(codPromo);
       }
     });
  });
   
 $(".btnGridPromoMrk").click(function(e) {
     e.preventDefault();
     var codPromo = $(this).attr("codpromo");
     var tipoElenco = $(this).attr("elencopromo");
     $(this).attr("attivo", "1");
     $(this).text('Nascondi Promo');
     if (tipoElenco == "E") {
       viewArticoliPromoDaGriglia(codPromo);
     } else if (tipoElenco == "C") { 
       viewPromoForLivello(codPromo);
     } else if (tipoElenco == "M") {
       viewPromoForMarca(codPromo);
     }
 });
 
 $(".btnMostraArticoliCapofilaPromo").each(function(e) {
   $(this).click(function(e) { 
     e.preventDefault();
     toggleArtPromo($(this).attr("cpf"));
   });
 });	

 $(".promoArticoloCls").each(function(e) {
   $(this).click(function(e) { 
     e.preventDefault();
     var art = $(this).attr("artinpromo");
     CatalogoWidget.vaiAPromoArticolo(art);
   });
 });	



}

function aggiungiListenersCatalogoBtnApri() {

 $(".btnMostraArticoli").each(function(i) {
  $(this).click(function(e) {     
    e.preventDefault();
    CatalogoWidget.lanciaRicercaArticoliDelCapofila(this);	
  });
 });
 
}

function aggiungiListenersCatalogoDft() {
    $(".radioElencoCatalogo").each(function (i) {
        $(this).click(function (e) {
            CatalogoFiltriWidget.setDefaultCatalogoSearch($(this).val());
            CatalogoFiltriWidget.reloadCatalogo();
        });
    });
    $(".catalogoDftLevelImage").each(function (i) {
        $(this).click(function (e) {
            var livello = $(this).attr("livello");
            CatalogoFiltriWidget.ricercaXLivelloDaCtgPage(livello);
        });
    });
    $(".catalogoDftMrkImage").each(function (i) {
        $(this).click(function (e) {
            var mrk = $(this).attr("mrk");
            CatalogoFiltriWidget.ricercaXMarchioDaCtgPage(mrk);
        });
    });
    $(".tabDivisioniCatalogoDft").each(function (i) {
        $(this).click(function (e) {
            var divisione = $(this).attr("divisione");
            eraseCookie("divisioneCatalogoDft");
            createCookie("divisioneCatalogoDft", divisione, 365);
            CatalogoWidget.loadCatalogoInitialPage();
        });
    });
     $(".inizialeMarchio").each(function (i) {
        $(this).click(function (e) {
            var elements = document.getElementsByName("checkMrkCatalogoAll");
            var arrayIniziali = [];
            for (let i = 0; i < elements.length; i++) {
              if (elements[i].checked) {
                arrayIniziali.push($(elements[i]).attr("iniziale"))
              } 
            }
            CatalogoFiltriWidget.setInizialeCatalogo(arrayIniziali);
            CatalogoWidget.loadCatalogoInitialPage();
        });
    });
}

function aggiungiListenersCatalogoBtnChiudi() {

 $(".btnChiudiArticoli").each(function(i) {
  $(this).click(function(e) {     
    e.preventDefault();
    CatalogoWidget.lanciaRicercaArticoliDelCapofila(this);
  });
 }); 
 
}

function removeListenerMenu() {
	$(".prefsImg").off("click");
	$(".prefsImgMobile").off("click");
	$(".printWindow").off("click");
	$(".utenteImg").off("click");
	$(".utenteImgMobile").off("click");
	$(".myAccount").off("click");
	$(".myAccountMobile").off("click");
	$(".whatsappImg").off("click");
	$(".whatsappImgMobile").off("click");
	$("#backToTop").off("click");
	$("#ricercadesElem").off("click");
  $("#ricercadesElemMobile").off("click");
  $(".tabCatalogoCls").off("click");
	$(".tabHomeCls").off("click");
	$(".tabPromoCls").off("click");
	$(".tabCarrelloCls").off("click");
	$(".tabTrackingCls").off("click");
	$(".tabVolantiniCls").off("click");
	$(".tabMercatinoCls").off("click");
	$(".tabDocumentiCls").off("click");
	$(".tabContenutiCls").off("click");
	$(".tabScontiCls").off("click");
  $(".tabLafecoinCls").off("click");
  $(".tabConsumiCls").off("click");
  
	
}

function aggiungiListeners() {
 removeListenerMenu();
 
 $(".prefsImg").click(function(e) {
     e.preventDefault();
     $("#myAccountPrefs").addClass("display-none");
     showPrefs();
 });

 $(".prefsImgMobile").click(function(e) {
     e.preventDefault();
     $("#myAccountPrefs").addClass("display-none");
     showPrefs();
 });
   
 $(".printWindow").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault();
     window.print();
   });
 });
 
 $(".utenteImg").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
     if ($("#statusBoxMobile").hasClass("visibileRight")) {
       $("#statusBoxMobile").toggleClass("visibileRight");
     }
     cambiaCliente();
   });
 }); 
 
 $(".utenteImgMobile").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
     if ($("#statusBoxMobile").hasClass("visibileRight")) {
       $("#statusBoxMobile").toggleClass("visibileRight");
     }
     cambiaCliente();
   });
 });  

 $(".myAccount").click(function(e) {
     e.preventDefault();
     if ($("#myAccountPrefs").hasClass("display-none")) {
       $("#myAccountPrefs").removeClass("display-none");
     } else {
       $("#myAccountPrefs").addClass("display-none");
     }
 });
  
 $(".myAccountMobile").click(function(e) {
     e.preventDefault();
     if ($("#myAccountPrefs").hasClass("display-none")) {
       $("#myAccountPrefs").removeClass("display-none");
     } else {
       $("#myAccountPrefs").addClass("display-none");
     }
 });  
  $(".whatsappImg").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
     window.open("https://api.whatsapp.com/send?phone=" + CommonApis.getSessionData().mapperParms.whatsapp);
     
   });
 });  
  
  $(".whatsappImgMobile").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
     window.open("https://api.whatsapp.com/send?phone=" + CommonApis.getSessionData().mapperParms.whatsapp);
     
   });
 }); 
   
 $("#backToTop").click(function(e) {
   e.preventDefault();
   vaiAdInizioPagina();
 });
  
 $("#ricercadesElem").on("change", function() {
      var wto;
      clearTimeout(wto);
      wto = setTimeout(function() {
                                  }, 100);
 });
 
 $("#ricercadesElemMobile").on("change", function() {
      var wto;
      clearTimeout(wto);
      wto = setTimeout(function() {
                                  }, 100);
 }); 
 
 /*$(".divMenuTabMobile").click(function(e) {
   e.preventDefault();
   $(".divMenuTabMobile").toggleClass("visibileLeft");
 });
 */
 addListenerMenu();
 }
 
 function addListenerMenu() {
// Aggiungo il listeners dei tab

 $(".tabConsumiCls").click(function (e) {
       segnalaMenuAttivo(e.target.id);
       showSection(e.target.id);
 });


 $(".tabCatalogoCls").click(function(e) {
   $("#myAccountPrefs").addClass("display-none"); 
   if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
   if (!$(".tabCatalogoCls img").hasClass("menuDisabled")) {
     e.preventDefault();
	 segnalaMenuAttivo("tabCatalogo");
	 showSection("tabCatalogo");
	 if (CatalogoWidget.getLastCatalogoView() == "") {
		 CatalogoFiltriWidget.reloadCatalogo();
	 }else{
		CatalogoWidget.setLastCatalogoView("");
	 }
	 CommonApis.setMenuAttivoSave("tabCatalogo");
   }
  });
  
 $(".tabHomeCls").click(function(e) {
     // $(".reloadCatalogo").click();
     segnalaMenuAttivo(e.target.id);
     showSection(e.target.id);
 });


 $(".tabLafecoinCls").click(function(e) {
  $("#myAccountPrefs").addClass("display-none");
  if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
  $("#statusBoxMobile").removeClass("visibileRight");
  if (!$(".tabLafecoinCls img").hasClass("menuDisabled")) {
   CommonApis.getMenuAttivo();
   e.preventDefault();
   segnalaMenuAttivo(e.target.id);
   showSection(e.target.id);
   CommonApis.setMenuAttivoSave(e.target.id);
  }
 });

  
 $(".tabPromoCls").click(function(e) {
   $("#myAccountPrefs").addClass("display-none");
   if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
   if (!$(".tabPromoCls img").hasClass("menuDisabled")) {
    CommonApis.getMenuAttivo();
    e.preventDefault();
    segnalaMenuAttivo(e.target.id);
    showSection(e.target.id);
	CommonApis.setMenuAttivoSave(e.target.id);
   }
 });

 $(".tabCarrelloCls").click(function(e) {
  $("#myAccountPrefs").addClass("display-none");
  if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
  $("#statusBoxMobile").removeClass("visibileRight");
  if (!$(".tabCarrelloCls img").hasClass("menuDisabled")) {
   CommonApis.getMenuAttivo();
   e.preventDefault();
   segnalaMenuAttivo(e.target.id);
   showSection(e.target.id);
   CommonApis.setMenuAttivoSave(e.target.id);
  }
 });

 $(".tabTrackingCls").click(function(e) {
  $("#myAccountPrefs").addClass("display-none");
  if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
  $("#statusBoxMobile").removeClass("visibileRight");
  if (!$(".tabTrackingCls img").hasClass("menuDisabled")) {
   CommonApis.getMenuAttivo();
   e.preventDefault();
   segnalaMenuAttivo(e.target.id);
   showSection(e.target.id);
   CommonApis.setMenuAttivoSave(e.target.id);
  }
 });

 $(".tabVolantiniCls").click(function(e) {
  $("#myAccountPrefs").addClass("display-none");
  if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
  $("#statusBoxMobile").removeClass("visibileRight");
  if (!$(".tabVolantiniCls img").hasClass("menuDisabled")) {
   CommonApis.getMenuAttivo();
   e.preventDefault();
   segnalaMenuAttivo(e.target.id);
   showSection(e.target.id);
   CommonApis.setMenuAttivoSave(e.target.id);
  }
 });
 
 $(".tabMercatinoCls").click(function(e) {
  $("#myAccountPrefs").addClass("display-none");
  if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
  if (!$(".tabMercatinoCls img").hasClass("menuDisabled")) {
   CommonApis.getMenuAttivo();
   e.preventDefault();
   segnalaMenuAttivo(e.target.id);
   showSection(e.target.id);
   CommonApis.setMenuAttivoSave(e.target.id);
  }
 });

 $(".tabDocumentiCls").click(function(e) {
  $("#myAccountPrefs").addClass("display-none");
  if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
  $("#statusBoxMobile").removeClass("visibileRight");
  if (!$(".tabDocumentiCls img").hasClass("menuDisabled")) {
   CommonApis.getMenuAttivo();
   e.preventDefault();
   segnalaMenuAttivo(e.target.id);
   showSection(e.target.id);
   CommonApis.setMenuAttivoSave(e.target.id);
  }
 });

 $(".tabContenutiCls").click(function(e) {
  $("#myAccountPrefs").addClass("display-none");
 if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
  if (!$("#tabContenutiCls img").hasClass("menuDisabled")) {
   CommonApis.getMenuAttivo();
   e.preventDefault();
   segnalaMenuAttivo(e.target.id);
   showSection(e.target.id);
   CommonApis.setMenuAttivoSave(e.target.id);
  }
 });
  
 $(".tabScontiCls").click(function(e) {
  $("#myAccountPrefs").addClass("display-none");
  if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
     $("#divMenuTabMobile").removeClass("visibileLeft");
   }
  $("#divMenuTabMobile").removeClass("visibileLeft");
  if (!$("#tabScontiCls img").hasClass("menuDisabled")) {
   CommonApis.getMenuAttivo();
   e.preventDefault();
   segnalaMenuAttivo(e.target.id);
   showSection(e.target.id);
   CommonApis.setMenuAttivoSave(e.target.id);
  }
 });
 
 addListenerWishListDaAnteprimaCarrello();
}


function addListenerWishListDaAnteprimaCarrello(){
	
	$(".tabWishListCls").off("click");
	
	$(".tabWishListCls").click(function(e) {
	  $("#myAccountPrefs").addClass("display-none");
	  if ($("#divMenuTabMobile").hasClass("visibileLeft") ) {
		 $("#divMenuTabMobile").removeClass("visibileLeft");
	   }
	  $("#statusBoxMobile").removeClass("visibileRight");
	  if (!$(".tabWishListCls img").hasClass("menuDisabled")) {
	   CommonApis.getMenuAttivo();
	   e.preventDefault();
	   segnalaMenuAttivo(e.target.id);
	   showSection(e.target.id);
	   CommonApis.setMenuAttivoSave(e.target.id);
	  }
	 });
	
}


function aggiungiListenerUltimiArrivi() {
 
 $("#nuoviArriviLink").click(function(e) {
  e.preventDefault();
  CatalogoWidget.showNuoviArrivi();
 });
 
 $(".lastPromoImageInside").each(function(a) {
  $(this).click(function(e) {
    e.preventDefault();
    CatalogoWidget.vaiAPromo($(this).attr("promo"));
  });
 });
}

function aggiungiListenerCarrello(){
	/*
  $(".shopIconDelete").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
		removeArticoloCarrello(this);
    });
  });
  */
  $(".shopIconPromo").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	    CatalogoWidget.vaiAPromoCarrello(this);
    });
  });  

  $(".shopIconPromoMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	    CatalogoWidget.vaiAPromoCarrello(this);
    });
  });
  
  $(".shopIconMercatino").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	    $(".tabMercatinoCls").click();
    });
  });  

  $(".shopIconMercatinoMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	    $(".tabMercatinoCls").click();
    });
  });
    
  
  $(".shopIconArtOmaggio").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	    $(".tabLafecoinCls").click();
    });
  });  

  $(".shopIconArtOmaggioMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	    $(".tabLafecoinCls").click();
    });
  });

  $(".shopIconNota").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	  addNotaArticolo(this);
    });
  });    		

  $(".imgDetailArticoloStart").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      CatalogoWidget.viewCatalogoArtDetail(this)
    });
  }); 
     
  $(".imgDetailArticoloStartMobile").click(function(e) {
     e.preventDefault();
     CatalogoWidget.viewCatalogoArtDetail(this);
  });
    	
  $(".garbageImageMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
		removeArticoloCarrello(this);
    });
  });		
  
  $(".garbageImage").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
		removeArticoloCarrello(this);
    });
  });
  
  $(".shopImage").each(function(i) {
    $(this).click(function(e) { 
     e.preventDefault();
     var capofila = $(this).attr("cpf");
     if (CommonApis.isMobile()) {
        $("#ricercadesElemMobile").val(capofila);
     } else {
        $("#ricercadesElem").val(capofila);
     }
	 
        CatalogoFiltriWidget.setDescrizioneDaFiltrare();
        CatalogoFiltriWidget.resetRicercheFatte();
	 
		CatalogoFiltriWidget.setCapofilaFromAutocomplete(true);
		CatalogoWidget.lanciaRicercaCapofila(); 
    });
  });	
  		
  $(".confermaOrdineBtn").each(function(a) {
    $(this).click(function(e) { 
     e.preventDefault();
	 lanciaValidaCarrello();
    });
  });			
  
  $("#prtOrdineBtn").click(function(e) { 
     e.preventDefault();
	   stampaOrdine($(this).attr("num"));
  });

  $("#infoPromoOrdine").click(function(e) { 
     e.preventDefault();
	   mostraInfoPromoOrdine(this);
  });



  $(".arrowDwChart").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	  removeQtaCarrello(this,"-");
    });
  });
  
  $(".arrowUpChart").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	  addQtaCarrello(this,"+");
    });
  });
  
	$(".inputQtaChart").each(function(i) {
     $(this).change(function(e) { 
      e.preventDefault();
		updateRigaCarrello($(this),"*");
    });
  });    

/*
	$(".fastInsertCod").each(function(i) {
     $(this).keypress(function(e) { 
      if ( e.which == 13 ) {
		e.preventDefault();
		inserimentoVeloce();
	  }
    });
  });   

	$(".fastInsertQta").each(function(i) {
   $(this).keypress(function(e) { 
     if ( e.which == 13 ) {
		 e.preventDefault();
		 inserimentoVeloce();
	  }
   });
  });   

*/

  $(".addVolantinoShop").click(function(e) {
     e.preventDefault();
     VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
  });
   
  $(".addVolantinoShopMobile").click(function(e) {
     e.preventDefault();
     VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
  });    	

 $(".addWishShop").click(function(e) {
     e.preventDefault();
     addWishFromCarrelloInCatalogoStep1($(this)[0], true, "CAR_");
 });
   
 $(".addWishShopMobile").click(function(e) {
     e.preventDefault();
     addWishFromCarrelloInCatalogoStep1($(this)[0], true, "CAR_");
  });
        	
 }

function aggiungiListenerNote() {
  $(".confermaNota").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
	    inserisciNotaRiga(this);
    });
  });
  
} 





function aggiungiListenerWishList(){

  $(".infoWishImg").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      CatalogoWidget.viewCatalogoArtDetail(this);
    });
  });	

  $(".infoWishImgMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      CatalogoWidget.viewCatalogoArtDetail(this);
    });
  });	
		
	
  $(".arrowDw").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      removeQtaLocalWish( this, "-");
    });
  });
  
  $(".arrowDwMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      removeQtaLocalWishMobile( this, "-");
    });
  });  
 
    $(".arrowUp").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      addQtaLocalWish( this, "+");
    });
  });

    $(".arrowUpMobile").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      addQtaLocalWishMobile( this, "+");
    });
  });
	
	$(".insVeloceWsh").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      insArticoloToCarrello(this, "");
    });
  });
	
	$(".garbageImageWsh").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      deleteArtWish(this);
    });
  });	
	
	$(".insVeloceWshMobile").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      insArticoloToCarrello(this, "_Mobile");
    });
  });
	
	$(".garbageImageWshMobile").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      deleteArtWish(this);
    });
  });	
	
  $("#wishSelectAllMobile").each(function(i) {
    $(this).click(function(e) { 
      if (this.checked) {
		checkAllWish(true);
	  }else
	  {
		checkAllWish(false);  
	  }

    });
  });
  
  $(".selCkWshHeader").each(function(i) {
    $(this).click(function(e) { 
      if (this.checked) {
		checkAllWish(true);
	  } else {
		checkAllWish(false);  
	  }

    });
  });  
  
  $(".selCkCatWsh").each(function(i) {
    $(this).click(function(e) {
    $("#aggiungiDaPreferiti").addClass("display-none");
    $("#eliminaDaiPreferiti").addClass("display-none");
    var almenoUno = false;
    var checks = document.getElementsByClassName("selCkCatWsh");
    for (var i = 0; i < checks.length; i++) {
      if(checks[i].checked) {
         almenoUno = true;
         break;
		}
	} 

	if (almenoUno) {
	 $("#aggiungiDaPreferiti").removeClass("display-none");
	 $("#eliminaDaiPreferiti").removeClass("display-none");
	}
	
	var codArt = $.data(this, 'data').cod_art;
	
	selArticoloCheckPromoWish(codArt);

    });
  });  
    
  	$("#aggiungiDaPreferiti").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      //insSelectToCarrello(this);
	  addCarrelloArticoliTabella("");
    });
  });	
  
  $("#eliminaDaiPreferiti").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      deleteSelect();
    });
  });
  
  
	$(".inputQtaWsh").each(function(i) {
     $(this).change(function(e) { 
      e.preventDefault();
		updateQtaWsh(this);
    });
  });	  
  
	$(".inputQtaWshMobile").each(function(i) {
     $(this).change(function(e) { 
      e.preventDefault();
		updateQtaWshMobile(this);
    });
  });
    
	

  $(".shopImage").each(function(i) {
    $(this).click(function(e) { 
     e.preventDefault();
     var capofila = $(this).attr("cpf");
     if (CommonApis.isMobile()) {
        $("#ricercadesElemMobile").val(capofila);
     } else {
        $("#ricercadesElem").val(capofila);
     }
	 
        CatalogoFiltriWidget.setDescrizioneDaFiltrare();
        CatalogoFiltriWidget.resetRicercheFatte();
	 
		CatalogoFiltriWidget.setCapofilaFromAutocomplete(true);
		CatalogoWidget.lanciaRicercaCapofila(); 
    });
  });	
  			
	
}


function aggiungiListenerTracking(){
	
  $(".arrowDw").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      removeQtaLocalTracking( this, "-");
    });
  });
  
  $(".arrowDwMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      removeQtaLocalTrackingMobile( this, "-");
    });
  });  
 
    $(".arrowUp").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      addQtaLocalTracking( this, "+");
    });
  });

    $(".arrowUpMobile").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      addQtaLocalTrackingMobile( this, "+");
    });
  });

  $(".insVeloceTrk").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      inserimentoVeloceTracking(this);
    });
  });  
  
  $(".insVeloceTrkMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      inserimentoVeloceTrackingMobile(this);
    });
  });    
	
  $("#showTrackFilterMobile").click(function(e) {
   e.preventDefault();
  $("#optionTrackingPanelFilter").toggleClass("visibileLeft");
 });
	
 $("#reloadTrackingBtn").click(function(e) {
   e.preventDefault();
  reloadTracking();
 });
 
 $(".infoTrk").each(function(i) {
   $(this).click(function(e) {
    e.preventDefault();
    CatalogoWidget.viewCatalogoArtDetail(this);
   });
 });	
 
 $(".addVolantinoTrk").each(function(i) {
   $(this).click(function(e) {
    e.preventDefault();
    VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
   });
 });

 $(".addVolantinoTrkMobile").each(function(i) {
   $(this).click(function(e) {
    e.preventDefault();
    VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
   });
 }); 	
 
 $(".dettaglioTrk").each(function(i) {
   $(this).click(function(e) {
    e.preventDefault();
    mostraDettaglioTracking($(this).attr("doc"));
   });
 });
 
 $(".mostraPdfTrk").each(function(i) {
   $(this).click(function(e) {
    e.preventDefault();
    mostraPdfDocumento($(this).attr("doc"));
   });
 });
 
 $(".inputQtaTrk").each(function(i) {
   $(this).click(function(e) {
    e.preventDefault();
    this.select();
   });
 });
 
 $("#oneCli").click(function(e) {
  enableAllDate(true);
 });
 
 $("#allCli").click(function(e) {
  enableAllDate(false);
 }); 
 
  $(".shopImageTrk").each(function(i) {
    $(this).click(function(e) { 
     e.preventDefault();
     var capofila = $(this).attr("cpf");
     if (CommonApis.isMobile()) {
        $("#ricercadesElemMobile").val(capofila);
     } else {
        $("#ricercadesElem").val(capofila);
     }
     CatalogoFiltriWidget.setDescrizioneDaFiltrare();
     CatalogoFiltriWidget.resetRicercheFatte();	 
	 CatalogoFiltriWidget.setCapofilaFromAutocomplete(true);
	 CatalogoWidget.lanciaRicercaCapofila(); 
    });
  }); 	
}
	
	
	
function rimuoviListenerCatalogo(capofila) {
	
	$(".imgPromoArtCpf").off("click");
	$(".catalogoImage").off("click");
	$(".viewLink").off("click");
	$(".vaiACarrello").off("click");
	$(".infoIcon").off("click");
	$(".artOfferta").off("click");
	$(".marcaImageGrid").off("click");
	$(".marcaImage").off("click");
	$(".toggleVisualizzazione").off("click");
	$(".reloadCatalogo").off("click");
	$(".offerteImgCls").off("click");
  $(".orderMode").off("click");
  $(".orderModeElem").off("click");
	$(".arrowDwCpf").off("click");
  $(".arrowUpCpf").off("click");
   $(".arrowUpCpfGrid").off("click");
   $(".arrowDwCpfGrid").off("click");
  $(".addWishListCpf").off("click");
  $(".addCarrelloDirettoCpf").off("click");
  $(".addVolantinoCpf").off("click");
  $(".recordLinea").off("click");
  $(".recordLineaGrid").off("click");
}	

function aggiungiListenerCatalogo(capofila) {
	
	rimuoviListenerCatalogo(capofila);

  /*
  $(".imgPromoArt").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      vaiAPromoArticolo($(this).attr("promo"), $(this).attr("art"));
    });
  });
  */  
 	$(".arrowDwCpf").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      CatalogoWidget.setQtaCpf($(this)[0], "-");
    });
  });
 
 	$(".arrowDwCpfGrid").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      CatalogoWidget.setQtaCpf($(this)[0], "-");
    });
  });
  
  $(".arrowUpCpf").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      CatalogoWidget.setQtaCpf($(this)[0], "+");
    });
  });
 
  $(".arrowUpCpfGrid").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      CatalogoWidget.setQtaCpf($(this)[0], "+");
    });
  });
 
  $(".addWishListCpf").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      addWishList(this, "");
      var cpf = $(this).attr("cpf");
      var inputs = document.getElementsByName("inputQtaCpf");
      for (var i = 0; i < inputs.length; i++) {
        if ($(inputs[i]).attr("cpf") == cpf) {
          var qta = parseInt($(inputs[i]).val());
          break;
        }
      }
      var checks = document.getElementsByName("chkCpf");
      var newId = "CKCAT_" + cpf;
      for (var i = 0; i < checks.length; i++) {
        if ($(checks[i]).attr("cpf") == cpf) {
          $(checks[i]).attr("id", newId);
          $(checks[i]).attr("val", qta);
          break;
        }
      }   
    });
  });

  $(".addWishListCpfGrid").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      var cpf = $(this).attr("cpf");
      var inputs = document.getElementsByName("inputQtaCpf");
      for (var i = 0; i < inputs.length; i++) {
        if ($(inputs[i]).attr("cpf") == cpf) {
          var qta = parseInt($(inputs[i]).val());
          break;
        }
      }
      var checks = document.getElementsByName("chkCpf");
      var newId = "CKCAT_" + cpf;
      for (var i = 0; i < checks.length; i++) {
        if ($(checks[i]).attr("cpf") == cpf) {
          $(checks[i]).attr("id", newId);
          $(checks[i]).attr("val", qta);
          break;
        }
      }         
      addWishList(this, "");
    });
  });
  
  $(".addCarrelloDirettoCpf").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      var cpf = $(this).attr("cpf");
      var inputs = document.getElementsByName("inputQtaCpf");
      for (var i = 0; i < inputs.length; i++) {
        if ($(inputs[i]).attr("cpf") == cpf) {
          var qta = parseInt($(inputs[i]).val());
          break;
        }
      }
      var checks = document.getElementsByName("chkCpf");
      var newId = "CKCAT_" + cpf;
      for (var i = 0; i < checks.length; i++) {
        if ($(checks[i]).attr("cpf") == cpf) {
          $(checks[i]).attr("id", newId);
          $(checks[i]).attr("val", qta);
          break;
        }
      }      
      addCarrelloDiretto(this,"");
    });
  });

  $(".addCarrelloDirettoCpfGrid").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      var cpf = $(this).attr("cpf");
      var inputs = document.getElementsByName("inputQtaCpfGrid");
      for (var i = 0; i < inputs.length; i++) {
        if ($(inputs[i]).attr("cpf") == cpf) {
          var qta = parseInt($(inputs[i]).val());
          break;
        }
      }
      var checks = document.getElementsByName("chkCpfGrid");
      var newId = "CKCAT_" + cpf;
      for (var i = 0; i < checks.length; i++) {
        if ($(checks[i]).attr("cpf") == cpf) {
          $(checks[i]).attr("id", newId);
          $(checks[i]).attr("val", qta);
          break;
        }
      }
      addCarrelloDiretto(this,"");
    });
  }); 
   
  $(".addVolantinoCpf").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
    });
  });
  
  $(".addVolantinoCpfGrid").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
    });
  });  
  $(".shopInCatalogoPick").click(function(a){
     a.preventDefault();
     if ($("#previewCarrelloMaster").hasClass("visibileRight")) {
        $("#previewCarrelloMaster").removeClass("visibileRight");
        $("#previewCarrelloMaster").removeClass("zindex-900");
        //$("#shopInCatalogoPick").removeClass("");
     } else {
       $("#previewCarrelloMaster").addClass("visibileRight");
       $("#previewCarrelloMaster").addClass("zindex-900");

     } 
  });
  
  $(".orderMode").click(function(e) {
    $(".orderModeList").removeClass("display-none");
    $(".orderModeList").css("top", $(".orderMode").position().top);
    $(".orderModeList").css("left", $(".orderMode").position().left);
    $(".orderModeList").css("width", $(".orderMode").width());
    
  });    
      
  $(".orderModeElem").each(function(a) {
    $(this).click(function(e) { 
     e.preventDefault();
     eraseCookie("orderMode");
     createCookie("orderMode", $(this).attr("ord"), 1);
     CatalogoWidget.showCapofila(CatalogoWidget.getCapofilaResponse());
    });
  });
  
  $(".imgPromoArtCpf").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      vaiAPromoCapofila($(this).attr("cpf"));
    });
  });                                        
  
  $(".viewLink").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      CatalogoWidget.viewAllegati($(this).attr("idx"));
    });
  });

  $(".vaiACarrello").click(function(e) {
       e.preventDefault();
       vaiACarrello();
  });
  
  $(".arrowDw"+capofila).each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      removeQtaLocal( this, "-", "");
    });
  });
 
   $(".arrowUp"+capofila).each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      addQtaLocal( this, "+", "");
    });
  });
  
  $(".arrowDwMobile"+capofila).each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      removeQtaLocal( this, "-", "MOBILE_");
    });
  });
 
    $(".arrowUpMobile"+capofila).each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      addQtaLocal( this, "+", "MOBILE_");
    });
  });
  
  $(".addCarrelloDiretto"+capofila).each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();      
      addCarrelloDiretto(this,"");
    });
  });
  
 $(".addVolantino").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
    });
  });
  
 $(".addVolantinoMobile").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
    });
  });  
  
  $(".addWishList"+capofila).each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      addWishList(this, "");
    });
  });
  
    $(".addCarrelloDirettoMobile"+capofila).each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      addCarrelloDiretto(this, "MOBILE_");
    });
  });
  
  $(".addWishListMobile"+capofila).each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      addWishList(this, "MOBILE_");
    });
  });
  
  $(".selCkCatHeader"+capofila).each(function(i) {
    $(this).click(function(e) { 
      var capofila = $(this).attr("capofila");
      $(this).checked = false;
      CatalogoWidget.selectAllArticoli(capofila);
    });
  });
  
 
	$(".inputQtaMobile"+capofila).each(function(i) {
     $(this).change(function(e) { 
      e.preventDefault();
		updateRigaLocal(this, "*", "MOBILE_");
    });
  });	

	$(".inputQtaMobile"+capofila).each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		this.select();
    });
  });

	$(".inputQta"+capofila).each(function(i) {
     $(this).change(function(e) { 
      e.preventDefault();
		updateRigaLocal(this, "*", "");
    });
  });
  
  
	$(".inputQta"+capofila).each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		this.select();
    });
  });
    
	$(".infoIcon").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		var codArt = $(this).attr("codArt");
		CatalogoWidget.viewCatalogoArtDetail(this);
    });
  });
    	
	$(".artOfferta").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		var art = $(this).attr("art");
		CatalogoWidget.vaiAPromoArticolo(art);
    });
  });		
  	
	
	$(".marcaImageGrid").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		var marchio = $(this).attr("marchio");
		CatalogoWidget.showMarca(marchio);
    });
  });	
  
	$(".marcaImage").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		var marchio = $(this).attr("marchio");
		CatalogoWidget.showMarca(marchio);
    });
  });	  	
			
	$(".recordLinea").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		  showLinea($(this));
    });
  });	
  
  	$(".recordLineaGrid").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		  showLinea($(this));
    });
  });
	
  $(".inputQta").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		  $(this).select();
    });
  });		
  
	$(".catalogoImage").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		if(!CommonApis.isMobile()) {
			var immagine = $(this).attr("immagine");
			mouseOverImage(immagine);
		}
    });
  });		
  
  
	$(".toggleVisualizzazione").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      // Se ho almeno un capofila espanso non posso cambiare
      var cambia = true;
      if (CatalogoWidget.getNumArtEspansi() > 0) {
        cambia = false;
      }
      if (cambia) {
		    CatalogoFiltriWidget.cambiaTipoVisualizzazione(this);
      }		
    });
  });	

  	$(".reloadCatalogo").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		  CatalogoFiltriWidget.reloadCatalogo();		
    });
  });		

  	$(".offerteImgCls").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		  CatalogoWidget.vaiAOfferte();		
    });
  });	
  
  $(".selCkCat").each(function(i) {
     $(this).change(function(e) { 
      e.preventDefault();
		  var codArt = $.data(this, 'data').cod_art;
		  //selArticolo(codArt);
		  selArticoloCheckPromo(codArt);
    });
  });	
  
  $(".chkDivisione").each(function(i) {
     $(this).click(function(e) { 
       e.preventDefault();
       CatalogoFiltriWidget.clearDivisioniFiltrate();
       var checkDivisioni = document.getElementsByName("chkDivisione");
       for (var i = 0; i < checkDivisioni.length; i++) {
          if (checkDivisioni[i].checked) {
            CatalogoFiltriWidget.setDivisioniFiltrate(checkDivisioni[i].value);
          }
       }
       CatalogoWidget.showCapofila(CatalogoWidget.getCapofilaResponse());
    });
  });	  
}

function aggiungiListenerbigImageButton(){
	
  	$(".bigImageButtonCls").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		var idDiv = $(this).attr("idDiv");
		closeDiv(idDiv);		
    });
  });		
}


function rimuoviListenerCarrelloInCatalogo() {
	
	$(".arrowDwChartInCat").off("click");
	$(".arrowUpChartInCat").off("click");
 	$(".shopInCatalogoDelete").off("click");
  $(".shopInCatalogoAddVolantino").off("click");
	$(".vaiACarrello").off("click");
	$(".vaiACarrelloImg").off("click");
	$(".inputQtaChartInCat").off("change");
	$(".shopInCatalogoAddWish").off("click");
  $(".vaiACarrelloDaCatalogo").off("click");
  $(".vaiAWishDaCatalogo").off("click");
  $(".arrowUpWishInCat").off("click");
  $(".arrowDwWishInCat").off("click");
	$(".inputQtaWishInCat").off("change");
	$(".fastInsertCod").off("keypress");
	$(".fastInsertQta").off("keypress");
	$("#insVeloceBtn").off("click");
}

function aggiungiListenerCarrelloInCatalogo() {
	
  rimuoviListenerCarrelloInCatalogo();
  

	$(".fastInsertCod").each(function(i) {
     $(this).keypress(function(e) { 
      if ( e.which == 13 ) {
		e.preventDefault();
		inserimentoVeloce();
	  }
    });
  });   

	$(".fastInsertQta").each(function(i) {
     $(this).keypress(function(e) { 
      if ( e.which == 13 ) {
		e.preventDefault();
		inserimentoVeloce();
	  }
    });
  });    
  
  
  	$("#insVeloceBtn").each(function(i) {
    $(this).click(function(e) { 
		e.preventDefault();
		inserimentoVeloce();
	  
    });
  });    
  
  
  
  
  $(".arrowUpWishInCat").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      addQtaLocalWish( this, "+");
    });
  });
  	
  $(".arrowDwWishInCat").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      removeQtaLocalWish( this, "-");
    });
  });  
  
  $(".vaiACarrelloDaCatalogo").click(function(e) {
    e.preventDefault();
    if ($(this).hasClass("carrelloInCatalogoSelect")) {
     $(".tabCarrelloCls").click();
	 menuEnable(true);
    } else {
       CatalogoFiltriWidget.setCarrelloInCatalogo(true);
       CatalogoFiltriWidget.setPreferitiInCatalogo(false);       
       CatalogoWidget.showCarrelloInCatalogo(".previewCarrello");
       $(".vaiAWishDaCatalogo").removeClass("carrelloInCatalogoSelect");
       $(".vaiACarrelloDaCatalogo").addClass("carrelloInCatalogoSelect");
       
    }
  });
  
  $(".vaiAWishDaCatalogo").click(function(e) {
    e.preventDefault();
    if ($(this).hasClass("carrelloInCatalogoSelect")) {
		addListenerWishListDaAnteprimaCarrello();
		$(".tabWishListCls").click();
		menuEnable(true);
    } else {
       CatalogoFiltriWidget.setCarrelloInCatalogo(false);
       CatalogoFiltriWidget.setPreferitiInCatalogo(true);    
       CatalogoWidget.showCarrelloInCatalogo(".previewCarrello");
       $(".vaiACarrelloDaCatalogo").removeClass("carrelloInCatalogoSelect");
       $(".vaiAWishDaCatalogo").addClass("carrelloInCatalogoSelect");
       
    }
  });
  	
	$(".arrowDwChartInCat").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      if(CatalogoFiltriWidget.isCarrelloInCatalogo()) { 
		    removeQtaCarrello(this,"-","CAT2_", "false");
      } else if (CatalogoFiltriWidget.isPreferitiInCatalogo()) {
        removeQtaLocalWish( this, "-");
      }
    });
  });	
  
 	$(".shopInCatalogoDelete").each(function(i) {
     $(this).click(function(e) {
      e.preventDefault();
      if(CatalogoFiltriWidget.isCarrelloInCatalogo()) { 
        removeArticoloCarrello(this);
      } else if (CatalogoFiltriWidget.isPreferitiInCatalogo()) {
        deleteArtWish(this);
      }
    });
  });
  
  $(".shopInCatalogoAddVolantino").each(function(i) {
     $(this).click(function(e) {
      e.preventDefault();
      VolantiniApis.richiediAggiungiArticoloVolantino($(this)[0]);
    });
  });
  
  $(".shopInCatalogoAddWish").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      if(CatalogoFiltriWidget.isCarrelloInCatalogo()) { 
		    addWishFromCarrelloInCatalogoStep1($(this)[0], false, "CAT2_");
      } else if (CatalogoFiltriWidget.isPreferitiInCatalogo()) {
        addCarrelloFromPreferitiInCatalogoStep1($(this)[0]);
      }
    });
  });			
		
	$(".arrowUpChartInCat").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      if(CatalogoFiltriWidget.isCarrelloInCatalogo()) { 
		    addQtaCarrello(this,"+","CAT2_", "false");
      } else if (CatalogoFiltriWidget.isPreferitiInCatalogo()) {
        addQtaLocalWish( this, "+");
      }
		  
    });
  });
  
	$(".vaiACarrelloImg").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
		var idRiga = $(this).attr("idRiga");
		var codArt = $(this).attr("codArt");
		var capofila = $(this).attr("capofila");
		 if (CommonApis.isMobile()) {
			$("#ricercadesElemMobile").val(codArt);
		 } else {
			$("#ricercadesElem").val(codArt);
		 }
	 
        CatalogoFiltriWidget.setDescrizioneDaFiltrare();
        CatalogoFiltriWidget.resetRicercheFatte();
		
		CatalogoWidget.viewArtDaShopInCatalogo(capofila);
    });
  });	
  
	$(".inputQtaChartInCat").each(function(i) {
     $(this).change(function(e) { 
      e.preventDefault();
		updateRigaCarrello($(this),"*", "false");
    });
  });  
  
  
  $(".inputQtaWishInCat").each(function(i) {
     $(this).change(function(e) { 
      e.preventDefault();
		 checkQta(this, "*");
    });
  });  
    
  $(".closeCarrelloInCatalogo").each(function(a) {
    $(this).click(function(e) { 
     e.preventDefault();
     CatalogoWidget.setChiudiCarrelloFromCatalogo(true);
	   lanciaValidaCarrello();
    });
  });	
}

function aggiungiListenerCatalogoButton() {
 	$("#addCarrelloBtn").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
	  CommonApis.setSelCk("selCkCat");
	  addCarrelloArticoliTabella("");
    });
  });
  
 $("#showCatalogoFilterMobile").click(function(e) {
   e.preventDefault();
  $("#filtriCatalogo").toggleClass("visibileLeft");
  if ($("#filtriCatalogo").position().left == 0){
	   $(".toggleViewCatalogo").removeClass("fa-angle-double-left");
	   $(".toggleViewCatalogo").addClass("fa-angle-double-right");  
     $("#filtriCatalogo").removeClass("ov-auto");
  }else{
	  $(".toggleViewCatalogo").removeClass("fa-angle-double-right");
    $(".toggleViewCatalogo").addClass("fa-angle-double-left");
    $("#filtriCatalogo").addClass("ov-auto");
  }
 });
 
}

function aggiungiListenerBoxNovita() {

 $("#rightArrowNovita").off("click");
 $("#leftArrowNovita").off("click");
 $(".novitaImageInside").off("click");
 
 $("#rightArrowNovita").click(function(e) {
    e.preventDefault();
    clearInterval(timerNovita);
    ruotaImmagineNovita(true);
 });
 
  $("#leftArrowNovita").click(function(e) {
    e.preventDefault();
    ruotaImmagineNovita(false);   
    
 });

 $(".novitaImageInside").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
     CatalogoWidget.lanciaRicercaNovita($(this).attr("cpf"));
   });
 });
 
}

function aggiungiListenerBoxBestSellers() {

    $(".rightArrowBestSellers").off("click");
    $(".leftArrowBestSellers").off("click");
    $(".bestSellersImageInside").off("click");

    $(".rightArrowBestSellers").click(function (e) {
        e.preventDefault();
        clearInterval(timerBestSeller);
        ruotaImmagineBestSellers(true);
    });

    $(".leftArrowBestSellers").click(function (e) {
        e.preventDefault();
        ruotaImmagineBestSellers(false);

    });

    $(".bestSellersImageInside").each(function (a) {
        $(this).click(function (e) {
            e.preventDefault();
            CatalogoFiltriWidget.setViewArtDaShopInCatalogo(true);
            CatalogoFiltriWidget.setCapofila($(this).attr("cpf"));
            CatalogoFiltriWidget.getRicercheFatte()[0] = $(this).attr("cpf");
            CatalogoWidget.lanciaRicercaCapofila();
        });
    });

}

function aggiungiListenerBoxArtInEvidenza() {

    $(".rightArrowArtInEvidenza").off("click");
    $(".leftArrowArtInEvidenza").off("click");
    $(".artInEvidenzaImageInside").off("click");

    $(".rightArrowArtInEvidenza").click(function (e) {
        e.preventDefault();
        clearInterval(timerBestSeller);
        ruotaImmagineArtInEvidenza(true);
    });

    $(".leftArrowArtInEvidenza").click(function (e) {
        e.preventDefault();
        ruotaImmagineArtInEvidenza(false);

    });

    $(".artInEvidenzaImageInside").each(function (a) {
        $(this).click(function (e) {
            e.preventDefault();
            $("#ricercadesElem").val($(this).attr("cod"));
            CatalogoWidget.lanciaRicercaCapofila();
        });
    });

}
function aggiungiListenerBoxUltimiVisti() {

 $("#rightArrowLastViewed").click(function(e) {
    e.preventDefault();
    clearInterval(timerNovita);
    ruotaImmagineUltimiVisti(true);
 });
 
  $("#leftArrowLastViewed").click(function(e) {
    e.preventDefault();
    ruotaImmagineUltimiVisti(false);   
    
 });

 $(".ultimiVistiImageInside").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
     CatalogoFiltriWidget.setViewArtDaShopInCatalogo(true);
     CatalogoFiltriWidget.setCapofila($(this).attr("cpf"));
     CatalogoFiltriWidget.getRicercheFatte()[0] = $(this).attr("cpf");
     CatalogoWidget.lanciaRicercaCapofila();
   });
 });
 
}

function aggiungiListenerBoxPromo() {

 $("#rightArrowLastPromo").click(function(e) {
    e.preventDefault();
    clearInterval(timerLastPromo);
    ruotaImmaginePromo(true); 
 });
 
  $("#leftArrowLastPromo").click(function(e) {
    e.preventDefault();
    ruotaImmaginePromo(false);   
    
 });
 
}

 function aggiungiListenerNewsEventi() {
 $("#rightArrowLastNewsEventi").off("click");
 $("#leftArrowLastNewsEventi").off("click");
 $("#newsContent").off("click");
 
 $("#rightArrowLastNewsEventi").click(function(e) {
    e.preventDefault();
    clearInterval(timerNewsEventi);
    ruotaImmagineNewsEventi(true); 
 });
 
  $("#leftArrowLastNewsEventi").click(function(e) {
    e.preventDefault();
    ruotaImmagineNewsEventi(false);   
    
 });
 $(".newsContent").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
     viewNews($(this).attr("id"));
   });
 });
 }

function rimuoviListenersAutocomplete() {
   $("#ricercadesElemautocomplete-list").off("click");
   $("#ricercadesElemMobileautocomplete-list").off("click");
   $("#findPromoArtautocomplete-list").off("click");
   $("#searchDocArtautocomplete-list").off("click");
}
 
function aggiungiListenersAutocomplete() {

 rimuoviListenersAutocomplete();
 $("#ricercadesElemautocomplete-list").click(function(e) {
    e.preventDefault();    
    CatalogoFiltriWidget.setDescrizioneDaFiltrare();
    CatalogoFiltriWidget.resetRicercheFatte();
    CatalogoFiltriWidget.setCapofilaFromAutocomplete(true);
    CatalogoWidget.lanciaRicercaCapofila(); 
          
 });
 
 $("#ricercadesElemMobileautocomplete-list").click(function(e) {
    e.preventDefault();  
    CatalogoFiltriWidget.setDescrizioneDaFiltrare();
    CatalogoFiltriWidget.resetRicercheFatte();
    CatalogoFiltriWidget.setCapofilaFromAutocomplete(true);
    CatalogoWidget.lanciaRicercaCapofila();    
 }); 

 $("#findPromoArtautocomplete-list").click(function(e) {
    e.preventDefault();
    ricercaArticoliInPromo();   
 });
 
 $("#searchDocArtautocomplete-list").click(function(e) {
    e.preventDefault();
    DocumentiWidget.showDocs();
 });
}

function aggiungiListersDocsTable() {

 $(".viewDoc").each(function(i) {
  $(this).click(function(e) {
    e.preventDefault();
    mostraPdfDocumento($(this).attr("iddoc"));
    });
 });
    
}

function aggiungiListenersDocumenti() {
   $("#docsFilterIconMobile").click(function(e) {
     e.preventDefault();
     $("#optionDocsPanelFilter").toggleClass("visibileLeft");
     if ($("#optionDocsPanelFilter").position().left == 0){
	     $(".toggleViewDocOpt").removeClass("fa-angle-double-left");
	     $(".toggleViewDocOpt").addClass("fa-angle-double-right");
         $("#optionDocsPanelFilter").removeClass("ov-auto");  
     } else {
	     $(".toggleViewDocOpt").removeClass("fa-angle-double-right");
         $(".toggleViewDocOpt").addClass("fa-angle-double-left");
         $("#optionDocsPanelFilter").addClass("ov-auto");
     }
   });
   
  $(".tipoDocList").each(function(i) {
   $(this).click(function(e) {
    e.preventDefault();
    var tipo = $(this).attr("tipodoc");
    var anni = document.getElementsByName("containerAnni");
    for (var i = 0; i < anni.length; i++) {
       if ($(anni[i]).attr("tipodoc").trim() == tipo.trim()) {
         $(anni[i]).toggleClass("display-none");
         if ($(anni[i]).hasClass("display-none")) {
            $(anni[i]).slideUp();
         } else {
            $(anni[i]).slideDown();
         }                        
         break;
       }
    }
    });      
 });
 
 //$(".annoDocumenti").each(function(i) {
 $(".docChkbox").each(function(i) {
   $(this).click(function(e) {
    if (CommonApis.isMobile()) {
     $("#optionDocsPanelFilter").toggleClass("visibileLeft");
     if ($("#optionDocsPanelFilter").position().left == 0){
	     $(".toggleViewDocOpt").removeClass("fa-angle-double-left");
	     $(".toggleViewDocOpt").addClass("fa-angle-double-right");
         $("#optionDocsPanelFilter").removeClass("ov-auto");  
     } else {
	     $(".toggleViewDocOpt").removeClass("fa-angle-double-right");
         $(".toggleViewDocOpt").addClass("fa-angle-double-left");
         $("#optionDocsPanelFilter").addClass("ov-auto");
     }
    }
    DocumentiWidget.checkDocsToView(this);
    });
 });
} 

function aggiungiListenersArticoliErrati() {

 $(".validaErrati").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault();
     validaArtErrati($(this).attr("continua"));
   });
 });
}


function aggiungiListenersArticoliMancanti() {

   $(".validaDisponibilita").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault();
     validaDisponibilita($(this).attr("continua"));
   });
 });
}

function aggiungiListenersBenefitPromo() {
 $(".checkRemovePromo").click(function(e) {
    if ($(".checkRemovePromo").is(":checked")) {
      $(".descrpromo").addClass("testo-barrato");
    } else {
      $(".descrpromo").removeClass("testo-barrato");
    }
 });
 $(".validaPromo").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault();
	 var value = $(this).attr("continua");
	 
	 if (value == 2){ //elimina promo da check
		eliminaPromoMulti();		
	 }else{
		inserisciBenefitInOrdine($(this).attr("continua"));
	 }
	 
   });
 });
 
 $(".infoPromoErrata").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault();
     infoPromo($(this).attr("promo"));
   });
 });

 $(".deletePromo").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault(); 
     removePromoInErrore($(this).attr("promo"));
   });
 });
 
 $(".insertBenefit").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault(); 
     inserisciBenefitInOrdine($(this).attr("continua"));
   });
 });
 
}

function aggiungiListenersInfoDiv() {
  $(".btnCloseDiv").each(function(i) {
   $(this).click(function(e) {
       e.preventDefault(); 
       if ($(this).attr("removehider") != "undefined") {
           closeDiv($(this).attr("divToClose"), $(this).attr("removehider"));
       } else {
           closeDiv($(this).attr("divToClose"));
       }
   });
 });
} 
 
function aggiungiListenersChiudiCarrello() {
 
 $(".confermaFinali").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault(); 
     validaDatiFinali($(this).attr("continua"));
   });
 }); 

 $("#consVettore").click(function(e) {
    // e.preventDefault(); 
     cambiaCalendario();
 });  

 $("#consDestinatario").click(function(e) {
    // e.preventDefault(); 
     cambiaCalendario();
 });   


 $("#agenteRb").click(function(e) {
    // e.preventDefault(); 
     checkAggOrdineEnabled();
 });   

 $("#aziendaRb").click(function(e) {
    // e.preventDefault(); 
     checkAggOrdineEnabled();
 });   

  // Show/hide magazzino al cambio consegna
  $("input[name='consegnaType']").on("change", function () {
    if ($(this).val() === "D") {
      $("#row-magazzino").css("display", "flex");
    } else {
      $("#row-magazzino").hide();
    }
  });




}

function aggiungiListenersSubMenu() {

 $(".subMenuSettings").on("mouseleave", function() {
    var divMenu = document.getElementById("menuPrefs");
    document.getElementsByTagName("body")[0].removeChild(divMenu);
 });
 
 $("#pwdChange").click(function(e) {
     e.preventDefault(); 
     chgPwd(1);
 }); 
 
 $("#delCookie").click(function(e) {
     e.preventDefault(); 
     deleteAllCookies();
 });
  
 $("#mailChange").click(function(e) {
     e.preventDefault(); 
     chgMail();
 });
 $("#viewSubscription").click(function(e) {
     e.preventDefault(); 
	 var par = "?cod_cli=" + CommonApis.getSessionData().cod_cl_des + "&email=" + CommonApis.getSessionData().email.trim() ;
     window.open(window.location.href.replace("workspace", "gestnewsletter") + par, '_blank').focus();
     var divMenu = document.getElementById("menuPrefs");
     document.getElementsByTagName("body")[0].removeChild(divMenu);
 });
 $("#remoteAccess").click(function(e) {
     e.preventDefault(); 
     window.open('http://get.teamviewer.com/h2b_qs', '_blank').focus();
     var divMenu = document.getElementById("menuPrefs");
     document.getElementsByTagName("body")[0].removeChild(divMenu);
 }); 
 
 $("#showHidePrz").click(function(e) {
     e.preventDefault(); 
     gestPrezziCookie();
 });
  
 $("#showHidePrzDoppio").click(function(e) {
     e.preventDefault(); 
     gestPrezziDoppiCookie();
 }); 
 
  $("#webParam").click(function(e) {
     e.preventDefault(); 
     CommonApis.requestWebParam();
 }); 

 $("#addToHome").click(function(e) {
     e.preventDefault(); 
     CommonApis.showAddToHomeScreen();
 }); 
 $("#showAddPromoAuto").click(function(e) {
     e.preventDefault(); 
     gestPromoAutoCookie();
	   CatalogoFiltriWidget.reloadCatalogo();
 });  
 
}

function aggiungiListenerInfoArticolo() {

 $(".closeDetailArticolo").click(function(e) {
   e.preventDefault(); 
   closeDiv('detailArticolo');
 });
}


function aggiungiListenersRemovePromo() { 
 if (CommonApis.addListenerRemovePromo()) {
   CommonApis.setAddListenerRemovePromo(false);
   $(".btnRemovePromo").each(function(i) {  
     $(this).click(function(e) {
      e.preventDefault(); 
      confirmRemovePromoErrore($(this).attr("conferma"), $(this).attr("codpromo"), true);
     });
   });
 }
}
function aggiungiListenersRemoveArt() { 
  $(".btnRemoveArt").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault(); 
     confirmRemoveArt($(this).attr("conferma"), $(this).attr("cod"), $(this).attr("riga"));
   });
  });
}
 
function aggiungiListenersWorkspace() { 
 $(".btnChgPwd").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault(); 
     modificaPwd($(this).attr("continua"));
   });
 });
  
 $(".btnChgMail").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault(); 
     modificaMail($(this).attr("continua"));
   });
 });
 aggiungiListenerShowPwd();   
}

function aggiungiListenersInfoPromo(element) {

    $(".btnCloseDivPromoScel").off("click");
    $(".btnCloseDivPromoNoScel").off("click");

   $(".infoPromolist").each(function(i) {
	   $(this).click(function(e) {
		 e.preventDefault();
		 //PromoApis.infoPromo($(this).attr("promo"));
		 PromoApis.infoPromo($(this));
	   });
   });
   
   $(".btnCloseDivInfoPromo").each(function(i) {
     $(this).click(function(e) {
       e.preventDefault(); 
			$("#infoPromoListDiv").remove();
			removeHider();
     } );
   });
   
   $(".eliminaPromoOrdine").each(function(i) {
     $(this).click(function(e) {
       e.preventDefault(); 
		 var codArt = $(this).attr("codpromo");
		 removeArticoloPromo(codArt, true);
     } );
   });   
   
   

}

function aggiungiListenersSelPromo(element) {
    $(".btnCloseDivPromoScel").off("click");
    $(".btnCloseDivNoPromoScel").off("click");

   $(".btnCloseDivPromoScel").each(function(i) {
     $(this).click(function(e) {
       e.preventDefault(); 
       selPromoInsDiretta(element);
     } );
   });

    $(".btnCloseDivNoPromoScel").each(function (i) {
        $(this).click(function (e) {
            e.preventDefault();
            noPromoInsDiretta(element);
        });
    });
   
   $(".infoPromolist").each(function(i) {
	   $(this).click(function(e) {
		 e.preventDefault();
		 //PromoApis.infoPromo($(this).attr("promo"));
		 PromoApis.infoPromo($(this));
	   });
   });
   

}


function aggiungiListenersErrorDiv() {

   $(".buttonErrorAndLogin").each(function(i) {
     $(this).click(function(e) {
       e.preventDefault(); 
       removeDialogAndLogin($(this).attr("divname"));
     } );
   });
 
  $(".buttonErrorNoLogin").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault(); 
     removeDialogAndLogoff($(this).attr("divname"));
     removeHider();
   });
 });
 
 $(".buttonErrorClose").each(function(i) {
   $(this).click(function(e) {
     e.preventDefault(); 
     removeDialog($(this).attr("divname"));
    // removeHider();
   });
 });
}

function removeListenersSconti() {
  $(".viewScontiClienti").off("click");
  $(".copiaScontiBtn").off("click");
  $(".tornaASconti").off("click");
  $(".updateScontiArticoloClienti").off("click");
  $(".viewScontiClientiMob").off("click");
  $("#validaScontiBtn").off("click");
}

function aggiungiListenersSconti() {
  removeListenersSconti();
  $(".viewScontiClienti").each(function(i) {
    $(this).click(function(e) {
      e.preventDefault(); 
      visualizzaScontiClienti(this);
    });
  });
  
  $(".copiaScontiBtn").each(function(i) {
    $(this).click(function(e) {
      e.preventDefault(); 
      copiaScontiStart();
    });
  });
 
  $(".tornaASconti").each(function(i) {
    $(this).click(function(e) {
      e.preventDefault();     
      getSconti();
    });
  }); 
    
  $(".updateScontiArticoloClienti").each(function(i) {
    $(this).click(function(e) {
      e.preventDefault(); 
      updateScontiArticoloClienti();
    });
  }); 
    
        
  $(".viewScontiClientiMob").each(function(i) {
    $(this).click(function(e) {
      e.preventDefault(); 
      visualizzaScontiClienti(this);
    });
  });
   
  $("#validaScontiBtn").click(function(e) {
   e.preventDefault();
     updateSconti();
  });
  
    $("#validaScontiBtnMob").click(function(e) {
   e.preventDefault();
     updateSconti();
  });
 
  $(".inputQta").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      this.select();
    });
  });
 
  $(".inputQtaCnf").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      this.select();
    });
  }); 

  $(".inputQtaMobile").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      this.select();
    });
  });
 
  $(".inputQtaCnfMobile").each(function(a) {
    $(this).click(function(e) {
      e.preventDefault();
      this.select();
    });
  });  
  $("#scontiFilterMobile").click(function(e) {
    e.preventDefault();
    $("#optionScontiPanelFilter").toggleClass("visibileLeft");
    if ($("#optionScontiPanelFilter").position().left == 0){
	    $(".toggleViewScontiOpt").removeClass("fa-angle-double-left");
	    $(".toggleViewScontiOpt").addClass("fa-angle-double-right");
      $("#optionScontiPanelFilter").removeClass("ov-auto");  
    } else {
	    $(".toggleViewScontiOpt").removeClass("fa-angle-double-right");
      $(".toggleViewScontiOpt").addClass("fa-angle-double-left");
      $("#optionScontiPanelFilter").addClass("ov-auto");
    }
  });  
}

function aggiungiListenersContenuti() {
  $(".tornaAFileList").off("click");
  $(".tornaAFileList").each(function(i) {
    $(this).click(function(e) {
      e.preventDefault(); 
      if ($(this).attr("espanso") == "0") {
        $(this).attr("espanso", "1");
        showFileListFromHeader(this);
      } else {
        $(this).attr("espanso", "0");
        removeFileListFromHeader(this);
      }
    });
  });

}

function aggiungiListenersLogin() {

  $(".sendLogin").click(function(e) {
    e.preventDefault(); 
    LoginWidget.checkCredentials();
  });
  
  $(".sendRecovery").each(function(a) {
    $(this).click(function(e) {
        e.preventDefault(); 
        LoginWidget.gestRecovery($(this).attr("continua"));
    });
  });
  
  $(".recoveryPwd").click(function(e) {
    e.preventDefault(); 
    LoginWidget.showRecovery();
  }); 

  $(".newSignup").click(function(e) {
    e.preventDefault(); 
    LoginWidget.newUserRequest();
  });  
  
  
  $("#loginComunicazioniButton").click(function(e) {
    e.preventDefault(); 
    LoginWidget.apriPDFComunicazioniLogin();
  });  
  
  

  aggiungiListenerShowPwd();  
}

function aggiungiListenerShowPwd() {

  $(".showEye").click(function(e) {
    var type = $("#password").attr("type");
    if (type == "password") {
      $(this).removeClass("fa-eye");
      $(this).addClass("fa-eye-slash");
      $(this).attr("alt", "Nascondi password");
      $(this).attr("title", "Nascondi password");
      $("#password").attr("type", "text");
      $("#password").addClass('textLowercase');
    } else {
      $(this).removeClass("fa-eye-slash");
      $(this).addClass("fa-eye");
      $(this).attr("alt", "Mostra password");
      $(this).attr("title", "Mostra password");
      $("#password").attr("type", "password");
      $("#password").removeClass('textLowercase');
    }
  });
  
 $(".showOldPwd").click(function(e) {
    var type = $("#oldPwd").attr("type");
    if (type == "password") {
      $(this).removeClass("fa-eye");
      $(this).addClass("fa-eye-slash");
      $(this).attr("alt", "Nascondi password");
      $(this).attr("title", "Nascondi password");
      $("#oldPwd").attr("type", "text");
      $("#oldPwd").addClass('textLowercase');
    } else {
      $(this).removeClass("fa-eye-slash");
      $(this).addClass("fa-eye");
      $(this).attr("alt", "Mostra password");
      $(this).attr("title", "Mostra password");
      $("#oldPwd").attr("type", "password");
      $("#oldPwd").removeClass('textLowercase');
    }
  }); 

 $(".showNewPwd").click(function(e) {
    var type = $("#newPwd").attr("type");
    if (type == "password") {
      $(this).removeClass("fa-eye");
      $(this).addClass("fa-eye-slash");
      $(this).attr("alt", "Nascondi password");
      $(this).attr("title", "Nascondi password");
      $("#newPwd").attr("type", "text");
      $("#newPwd").addClass('textLowercase');
    } else {
      $(this).removeClass("fa-eye-slash");
      $(this).addClass("fa-eye");
      $(this).attr("alt", "Mostra password");
      $(this).attr("title", "Mostra password");
      $("#newPwd").attr("type", "password");
      $("#newPwd").removeClass('textLowercase');
    }
  }); 
  
 $(".showNewPwd2").click(function(e) {
    var type = $("#newPwd2").attr("type");
    if (type == "password") {
      $(this).removeClass("fa-eye");
      $(this).addClass("fa-eye-slash");
      $(this).attr("alt", "Nascondi password");
      $(this).attr("title", "Nascondi password");
      $("#newPwd2").attr("type", "text");
      $("#newPwd2").addClass('textLowercase');
    } else {
      $(this).removeClass("fa-eye-slash");
      $(this).addClass("fa-eye");
      $(this).attr("alt", "Mostra password");
      $(this).attr("title", "Mostra password");
      $("#newPwd2").attr("type", "password");
      $("#new2Pwd").removeClass('textLowercase');
    }
  });     
}
function aggiungiListenersVolantini() {

   $("#showVolantiniFilterMobile").click(function(e) {
   e.preventDefault();
   $("#optionVolantiniPanelFilter").toggleClass("visibileLeft");
     if ($("#optionVolantiniPanelFilter").position().left == 0){
	      $(".toggleViewVolantiniOpt").removeClass("fa-angle-double-left");
	      $(".toggleViewVolantiniOpt").addClass("fa-angle-double-right");
        $("#optionVolantiniPanelFilter").removeClass("ov-auto");  
     } else {
	      $(".toggleViewVolantiniOpt").removeClass("fa-angle-double-right");
        $(".toggleViewVolantiniOpt").addClass("fa-angle-double-left");
        $("#optionVolantiniPanelFilter").addClass("ov-auto");
     }
  });
  
   $("#newVolantinoBtn").click(function(e) {
    e.preventDefault(); 
    VolantiniApis.newVolantinoRequest($(this).attr("operazione"));
  });
  
  $(".toggleVolantini").each(function(a) {
    $(this).click(function(e) {
        e.preventDefault();
        if ($(this).attr("numrighe") != 0) { 
          VolantiniApis.mostraDettaglioVolantino($(this).attr("doc"));
        }
    });
  });
  
  $(".btnStampaVolantino").each(function(a) {
    $(this).click(function(e) {
        e.preventDefault(); 
        VolantiniApis.richiediStampaVolantino($(this)[0]);
    });
  });

  $(".btnStampaVolantinoMobile").each(function(a) {
    $(this).click(function(e) {
        e.preventDefault(); 
        VolantiniApis.richiediStampaVolantino($(this)[0]);
    });
  });
  
  $(".btnModVolantino").each(function(a) {
    $(this).click(function(e) {
        e.preventDefault(); 
        VolantiniApis.newVolantinoRequest("chg", $(this)[0]);
    });
  });

  $(".btnModVolantinoMobile").each(function(a) {
    $(this).click(function(e) {
        e.preventDefault(); 
        VolantiniApis.newVolantinoRequest("chg", $(this)[0]);
    });
  });

  $(".inputPrzVolantino").each(function(a) {
    $(this).change(function(e) {
      e.preventDefault();
      VolantiniApis.viewBtnModificaRighe();
    });
  });

  $(".inputRicVolantino").each(function(a) {
    $(this).change(function(e) {
      e.preventDefault();
      VolantiniApis.viewBtnModificaRighe();
    });
  });  
   
  $(".sequenzaVolantino").each(function(a) {
   $(this).change(function(e) {
     e.preventDefault();
     VolantiniApis.viewBtnModificaRighe();
   });
 });
 
 $(".inputPrzMobile").each(function(a) {
    $(this).change(function(e) {
      e.preventDefault();
      VolantiniApis.viewBtnModificaRighe();
    });
  });
   
  $(".sequenzaMobile").each(function(a) {
   $(this).change(function(e) {
     e.preventDefault();
     VolantiniApis.viewBtnModificaRighe();
   });
 }); 
   
 $("#chgVolantinoBtn").click(function(e) {
   e.preventDefault();
   VolantiniApis.modificaArticoloVolantino();
 }); 

 $(".delArticoloVolantino").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
     VolantiniApis.requestDeleteArtVolantino($(this)[0]);
   });
 });
 
 $(".infoArticoloVolantino").each(function(a) {
   $(this).click(function(e) {
     e.preventDefault();
       //VolantiniApis.viewBtnModificaRighe();
       VolantiniApis.viewInfoArtDaVolantino(this);
   });
 }); 
 
 $(".deleteVolantino").each(function(a) {
    $(this).click(function(e) {
       e.preventDefault();
       VolantiniApis.requestDeleteVolantino($(this)[0]);
   });
 });  

 $(".shopImageVolantino").each(function(a) {
    $(this).click(function(e) {
     e.preventDefault();
     var capofila = $(this).attr("cpf");
     if (CommonApis.isMobile()) {
        $("#ricercadesElemMobile").val(capofila);
     } else {
        $("#ricercadesElem").val(capofila);
     }
     CatalogoFiltriWidget.setDescrizioneDaFiltrare();
     CatalogoFiltriWidget.resetRicercheFatte();	 
	 CatalogoFiltriWidget.setCapofilaFromAutocomplete(true);
	 CatalogoWidget.lanciaRicercaCapofila();
   });
 });
}
 function rimuoviListenerMercatino() {
   $(".mrkMercatinoChk").off("click");
   $(".btnAddArtMercatino").off("click");
   $(".mrkMercatinoChk").off("click");
   $("#showMercatinoFilterMobile").off("click");
   $(".catalogoImageMercatino").off("click");
   $(".arrowUpMercatino").off("click");
   $(".arrowDwMercatino").off("click");
   $(".inputQtaPromo").off("click");  
   $(".infoWishMercatino").off("click");
   $(".tabDivisioniPromoMercatino ").off("click");
 }
 
 function aggiungiListenersMercatino() {
  rimuoviListenerMercatino();

  $(".tabDivisioniPromoMercatino").click(function(e) {
     e.preventDefault();
      eraseCookie("divisioneAttiva");
      createCookie("divisioneAttiva", $(this).attr("divisione"));
     MercatinoApis.getMercatino();
  });  
    
  $("#showMercatinoFilterMobile").click(function(e) {
   e.preventDefault();
   $("#optionMercatinoPanelFilter").toggleClass("visibileLeft");
     if ($("#optionMercatinoPanelFilter").position().left == 0){
	      $(".toggleViewMercatinoOpt").removeClass("fa-angle-double-left");
	      $(".toggleViewMercatinoOpt").addClass("fa-angle-double-right");
        $("#optionMercatinoPanelFilter").removeClass("ov-auto");  
     } else {
	      $(".toggleViewMercatinoOpt").removeClass("fa-angle-double-right");
        $(".toggleViewMercatinoOpt").addClass("fa-angle-double-left");
        $("#optionMercatinoPanelFilter").addClass("ov-auto");
     }
  });
     
  $(".mrkMercatinoChk").each(function(a) {
    $(this).click(function(e) {
       //e.preventDefault();
       MercatinoApis.setMrkMercatino();
   });
 });  
 
 $(".annullaFiltroMrk").each(function(a) {
    $(this).click(function(e) {
       e.preventDefault();
       var mrkMercatino = JSON.parse(readCookie("mrkMercatino"));
       mrkMercatino.splice(mrkMercatino.indexOf($(this).attr("mrk")), 1);
       eraseCookie("mrkMercatino");
       if (mrkMercatino.length != 0) {
         createCookie("mrkMercatino", JSON.stringify(mrkMercatino), 1); 
       } 
       MercatinoApis.getMercatino();
   });
 });  
 
 $(".btnAddArtMercatino").each(function(a) {
    $(this).click(function(e) {
       e.preventDefault();
       MercatinoApis.addArtMercatino($(this).attr("artMercatino"));
   });
 }); 
 
 $(".catalogoImageMercatino").each(function(a) {
    $(this).click(function(e) {
       e.preventDefault();
       mouseOverImage($(this).attr("cod"));
   });
 });   
 
 $(".arrowUpMercatino").each(function(a) {
    $(this).click(function(e) {
       e.preventDefault();
       MercatinoApis.checkQta($(this), "+");  
   });
 });  

 $(".arrowDwMercatino").each(function(a) {
    $(this).click(function(e) {
       e.preventDefault();
      MercatinoApis.checkQta($(this), "-");
   });
 });   
 

  $(".inputQtaPromo").each(function(a) {
    $(this).change(function(e) {
       e.preventDefault();
      MercatinoApis.checkQta($(this), "*");
   });
 });   
 
 
  $(".infoWishMercatino").each(function(i) {
    $(this).click(function(e) { 
      e.preventDefault();
      CatalogoWidget.viewCatalogoArtDetail(this);
    });
  });	 
 
 }
 
 function aggiungiListenerStampaVolantino() {
   $(".confermaStampaVolantino").each(function(a) {
     $(this).click(function(e) {
      if ($(this).attr("continua") == "1") { 
       VolantiniApis.stampaVolantino($(this)[0]);              
      } else {
       document.getElementsByTagName("body")[0].removeChild(document.getElementById("reqStampaVolantino"));
       removeHider(); 
      }
     })
   });
 }
 
 function removeListenerStampaVolantino() {
   $(".confermaStampaVolantino").off("click");   
 }

 function aggiungiListenersMenuMyAccount() {
  $(".logOut").each(function(a) {
    $(this).click(function(e) {
     e.preventDefault();
     logout();
     });   
  });
  $(".subMenuAccount").on("mouseleave", function() {
     $(".showPrefContainer").addClass("display-none");
    });

  addListenerMenu();
 } 
 
function aggiungiListenerPwdRecovery() {
 
 $(".chgPwdFromRecovery").off("click");
 $(".chgPwdFromRecovery").click(function(e) {
   e.preventDefault();
   LoginWidget.changePwdFromRecovery();
 });
}

function addListenerCatalogoPremi() {
    $(".btnInsPremio").each(function (a) {
        $(this).click(function (e) {
            e.preventDefault();
            LafeCoinWidget.inserisciPremio(this);
        });
    });
    /*
    $(".arrowUp").each(function(i) {
     $(this).click(function(e) { 
      e.preventDefault();
      LafeCoinWidget.addQtaLocalLfc( this, "+");
    });
  });
*/
}

function addListenerConsumi() {
    $(".tabDivisioniConsumiDft").each(function (a) {
        $(this).click(function (e) {
            e.preventDefault();
            var divisione = $(this).attr("divisione");
            eraseCookie("mrkConsumi");
            eraseCookie("divisioneAttiva");
            createCookie("divisioneAttiva", divisione, 365);
            ConsumiApis.caricaConsumi();
        });
    });

    $(".mrkConsumiChk").each(function (a) {
        $(this).click(function (e) {
            e.preventDefault();
            ConsumiApis.setMrkConsumi();
        });
    });
    $(".arrowDwConsumi").each(function (a) {
        $(this).click(function (e) {
            e.preventDefault();
            ConsumiApis.setQtaConsumi(this);
        });
    });
    $(".arrowUpConsumi").each(function (a) {
        $(this).click(function (e) {
            e.preventDefault();
            ConsumiApis.setQtaConsumi(this);
        });
    });
    $(".addCarrelloDaConsumi").each(function (i) {
        $(this).click(function (e) {
            e.preventDefault();
            ConsumiApis.addArticoloDaConsumi(this);
   
        });
    });
    $(".addWishDaConsumi").each(function (i) {
        $(this).click(function (e) {
            e.preventDefault();
            ConsumiApis.addWishListDaConsumi(this);
        });
    });

    $(".addVolantinoDaConsumi").each(function (i) {
        $(this).click(function (e) {
            e.preventDefault();
            ConsumiApis.addVolantinoDaConsumi($(this));
        });
    });

    $(".radioDataConsumi").each(function (i) {
      $(this).click(function (e) {
            e.preventDefault();
            eraseCookie("consumiPeriod");
            createCookie("consumiPeriod", $(this).attr("giorni"));
            ConsumiApis.caricaConsumi();
        });
    });

    $(".marcaConsumi").each(function (i) {
      $(this).click(function (e) {
        e.preventDefault();
        eraseCookie("mrkConsumi");
        createCookie("mrkConsumi", $(this).attr("mrk"), 365);
        CatalogoWidget.lanciaRicercaCapofila("");
      });
    });
}

function addListenerCatalogoPremi() {
    $(".btnInsPremio").each(function (a) {
        $(this).click(function (e) {
            e.preventDefault();
            LafeCoinWidget.inserisciPremio(this);
        });
    });
}

function removeListenerConsumi() {
    $(".tabDivisioniConsumiDft").off("click");  
    $(".mrkConsumiChk").off("click");
}

