function updater_zip_tar() {
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.updaterziptar";
    var ms = $("#modulcreator_project_edit").serialize();
    var wait = BX.showWait('updater_zip');
    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            updaterziptar: "YES",
            ms: ms,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(".updater-zip-tar").html(total.data);
            BX.closeWait('updater_zip', wait);
            return true;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return true;
}
function set_version_input() {
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.setversioninput";
    var ms = $("#modulcreator_project_edit").serialize();
    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            setversioninput: "YES",
            ms: ms,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;

            if(total.data.fl == 1) {
                $(".js-version").html(total.data.out);
                $(".to-version").html("");
            }
            if(total.data.fl == 0) {
                $(".js-version").html("");
                $(".to-version").html(total.data.out);
            }
            if(total.data.fl == 2) {
                $(".js-version").html("");
                $(".to-version").html("");
            }


            return true;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return true;
}
function fill_zip_tar() {
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.fillziptar";
    var ms = $("#modulcreator_project_edit").serialize();
    var wait = BX.showWait('full_zip');
    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            fillziptar: "YES",
            ms: ms,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(".full-zip").html(total.data);
            BX.closeWait('full_zip', wait);
            return false;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return false;
}
function get_gramatik() {
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.Getgramatik";
    var ms = $("#modulcreator_project_edit").serialize();
    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            Getgramatik: "YES",
            ms: ms,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(".itog-papka_gramatika").html(total.data);
            return false;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return false;
}

function zamena_parner_modul(eto,str) {
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.zamenaparnermodul";
    var part = $('input.part').val();
    var modul = $('input.modul').val();
    var name = $('input.name').val();
    if ($('input.comp').prop('checked') === true) {
        var comp = 1;
    } else {
        var comp = 0;
    }
    if ($('input.d7').prop('checked') === true) {
        var d7 = 1;
    } else {
        var d7 = 0;
    }
    var fl_new = 0;
    var newpart = $('input#in22').val();
    var newmodul = $('input#in23').val();
    var newnameprj = $('input#in24').val();
    if (newpart) {
        if (newmodul) {
            if (newnameprj) {
                if (newpart.length > 0 && newmodul.length > 0 && newnameprj.length > 0) {
                    fl_new = 1;
                }
            }
        }
    }
    var msgMs = jQuery.parseJSON(str);
    if (fl_new === 0) {
        alert(msgMs.err1);
        return false;
    }
    var ms = $("#modulcreator_project_edit").serialize();
    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            zamena_part: "YES",
            part: part,
            modul: modul,
            comp: comp,
            d7: d7,
            ms: ms,
            sessid: $('#sessid-m').val(),
            newnameprj:newnameprj
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(".zamens-rezult").html(total.data);
            return false;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });

    return false;
}

