
document.addEventListener('DOMContentLoaded', function() {
    console.log("Window loaded");
    header_setting.style.display = 'block';
    p_header_setting.className = 'isi_menu_settings_adm_active';
});

p_header_setting.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm_active';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm';
    header_setting.style.display = 'block';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'none';
    p_kurir.className = 'isi_menu_settings_adm';
    kurir_setting.style.display = 'none';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_footer_setting.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm_active';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'block';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'none';
    p_kurir.className = 'isi_menu_settings_adm';
    kurir_setting.style.display = 'none';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_apikey_setting.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm_active';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'block';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'none';
    p_kurir.className = 'isi_menu_settings_adm';
    kurir_setting.style.display = 'none';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_lokasi_setting.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm_active';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'block';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'none';
    p_kurir.className = 'isi_menu_settings_adm';
    kurir_setting.style.display = 'none';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_metode_pembayaran.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm_active';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'block';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'none';
    p_kurir.className = 'isi_menu_settings_adm';
    kurir_setting.style.display = 'none';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_email_smtp.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm_active';
    p_akses_login.className = 'isi_menu_settings_adm';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'block';
    akses_login_setting.style.display = 'none';
    p_kurir.className = 'isi_menu_settings_adm';
    kurir_setting.style.display = 'none';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_akses_login.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm_active';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'block';
    p_kurir.className = 'isi_menu_settings_adm';
    kurir_setting.style.display = 'none';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_kurir.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm';
    p_kurir.className = 'isi_menu_settings_adm_active';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'none';
    kurir_setting.style.display = 'block';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_about.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm';
    p_kurir.className = 'isi_menu_settings_adm';
    p_about.className = 'isi_menu_settings_adm_active';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'none';
    kurir_setting.style.display = 'none';
    about_setting.style.display = 'block';
    p_warna.className = 'isi_menu_settings_adm';
    warna_setting.style.display = 'none';
}

p_warna.onclick = function () {
    p_header_setting.className = 'isi_menu_settings_adm';
    p_footer_setting.className = 'isi_menu_settings_adm';
    p_apikey_setting.className = 'isi_menu_settings_adm';
    p_lokasi_setting.className = 'isi_menu_settings_adm';
    p_metode_pembayaran.className = 'isi_menu_settings_adm';
    p_email_smtp.className = 'isi_menu_settings_adm';
    p_akses_login.className = 'isi_menu_settings_adm';
    p_kurir.className = 'isi_menu_settings_adm';
    p_about.className = 'isi_menu_settings_adm_active';
    header_setting.style.display = 'none';
    footer_setting.style.display = 'none';
    apikey_setting.style.display = 'none';
    lokasi_setting.style.display = 'none';
    metode_pembayaran_setting.style.display = 'none';
    email_smtp_setting.style.display = 'none';
    akses_login_setting.style.display = 'none';
    kurir_setting.style.display = 'none';
    p_about.className = 'isi_menu_settings_adm';
    about_setting.style.display = 'none';
    warna_setting.style.display = 'block';
}

function c_ubah_logo() {
    ubah_logo_cf_hs.click();
}

function change_ubah_logo(event) {
    const file = document.getElementById('ubah_logo_cf_hs').files[0];
    const fileType = file['type'];
    const validImageTypes = ['image/svg+xml', 'image/png', 'image/jpeg', 'image/jpg'];
    if (!validImageTypes.includes(fileType)) {
        err_foto_hs.style.display = 'block';
        ubah_logo_cf_hs.value = '';
    } else {
        var reader = new FileReader();
        reader.onload = function () {
            var output = document.getElementById('view_logo_hs');
            output.src = reader.result;
        }
        reader.readAsDataURL(event.target.files[0]);
        err_foto_hs.style.display = 'none';
    }
}

function c_ubah_favicon() {
    ubah_favicon_cf_hs.click();
}

function change_ubah_favicon(event) {
    const file = document.getElementById('ubah_favicon_cf_hs').files[0];
    const fileType = file['type'];
    const validImageTypes = ['image/png', 'image/jpeg', 'image/jpg','image/x-icon'];
    if (!validImageTypes.includes(fileType)) {
        err_favicon_hs.style.display = 'block';
        ubah_favicon_cf_hs.value = '';
    } else {
        var reader = new FileReader();
        reader.onload = function () {
            var output = document.getElementById('view_favicon_hs');
            output.src = reader.result;
        }
        reader.readAsDataURL(event.target.files[0]);
        err_favicon_hs.style.display = 'none';
    }
}

