var artists = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  remote: {
    url: '/api/artists/?format=json&term=%QUERY',
    wildcard: '%QUERY',
    rateLimitBy: 100,
  }
});

var tracks = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  remote: {
    url: '/api/tracks/?format=json&track=%QUERY',
    wildcard: '%QUERY',
    rateLimitBy: 100,
    transform: function(result) {
        return result.results;
    }
  }
});


$('.typeahead-artist').each(function() {
    $(this).typeahead(null, {
        name: 'artists',
        source: artists,
        limit: 10,
});
});

var localCount = 0;
var ausCount = 0;
var femaleCount = 0;

$('.local_check').each(function() {
    if ($(this).is(':checked'))
        localCount++;
    $(this).click(function() {
        if ($(this).is(':checked'))
            localCount++;
        else
            localCount--;
        $('#local_quota').html(localCount);
    });
    $('#local_quota').html(localCount);
});

$('.australian_check').each(function() {
    if ($(this).is(':checked'))
        ausCount++;
    $(this).click(function() {
        if ($(this).is(':checked'))
            ausCount++;
        else
            ausCount--;
        $('#aus_quota').html(ausCount);
    });
    $('#aus_quota').html(ausCount);
});

$('.female_check').each(function() {
    if ($(this).is(':checked'))
        femaleCount++;
    $(this).click(function() {
        if ($(this).is(':checked'))
            femaleCount++;
        else
            femaleCount--;
        $('#female_quota').html(femaleCount);
    });
    $('#female_quota').html(femaleCount);
});



$('.typeahead-track').each(function() {
    console.log($(this)[0].id);
    $(this).typeahead(null, {
        name: 'tracks',
        source: tracks ,
        display: function(suggestion) {
            return suggestion.tracktitle;
        }
});
});


// Prevent return key from submitting form
$(document).ready(function() {
  $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});


@@ -1,12 +1,92 @@
+var trackCount = 0;%0Avar localCount = 0;%0Avar ausCount = 0;%0Avar femaleCount = 0;%0A%0A
 var artists 
@@ -827,65 +827,334 @@
 );%0A%0A
-var localCount = 0;%0Avar ausCount = 0;%0Avar femaleCount = 0
+$('.typeahead-track').each(function() %7B%0A    if ($(this).val() == %22%22) %7B%0A%0A    %7D%0A    else %7B%0A        trackCount++;%0A    %7D%0A    console.log($(this)%5B0%5D.id);%0A    $(this).typeahead(null, %7B%0A        name: 'tracks',%0A        source: tracks ,%0A        display: function(suggestion) %7B%0A            return suggestion.tracktitle;%0A        %7D%0A%7D);%0A%7D)
 ;%0A%0A$
@@ -1397,37 +1397,61 @@
 al_quota').html(
-local
+%22%22 + localCount + %22/%22 + track
 Count);%0A    %7D);%0A
@@ -1477,21 +1477,45 @@
 ').html(
-local
+%22%22 + localCount + %22/%22 + track
 Count);%0A
@@ -2162,259 +2162,8 @@
 %0A%0A%0A%0A
-$('.typeahead-track').each(function() %7B%0A    console.log($(this)%5B0%5D.id);%0A    $(this).typeahead(null, %7B%0A        name: 'tracks',%0A        source: tracks ,%0A        display: function(suggestion) %7B%0A            return suggestion.tracktitle;%0A        %7D%0A%7D);%0A%7D);%0A
 %0A%0A//

Update number of tracks in a show as they are entered.