(function(){
	var PackagesPurchase = function() {
    return {

    	init: function() {
    		var totalCost = $('#total_cost span');
            var totalCart = $('#total_cart span');

    		$('.select-processor-fund').on('change', function(){
              var fee = $('.select-processor-fund option:selected').data('fee');
              var val = $('#amount_transfer').val();

              if( $(this).val() == 6 ) {
                $('#amount-container').hide();
                $('#fee-container').hide();
                $('#gc-container').removeClass('hidden');
              } else {
                $('#gc-container').addClass('hidden');
                $('#amount-container').show();
                $('#fee-container').show();
                //calculateFee(fee, val);
              }

          });

    		$('.select-processor-fund').trigger('change');

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

				App.ajax({
					url: ajax_url_packages_addTo,
					data: {
						id: id,
						name: name,
						quantity: quantity
					}
				}, function( data ) {
					if( data && data.data.result == true ) {
						totalCost.html( data.data.totalCost );
                        totalCart.html( data.data.packageName + ': ' + data.data.packageQuantity );
					}
				});
			});
		}
    };
  }();

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

})();