function simpan_header() {
    var data_header_hs = new FormData();
    data_header_hs.append('ubah_logo_cf_hs', document.getElementById('ubah_logo_cf_hs').files[0]);
    data_header_hs.append('ubah_favicon_cf_hs', document.getElementById('ubah_favicon_cf_hs').files[0]);
    data_header_hs.append('nama_perusahaan_hs', document.getElementById('nama_perusahaan_hs').value);
    data_header_hs.append('slogan_hs', document.getElementById('slogan_hs').value);
    data_header_hs.append('meta_description_hs', document.getElementById('meta_description_hs').value);
    data_header_hs.append('meta_keyword_hs', document.getElementById('meta_keyword_hs').value);
    data_header_hs.append('google_verification_hs', document.getElementById('google_verification_hs').value);
    data_header_hs.append('bing_verification_hs', document.getElementById('bing_verification_hs').value);
    data_header_hs.append('ahrefs_verification_hs', document.getElementById('ahrefs_verification_hs').value);
    data_header_hs.append('yandex_verification_hs', document.getElementById('yandex_verification_hs').value);
    data_header_hs.append('norton_verification_hs', document.getElementById('norton_verification_hs').value);
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 1) {
            text_s_hs.style.display = 'none';
            loading_s_hs.style.display = 'flex';
        }
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById('res').innerHTML = this.responseText;
            text_s_hs.style.display = 'flex';
            loading_s_hs.style.display = 'none';
            var getscriptres = document.getElementsByTagName('script');
            for (var i = 0; i < getscriptres.length - 0; i++) {
                if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
            }
        }
    }
    xhttp.open('POST', '../../system/admin/settings/header.php', true);
    xhttp.send(data_header_hs);
}

function simpan_footer() {
    var data_social_fo = new FormData();
    data_social_fo.append('link_social_fo1', document.getElementById('link_social_fo1').value);
    data_social_fo.append('link_social_fo2', document.getElementById('link_social_fo2').value);
    data_social_fo.append('link_social_fo3', document.getElementById('link_social_fo3').value);
    data_social_fo.append('link_social_fo4', document.getElementById('link_social_fo4').value);
    data_social_fo.append('link_social_fo5', document.getElementById('link_social_fo5').value);
    data_social_fo.append('link_social_fo6', document.getElementById('link_social_fo6').value);
    data_social_fo.append('fo_copyright', document.getElementById('fo_copyright').value);
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 1) {
            text_s_fo.style.display = 'none';
            loading_s_fo.style.display = 'flex';
        }
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById('res').innerHTML = this.responseText;
            text_s_fo.style.display = 'flex';
            loading_s_fo.style.display = 'none';
            var getscriptres = document.getElementsByTagName('script');
            for (var i = 0; i < getscriptres.length - 0; i++) {
                if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
            }
        }
    }
    xhttp.open('POST', '../../system/admin/settings/footer.php', true);
    xhttp.send(data_social_fo);
}

