function select_district() {
  $('#district_checkbox input[type=checkbox]').attr("checked", "checked");
}
function unselect_district() {
  $('#district_checkbox input[type=checkbox]').removeAttr("checked");
}

$().ready(function() {
  var url = "/town/list.js";
  $("input.town_input").autocomplete(url, {
    dataType: "json",
    selectFirst: true,
    //mustMatch: true,
    //autoFill: true,
    minChars: 0,
    parse: function(data) {
      return $.map(data, function(row) {
        return {
          data: row,
          value: row,
          result: row
        }
      })
    },
    formatItem: function(item) {
      return item
    }
  });
  
  var town_list = jQuery('#town_list');
  town_list.accordion({
    autoheight: false
  });
  jQuery('#show_accrordion').toggle(
    function () {
      $(this).text('Скрыть');
      
      town_list.css('display', 'block');
    }, function () {
      $(this).text('Показать все города списком');
      town_list.css('display', 'none');
    }
  )
  
  $("#count_roomer_find li").each(function(index_li) {
    var li_element = $(this);
    li_element.addClass('roomer_li').click(function() {
      var this_element = $(this);
      if (this_element.hasClass("roomer_li_selected")) {
        this_element.removeClass("roomer_li_selected");
        $('input[type=checkbox]', this).removeAttr('checked');
      } else {
        this_element.addClass("roomer_li_selected");
        $('input[type=checkbox]', this).attr('checked', 'checked');
      }
      return false;
    });
    $('input[type=checkbox]', this).each(function(index_checkbox) {
      if ($(this).attr("checked")) {
        li_element.addClass('roomer_li_selected');
      }
      $(this).hide();
    });
  });
})

