﻿
// checks if the key pressed while in the textbox should commit the tags
function checkKeyPress(obj, event) {
    // esc, enter, tab
    if (event.keyCode == 27 || event.keyCode == 13 || event.keyCode == 9) {
        //commitTagsUpdate(obj);
        
        // cancel event to prevent these keys from committing changes immediately
        event.cancelBubble = true;
        return false;
    }
}

// triggers async call to save tags on server side
function commitTagsUpdate(obj) {
    var updatePanelId = $(obj).parent().attr('id').replace(/_/g, '$');
    __doPostBack(updatePanelId, '');
}

$(document).ready(function() {
    // hover effect
    $('.tag-widget-wrap').hover(
        function() { $(this).addClass('tag-widget-wrap-hover'); },
        function() { $(this).removeClass('tag-widget-wrap-hover'); }
    );

    // change read mode to write mode when clicked
    $('.tag-widget-wrap').click(function() {
        var readObj = $('.tag-widget-read', $(this));
        var writeObj = $('.tag-widget-write', $(this));
        var saveObj = $('.tag-widget-save', $(this));

        // only if textbox isn't already visible
        if (!writeObj.is(':visible')) {
            readObj.hide();
            writeObj.show();
            writeObj.focus();
            writeObj.select();
            saveObj.show();
        }
    });
});