function simpan_apikey() {
    if (google_client_id_key_ak.value == '') {
        p_google_client_id_key_ak.style.color = '#EA2027';
        google_client_id_key_ak.style.border = '1px solid #EA2027';
    } else {
        p_google_client_id_key_ak.style.color = '#959595';
        google_client_id_key_ak.style.border = '1px solid #e2e2e2';
    }
    if (google_client_secret_key_ak.value == '') {
        p_google_client_secret_key_ak.style.color = '#EA2027';
        google_client_secret_key_ak.style.border = '1px solid #EA2027';
    } else {
        p_google_client_secret_key_ak.style.color = '#959595';
        google_client_secret_key_ak.style.border = '1px solid #e2e2e2';
    }
    if (midtrans_client_key_ak.value == '') {
        p_midtrans_client_key_ak.style.color = '#EA2027';
        midtrans_client_key_ak.style.border = '1px solid #EA2027';
    } else {
        p_midtrans_client_key_ak.style.color = '#959595';
        midtrans_client_key_ak.style.border = '1px solid #e2e2e2';
    }
    if (midtrans_server_key_ak.value == '') {
        p_midtrans_server_key_ak.style.color = '#EA2027';
        midtrans_server_key_ak.style.border = '1px solid #EA2027';
    } else {
        p_midtrans_server_key_ak.style.color = '#959595';
        midtrans_server_key_ak.style.border = '1px solid #e2e2e2';
    }
    if (rajaongkir_key_ak.value == '') {
        p_rajaongkir_key_ak.style.color = '#EA2027';
        rajaongkir_key_ak.style.border = '1px solid #EA2027';
    } else {
        p_rajaongkir_key_ak.style.color = '#959595';
        rajaongkir_key_ak.style.border = '1px solid #e2e2e2';
    }
    if (tinypng_key_ak.value == '') {
        p_tinypng_key_ak.style.color = '#EA2027';
        tinypng_key_ak.style.border = '1px solid #EA2027';
    } else {
        p_tinypng_key_ak.style.color = '#959595';
        tinypng_key_ak.style.border = '1px solid #e2e2e2';
    }
    if (google_client_id_key_ak.value && google_client_secret_key_ak.value && midtrans_client_key_ak.value && midtrans_server_key_ak.value) {
        var data_apikey_ak = new FormData();
        data_apikey_ak.append('google_client_id_key_ak', document.getElementById('google_client_id_key_ak').value);
        data_apikey_ak.append('google_client_secret_key_ak', document.getElementById('google_client_secret_key_ak').value);
        data_apikey_ak.append('whatsapp_api_key', document.getElementById('whatsapp_api_key').value);
        data_apikey_ak.append('whatsapp_bot_number', document.getElementById('whatsapp_bot_number').value);
        data_apikey_ak.append('midtrans_client_key_ak', document.getElementById('midtrans_client_key_ak').value);
        data_apikey_ak.append('midtrans_server_key_ak', document.getElementById('midtrans_server_key_ak').value);
        data_apikey_ak.append('rajaongkir_key_ak', document.getElementById('rajaongkir_key_ak').value);
        data_apikey_ak.append('tinypng_key_ak', document.getElementById('tinypng_key_ak').value);
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (this.readyState == 1) {
                text_s_ak.style.display = 'none';
                loading_s_ak.style.display = 'flex';
            }
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById('res').innerHTML = this.responseText;
                text_s_ak.style.display = 'flex';
                loading_s_ak.style.display = 'none';
                var getscriptres = document.getElementsByTagName('script');
                for (var i = 0; i < getscriptres.length - 0; i++) {
                    if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
                }
            }
        }
        xhttp.open('POST', '../../system/admin/settings/apikey.php', true);
        xhttp.send(data_apikey_ak);
    }
}

function change_provinsi() {
    var data_lokasi_provinsi = new FormData();
    data_lokasi_provinsi.append('id_provinsi', document.getElementById('provinsi_ls').value);
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 1) {
            kota_ls.value = '';
            kecamatan_ls.value = '';
        }
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById('kota_ls').innerHTML = this.responseText;
            var getscriptres = document.getElementsByTagName('script');
            for (var i = 0; i < getscriptres.length - 0; i++) {
                if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
            }
        }
    }
    xhttp.open('POST', '../../system/location/kota.php', true);
    xhttp.send(data_lokasi_provinsi);
}

function change_kota() {
    var data_lokasi_kota = new FormData();
    data_lokasi_kota.append('id_kota', document.getElementById('kota_ls').value);
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 1) {
            kecamatan_ls.value = '';
        }
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById('kecamatan_ls').innerHTML = this.responseText;
            var getscriptres = document.getElementsByTagName('script');
            for (var i = 0; i < getscriptres.length - 0; i++) {
                if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
            }
        }
    }
    xhttp.open('POST', '../../system/location/kecamatan.php', true);
    xhttp.send(data_lokasi_kota);
}

