(function($) {
    $( document ).ready(function() {

        function loadTemplateToEditor(url){
            $.ajax({
                url: url,
                data: {'delivery_method':this.value},
                type: 'get'
            }).success(function(response){
                if (navigator.appName=="Microsoft Internet Explorer"){
                    if (window.parent.tinyMCE) {
                        window.parent.tinyMCE.selectedInstance.selection.moveToBookmark(window.parent.global_ie_bookmark);
                    }
                }
                tinyMCE.get('description').focus();
                tinyMCE.activeEditor.setContent(response);

            });

        }

        $('#load_defualt').on('click', function(e){
            e.stopPropagation();
            e.preventDefault();

            var  url = 'index.php?option=com_jlticketcenter&controller=tickettemplate&format=raw'
            loadTemplateToEditor(url);
        });

        $('#load_defualt_free').on('click', function(e){
            e.stopPropagation();
            e.preventDefault();

            var  url = 'index.php?option=com_jlticketcenter&controller=tickettemplate&format=raw&task=free'
            loadTemplateToEditor(url);
        });
    });

})(jQuery);
