function show_add_practice_system() 
{
    jQuery("#full_psn_main_section").toggle();
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function add_practice_system() 
{
    // //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    var main_x;
    var d = new Date();
    var n = d.getMilliseconds() + 'practice';
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    main_x = jQuery(".psn_main_section").clone(true);
    main_x.removeClass('psn_main_section').addClass('psn_section').appendTo("#psn_main_section");
    jQuery("#full_psn_main_section .psn_section").last().find('input[type=text]').val('');//.attr('id', n)
    // //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function remove_practice_system(mainThis) {
    if (mainThis.id != 'pmid') {
        //jQuery(mainThis).remove();
        jQuery(mainThis).parents('.psn_section').remove();
    }
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function add_q(id) {
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    var main_x;
    var d = new Date();
    var n = d.getMilliseconds() + '_question_' + id;
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    main_x = jQuery(".question_" + id).clone(true);
    main_x.removeClass('question_' + id).appendTo("#question_" + id);
    jQuery("#question_" + id + " input[type=text]").last().val(' ');
    jQuery("#question_" + id + " a").last().attr('id', n);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function remove_q(mainThis) {
    if ((mainThis.id == 'start_4_quetion') || (mainThis.id == 'start_5_quetion') || (mainThis.id == 'start_6_quetion')) {
        console.log(mainThis.id);
    } else {
        jQuery(mainThis).parent().parent().parent().remove();
    }
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*function add_section() {
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    var main_x;
    var d = new Date();
    var n = d.getMilliseconds() + '_section';
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    main_x = jQuery(".main_section").clone(true);
    main_x.removeClass('main_section').addClass(n).appendTo("#all_section");
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    var t = jQuery("#all_section").find('.batch-tab-box1').length;
    jQuery('.'+n+' h4 b').text(t);
    jQuery('.'+n).find('input,textarea').each(function(){jQuery(this).val('');});;
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*function add_lecture() {
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    var main_x;
    var d = new Date();
    var n = d.getMilliseconds() + '_lecture';
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    main_x = jQuery(".main_lecture").clone(true);
    main_x.removeClass('main_lecture').addClass(n).appendTo("#all_lecture");
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    var t = jQuery("#all_lecture").find('.batch-tab-box1').length;
    jQuery('.'+n+' h4 label').text(t);
    jQuery('.'+n).find('input,textarea,select').each(function(){jQuery(this).val('');});;
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function set_save_and_next(id) {
    jQuery("#is_save_and_next").val(id);
     // window.scrollTo(0, 0);
}
function set_save_and_next2(id) {
    jQuery("#is_save_and_next").val(id);
    jQuery("a[href='#tab-content-"+id+"']").click();
    // window.scrollTo(0, 0);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function parctice_free() {
    if (jQuery("#is_the_couse_free").prop('checked') == true) {
        jQuery("#course_currency").prop('disabled', true);
        jQuery("#course_amount").prop('disabled', true);
    } else {
        jQuery("#course_currency").prop('disabled', false);
        jQuery("#course_amount").prop('disabled', false);
    }
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jQuery(document).ready(function(e) {
    jQuery("form#form_step_1").submit(function(e) {
        e.preventDefault();
        tinymce.triggerSave(true, true);
        $('.help-block').html('');
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var _action_url = jQuery('form#form_step_1').attr('action');
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var formData = new FormData(this);
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        jQuery.ajax({
            url: _action_url,
            type: 'POST',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            dataType: "json",
            beforeSend: function() {
                // setting a timeout
                jQuery("#the_main_preloader").show();
            },
            success: function(res) {
                jQuery("#the_main_preloader").hide();
                // jQuery("#ajax_preloader_for_ajax_call").hide();
                if (res.flag) {
                    Swal.fire({
                        icon: "success",
                        title: "Great!",
                        text: res.msg.toString()
                    }).then(function() {
                        jQuery("#submit_for_review").addClass('active');
                        if (res.course_image) {
                            jQuery(".course_image_container").empty().html('<img src="'+res.course_image+'" alt="" class="w-25">');
                            jQuery("input[name=course_image]").val('');
                        }
                        if (res.course_video) {
                            jQuery(".course_video_container").empty().html('<a href="'+res.course_video+'" target="_blank"><i class="fa fa-download" aria-hidden="true"></i> '+res.course_video_name+'</a>');
                            jQuery("input[name=course_video]").val('');
                        }
                        if (jQuery("#is_save_and_next").val() == 2) {
                            // jQuery("#tab-content-2").tab('show');
                            jQuery("a[href='#tab-content-2']").click();
                            window.scrollTo(0, 0);
                        }
                        jQuery(".tab_content_1 .fa").removeClass('fa-circle').addClass('fa-check text-primary');
                    });
                } else {
                    /*Swal.fire({
                        icon: "error",
                        title: "Oops.",
                        text: res.msg.toUpperCase()
                    });*/
                    $.each(res.msg, function (key, val) {
                        if (key == 'category_id') {
                            $('form#form_step_1').find('[name="' + key + '[]"]').parent().find('.help-block').html(val[0]);
                        }
                        if (key == 'practice_system.0' || key == 'practice_system.1' || key =='practice_system.2' || key=='practice_system.3') {
                            $('form#form_step_1').find('[name="practice_system[]"]').parents('#full_psn_main_section').parent().find('.help-block').html(val[0]);
                        }
                        if (key == 'course_video_mimes') {
                            $('form#form_step_1').find('[name="course_video"]').parent().find('.help-block').html(val[0]);
                        }
                        //$('form#form_step_1').find('[name="' + key + '"]').closest('.form-group').find('.help-block').html(val[0]);
                        // $('form#form_step_1').find('[name="' + key + '"]').closest('.help-block').html(val[0]);
                        $('form#form_step_1').find('[name="' + key + '"]').parent().parent().find('.help-block').html(val[0]);
                    });
                }
            },
            error: function(res) {
                jQuery("#the_main_preloader").hide();
                Swal.fire({
                    icon: "error",
                    title: "Oh no!",
                    text: res.msg.toString()
                });
            }
        });
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    });
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//    new-nav-dropdown-js
jQuery(document).ready(function(){
    jQuery(".core-menu li").hover(function(){
        jQuery(this).children('ul').slideDown('fast');
    },  function () {
        jQuery('ul', this).slideUp('fast');
    });
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jQuery(document).ready(function(e) {
    jQuery("form#form_step_2").submit(function(e) {
        e.preventDefault();
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var _action_url = jQuery('form#form_step_2').attr('action');
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var formData = new FormData(this);
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        jQuery.ajax({
            url: _action_url,
            type: 'POST',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            dataType: "json",
            success: function(res) {
                // jQuery("#ajax_preloader_for_ajax_call").hide();
                if (res.flag) {
                    Swal.fire({
                        icon: "success",
                        title: "Great!",
                        text: res.msg.toString()
                    }).then(function() {
                        if (jQuery("#is_save_and_next").val() == 3) {
                            jQuery("a[href='#tab-content-3']").click();
                            window.scrollTo(0, 0);
                        }
                        jQuery(".tab_content_2 .fa").removeClass('fa-circle').addClass('fa-check text-primary');
                    });
                } else {
                    Swal.fire({
                        icon: "error",
                        title: "Oh no!",
                        text: res.msg.toString()
                    });
                }
            },
            error: function(res) {
                Swal.fire({
                    icon: "error",
                    title: "Oh no!",
                    text: res.msg.toString()
                });
            }
        });
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    });
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jQuery(document).ready(function(e) {
    jQuery("form#form_step_3").submit(function(e) {
        e.preventDefault();
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var _action_url = jQuery('form#form_step_3').attr('action');
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var formData = new FormData(this);
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        jQuery.ajax({
            url: _action_url,
            type: 'POST',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            dataType: "json",
            success: function(res) {
                // jQuery("#ajax_preloader_for_ajax_call").hide();
                if (res.flag) {
                    Swal.fire({
                        icon: "success",
                        title: "Great!",
                        text: res.msg.toString()
                    }).then(function() {
                        if (jQuery("#is_save_and_next").val() == 4) {
                            jQuery("a[href='#tab-content-4']").click();

                            window.scrollTo(0, 0);
                        }
                        jQuery(".tab_content_3 .fa").removeClass('fa-circle').addClass('fa-check text-primary');
                    });
                } else {
                    Swal.fire({
                        icon: "error",
                        title: "Oh no!",
                        text: res.msg.toString()
                    });
                }
            },
            error: function(res) {
                Swal.fire({
                    icon: "error",
                    title: "Oh no!",
                    text: res.msg.toString()
                });
            }
        });
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    });
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jQuery(document).ready(function(e) {
    jQuery("form#form_step_4").submit(function(e) {
        e.preventDefault();
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var _action_url = jQuery('form#form_step_4').attr('action');
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        // var formData = new FormData(this);
        var formData = new FormData($('form#form_step_4')[0]);
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        jQuery.ajax({
            url: _action_url,
            type: 'POST',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            dataType: "json",
            success: function(res) {
                // jQuery("#ajax_preloader_for_ajax_call").hide();
                if (res.flag) {
                    // Swal.fire({
                    //     icon: "success",
                    //     title: "Great!",
                    //     text: res.msg.toUpperCase()
                    // }).then(function() {
                        if (res.rd) {
                            $('.minsectionselect').html('');
                            $('.minsectionselect').html(res.rd);
                            var selectedData = new Array();
                            $('#all_section > .draggable').each(function() {
                                selectedData.push($(this).data("id"));
                            });
                            updateOrder(selectedData, 'section');
                        }
                        if (jQuery("#is_save_and_next").val() == 6) {
                            jQuery("a[href='#tab-content-6']").click();
                            window.scrollTo(0, 0);
                        }
                        jQuery(".tab_content_4 .fa").removeClass('fa-circle').addClass('fa-check text-primary');
                    // });
                } else {
                    Swal.fire({
                        icon: "error",
                        title: "Oh no!",
                        text: res.msg.toString()
                    });
                }
            },
            error: function(res) {
                Swal.fire({
                    icon: "error",
                    title: "Oh no!",
                    text: res.msg.toString()
                });
            }
        });
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    });
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jQuery(document).ready(function(e) {
    jQuery("form#form_step_5").submit(function(e) {
        e.preventDefault();
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var _action_url = jQuery('form#form_step_5').attr('action');
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var formData = new FormData(this);
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        jQuery.ajax({
            url: _action_url,
            type: 'POST',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            dataType: "json",
            success: function(res) {
                // jQuery("#ajax_preloader_for_ajax_call").hide();
                if (res.flag) {
                    Swal.fire({
                        icon: "success",
                        title: "Great!",
                        text: res.msg.toString()
                    }).then(function() {
window.scrollTo(0, 0);
                    });
                } else {
                    Swal.fire({
                        icon: "error",
                        title: "Oh no!",
                        text: res.msg.toString()
                    });
                }
            },
            error: function(res) {
                Swal.fire({
                    icon: "error",
                    title: "Oh no!",
                    text: res.msg.toUpperCase()
                });
            }
        });
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    });
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jQuery(document).ready(function(e) {
    jQuery("form#form_step_6").submit(function(e) {
        e.preventDefault();
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var _action_url = jQuery('form#form_step_6').attr('action');
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        var formData = new FormData(this);
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        jQuery.ajax({
            url: _action_url,
            type: 'POST',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            dataType: "json",
            success: function(res) {
                // jQuery("#ajax_preloader_for_ajax_call").hide();
                if (res.flag) {
                    Swal.fire({
                        icon: "success",
                        title: "Great!",
                        text: res.msg.toString()
                    }).then(function() {window.scrollTo(0, 0);});
                } else {
                    Swal.fire({
                        icon: "error",
                        title: "Oh no!",
                        text: res.msg.toString()
                    });
                }
            },
            error: function(res) {
                Swal.fire({
                    icon: "error",
                    title: "Oh no!",
                    text: res.msg.toString()
                });
            }
        });
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    });
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function delete_section(id,type) {
    jQuery("#section_delete_id").val(id);
    jQuery("#section_delete_type").val(type);
    if (type=='section') {
        Swal.fire({
            title: 'Confirm',
            text: "Lectures under this section will be deleted.",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
            if (result.isConfirmed) {
                var _action_url = jQuery('form#section_delete').attr('action');
                var formData = new FormData(jQuery('form#section_delete')[0]);
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                jQuery.ajax({
                    url: _action_url,
                    type: 'POST',
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    dataType: "json",
                    success: function(res) {
                        if (res.flag) {
                            var selectedData = new Array();
                            $('#all_section > .draggable').each(function() {
                                selectedData.push($(this).data("id"));
                            });
                            updateOrder(selectedData, 'section');

                            Swal.fire({
                                icon: "success",
                                title: "Great!",
                                text: res.msg.toString()
                            }).then(function() {
                                jQuery("form#form_step_4").submit();
                            });
                        } else {
                            Swal.fire({
                                icon: "error",
                                title: "Oh no!",
                                text: res.msg.toString()
                            }).then(function() {});
                        }
                    },
                    error: function(res) {
                        Swal.fire({
                            icon: "error",
                            title: "Oh no!",
                            text: res.msg.toString()
                        });
                    }
                });
            }
        });
    }else if (type=='lecture') {
        Swal.fire({
            title: 'Are you sure?',
            text: "You want to delete the lecture permanently!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
            if (result.isConfirmed) {
                var _action_url = jQuery('form#section_delete').attr('action');
                var formData = new FormData(jQuery('form#section_delete')[0]);
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                jQuery.ajax({
                    url: _action_url,
                    type: 'POST',
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    dataType: "json",
                    success: function(res) {
                        if (res.flag) {
                                jQuery("form#form_step_4").submit();

                            Swal.fire({
                                icon: "success",
                                title: "Great!",
                                text: res.msg.toString()
                            }).then(function() {
                                $('.all_lecture').each(function() {
                                    var selectedData = new Array();
                                    $(this).find('.lecturedrag').each(function() {
                                        selectedData.push($(this).data("id"));
                                    });
                                    updateOrder(selectedData,'lecture');
                                });
                            });
                        } else {
                            Swal.fire({
                                icon: "error",
                                title: "Oh no!",
                                text: res.msg.toString()
                            }).then(function() {});
                        }
                    },
                    error: function(res) {
                        Swal.fire({
                            icon: "error",
                            title: "Oh no!",
                            text: res.msg.toString()
                        });
                    }
                });
            }
        });
    }
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function submitForReview() {
    Swal.fire({
        title: 'Confirm',
        text: "Are you sure you want to submit the course? You will not be able to edit the course after submission.",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, submit it!'
    }).then((result) => {
        if (result.isConfirmed) {
            var _action_url = jQuery('form#submit_for_review').attr('action');
            //jQuery('form#submit_for_review').submit();
            //window.location.href = _action_url;
            var formData = new FormData(jQuery('form#submit_for_review')[0]);
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            jQuery.ajax({
                url: _action_url,
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function(res) {
                    // jQuery("#ajax_preloader_for_ajax_call").hide();
                    if (res.flag) {
                        Swal.fire({
                            icon: "success",
                            title: "Great!",
                            text: res.msg.toString()
                        }).then(function() {
                            if (res.rd) {
                                window.location.href = res.rd;
                            }                            
                        });
                    } else {
                        Swal.fire({
                            icon: "error",
                            title: "Oh no!",
                            text: res.msg.toString()
                        }).then(function() {
                            if (res.rd) {
                                window.location.href = window.location.href;
                            }                            
                        });
                    }
                },
                error: function(res) {
                    Swal.fire({
                        icon: "error",
                        title: "Oh no!",
                        text: res.msg.toString()
                    });
                }
            });
        }
    })
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++


$('body').on('click', 'a[data-confirm]', function(e){
    e.preventDefault();
    var confirm = $(this).attr('data-confirm');
    if (confirm == null || !confirm) {
      confirm = "You won't be able to revert this!"
    }

    Swal.fire({
        title: 'Are you sure?',
        text: 'confirm',
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
        if (result.isConfirmed) {
            var _action_url = jQuery(this).attr('href');
            window.location.href = _action_url;
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        }
    });

});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$('body').on('click', '.copy-data', function(e){
    e.preventDefault();
    var $temp = $("<input>");
    var data = $(this).val();
    if (!data) {
        data = $(this).attr('href');
    }
    $("body").append($temp);
    $temp.val(data).select();
    document.execCommand("copy");
    $temp.remove();
    //$(this).addClass('active');
    $(this).attr('data-original-title', 'Copied!').tooltip('show');
});

$(function () {
  $('[data-toggle="tooltip"]').tooltip();
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