function sinc_component(eto) {
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.sinccomponent";
    var part = $('input.part').val();
    var modul = $('input.modul').val();
    var name = $('input.name').val();
    if ($('input.comp').prop('checked') === true) {
        var comp = 1;
    } else {
        var comp = 0;
    }
    if ($('input.d7').prop('checked') === true) {
        var d7 = 1;
    } else {
        var d7 = 0;
    }
    var ms = $("#modulcreator_project_edit").serialize();
    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            ajfromcomp: "YES",
            part: part,
            modul: modul,
            comp: comp,
            d7: d7,
            ms: ms,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(".itog-papka3").html(total.data);
            return false;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return false;
}
function mk_lang_mess() {
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.mklangmess";
    var part = $('input.part').val();
    var modul = $('input.modul').val();
    var name = $('input.name').val();
    if ($('input.comp').prop('checked') === true) {
        var comp = 1;
    } else {
        var comp = 0;
    }
    if ($('input.d7').prop('checked') === true) {
        var d7 = 1;
    } else {
        var d7 = 0;
    }
    var ms = $("#modulcreator_project_edit").serialize();

    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            ajlang: "YES",
            part: part,
            modul: modul,
            comp: comp,
            d7: d7,
            ms: ms,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(".itog-papka_lang-0").html(total.data);
            return false;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return false;
}
function show_hid_work_page() {
    if($("#in35").prop("checked")=== true) {
        if($(".work_page").hasClass("hidd")) {
            $(".work_page").removeClass("hidd");
        }
    }else {
        if($(".work_page").hasClass("hidd")) {
        }else {
            $(".work_page").addClass("hidd");
        }
    }
}
function set_warn_mess(str) {
    var part = $("#in1").val();
    var mod = $("#in2").val();
    var part2="partnerlatinica";
    var mod2="modullatinica";
    var fl_mod = 0;
    if(part) {
        if(part.length>0) {
            part2 = part;
        }
    }
    if(mod) {
        if(mod.length>0) {
            mod2 = mod;
            fl_mod = 1;
        }
    }
    /* Сноска помощи */
    $(".p-modul-warning").html(' (' + str.err1 + ' /bitrix/modules/<b>' + part + '.' + mod + '</b>/)');
    $(".s-part").html(part2);
    $(".s-mod").html(mod2);
    /*Видимость выбора файла обновления updater updater-text*/
    if($("#in30").prop("checked")=== true) {
        if($(".updater-text").hasClass("hidd")) {
        }else {
            $(".updater-text").addClass("hidd");
        }
        $(".updater-file").removeClass("hidd");
    }else {
        if($(".updater-file").hasClass("hidd")) {
        }else {
            $(".updater-file").addClass("hidd");
        }
        $(".updater-text").removeClass("hidd");
    }
    /* Видимость копирования компонента */
    var fl = 0;
    if($("#in3").prop("checked")=== true && fl_mod === 1) {
        if( $("#in4").val().length>0 && $("#in5").val().length>0) {
            fl = 1;
        }
    }
    if(fl === 0) {
         if($(".copy-component").hasClass("hidd")) {
         }else {
             $(".copy-component").addClass("hidd");
         }
    }else {
        $(".copy-component").removeClass("hidd");
        /**/
        var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.messagecopycomponent";
        var part = $('input.part').val();
        var modul = $('input.modul').val();
        if ($('input.comp').prop('checked') === true) {
            var comp = 1;
        } else {
            var comp = 0;
        }
        if ($('input.d7').prop('checked') === true) {
            var d7 = 1;
        } else {
            var d7 = 0;
        }
        var ms = $("#modulcreator_project_edit").serialize();
        var papka = "/bitrix/modules/" + part + "." + modul + "/";
        $.ajax({
            url: url,
            type: "post",
            async: true,
            data: {
                aj: "YES",
                part: part,
                modul: modul,
                comp: comp,
                d7: d7,
                ms: ms,
                sessid: $('#sessid-m').val()
            },
            success: function (responseData, textStatus, jqXHR) {
                var total = responseData;
                $(".itog-papka3").html(total.data);
                return false;
            },
            error: function (responseData, textStatus, errorThrown) {
            }
        });
        /**/
    }
    return true;
}

function mk_dir_strukture(str) {
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.mkdirstrukture";
    var part = $('input.part').val();
    var modul = $('input.modul').val();
    if ($('input.comp').prop('checked') === true) {
        var comp = 1;
    } else {
        var comp = 0;
    }
    if ($('input.d7').prop('checked') === true) {
        var d7 = 1;
    } else {
        var d7 = 0;
    }
    var ms = $("#modulcreator_project_edit").serialize();
    var papka = "/bitrix/modules/" + part + "." + modul + "/";
    if (confirm(str.err1 + " " + papka + " " + str.err2)) {
    } else {
        return false;
    }

    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            aj: "YES",
            part: part,
            modul: modul,
            comp: comp,
            d7: d7,
            ms: ms,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(".itog-papka").html(total.data);
            return false;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return false;
}
function add_lang_mess_file(eto, lat_msg2, cls_val, lang_put) {
    var val_input = $(cls_val).val();
    var val_input = encodeURIComponent(val_input);
    var lat_msg = encodeURIComponent(lat_msg2);
    var put = encodeURIComponent(lang_put);
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.addlang";
    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            add_lang: "YES",
            val_input: val_input,
            lat_msg: lat_msg,
            put: put,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(eto).removeClass("btn-success");$(eto).removeClass("adm-btn-save");
            $(eto).addClass("btn-secondary");
            global_count++;
            return false;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return false;
}

