﻿jQuery(function($){

    // focus the first field in the first form
    $('form:first :input:visible:enabled:first').focus();

    // enable tabs
    $(".tabs > ul").tabs();
    
    // enable table sorting
    $.tablesorter.defaults.sortList = [[1, 0]];
    $("table.tablesorter").tablesorter({
        headers: {
            0: { sorter: false },
            7: { sorter: false }
        }
    });

});

function deleteEntity(id, entity) {
    if (confirm('WARNING: This action cannot be undone.\nDo you want to continue?')) $('#delete-' + entity + '-' + id).submit();
    return false;
}

function cancelEntity(id, entity) {
    if (confirm('WARNING: This action cannot be undone.\nDo you want to continue?')) $('#cancel-' + entity + '-' + id).submit();
    return false;
}

function picker(id) {
    $(id).ColorPicker({
        onChange: function(hsb, hex, rgb) {
            $(id).val('#' + hex).css('color', $(id).val());
        },
        onSubmit: function(hsb, hex, rgb, el) {
            $(el).val('#' + hex);
            $(el).ColorPickerHide();
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });
}

function sidebarToggle(el) {
    $(el).siblings('ul').slideToggle(400, function() {
        var name = this.id;
        if($(this).is(':visible')) {
            Cookie.create(name, true);
        }
        else {
            Cookie.erase(name);
        }
    });
    return false;
}

