anchor.diff:    <% for mage in Mage.all %> mageMap['<%= mage.name %>'] = {}; <% end  %>
     <% for ms in MageSchool.all %> mageMap['<%= ms.mage_name %>']['<%= ms.school_name %>'] = <%= ms.cost %>; <% end %>
   
  +  var costMap = function() {
  +    return mageMap[mage()]
  +  } 
  +
  +  var deck = {
  +    _entries : {},
  +    get : function(code) {
  +      return this._entries[code]
  +    },
  +    add : function(card) {
  +      var card_entry = this._entries[card.code]
  +      if(!card_entry) {
  +        card_entry = this._entries[card.code] = {card : $.extend({}, card), amount : 0}
  +      } 
  +      card_entry.amount += 1
  +      return card_entry
  +    },
  +    remove : function(code) {
  +      delete this._entries[code]
  +    },
  +    cost : function() {
  +      return  _.reduce(this._entries, function(memo, card_entry) {
  +        return memo + card_entry.amount * card_entry.card.cost()
  +      }, 0)
  +    },
  +    codes : function() {
  +      return _.keys(this._entries)
  +    },
  +    entries : function() {
  +      return _.values(this._entries)
  +    }
  +  }
  + 
     var buildParams = function() {
       return {
         for_type : _.map($("#for_type input:checked"), function(e) {
  
positive.code:        var select = $('<select/>').appendTo(td).change(function() {
           var card_entry = deck.get(tr.data('code'))
           card_entry.amount = parseInt($(this).val())
           updateDeckTr(tr)
           updateTotalDeckCost()
         })
  
  
negative.code: 
    $('#card_list_table').on('click', 'tbody tr button', function() {
      var listTr = $(this).closest('tr')
      deck.add(listTr.data('card'))
      deckTable.dataTable().fnDraw()
      updateTotalDeckCost()
    })
  
  