
/*
 * Zuständig dafür die sonstigen Felder und werte aktuell zu halten
 */

function MiscListener() {

  this.notify = function(item) {

    add2CartFormValue = $('#formItemId');
    add2CartFormValue.attr('value', item.id);
    for(var j = 0; j < item.vari.length; j++) {
      if (item.vari[j].indexOf('warranty_MOD') != -1 && item.vari[j].indexOf('\xa7') != -1) {
        $('#formPromEndz').attr('value', item.promEndz);
        break;
      }
    }
    /*
    add2CartFormValue.each(function() {
      var t = $(this);
      if( t.attr('value')) {
        t.attr('value', item.id);
       // console.debug("item id: " + item.id);
      }
     });
    */

    $('#NewPriceValue').text(item.price);

    /* Neue Maßartikel-Logik benötigt dieses Feld nicht mehr
    if (item.pricePerSellingUnit != '' && item.pricePerSellingUnit != null) {
      $('#PricePerSellingUnit').text(item.pricePerSellingUnit);
    } else {
      $('#PricePerSellingUnit').text('');
    }
    */

    if (item.savedAmount != '' && item.savedPercentage != '') {
      $('#SaveMoneyValue').text(item.savedAmount);
      $('#SaveMoneyPercent').text( item.savedPercentage);
      $('.SaveMoney').each(function() {
        $(this).css("display", "block");
        });
     } else {
       $('.SaveMoney').each(function() {
         $(this).css("display", "none");
         });
     }


    oldPrice = $('.OldPrice');
    oldPrice.each(function() {
      var t = $(this);
      if( item.oldPrice != '' && item.oldPrice != null) {
        $('.OldPrice').css("text-decoration", "line-through");
        t.text(item.oldPrice);
        $('#priceValueBox').addClass("NewPrice");
        $('#priceValueBox').removeClass("Price");
      } else if( item.uvpPrice != '' && item.uvpPrice != null) {
        $('.OldPrice').css("text-decoration", "none");
        //t.text("UVP** " + item.uvpPrice); // TODO RM
        t.html(RRP + " <span style='text-decoration: line-through;'>" + item.uvpPrice + "</span>");
        $('#priceValueBox').addClass("NewPrice");
        $('#priceValueBox').removeClass("Price");
      } else {
        $('.OldPrice').css("text-decoration", "line-through");
        $('#priceValueBox').removeClass("NewPrice");
        $('#priceValueBox').addClass("Price");
        t.html('');
      }
     });

    setPrice = $('.SetPrice');
    setPrice.each(function() {
      var t = $(this);
      if( t.attr('value')) {
        t.attr('value', '');
      }
     });

     // if (shop.nl == 'true') {
     available = $('.Available P');
     available.each(function() {
       var t = $(this);

       if( item.availability != '' && showOverallAvailibilityStatement) {
         t.html(item.availability);
       } else {
         t.html('');
       }

      });
     // für AT nicht mehr notwendig, da auf KAL umgestellt
     // } else if (shop.at == 'true') {
     // // Availability wieder an, falls aus
     // if ($('#availabilityCheck').hasClass('hidden')) {
     //   $('#availabilityCheck').removeClass('hidden');
     //   $('#availabilityText').addClass('hidden');
     // }
     // }

    artNr = $('.OrderNumber span');
    artNr.each(function() {
      var t = $(this);
      if( item.artNo != '') {
        t.text(item.artNo);
      } else {
        t.html('');
      }
     });
    quantity = $('#quantity');
    quantity.each(function() {
      var t = $(this);
      // selectbox leeren
      t.children().each(function() {
        $(this).remove();
      });
      t.addOption(1 , 1, true);

      if( item.maxOrderAmount > 1) {
        j = 2;
        while (j <= item.maxOrderAmount) {
          t.addOption(j , j, false);
          j++;
        }
      }
     //t.sortOptions();
     });




    // button für weitere bilder ein oder ausblenden
    if (PictureSlidesSet[item.id] != null && PictureSlidesSet[item.id].length > 1) {
      $("#furtherImgLink").css("display", "inline");
    } else if (PictureSlidesSet[0] != null && PictureSlidesSet[0].length > 1) {
      $("#furtherImgLink").css("display", "inline");
    } else {
      $("#furtherImgLink").css("display", "none");
    }

    // button für 3d bild ein oder ausblenden
    // TODO
    if (numberOfMovies > 0) {
      $("#3dLink").css("display", "inline");
      extensionBox = true;
    } else {
      $("#3dLink").css("display", "none");
    }

    // update sellingpoints
    if (shopIsNL == 'false' ) {
      $.ajax({
        url: shop.baseUrl+'itemUSP',
        data: ({id: item.id}),
          success: function (data) {
            $('.ProductProperties#SellingPointsList').html(data);
          }
      });
    }
  };
}

/*
 * Zuständig dafür den Farbwähler aktuell zu halten
 * Für das ZoomoPopup
 */

function ColorListListener() {

  this.notify = function(item) {
    nextSelectBox = $('.ADSPictureWrapper');
    nextSelectBox.children().each(function() {
     var t = $(this);
     if( t.attr('imageset') == item.id) {
       t.click();
       return;
     }
    });

    try {
      // TODO auf der zoomo Seite

      nextSelectBox = $('.ADSColors');
     /*
      nextSelectBox.children().each(function() {
        var t = $(this);
        if( t.attr('rel') == item.id) {
          // TODO Hier bitte die Selection der box einbauen
          console.debug(item.id + " => select: " + itemidZoomImg);


        }
       });
       */
      //console.debug(itemidZoomImg[item.id]);
      setnewpicture(itemidZoomImg[item.id][0]);
    } catch (e) {
      // console.debug(e);
    }
    
    /* Umschalten der einfachen 7-Schritte-Anzeige */
    $('#Galery .clearfix').each(function() {
      $(this).css("display", "none");
    });
    $('#Galery #ADSThumbNavi_' + item.plainColor).css("display", "block");
    
    /* Umschalten der 7-Schritte-Anzeige von Multivisio */
    if (PictureSlidesSet[item.id].length < 2) {
      $('.ADSPictureNavi').css("display", "none");
    } else {
      $('.ADSPictureNavi').css("display", "block");
    }
  };
}