function add_lang_mess_file_real(eto, lat_msg2, cls_val, lang_put) {
    var val_input = $(cls_val).val();
    var val_input = encodeURIComponent(val_input);
    var lat_msg = encodeURIComponent(lat_msg2);
    var put = encodeURIComponent(lang_put);
    var url = "/bitrix/services/main/ajax.php?action=directoriya:modulcreator.api.allajax.addlang";
    $.ajax({
        url: url,
        type: "post",
        async: true,
        data: {
            add_lang: "YES",
            val_input: val_input,
            lat_msg: lat_msg,
            put: put,
            sessid: $('#sessid-m').val()
        },
        success: function (responseData, textStatus, jqXHR) {
            var total = responseData;
            $(eto).removeClass("btn-success");$(eto).removeClass("adm-btn-save");
            $(eto).addClass("btn-secondary");
            global_count++;
            return false;
        },
        error: function (responseData, textStatus, errorThrown) {
        }
    });
    return false;
}

var global_count = 0;
var IntevalId;

function save_all_lang_msg(eto) {
    $(".button-all-make").attr("disabled", "disabled");
    $(".s1-preloader").removeClass("hidd");
    global_count = 0;
    var param_str = $(eto).data('allparam');
    var ms1 = param_str.split('#');
    for (var iz = 0; iz < ms1.length; iz++) {
        var ms2 = ms1[iz].split('^');
        eto2 = $('.button_msg_' + ms2[0]);
        var lat = '.lang_msg_' + ms2[0];
        var dd = add_lang_mess_file(eto2, ms2[1], lat, ms2[2]);
    }
    IntevalId = setInterval(function () {
        var ff = all_button_wait(eto, ms1.length);
    }, 1000);
    return false;
}
function save_all_lang_msg_real2(eto) {
    $(".button-all-make").attr("disabled", "disabled");
    $(".s1-preloader").removeClass("hidd");
    global_count = 0;
    var param_str = $(eto).data('allparam');
    var ms1 = param_str.split('#');
    for (var iz = 0; iz < ms1.length; iz++) {
        var ms2 = ms1[iz].split('^');
        eto2 = $('.button_msg_real_' + ms2[0]);
        var lat = '.lang_msg_real_' + ms2[0];
        var dd = add_lang_mess_file_real(eto2, ms2[1], lat, ms2[2]);
    }
    IntevalId = setInterval(function () {
        var ff = all_button_wait(eto, ms1.length);
    }, 1000);
    return false;
}

function all_button_wait(eto, num) {
    if (global_count >= num) {
        $(eto).removeClass("btn-primary");
        $(eto).addClass("btn-secondary"); $(eto).removeClass("adm-btn-save");
        global_count = 0;
        clearInterval(IntevalId);
        $(".s1-preloader").addClass("hidd");
        $(".button-all-make").removeAttr("disabled");
    }
    return true;
}

function show_hid_comp_block() {
    if ($("#in3").prop("checked") === true) {
        $(".component-block").removeClass("hidd");
    } else {
        if ($(".component-block").hasClass("hidd")) {
        } else {
            $(".component-block").addClass("hidd");
        }
    }
    var dd = set_warn_mess();
    return true;
}

function show_hid_sql_block() {
    if ($("#in15").prop("checked") === true) {
        $(".sql_put").removeClass("hidd");
    } else {
        if ($(".sql_put").hasClass("hidd")) {
        } else {
            $(".sql_put").addClass("hidd");
        }
    }
    return true;
}
function show_file_run_full_php() {
    if ($("#in38").prop("checked") === true) {
        $(".fullarchiv-file").removeClass("hidd");
    } else {
        if ($(".fullarchiv-file").hasClass("hidd")) {
        } else {
            $(".fullarchiv-file").addClass("hidd");
        }
    }
    return true;
}
function show_file_run_update_php() {
    if ($("#in40").prop("checked") === true) {
        $(".updatearchiv-file").removeClass("hidd");
    } else {
        if ($(".updatearchiv-file").hasClass("hidd")) {
        } else {
            $(".updatearchiv-file").addClass("hidd");
        }
    }
    return true;
}