<script type="text/javascript">
(function(Con, $) {
    $(function() {
        // replace the text div with an input field if the div or the edit button is clicked
        $('#{PREFIX}_editbutton_{ID}, #{PREFIX}_text_{ID}').click(function() {
            var text = $('#{PREFIX}_text_{ID}').text();
            $('#{PREFIX}_text_{ID}').replaceWith('{TEXTBOX}');
            $('#{PREFIX}_text_{ID}').val(text);
            $('#{PREFIX}_text_{ID}').focus();
            $('#{PREFIX}_editbutton_{ID}').replaceWith('{SAVEBUTTON}');
        });
        // submit the form if the save button or enter is clicked
        $(document).on('click', '#{PREFIX}_savebutton_{ID}', function() {
            cContentType{PREFIX}Save{ID}();
        });

        /**
         * Adds the given name/value pair as a hidden field to the editform so that it
         * is submitted to CONTENIDO. If a hidden field with the given name already
         * exists, the value is overriden.
         *
         * @param {String} name The name of the form field which should be added.
         * @param {String} value The value of the form field which should be added.
         */
        function cContentType{PREFIX}AppendFormField{ID}(name, value) {
            // if a hidden input field with the given name already exists, just set the value
            if ($('form[name="editcontent"] input[type="hidden"][name="' + name + '"]').length > 0) {
                $('form[name="editcontent"] input[type="hidden"][name="' + name + '"]').val(value);
            } else {
                // otherwise append a new field to the form
                $('form[name="editcontent"]').append('<input type="hidden" value="" name="' + name + '">');
                $('form[name="editcontent"] input[type="hidden"][name="' + name + '"]').val(value);
            }
        };

        /**
         * Saves the entered text.
         */
        function cContentType{PREFIX}Save{ID}() {
            cContentType{PREFIX}AppendFormField{ID}('{PREFIX}_action', 'store');
            cContentType{PREFIX}AppendFormField{ID}('{PREFIX}_id', '{ID}');
            var text = $('#{PREFIX}_text_{ID}').val();
            cContentType{PREFIX}AppendFormField{ID}('{PREFIX}_text_{ID}', text);
            // save changes done in tinymce
            Con.Tiny.setContent('{IDARTLANG}');
        }
    });
})(Con, Con.$);

</script>