$(function() {
    $('ul.sortable').sortable({ axis: "y", stop: saveStatusOrder, handle: '.handle' });
});

function saveStatusOrder()
{
    var ids = $('ul.sortable').sortable('toArray');
    $.getJSON(base + 'tasktype.ivp/saveorder', { ids: ids, timestamp: new Date().toString() });
}

function showDeletingDialog(id) {
    $('#deletingdialogwrapper').remove();
    $('li[id=' + id + ']').append('<div id="deletingdialogwrapper" class="popupwrapper"><div id="deletingdialog" class="popup"></div></div>');
    $('#deletingdialog').load(base + 'tasktype.ivp/showdeletingdialog/' + id, null, function() { $('#deletingdialogwrapper').show(); });
    return false;
}

function deleteTaskType(id) {
    $.getJSON(base + 'tasktype.ivp/delete/', { id: id, json: true, timestamp: new Date().toString() }, taskTypeDeleted);
    return false;
}

function taskTypeDeleted(result) {
    if (!result.IsOK) alert(result.Description);
    else {
        $('#deletingdialogwrapper').remove();
        $('li[id=' + result.Id + ']').remove();
    }
}
