var $selectedItem;
var selectItem = function(item)
{
    $selectedItem = $(item).first();
    var modal  = $('#ajaxModal');
    var params = v.params + 'customers=' + $('input[type=hidden][name*=customers]').val() + ',' + $selectedItem.data('key')
    var link   = createLink(v.module, v.method, params);
    modal.load(link, function()
    {
        $('#customers.chosen').chosen();
        $(this).find('.modal-dialog').css('width', $(this).data('width'));
        $.zui.ajustModalPosition()
    })
};

$(document).ready(function()
{
    var showSearchModal = function()
    {
        var key       = $('#customers_chosen .chosen-results > li.no-results > span').text();
        var customers = $('[name*=customer]').val().join(',').replace(',showmore', '');
        var link      = createLink('customer', 'ajaxSearchCustomer', 'key=' + key + '&relation=&customers=' + customers);
        $('#ajaxModal').load(link);
    };

    $(document).on('change', '#customers', function()
    {
        if($.inArray('showmore', $(this).val()) > 0)
        {
             showSearchModal();
        }
    });

    $(document).on('click', '#customers_chosen .chosen-results > li.no-results', showSearchModal);

})