function simpan_lokasi() {
    if (provinsi_ls.value == '') {
        p_provinsi_ls.style.color = '#EA2027';
        provinsi_ls.style.border = '1px solid #EA2027';
    } else {
        p_provinsi_ls.style.color = '#959595';
        provinsi_ls.style.border = '1px solid #e2e2e2';
    }
    if (kota_ls.value == '') {
        p_kota_ls.style.color = '#EA2027';
        kota_ls.style.border = '1px solid #EA2027';
    } else {
        p_kota_ls.style.color = '#959595';
        kota_ls.style.border = '1px solid #e2e2e2';
    }
    if (kecamatan_ls.value == '') {
        p_kecamatan_ls.style.color = '#EA2027';
        kecamatan_ls.style.border = '1px solid #EA2027';
    } else {
        p_kecamatan_ls.style.color = '#959595';
        kecamatan_ls.style.border = '1px solid #e2e2e2';
    }
    if (provinsi_ls.value && kota_ls.value && kecamatan_ls.value) {
        var data_lokasi_update = new FormData();
        data_lokasi_update.append('tipe_user_vt', document.getElementById('tipe_user_vt').value);
        data_lokasi_update.append('provinsi_ls', document.getElementById('provinsi_ls').value);
        data_lokasi_update.append('kota_ls', document.getElementById('kota_ls').value);
        data_lokasi_update.append('kecamatan_ls', document.getElementById('kecamatan_ls').value);
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (this.readyState == 1) {
                text_s_lc.style.display = 'none';
                loading_s_lc.style.display = 'flex';
            }
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById('res').innerHTML = this.responseText;
                text_s_lc.style.display = 'flex';
                loading_s_lc.style.display = 'none';
                var getscriptres = document.getElementsByTagName('script');
                for (var i = 0; i < getscriptres.length - 0; i++) {
                    if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
                }
            }
        }
        xhttp.open('POST', '../../system/admin/settings/location.php', true);
        xhttp.send(data_lokasi_update);
    }
}

function simpan_metode_pembayaran() {
    if (nama_bank.value == '') {
        p_nama_bank.style.color = '#EA2027';
        nama_bank.style.border = '1px solid #EA2027';
    } else {
        p_nama_bank.style.color = '#959595';
        nama_bank.style.border = '1px solid #e2e2e2';
    }
    if (norek.value == '') {
        p_norek.style.color = '#EA2027';
        norek.style.border = '1px solid #EA2027';
    } else {
        p_norek.style.color = '#959595';
        norek.style.border = '1px solid #e2e2e2';
    }
    if (atas_nama.value == '') {
        p_atas_nama.style.color = '#EA2027';
        atas_nama.style.border = '1px solid #EA2027';
    } else {
        p_atas_nama.style.color = '#959595';
        atas_nama.style.border = '1px solid #e2e2e2';
    }
    if (nama_bank.value && norek.value && atas_nama.value) {
        var data_metode_pembayaran = new FormData();
        var select = document.getElementById("inp_tipe_bk");
        var selectedOption = select.options[select.selectedIndex].value;
        data_metode_pembayaran.append('inp_tipe_mp', document.getElementById('inp_tipe_mp').value);
        data_metode_pembayaran.append('nama_bank', document.getElementById('nama_bank').value);
        data_metode_pembayaran.append('inp_tipe_bk', selectedOption);
        data_metode_pembayaran.append('norek', document.getElementById('norek').value);
        data_metode_pembayaran.append('atas_nama', document.getElementById('atas_nama').value);
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (this.readyState == 1) {
                text_s_lmp.style.display = 'none';
                loading_s_lmp.style.display = 'flex';
            }
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById('res').innerHTML = this.responseText;
                text_s_lmp.style.display = 'flex';
                loading_s_lmp.style.display = 'none';
                var getscriptres = document.getElementsByTagName('script');
                for (var i = 0; i < getscriptres.length - 0; i++) {
                    if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
                }
            }
        }
        xhttp.open('POST', '../../system/admin/settings/metode-pembayaran.php', true);
        xhttp.send(data_metode_pembayaran);
    }
}

