(function(){
	var GiftCardsPurchase = function() {
    return {

    	init: function() {

			$('.btn-addToCart').on('click', function(e){
				var self = $(this),
					parent = self.parents('tr'),
					id = parent.data('id'),
					quantity = parent.find('select').val(),
					form = $('.gfBuyForm');

				form.find('input[name="quantity"]').val(quantity);
				form.find('input[name="item"]').val(id);

				form.submit();
			});

			$('a#gift-card-id-button').on('click', function(){
                var url = ajax_url_activateGiftCard;
                var code = $('#gift-card-id-value').val();

                //console.log(code);

                App.ajax({
                    type: 'POST',
                    url: url,
                    data: {
                        uid: code
                    },
                    dataType: 'json',
                    //block: true,
                    //blockTarget: loading
                }, function ( response ) {
                    //refreshCounters( result.data.counters );
                    //reloadAfterChange();
					if(response.data.result === true){
                        window.location = success_activation_url;
					}
					//if(result)
                });

            });
		}
    };
  }();

	$(document).ready(function() {
		GiftCardsPurchase.init();
	});

})();
