$(function()
{
    $('[name^=type]').change(function()
    {
        var $tr = $(this).parents('tr');
        $tr.find('[name^=category]').load(createLink('cash.trade', 'ajaxGetCategories', 'type=' + $(this).val()), function()
        {
            $tr.find('[name^=category]').trigger('chosen:updated');
        });
    });

    $.setAjaxForm('#batchCreateForm', function(response)
    {
        if(response.result == 'fail' && response.repeatedKeys !== undefined)
        {
            $.each(response.repeatedKeys, function(key)
            {
                $('[id=type' + key + ']').parents('tr').addClass('hl-warning');
            })
        }
        else
        {
            setTimeout(function(){location.href = response.locate;}, 1200);
        }
    });
})