function simpan_email_smtp() {
    if (email_notif_adm.value == '') {
        p_email_notif_adm.style.color = '#EA2027';
        email_notif_adm.style.border = '1px solid #EA2027';
    } else {
        p_email_notif_adm.style.color = '#959595';
        email_notif_adm.style.border = '1px solid #e2e2e2';
    }
    if (host_smtp.value == '') {
        p_host_smtp.style.color = '#EA2027';
        host_smtp.style.border = '1px solid #EA2027';
    } else {
        p_host_smtp.style.color = '#959595';
        host_smtp.style.border = '1px solid #e2e2e2';
    }
    if (port_smtp.value == '') {
        p_port_smtp.style.color = '#EA2027';
        port_smtp.style.border = '1px solid #EA2027';
    } else {
        p_port_smtp.style.color = '#959595';
        port_smtp.style.border = '1px solid #e2e2e2';
    }
    if (username_smtp.value == '') {
        p_username_smtp.style.color = '#EA2027';
        username_smtp.style.border = '1px solid #EA2027';
    } else {
        p_username_smtp.style.color = '#959595';
        username_smtp.style.border = '1px solid #e2e2e2';
    }
    if (password_smtp.value == '') {
        p_password_smtp.style.color = '#EA2027';
        password_smtp.style.border = '1px solid #EA2027';
    } else {
        p_password_smtp.style.color = '#959595';
        password_smtp.style.border = '1px solid #e2e2e2';
    }
    if (setfrom_smtp.value == '') {
        p_setfrom_smtp.style.color = '#EA2027';
        setfrom_smtp.style.border = '1px solid #EA2027';
    } else {
        p_setfrom_smtp.style.color = '#959595';
        setfrom_smtp.style.border = '1px solid #e2e2e2';
    }
    if (email_notif_adm.value && host_smtp.value && port_smtp.value && username_smtp.value && password_smtp.value && setfrom_smtp.value) {
        var data_email_smtp = new FormData();
        data_email_smtp.append('email_notif_adm', document.getElementById('email_notif_adm').value);
        data_email_smtp.append('host_smtp', document.getElementById('host_smtp').value);
        data_email_smtp.append('port_smtp', document.getElementById('port_smtp').value);
        data_email_smtp.append('username_smtp', document.getElementById('username_smtp').value);
        data_email_smtp.append('password_smtp', document.getElementById('password_smtp').value);
        data_email_smtp.append('setfrom_smtp', document.getElementById('setfrom_smtp').value);
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (this.readyState == 1) {
                text_s_esmtp.style.display = 'none';
                loading_s_esmtp.style.display = 'flex';
            }
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById('res').innerHTML = this.responseText;
                text_s_esmtp.style.display = 'flex';
                loading_s_esmtp.style.display = 'none';
                var getscriptres = document.getElementsByTagName('script');
                for (var i = 0; i < getscriptres.length - 0; i++) {
                    if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
                }
            }
        }
        xhttp.open('POST', '../../system/admin/settings/email-smtp.php', true);
        xhttp.send(data_email_smtp);
    }
}

function simpan_fitur_setting() {
    var text_s_ealog = document.getElementById('text_s_ealog');
    var loading_s_ealog = document.getElementById('loading_s_ealog');

    var data_fitur_setting = new FormData();
    data_fitur_setting.append('sf_view_produk', document.getElementById('sf_view_produk').value);
    data_fitur_setting.append('sf_tipe_toko', document.getElementById('sf_tipe_toko').value);
    data_fitur_setting.append('sf_midtrans_mode', document.getElementById('sf_midtrans_mode').value);
    data_fitur_setting.append('sf_cod', document.getElementById('sf_cod').value);
    data_fitur_setting.append('sf_format_harga', document.getElementById('sf_format_harga').value);
    data_fitur_setting.append('sf_jumlah_persen', document.getElementById('sf_jumlah_persen').value);
    data_fitur_setting.append('sf_minimal_penarikan', document.getElementById('sf_minimal_penarikan').value);

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState === XMLHttpRequest.OPENED) {
            text_s_ealog.style.display = 'none';
            loading_s_ealog.style.display = 'flex';
        }
        if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
            document.getElementById('res').innerHTML = this.responseText;
            text_s_ealog.style.display = 'flex';
            loading_s_ealog.style.display = 'none';
            var getscriptres = document.getElementsByTagName('script');
            for (var i = 0; i < getscriptres.length; i++) {
                if (getscriptres[i].text != null) {
                    eval(getscriptres[i].text);
                }
            }
        }
    };

    xhttp.open('POST', '../../system/admin/settings/fitur-setting.php', true);
    xhttp.send(data_fitur_setting);
}


function simpan_kurir() {
    var data_kurir_setting = new FormData();
    for (let lopkuririd = 1; lopkuririd < 24; lopkuririd++) {
        var idkurad = 'impkur' + lopkuririd;
        data_kurir_setting.append(idkurad, document.getElementById(idkurad).value);
    }
    if (document.getElementById("etd")) {
        data_kurir_setting.append("etd", document.getElementById("etd").value);
    }
    if (document.getElementById("status")) {
        data_kurir_setting.append("status", document.getElementById("status").value);
    }
    
    if (document.getElementById("status_kurir_ro")) {
        data_kurir_setting.append("status_kurir_ro", document.getElementById("status_kurir_ro").value);
    }

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 1) {
            text_s_kurir.style.display = 'none';
            loading_s_kurir.style.display = 'flex';
        }
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById('res').innerHTML = this.responseText;
            text_s_kurir.style.display = 'flex';
            loading_s_kurir.style.display = 'none';
            var getscriptres = document.getElementsByTagName('script');
            for (var i = 0; i < getscriptres.length - 0; i++) {
                if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
            }
        }
    }
    xhttp.open('POST', '../../system/admin/settings/kurir-setting.php', true);
    xhttp.send(data_kurir_setting);
}

