$(function () {
  $("#keyword").defaultvalue("bicycle");
  $("#email").defaultvalue("your@email.com");
  $("#location").defaultvalue("craigslist city");

  $(".delete").click(function () {
    var msg = $(this).attr("confirm");
    if (!msg) { msg = 'Are you sure?'; };
    if (confirm(msg)) {
      var f = document.createElement('form');
      f.style.display = 'none';
      this.parentNode.appendChild(f);
      f.method = 'POST';
      f.action = this.href;
      var m = document.createElement('input');
      m.setAttribute('type', 'hidden');
      m.setAttribute('name', '_method');
      m.setAttribute('value', 'delete');
      f.appendChild(m);
      f.submit();
    };
    return false;
  });

  $("#edit-user-name-link").toggle(
    function () {
      $("#edit-user-name-link").html("&#9660;");
      $("#user-form-container").show();
    },
    function () {
      $("#edit-user-name-link").html("&#9668;");
      $("#user-form-container").hide();
    }
  );

  $("#location").autocomplete("/locations", {scrollHeight: 210, width: 400});
  $("#location").result(function(event, data, formatted) {
    if (data) {
      $("#location_id").val(data[1]);
    }
  });

  // TODO: figure out a good flash color system.
  // $("#flash").effect("highlight", {"color":"#dff4ff"}, 600);
});