jQuery(function() {
    jQuery( "#sortable" ).sortable();
    jQuery( "#sortable" ).disableSelection();
});

jQuery(document).ready(function(){
    jQuery('#select_action_banner').change(
        function(){
            if (this.value == '1') {
                jQuery("#product_list").addClass("hide");
                jQuery("#category_list").addClass("hide");
                jQuery("#link_list").addClass("hide");
                jQuery("#product_list").removeClass("hide");
            }else if (this.value == '2') {
                jQuery("#product_list").addClass("hide");
                jQuery("#category_list").addClass("hide");
                jQuery("#link_list").addClass("hide");
                jQuery("#category_list").removeClass("hide");
            } else if (this.value == '3') {
                jQuery("#product_list").addClass("hide");
                jQuery("#category_list").addClass("hide");
                jQuery("#link_list").addClass("hide");
                jQuery("#link_list").removeClass("hide");
            }
        });
    jQuery('#select_action_banner1').change(
        function(){
            if (this.value == '1') {
                jQuery("#product_list1").addClass("hide");
                jQuery("#category_list1").addClass("hide");
                jQuery("#link_list1").addClass("hide");
                jQuery("#product_list1").removeClass("hide");
            }else if ( this.value == '2') {
                jQuery("#product_list1").addClass("hide");
                jQuery("#category_list1").addClass("hide");
                jQuery("#link_list1").addClass("hide");
                jQuery("#category_list1").removeClass("hide");
            }else if (this.value == '3') {
                jQuery("#product_list1").addClass("hide");
                jQuery("#category_list1").addClass("hide");
                jQuery("#link_list1").addClass("hide");
                jQuery("#link_list1").removeClass("hide");
            }
        });
    jQuery('#select_action_banner2').change(
        function(){
            if ( this.value == '1') {
                jQuery("#product_list2").addClass("hide");
                jQuery("#category_list2").addClass("hide");
                jQuery("#link_list2").addClass("hide");
                jQuery("#product_list2").removeClass("hide");
            }else if ( this.value == '2') {
                jQuery("#product_list2").addClass("hide");
                jQuery("#category_list2").addClass("hide");
                jQuery("#link_list2").addClass("hide");
                jQuery("#category_list2").removeClass("hide");
            } else if (this.value == '3') {
                jQuery("#product_list2").addClass("hide");
                jQuery("#category_list2").addClass("hide");
                jQuery("#link_list2").addClass("hide");
                jQuery("#link_list2").removeClass("hide");
            }
        });
    jQuery('#select_action_banner3').change(
        function(){
            if (this.value == '1') {
                jQuery("#product_list3").addClass("hide");
                jQuery("#category_list3").addClass("hide");
                jQuery("#link_list3").addClass("hide");
                jQuery("#product_list3").removeClass("hide");
            }else if (this.value == '2') {
                jQuery("#product_list3").addClass("hide");
                jQuery("#category_list3").addClass("hide");
                jQuery("#link_list3").addClass("hide");
                jQuery("#category_list3").removeClass("hide");
            } else if (this.value == '3') {
                jQuery("#product_list3").addClass("hide");
                jQuery("#category_list3").addClass("hide");
                jQuery("#link_list3").addClass("hide");
                jQuery("#link_list3").removeClass("hide");
            }
        });
    jQuery('#select_action_banner4').change(
        function(){
            if (this.value == '1') {
                jQuery("#product_list4").addClass("hide");
                jQuery("#category_list4").addClass("hide");
                jQuery("#link_list4").addClass("hide");
                jQuery("#product_list4").removeClass("hide");
            }else if (this.value == '2') {
                jQuery("#product_list4").addClass("hide");
                jQuery("#category_list4").addClass("hide");
                jQuery("#link_list4").addClass("hide");
                jQuery("#category_list4").removeClass("hide");
            } else if (this.value == '3') {
                jQuery("#product_list4").addClass("hide");
                jQuery("#category_list4").addClass("hide");
                jQuery("#link_list4").addClass("hide");
                jQuery("#link_list4").removeClass("hide");
            }
        });

    jQuery('#select_item_option').change(function(){

        if(this.value >= 1000 & this.value < 2000){
// change demo img
            jQuery(".img_product_list").addClass('hide');
            jQuery("#demo_PList_" + this.value ).removeClass('hide');

            /// change demo img

            jQuery("#alert_item").html("");
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            if ( this.value == 1003) {

                jQuery(".div_mainpage").addClass("hide");
                jQuery(".div_pishnehad_vizhe").removeClass("hide");
                jQuery("#tr_list_image").removeClass('hide')
            }
            else{
                jQuery(".div_mainpage").addClass("hide");
                jQuery(".div_list_vertical").removeClass("hide");
                jQuery("#tr_list_image").addClass('hide')
            }

            if ( this.value == 1004) {
                jQuery("#tr_list_image").removeClass('hide')
            }
        }
        else if(this.value >= 2000 & this.value < 3000){
// change demo img
            jQuery(".img_post_list").addClass('hide');
            jQuery("#demo_PostList_" + this.value ).removeClass('hide');
            /// change demo img
            jQuery("#alert_item").html("");
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
        }

    });

    jQuery("#btn_form_order").click(function(){
        var r ="";
        jQuery("#img_load").removeClass("hide");
        var x = jQuery("#form_sort").serializeArray();
        jQuery.each(x, function(i, field){
            r += (field.value + "_");
        });
        jQuery.ajax({
            url: ajaxurl,
            data:{
                action:'save_order_woo_item',
                id : r
            } ,
            type : "post" ,
            success:function(data) {
                jQuery("#img_load").addClass("hide");
                data = data.substring(0,data.length -1);
                if(data == 1){
                    jQuery("#alert_sort").removeClass("hide");
                    jQuery("#alert_sort").removeClass("alert-danger");
                    jQuery("#alert_sort").removeClass("alert-success");
                    jQuery("#alert_sort").addClass("alert-success");
                    jQuery("#alert_sort").html("Sorting done.");
                    setTimeout(function(){
                        jQuery("#alert_sort").addClass("hide");
                    }, 3000);
                }
            }
        });
    });

    jQuery("#check_list_cat_mainpage").change(function(){
        var r = 0;
        if (this.checked) {
            r=1;
        }else{
            r=0;
        }
        jQuery.ajax({
            url: ajaxurl,
            data:{
                action:'change_show_btn_catlst',
                id : r
            } ,
            type : "post" ,
            success:function(data) {
            }
        });
    });

    jQuery("#check_map_mainpage").change(function(){
        var r = 0;
        if (this.checked) {
            r=1;
        }else{
            r=0;
        }
        jQuery.ajax({
            url: ajaxurl,
            data:{
                action:'change_show_map',
                id : r
            } ,
            type : "post" ,
            success:function(data) {
            }
        });
    });

    //-------------slash set------------------------------------------
    jQuery("#btn_form_splash").click(function(){
        var delay_splash = jQuery("#delay_splash").val();
        var url_splash = jQuery("#txt_url_item_hami1").val();
        if(delay_splash.length <= 0 || url_splash.length <= 0 )
        {
            jQuery("#alert_splash").removeClass("hide");
            jQuery("#alert_splash").removeClass("alert-success");
            jQuery("#alert_splash").removeClass("alert-danger");
            jQuery("#alert_splash").addClass("alert-danger");
            jQuery("#alert_splash").html("Please do not leave the splash image and delay time blank. /");
            setTimeout(function(){
                jQuery("#alert_splash").addClass("hide");
            }, 3000);
            return false;
        }
        jQuery.ajax({
            url: ajaxurl,
            data:{
                action:'woo2app_setsplash',
                delay_splash : delay_splash,
                url_splash : url_splash
            } ,
            type : "post" ,
            success:function(data) {
                data = data.substring(0,data.length -1);
                if(data == 1){
                    jQuery("#alert_splash").removeClass("hide");
                    jQuery("#alert_splash").removeClass("alert-success");
                    jQuery("#alert_splash").removeClass("alert-danger");
                    jQuery("#alert_splash").addClass("alert-success");
                    jQuery("#alert_splash").html("Your settings have been saved.");
                    setTimeout(function(){
                        jQuery("#alert_splash").addClass("hide");
                    }, 3000);
                }else{
                    jQuery("#alert_splash").removeClass("hide");
                    jQuery("#alert_splash").removeClass("alert-success");
                    jQuery("#alert_splash").removeClass("alert-danger");
                    jQuery("#alert_splash").addClass("alert-danger");
                    jQuery("#alert_splash").html("Error saving data.");
                    setTimeout(function(){
                        jQuery("#alert_splash").addClass("hide");
                    }, 3000);
                }
            }
        });
    });
    //----------------------------------------------------------------
});
function add_item_mainpage(){
    opt = jQuery("#select_item_option").val();
    if (opt == 1) {

        showtype = 1;
        title = jQuery("#txt_title_banner_item").val();
        pic = jQuery("#txt_url_item_hami").val();
        type = jQuery("#select_action_banner").val();
        value = "";
        flag = 0;
        if(type == 2){
            value = jQuery('#value_cat_items').val();
        }else if (type == 1) {
            value = jQuery('#value_post_items').val();
        }else if (type == 3) {
            value = jQuery('#value_link_items').val();
        }
        if (pic == "") {
            flag = 2;
        }
        if (value == "" || value == null || value == 0) {
            flag = 3;
        }
        if(flag == 0){
            jQuery("#img_load1").removeClass("hide");
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "add_item_hami_woo",
                    "title": title , "type" : type ,   "value" : value , "showtype" : showtype , "pic" : pic
                },
                success:function(data) {
                    //jQuery("#img_load1").addClass("hide");
                    if(data == 10){
                        jQuery("#alert_item").removeClass("hide");
                        jQuery("#alert_item").removeClass("alert-danger");
                        jQuery("#alert_item").removeClass("alert-success");
                        jQuery("#alert_item").addClass("alert-success");
                        jQuery("#alert_item").html("Your item has been registered.");
                        setTimeout(function(){
                            jQuery("#alert_item").addClass("hide");
                        }, 3000);
                        jQuery.ajax({
                            url: ajaxurl,
                            data: {
                                action: "load_item_hami_woo"
                            },
                            success:function(data) {
                                data = data.substring(0,data.length -1);
                                jQuery("#sortable").html(data);
                            }
                        });
                    }
                }
            });
        }else{
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            jQuery("#alert_item").addClass("alert-danger");
            if(flag ==1) jQuery("#alert_item").html("Enter the title.");
            if(flag ==2) jQuery("#alert_item").html("Choose a banner image.");
            if(flag ==3) jQuery("#alert_item").html("Select a topic from the list.");
        }
    }
    else if (opt == 2) {
        showtype = 2;
        count_load = jQuery("#txt_number_load_ver_item").val();
        pic = "";
        title = jQuery("#txt_title_ver_item").val();
        value = type_value = jQuery('#value_cat_items_ver').val();
        if(value == 'all') value = '';
        value = {'value':value, 'count_load':count_load};
        type = 2;
        if(jQuery('#cat_tag_ver').val() == 'tag_ver') {
            value = type_value = jQuery('#value_tag_items_ver').val();
            if(value == 'all') value = '';
            value = {'value':value, 'count_load':count_load};
            type = 3;
        }
        sort = jQuery('#value_sort_ver').val();
        flag = 0;
        //alert(value.value)
        if (type_value == "" || type_value == null || type_value == 0) {
            flag = 3;
        }

        //console.log(JSON.stringify(showtypeObj))
        if(flag == 0){
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "add_item_hami_woo",
                    "title": title , "type" : type ,   "value" : JSON.stringify(value) , 'sort':sort , "showtype" : showtype , "pic" : pic
                },
                success:function(data) {
                    jQuery("#img_load1").addClass("hide");
                    console.log(data)
                    if(data == 10){
                        jQuery("#alert_item").removeClass("hide");
                        jQuery("#alert_item").removeClass("alert-danger");
                        jQuery("#alert_item").removeClass("alert-success");
                        jQuery("#alert_item").addClass("alert-success");
                        jQuery("#alert_item").html("Your item has been registered.");
                        setTimeout(function(){
                            jQuery("#alert_item").addClass("hide");
                        }, 3000);
                        jQuery.ajax({
                            url: ajaxurl,
                            data: {
                                action: "load_item_hami_woo"
                            },
                            success:function(data) {
                                data = data.substring(0,data.length -1);
                                jQuery("#sortable").html(data);
                            }
                        });
                    }
                }
            });
        }else{
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            jQuery("#alert_item").addClass("alert-danger");
            if(flag ==1) jQuery("#alert_item").html("Enter the title.");
            if(flag ==2) jQuery("#alert_item").html("Choose a banner image.");
            if(flag ==3) jQuery("#alert_item").html("Select a topic from the list.");
        }
    }
    else if (opt == 3) {
        showtype = 3;
        count_load = jQuery("#txt_number_load_hor_item").val();
        pic = "";
        title = jQuery("#txt_title_hor_item").val();
        value = type_value = jQuery('#value_cat_items_hor').val();
        if(value == 'all') value = '';
        value = {'value':value, 'count_load':count_load};
        type = 2;
        if(jQuery('#cat_tag').val() == 'tag') {
            value = type_value = jQuery('#value_tag_items_hor').val();
            if(value == 'all') value = '';
            value = {'value':value, 'count_load':count_load};
            type = 3;
        }
        sort = jQuery('#value_sort_hor').val();
        flag = 0;
        if (type_value == "" || type_value == null || type_value == 0) {
            flag = 3;
        }

        if(flag == 0){
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "add_item_hami_woo",
                    "title": title , "type" : type ,   "value" : JSON.stringify(value) ,'sort':sort, "showtype" : showtype , "pic" : pic
                },
                success:function(data) {
                    jQuery("#img_load1").addClass("hide");
                    if(data == 10){
                        jQuery("#alert_item").removeClass("hide");
                        jQuery("#alert_item").removeClass("alert-danger");
                        jQuery("#alert_item").removeClass("alert-success");
                        jQuery("#alert_item").addClass("alert-success");
                        jQuery("#alert_item").html("Your item has been registered.");
                        setTimeout(function(){
                            jQuery("#alert_item").addClass("hide");
                        }, 3000);
                        jQuery.ajax({
                            url: ajaxurl,
                            data: {
                                action: "load_item_hami_woo"
                            },
                            success:function(data) {
                                data = data.substring(0,data.length -1);
                                jQuery("#sortable").html(data);
                            }
                        });
                    }
                }
            });
        }else{
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            jQuery("#alert_item").addClass("alert-danger");
            if(flag ==1) jQuery("#alert_item").html("Enter the title.");
            if(flag ==2) jQuery("#alert_item").html("Choose a banner image.");
            if(flag ==3) jQuery("#alert_item").html("Select a topic from the list.");
        }
    }
    else if (opt == 11) {
        jQuery("#img_load1").removeClass("hide");
        showtype = 11;
        pic = "";
        title = jQuery("#txt_title_ver_item").val();
        value = jQuery('#value_cat_items_ver').val();
        sort = "";
        type = 2;
        flag = 0;
        if (value == "" || value == null || value == 0) {
            flag = 3;
        }
        if(value == 'all') value = '';
        if(flag == 0){
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "add_item_hami_woo",
                    "title": title , "type" : type ,   "value" : value ,'sort':sort, "showtype" : showtype , "pic" : pic
                },
                success:function(data) {
                    console.log(data)
                    jQuery("#img_load1").addClass("hide");
                    if(data == 10){
                        jQuery("#alert_item").removeClass("hide");
                        jQuery("#alert_item").removeClass("alert-danger");
                        jQuery("#alert_item").removeClass("alert-success");
                        jQuery("#alert_item").addClass("alert-success");
                        jQuery("#alert_item").html("Your item has been registered.");
                    }
                }
            });
        }else{
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            jQuery("#alert_item").addClass("alert-danger");
            if(flag ==1) jQuery("#alert_item").html("Enter the title.");
            if(flag ==2) jQuery("#alert_item").html("Choose a banner image.");
            if(flag ==3) jQuery("#alert_item").html("Select a topic from the list.");
        }
    }
    else if (opt == 4){
        showtype = 4;
        title1 = jQuery("#txt_title_4banner1_item").val();
        title2 = jQuery("#txt_title_4banner2_item").val();
        title3 = jQuery("#txt_title_4banner3_item").val();
        title4 = jQuery("#txt_title_4banner4_item").val();
        pic1 = jQuery("#txt_url_item_hami1").val();
        pic2 = jQuery("#txt_url_item_hami2").val();
        pic3 = jQuery("#txt_url_item_hami3").val();
        pic4 = jQuery("#txt_url_item_hami4").val();
        type1 = jQuery("#select_action_banner1").val();
        type2 = jQuery("#select_action_banner2").val();
        type3 = jQuery("#select_action_banner3").val();
        type4 = jQuery("#select_action_banner4").val();
        value1 = "";
        value2 = "";
        value3 = "";
        value4 = "";
        if(type1 == 2){
            value1 = jQuery('#value_cat_items1').val();
        }else if (type1 == 1) {
            value1 = jQuery('#value_post_items1').val();
        }else if (type1 == 3) {
            value1 = jQuery('#value_link_items1').val();
        }
        if(type2 == 2){
            value2 = jQuery('#value_cat_items2').val();
        }else if (type2 == 1) {
            value2 = jQuery('#value_post_items2').val();
        }else if (type2 == 3) {
            value2 = jQuery('#value_link_items2').val();
        }
        if(type3 == 2){
            value3 = jQuery('#value_cat_items3').val();
        }else if (type3 == 1) {
            value3 = jQuery('#value_post_items3').val();
        }else if (type3 == 3) {
            value3 = jQuery('#value_link_items3').val();
        }
        if(type4 == 2){
            value4 = jQuery('#value_cat_items4').val();
        }else if (type4 == 1) {
            value4 = jQuery('#value_post_items4').val();
        }else if (type4 == 3) {
            value4 = jQuery('#value_link_items4').val();
        }
        flag = 0;
        // if(title1.trim() == "" || title2.trim() == "" || title3.trim() == "" || title4.trim() == ""){
        // 	flag = 1;
        // }
        if (pic1 == "" || pic2 == "" || pic3 == "" || pic4 == "") {
            flag = 2;
        }
        if (value1 == "" || value1 == null || value1 == 0 ||
            value2 == "" || value2 == null || value2 == 0 ||
            value3 == "" || value3 == null || value3 == 0 ||
            value4 == "" || value4 == null || value4 == 0 ) {
            flag = 3;
        }
        if(flag == 0){
            var b0 = '{ "banner4" : [';
            var b1 =  '{ "title"  : "' + title1 + '" , "type" :"' + type1 +'" , "value" : "' + value1 + '" , "pic" : "' + pic1 + '"},';
            var b2 =  '{ "title"  : "' + title2 + '" , "type" :"' + type2 +'" , "value" : "' + value2 + '" , "pic" : "' + pic2 + '"},';
            var b3 =  '{ "title"  : "' + title3 + '" , "type" :"' + type3 +'" , "value" : "' + value3 + '" , "pic" : "' + pic3 + '"},';
            var b4 =  '{ "title"  : "' + title4 + '" , "type" :"' + type4 +'" , "value" : "' + value4 + '" , "pic" : "' + pic4 + '"}]}';
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "add_item_hami_woo",
                    "title": "بنر 4تایی" , "type" : "" , "b0" : b0,"b1" : b1,"b2" : b2,"b3" : b3,"b4" : b4 , "showtype" : showtype , "pic" : ""
                },
                success:function(data) {
                    jQuery("#img_load1").addClass("hide");
                    if(data == 10){
                        jQuery("#alert_item").removeClass("hide");
                        jQuery("#alert_item").removeClass("alert-danger");
                        jQuery("#alert_item").removeClass("alert-success");
                        jQuery("#alert_item").addClass("alert-success");
                        jQuery("#alert_item").html("Your item has been registered.");
                        setTimeout(function(){
                            jQuery("#alert_item").addClass("hide");
                        }, 3000);
                        jQuery.ajax({
                            url: ajaxurl,
                            data: {
                                action: "load_item_hami_woo"
                            },
                            success:function(data) {
                                data = data.substring(0,data.length -1);
                                jQuery("#sortable").html(data);
                            }
                        });
                    }
                }
            });
        }else{
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            jQuery("#alert_item").addClass("alert-danger");
            if(flag ==1) jQuery("#alert_item").html("Enter the title.");
            if(flag ==2) jQuery("#alert_item").html("Choose a banner image.");
            if(flag ==3) jQuery("#alert_item").html("Select a topic from the list.");
        }
    }
    else if (opt == 1003) {
        showtype = opt;
        value = jQuery('#value_pishnehad_vizhe').val();
        title = jQuery("#value_pishnehad_vizhe option:selected").text();
        type = jQuery('#value_pishnehad_vizhe_time').val();
        pic = jQuery('#ListImage').val();
        flag = 0;
        if (value == "" || value == null || value == 0) {
            flag = 3;
        }
        if(flag == 0){
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "add_item_hami_woo",
                    "title":  title, "type" : type ,   "value" : value ,'sort':"", "showtype" : showtype , "pic" : pic			    },
                success:function(data) {
                    jQuery("#img_load1").addClass("hide");
                    if(data == 10){
                        jQuery("#alert_item").removeClass("hide");
                        jQuery("#alert_item").removeClass("alert-danger");
                        jQuery("#alert_item").removeClass("alert-success");
                        jQuery("#alert_item").addClass("alert-success");
                        jQuery("#alert_item").html("Your item has been registered.");
                        setTimeout(function(){
                            jQuery("#alert_item").addClass("hide");
                        }, 3000);
                        jQuery.ajax({
                            url: ajaxurl,
                            data: {
                                action: "load_item_hami_woo"
                            },
                            success:function(data) {
                                data = data.substring(0,data.length -1);
                                jQuery("#sortable").html(data);
                            }
                        });
                    }
                }
            });
        }else{
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            jQuery("#alert_item").addClass("alert-danger");
            if(flag ==3) jQuery("#alert_item").html("Please select from the list.");
        }
    }
    else if (opt > 1000 && opt <= 1009){
        showtype = opt;
        count_load = jQuery("#txt_number_load_ver_item").val();
        pic = "";
        if(opt == 1004){
            pic = jQuery("#ListImage").val();
        }
        title = jQuery("#txt_title_ver_item").val();
        value = type_value = jQuery('#value_cat_items_ver').val();
        if(value == 'all') value = '';
        value = {'value':value, 'count_load':count_load};
        type = 2;
        if(jQuery('#cat_tag_ver').val() == 'tag_ver') {
            value = type_value = jQuery('#value_tag_items_ver').val();
            if(value == 'all') value = '';
            value = {'value':value , 'count_load':count_load};
            type = 3;


        }
        if(jQuery('#cat_tag_ver').val() == 'custom_list') {
            value = jQuery('#value_custom_list').val();
            type = 4;
        }
        sort = jQuery('#value_sort_ver').val();
        flag = 0;
        //alert(value.value)
        if (type_value == "" || type_value == null || type_value == 0) {
            flag = 3;
        }

        //console.log(JSON.stringify(showtypeObj))
        if(type != 4){
            value = JSON.stringify(value)
        }
        if(flag == 0){
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "add_item_hami_woo",
                    "title": title , "type" : type ,   "value" : value , 'sort':sort , "showtype" : showtype , "pic" : pic
                },
                success:function(data) {
                    jQuery("#img_load1").addClass("hide");
                    console.log(data)
                    if(data == 10){
                        jQuery("#alert_item").removeClass("hide");
                        jQuery("#alert_item").removeClass("alert-danger");
                        jQuery("#alert_item").removeClass("alert-success");
                        jQuery("#alert_item").addClass("alert-success");
                        jQuery("#alert_item").html("Your item has been registered.");
                        setTimeout(function(){
                            jQuery("#alert_item").addClass("hide");
                        }, 3000);
                        jQuery.ajax({
                            url: ajaxurl,
                            data: {
                                action: "load_item_hami_woo"
                            },
                            success:function(data) {
                                data = data.substring(0,data.length -1);
                                jQuery("#sortable").html(data);
                            }
                        });
                    }
                }
            });
        }else{
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            jQuery("#alert_item").addClass("alert-danger");
            if(flag ==1) jQuery("#alert_item").html("Enter the title.");
            if(flag ==2) jQuery("#alert_item").html("Choose a banner image.");
            if(flag ==3) jQuery("#alert_item").html("Select a topic from the list.");
        }
    }
    else if (opt >= 2000 && opt <= 2004){
        //alert(111)
        jQuery("#img_load1").removeClass("hide");
        showtype = opt;
        pic = "";
        title = jQuery("#txt_title_hor_item").val();
        value = jQuery('#value_cat_items_hor').val();
        sort = "";
        type = 2;
        flag = 0;
        if (value == "" || value == null || value == 0) {
            flag = 3;
        }
        if(value == 'all') value = '';
        console.log(value)
        if(flag == 0){
            jQuery.ajax({
                url: ajaxurl,
                data: {
                    action: "add_item_hami_woo",
                    "title": title , "type" : type ,   "value" : value ,'sort':sort, "showtype" : showtype , "pic" : pic
                },
                success:function(data) {
                    jQuery("#img_load1").addClass("hide");
                    if(data == 10){
                        jQuery("#alert_item").removeClass("hide");
                        jQuery("#alert_item").removeClass("alert-danger");
                        jQuery("#alert_item").removeClass("alert-success");
                        jQuery("#alert_item").addClass("alert-success");
                        jQuery("#alert_item").html("Your item has been registered.");

                    }
                }
            });
        }else{
            jQuery("#alert_item").removeClass("hide");
            jQuery("#alert_item").removeClass("alert-danger");
            jQuery("#alert_item").removeClass("alert-success");
            jQuery("#alert_item").addClass("alert-danger");
            if(flag ==1) jQuery("#alert_item").html("Enter the title.");
            if(flag ==2) jQuery("#alert_item").html("Choose a banner image.");
            if(flag ==3) jQuery("#alert_item").html("Select a topic from the list.");
        }
    }

}
//----------------------------------------------------------------
function delete_item_mainepage_woo(id){
    if(confirm("Are You Sure ?")){
        jQuery("#img_load").removeClass("hide");
        jQuery.ajax({
            url: ajaxurl,
            data: {
                action: "delete_item_mainepage_woo",
                id : id
            },
            success:function(data) {
                jQuery("#img_load").addClass("hide");
                data = data.substring(0,data.length -1);
                if(data == 1){
                    jQuery("#record" + id).remove();
                }
            }
        });
    }
}