function simpan_about() {
    var data_about = new FormData();
    data_about.append('kp_about', document.getElementById('kp_about').value);
    data_about.append('tk_about', document.getElementById('tk_about').value);
    data_about.append('sk_about', document.getElementById('sk_about').value);
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 1) {
            text_s_abt.style.display = 'none';
            loading_s_abt.style.display = 'flex';
        }
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById('res').innerHTML = this.responseText;
            text_s_abt.style.display = 'flex';
            loading_s_abt.style.display = 'none';
            var getscriptres = document.getElementsByTagName('script');
            for (var i = 0; i < getscriptres.length - 0; i++) {
                if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
            }
        }
    }
    xhttp.open('POST', '../../system/admin/settings/about-setting.php', true);
    xhttp.send(data_about);
}

function simpan_warna() {
    var data_warna = new FormData();

    // Mengambil nilai input untuk setiap variabel warna
    var inputFields = document.querySelectorAll('.input');
    inputFields.forEach(function(field) {
        data_warna.append(field.id, field.value);
    });

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 1) {
            text_s_warna.style.display = 'none';
            loading_s_warna.style.display = 'flex';
        }
        if (this.readyState == 4 && this.status == 200) {
            // Handle respon dari server di sini
            document.getElementById('res').innerHTML = this.responseText;
            text_s_warna.style.display = 'flex';
            loading_s_warna.style.display = 'none';
            var getscriptres = document.getElementsByTagName('script');
            for (var i = 0; i < getscriptres.length - 0; i++) {
                if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
            }
        }
    }

    // Mengirim data ke server
    xhttp.open('POST', '../../system/admin/settings/setting-warna.php', true);
    xhttp.send(data_warna);
}


function edit_lokasi_peng(idlokasiset, provinsi_val) {
    back_plp.style.display = 'block';
    tipe_eorc.innerHTML = 'Ubah';
    loklengkapedt.innerHTML = provinsi_val;
    lokasiidedit.value = idlokasiset;
}

function buat_lokasi_baruseet() {
    back_plp.style.display = 'block';
    tipe_eorc.innerHTML = 'Buat';
    loklengkapedt.innerHTML = '';
    lokasiidedit.value = '';
}

function close_plpset() {
    back_plp.style.display = 'none';
    tipe_eorc.innerHTML = '';
    loklengkapedt.innerHTML = '';
    lokasiidedit.value = '';
}

function hapus_lokasi_peng(idlokasihap, hideidlok) {
    let text = "Apakah anda yakin ingin menghapus lokasi ini ?";
    if (confirm(text) == true) {
        var data_hapus_lokasi = new FormData();
        data_hapus_lokasi.append('idlokasihap', idlokasihap);
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (this.readyState == 1) {}
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById(hideidlok).style.display = 'none';
                document.getElementById('res').innerHTML = this.responseText;
                var getscriptres = document.getElementsByTagName('script');
                for (var i = 0; i < getscriptres.length - 0; i++) {
                    if (getscriptres[i + 0].text != null) eval(getscriptres[i + 0].text);
                }
            }
        }
        xhttp.open('POST', '../../system/admin/settings/hapus-lokasi.php', true);
        xhttp.send(data_hapus_lokasi);
    } else {}
}

function reset_default() {
        // Array berisi nilai-nilai default yang telah ditentukan sebelumnya
        const defaultColors = [
            { variabel: '--black', code: '#111111' },
            { variabel: '--semi-black', code: '#505050' },
            { variabel: '--white', code: '#ffffff' },
            { variabel: '--orange', code: '#189659' },
            { variabel: '--deep-orange', code: '#288531' },
            { variabel: '--semi-orange', code: '#3bc449' },
            { variabel: '--grey', code: '#959595' },
            { variabel: '--border-grey', code: '#e2e2e2' },
            { variabel: '--semi-grey', code: '#f5f5f5' },
            { variabel: '--red', code: '#EA2027' }
        ];

        // Mendapatkan semua elemen input warna
        const colorInputs = document.querySelectorAll('.input[type="color"]');

        // Mengatur nilai-nilai default ke masing-masing input warna
        defaultColors.forEach(color => {
            const input = document.getElementById(color.variabel);
            if (input) {
                input.value = color.code;
            }
        });
    }