Date.prototype.customFormat = function (formatString) {
    var YYYY, YY, MMMM, MMM, MM, M, DDDD, DDD, DD, D, hhhh, hhh, hh, h, mm, m, ss, s, ampm, AMPM, dMod, th;
    var dateObject = this;
    YY = ((YYYY = dateObject.getFullYear()) + "").slice(-2);
    MM = (M = dateObject.getMonth() + 1) < 10 ? ('0' + M) : M;
    MMM = (MMMM = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][M - 1]).substring(0, 3);
    DD = (D = dateObject.getDate()) < 10 ? ('0' + D) : D;
    DDD = (DDDD = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][dateObject.getDay()]).substring(0, 3);
    th = (D >= 10 && D <= 20) ? 'th' : ((dMod = D % 10) == 1) ? 'st' : (dMod == 2) ? 'nd' : (dMod == 3) ? 'rd' : 'th';
    formatString = formatString.replace("#YYYY#", YYYY).replace("#YY#", YY).replace("#MMMM#", MMMM).replace("#MMM#", MMM).replace("#MM#", MM).replace("#M#", M).replace("#DDDD#", DDDD).replace("#DDD#", DDD).replace("#DD#", DD).replace("#D#", D).replace("#th#", th);

    h = (hhh = dateObject.getHours());
    if (h == 0) h = 24;
    if (h > 12) h -= 12;
    hh = h < 10 ? ('0' + h) : h;
    hhhh = hhh < 10 ? ('0' + hhh) : hhh;
    AMPM = (ampm = hhh < 12 ? 'am' : 'pm').toUpperCase();
    mm = (m = dateObject.getMinutes()) < 10 ? ('0' + m) : m;
    ss = (s = dateObject.getSeconds()) < 10 ? ('0' + s) : s;
    return formatString.replace("#hhhh#", hhhh).replace("#hhh#", hhh).replace("#hh#", hh).replace("#h#", h).replace("#mm#", mm).replace("#m#", m).replace("#ss#", ss).replace("#s#", s).replace("#ampm#", ampm).replace("#AMPM#", AMPM);
}

function error_alert(judul, pesan, type_alert = 'error') {
    swal(
        judul,
        pesan,
        type_alert
    )
}

function just_aler(judul, pesan, btn_yes_str='OK') {
    swal({
        title: judul,
        text: pesan,

        showCancelButton: false,

        confirmButtonColor: '#3085d6',
//        cancelButtonColor: '#d33',
//                confirmButtonText: 'Yes, gak papa!'
        confirmButtonText: btn_yes_str
    })
}

function delete_confirm(judul, pesan, executor) {
    swal({
        title: judul,
        text: pesan,

        showCancelButton: true,
        confirmButtonColor: '#FF7F27',
        cancelButtonColor: '#7092BE',
        confirmButtonText: 'OK'
    }).then(function () {
//                        swal(
//                                'Deleted!',
//                                'data telah dihapus',
//                                'success'
//                        ),
        location.href = executor
    })
}

function confirm_alert(judul, pesan, executor, btn_yes_str='OK') {

    swal({
        title: judul,
        text: pesan,

        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: btn_yes_str
    }).then((result) => {
        if (result.value){

        location.href = executor
    }
})
}

function confirm_submit(judul, pesan, executor, btn_yes_str) {
    swal({
        title: judul,
        text: pesan,

        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
//                confirmButtonText: 'Yes, gak papa!'
        confirmButtonText: btn_yes_str
    }).then(function () {

        document.getElementById(executor).submit();
    })
}

function confirm_alert_result(judul, pesan, executor, btn_yes_str='OK'){
    swal({
        title: judul,
        html: pesan,
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: btn_yes_str
    }).then(function () {
        top.swal("SEDANG MEMPROSES<BR>MOHON TUNGGU SEBENTAR<BR><small><b><r>JANGAN TUTUP BROWSER ANDA</r></b></small>")
        top.swal.enableLoading()
        setTimeout(function(){
            document.getElementById('result').src = executor
        },400)
    })
}

function btn_alert_result(judul, pesan, executor, btn_yes_str='OK'){
    swal({
        title: judul,
        html: pesan,
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: btn_yes_str
    }).then(function () {
        document.getElementById('result').src = executor
    })
}

function btn_result(executor){
    document.getElementById('result').src = executor
}

function confirm_password_result(judul, executor, btn_yes_str='Submit'){
    swal({
        title: judul,
        input: 'password',
        inputPlaceholder: 'masukan password admin',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: btn_yes_str
    }).then(function () {

        document.getElementById('result').src = executor
    })
}

function refreshResult(){
    // document.getElementById('result').src = targets
    var ifr = document.getElementsById('result2')[0];
    // var src =  $src;
    ifr.src = ifr.src;
}


//$(document).on('ready', function(){
//    var snackbar = $('.snackbar');
//    if(snackbar.length<1){
//        $('body').append('<div class="hidden" id="snackbar">Some text some message..</div>');
//        console.log('adding snackbar');
//    }
//
//    var varGeo, target, options;
//    var baseURL = $('#baseURL').html();
//    console.log(baseURL);
//    function success(pos) {
//        var crd = pos.coords;
//
//        console.log(pos.coords.accuracy);
//        console.log(pos.coords.latitude);
//        console.log(pos.coords.longitude);
////
////    showToast("lat: "+ pos.coords.latitude + " lng: " + pos.coords.longitude + " acc: "+ pos.coords.accuracy);
//        fetch(baseURL + "Login/updateAuthField?_long="+pos.coords.longitude+"&_latt="+pos.coords.latitude+"&_acc="+pos.coords.accuracy+"");
//
//        if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
////        console.log('Congratulations, you reached the target');
//            navigator.geolocation.clearWatch(varGeo);
//        }
//    }
//
//    function error(err) {
//        console.warn('ERROR(' + err.code + '): ' + err.message);
//        navigator.permissions.query({
//            name: 'geolocation'
//        })
//            .then(function(result) {
//                if (result.state == 'granted') {
//                    console.log(result.state);
////                    navigator.geolocation.watchPosition(gpsSunccuss, gpsFailed, positionOption);
////                    showToast("granted brow");
//                }
//                else if (result.state == 'prompt') {
//                    console.log(result.state);
//                    navigator.geolocation.watchPosition(gpsSunccuss, gpsFailed, positionOption);
////                    showToast("prompt brow");
//                }
//                else if (result.state == 'denied') {
//                    console.log(result.state);
//                    //dimatikan dulu
////                    swal({
////                        title               : 'Untuk LANJUT, Kita Butuh Akses Lokasi Nih...',
////                        type                : 'info',
////                        html                : 'Belum tau CARANYA?, Klik di ' +
////                            '<a target="_blank" href="//support.google.com/chrome/answer/142065?hl=id&co=GENIE.Platform%3DAndroid&oco=1">SINI</a> yah',
////                        showCloseButton     : true,
////                        showCancelButton    : false,
////                        confirmButtonText   : '<i class="fa fa-thumbs-up"></i> OK...!',
////                        cancelButtonText    : '<i class="fa fa-times"></i> BATAL'
////                    }).then((result) => {
////                        console.log( JSON.stringify(result) );
////                    var current_ip;
////
////                    if(typeof current_ip === 'undefined'){
////                        var url = 'https://api.ipify.org/?format=json';
////                        var result = fetch(url,{ method: 'get' })
////                            .then(function(response){
////                                return response.json();
////                            })
////                            .then(function(data){
////                                console.log( JSON.stringify(data.ip) );
////                                return fetch("https://geo.ipify.org/api/v1?apiKey=at_WCHfdmsP2ygpWkFF9x1492UWpLLbT&ipAddress="+data.ip)
////                            })
////                            .then(function(response){
////                                return response.json();
////                            })
////                            .then(function(data2){
////                                console.log( JSON.stringify(data2.location.lat) );
////                                console.log( JSON.stringify(data2.location.lng) );
////                                console.log( JSON.stringify(data2.location.geonameId) );
////                                showToast("lat: "+ JSON.stringify(data2.location.lat) + " lng: " + JSON.stringify(data2.location.lng) + " ");
////                            })
////                            .catch(function(error){
////                                console.log('Request failed', error)
////                            })
////                    }
////                });
//            }
//        result.onchange = function() {
//            console.log(result.state);
//        }
//    });
//}
//
//target = {
//    latitude : 0,
//    longitude: 0
//};
//
//options = {
//    enableHighAccuracy: false,
//    timeout: 5000,
//    maximumAge: 0
//};
//
//varGeo = navigator.geolocation.watchPosition(success, error, options);
//
////var positionOption = { timeout: 500, enableHighAccuracy: true };
////var gpsSunccuss = function(currentPosition) {
////
////    console.log(currentPosition.coords.accuracy);
////    console.log(currentPosition.coords.latitude);
////    console.log(currentPosition.coords.longitude);
////
////    showToast("lat: "+ currentPosition.coords.latitude + " lng: " + currentPosition.coords.longitude + " acc: "+ currentPosition.coords.accuracy);
////    fetch("{base}Login/updateAuthField?_long="+currentPosition.coords.longitude+"&_latt="+currentPosition.coords.latitude+"&_acc="+currentPosition.coords.accuracy+"");
////};
////var gpsFailed = function() {
////    console.log("failed");
////            navigator.permissions.query({
////                name: 'geolocation'
////            })
////            .then(function(result) {
////                if (result.state == 'granted') {
////                    console.log(result.state);
//////                    navigator.geolocation.watchPosition(gpsSunccuss, gpsFailed, positionOption);
////                    showToast("granted brow");
////                }
////                else if (result.state == 'prompt') {
////                    console.log(result.state);
////                    navigator.geolocation.watchPosition(gpsSunccuss, gpsFailed, positionOption);
////                    showToast("prompt brow");
////                }
////                else if (result.state == 'denied') {
////                    console.log(result.state);
////                    swal({
////                        title               : 'Untuk LANJUT, Kita Butuh Akses Lokasi Nih...',
////                        type                : 'info',
////                        html                : 'Belum tau CARANYA?, Klik di ' +
////                                '<a target="_blank" href="//support.google.com/chrome/answer/142065?hl=id&co=GENIE.Platform%3DAndroid&oco=1">SINI</a> yah',
////                        showCloseButton     : true,
////                        showCancelButton    : false,
////                        confirmButtonText   : '<i class="fa fa-thumbs-up"></i> OK...!',
////                        cancelButtonText    : '<i class="fa fa-times"></i> BATAL'
////                    }).then((result) => {
////                        console.log( JSON.stringify(result) );
////                    var current_ip;
////
////                    if(typeof current_ip === 'undefined'){
////                        var url = 'https://api.ipify.org/?format=json';
////                        var result = fetch(url,{ method: 'get' })
////                                .then(function(response){
////                                    return response.json();
////                                })
////                                .then(function(data){
////                                    console.log( JSON.stringify(data.ip) );
////                                    return fetch("https://geo.ipify.org/api/v1?apiKey=at_WCHfdmsP2ygpWkFF9x1492UWpLLbT&ipAddress="+data.ip)
////                                })
////                                .then(function(response){
////                                    return response.json();
////                                })
////                                .then(function(data2){
////                                    console.log( JSON.stringify(data2.location.lat) );
////                                    console.log( JSON.stringify(data2.location.lng) );
////                                    console.log( JSON.stringify(data2.location.geonameId) );
////                                    showToast("lat: "+ JSON.stringify(data2.location.lat) + " lng: " + JSON.stringify(data2.location.lng) + " ");
////                                })
////                                .catch(function(error){
////                                    console.log('Request failed', error)
////                                })
////                    }
////                });
////            }
////    result.onchange = function() {
////        console.log(result.state);
////    }
////});
////};
////document.getElementById('pihakName').addEventListener('click', function(){
////    navigator.geolocation.watchPosition(gpsSunccuss, gpsFailed, positionOption);
////});
//
//});

function showToast(strText='') {
    var x = document.getElementById("snackbar");
    x.className = "show";
    x.innerHTML = strText;
    setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2000);
}

function custom_holdon(){

//        theme avail
//        sk-rect
//        sk-bounce
//        sk-folding-cube
//        sk-circle
//        sk-dot
//        sk-bounce
//        sk-falding-circle
//        sk-cube-grid

//        custom (then the message setting will be available)

    var options = {
        theme:"sk-rect",
        message:'memuat...',
        backgroundColor:"#1847B1",
        textColor:"white"
    };
    HoldOn.open(options);

    setTimeout( function(){
        var options = {
            theme:"custom",
            // If theme == "custom" , the content option will be available to customize the logo
            content:'<img style="width:80px;" src="//www.google.de/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" class="center-block">',
            message:' Proses masih berlangsung... <br> <span onclick="HoldOn.close();">Tutup</span>',
            backgroundColor:"#1847B1",
            textColor:"white"
        };

        HoldOn.open(options);
    }, 15000);

}

function close_holdon(){
    HoldOn.close();
}

function open_holdon(){
    HoldOn.open();
}

var displayListAtas=function(){
    $.fn.reverse=[].reverse
    var triggerAtas=$("#trigger-atas"),
        mainTargetAtas=$(".my-nav-atas"),
        targetItemAtas=$('.my-nav__item-atas'),
        htmlAtas=$("html")
    triggerAtas.on("click", function(event) {
        mainTargetAtas.toggleClass("reveal-atas unreveal-atas")
        $(".my-nav-bawah-f").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-WT").removeClass("reveal-bawah unreveal-bawah")
        targetItemAtas.each(function(i, el) {
            setTimeout(function() {
                $(el).toggleClass("visible-atas");
            }, i * 15)
        })
        $('.my-nav__item-bawah-f').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah");
            }, i * 15)
        })
        $('.my-nav__item-bawah-WT').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah");
            }, i * 15)
        })
        htmlAtas.on("click", function() {
            targetItemAtas.removeClass("visible-atas");
            mainTargetAtas.removeClass("reveal-atas");
            $('.my-nav__item-bawah-f').removeClass("visible-bawah");
            $(".my-nav-bawah-f").removeClass("reveal-bawah");
            $('.my-nav__item-bawah-WT').removeClass("visible-bawah");
            $(".my-nav-bawah-WT").removeClass("reveal-bawah");
        })
        event.preventDefault()
        event.stopPropagation()
    })
    $('.btn__trigger--views-atas').css('background-color', '#00a65a')
}


var displayListBawahMb=function() {
    $.fn.reverse = [].reverse
    var trigger = $("#trigger-bawah-mb"),
        mainTarget = $(".my-nav-bawah-mb"),
        targetItem = $('.my-nav__item-bawah-mb'),
        html = $("html")
    trigger.on("click", function(event) {
        mainTarget.toggleClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-f-mb").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-f-ds").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-WT-mb").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-WT-ds").removeClass("reveal-bawah unreveal-bawah")
        targetItem.reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).toggleClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-f-mb').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-f-ds').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-WT-mb').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-WT-ds').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        html.on("click", function() {
            targetItem.removeClass("visible-bawah")
            mainTarget.removeClass("reveal-bawah")
            $('.my-nav__item-bawah-f-mb').removeClass("visible-bawah")
            $('.my-nav__item-bawah-f-ds').removeClass("visible-bawah")
            $(".my-nav-bawah-f-mb").removeClass("reveal-bawah")
            $(".my-nav-bawah-f-ds").removeClass("reveal-bawah")
            $('.my-nav__item-bawah-WT-mb').removeClass("visible-bawah")
            $('.my-nav__item-bawah-WT-ds').removeClass("visible-bawah")
            $(".my-nav-bawah-WT-mb").removeClass("reveal-bawah")
            $(".my-nav-bawah-WT-ds").removeClass("reveal-bawah")
        });
        event.preventDefault()
        event.stopPropagation()
    })
    $('.btn__trigger--views-bawah-mb').css('background-color', '#00a65a')
}
var displayListBawahDs=function() {
    $.fn.reverse = [].reverse
    var trigger = $("#trigger-bawah-ds"),
        mainTarget = $(".my-nav-bawah-ds"),
        targetItem = $('.my-nav__item-bawah-ds'),
        html = $("html")
    trigger.on("click", function(event) {
        mainTarget.toggleClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-f-mb").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-f-ds").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-WT-mb").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-WT-ds").removeClass("reveal-bawah unreveal-bawah")
        targetItem.reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).toggleClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-f-mb').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-f-ds').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-WT-mb').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-WT-ds').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        html.on("click", function() {
            targetItem.removeClass("visible-bawah")
            mainTarget.removeClass("reveal-bawah")
            $('.my-nav__item-bawah-f-mb').removeClass("visible-bawah")
            $('.my-nav__item-bawah-f-ds').removeClass("visible-bawah")
            $(".my-nav-bawah-f-mb").removeClass("reveal-bawah")
            $(".my-nav-bawah-f-ds").removeClass("reveal-bawah")
            $('.my-nav__item-bawah-WT-mb').removeClass("visible-bawah")
            $('.my-nav__item-bawah-WT-ds').removeClass("visible-bawah")
            $(".my-nav-bawah-WT-mb").removeClass("reveal-bawah")
            $(".my-nav-bawah-WT-ds").removeClass("reveal-bawah")
        });
        event.preventDefault()
        event.stopPropagation()
    })
    $('.btn__trigger--views-bawah-ds').css('background-color', '#00a65a')
}

var displayListBawahF_mb=function() {
    $.fn.reverse = [].reverse
    var trigger = $("#trigger-bawah-f-mb"),
        mainTarget = $(".my-nav-bawah-f-mb"),
        targetItem = $('.my-nav__item-bawah-f-mb'),
        html = $("html")
    trigger.on("click", function(event) {
        mainTarget.toggleClass("reveal-bawah unreveal-bawah")
        $(".my-nav-atas").removeClass("reveal-atas unreveal-atas")
        $(".my-nav-bawah-mb").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-WT-mb").removeClass("reveal-bawah unreveal-bawah")
        targetItem.reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).toggleClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-atas').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-atas")
            }, i * 15)
        })
        $('.my-nav__item-bawah-mb').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-WT-mb').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        html.on("click", function() {
            targetItem.removeClass("visible-bawah")
            mainTarget.removeClass("reveal-bawah")
            $('.my-nav__item-atas').removeClass("visible-atas")
            $(".my-nav-atas").removeClass("reveal-atas")
            $('.my-nav__item-bawah').removeClass("visible-bawah")
            $(".my-nav-bawah").removeClass("reveal-bawah")
            $('.my-nav__item-bawah-WT-mb').removeClass("visible-bawah")
            $(".my-nav-bawah-WT-mb").removeClass("reveal-bawah")
        })
        event.preventDefault()
        event.stopPropagation()
    })
    $('.btn__trigger--views-bawah-f-mb').css('background-color', '#dd4b39')

    //console.log('callback displayListBawahF')

    $('.btn__trigger-bawah-f-mb').on('click', function(event){
        var hasClass = $('body').hasClass('sidebar-open');
        if(hasClass){
            $('body').toggleClass('sidebar-open');
        }
    });
}
var displayListBawahF_ds=function() {
    $.fn.reverse = [].reverse
    var trigger = $("#trigger-bawah-f-ds"),
        mainTarget = $(".my-nav-bawah-f-ds"),
        targetItem = $('.my-nav__item-bawah-f-ds'),
        html = $("html")
    trigger.on("click", function(event) {
        mainTarget.toggleClass("reveal-bawah unreveal-bawah")
        $(".my-nav-atas").removeClass("reveal-atas unreveal-atas")
        $(".my-nav-bawah-ds").removeClass("reveal-bawah unreveal-bawah")
        $(".my-nav-bawah-WT-ds").removeClass("reveal-bawah unreveal-bawah")
        targetItem.reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).toggleClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-atas').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-atas")
            }, i * 15)
        })
        $('.my-nav__item-bawah-ds').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        $('.my-nav__item-bawah-WT-ds').reverse().each(function(i, el) {
            setTimeout(function() {
                $(el).removeClass("visible-bawah")
            }, i * 15)
        })
        html.on("click", function() {
            targetItem.removeClass("visible-bawah")
            mainTarget.removeClass("reveal-bawah")
            $('.my-nav__item-atas').removeClass("visible-atas")
            $(".my-nav-atas").removeClass("reveal-atas")
            $('.my-nav__item-bawah').removeClass("visible-bawah")
            $(".my-nav-bawah").removeClass("reveal-bawah")
            $('.my-nav__item-bawah-WT-ds').removeClass("visible-bawah")
            $(".my-nav-bawah-WT-ds").removeClass("reveal-bawah")
        })
        event.preventDefault()
        event.stopPropagation()
    })
    $('.btn__trigger--views-bawah-f-ds').css('background-color', '#dd4b39')

    //console.log('callback displayListBawahF')

    $('.btn__trigger-bawah-f-ds').on('click', function(event){
        var hasClass = $('body').hasClass('sidebar-open');
        if(hasClass){
            $('body').toggleClass('sidebar-open');
        }
    });

}

var displayListBawahWT_mb=function() {
        $.fn.reverse = [].reverse
        var trigger = $("#trigger-bawah-WT-mb"),
            mainTarget = $(".my-nav-bawah-WT-mb"),
            targetItem = $('.my-nav__item-bawah-WT-mb'),
            html = $("html")
        trigger.on("click", function(event) {
            mainTarget.toggleClass("reveal-bawah unreveal-bawah")
            $(".my-nav-atas").removeClass("reveal-atas unreveal-atas")
            $(".my-nav-bawah-mb").removeClass("reveal-bawah unreveal-bawah")
            $(".my-nav-bawah-f-mb").removeClass("reveal-bawah unreveal-bawah")
            targetItem.reverse().each(function(i, el) {
                setTimeout(function() {
                    $(el).toggleClass("visible-bawah")
                }, i * 15)
            })
            $('.my-nav__item-atas').reverse().each(function(i, el) {
                setTimeout(function() {
                    $(el).removeClass("visible-atas")
                }, i * 15)
            })
            $('.my-nav__item-bawah-mb').reverse().each(function(i, el) {
                setTimeout(function() {
                    $(el).removeClass("visible-bawah")
                }, i * 15)
            })
            $('.my-nav__item-bawah-f-mb').reverse().each(function(i, el) {
                setTimeout(function() {
                    $(el).removeClass("visible-bawah")
                }, i * 15)
            })
            html.on("click", function() {
                targetItem.removeClass("visible-bawah")
                mainTarget.removeClass("reveal-bawah")
                $('.my-nav__item-atas').removeClass("visible-atas")
                $(".my-nav-atas").removeClass("reveal-atas")
                $('.my-nav__item-bawah').removeClass("visible-bawah")
                $(".my-nav-bawah").removeClass("reveal-bawah")
                $('.my-nav__item-bawah-f-mb').removeClass("visible-bawah")
                $(".my-nav-bawah-f-mb").removeClass("reveal-bawah")
            })
            event.preventDefault()
            event.stopPropagation()
        })
        $('.btn__trigger--views-bawah-WT-mb').css('background-color', 'rgba(223, 140, 13, 0.8)')
        if(top.$('#gethuk_mb').html()!==''){
            $('.btn__trigger-bawah-WT-mb').css('right', '9.5rem')
            $('.my-nav--list-bawah-WT-mb').css('bottom', '5.5rem')
            $('.my-nav--list-bawah-WT-mb').css('right', '9.5rem')
        }

    $('.btn__trigger-bawah-WT-mb').on('click', function(event){
        var hasClass = $('body').hasClass('sidebar-open');
        if(hasClass){
            $('body').toggleClass('sidebar-open');
        }
    });

}
var displayListBawahWT_ds=function() {
        $.fn.reverse = [].reverse
        var trigger = $("#trigger-bawah-WT-ds"),
            mainTarget = $(".my-nav-bawah-WT-ds"),
            targetItem = $('.my-nav__item-bawah-WT-ds'),
            html = $("html")
        trigger.on("click", function(event) {
            mainTarget.toggleClass("reveal-bawah unreveal-bawah")
            $(".my-nav-atas").removeClass("reveal-atas unreveal-atas")
            $(".my-nav-bawah-ds").removeClass("reveal-bawah unreveal-bawah")
            $(".my-nav-bawah-f-ds").removeClass("reveal-bawah unreveal-bawah")
            targetItem.reverse().each(function(i, el) {
                setTimeout(function() {
                    $(el).toggleClass("visible-bawah")
                }, i * 15)
            })
            $('.my-nav__item-atas').reverse().each(function(i, el) {
                setTimeout(function() {
                    $(el).removeClass("visible-atas")
                }, i * 15)
            })
            $('.my-nav__item-bawah-ds').reverse().each(function(i, el) {
                setTimeout(function() {
                    $(el).removeClass("visible-bawah")
                }, i * 15)
            })
            $('.my-nav__item-bawah-f-ds').reverse().each(function(i, el) {
                setTimeout(function() {
                    $(el).removeClass("visible-bawah")
                }, i * 15)
            })
            html.on("click", function() {
                targetItem.removeClass("visible-bawah")
                mainTarget.removeClass("reveal-bawah")
                $('.my-nav__item-atas').removeClass("visible-atas")
                $(".my-nav-atas").removeClass("reveal-atas")
                $('.my-nav__item-bawah').removeClass("visible-bawah")
                $(".my-nav-bawah").removeClass("reveal-bawah")
                $('.my-nav__item-bawah-f-ds').removeClass("visible-bawah")
                $(".my-nav-bawah-f-ds").removeClass("reveal-bawah")
            })
            event.preventDefault()
            event.stopPropagation()
        })
        $('.btn__trigger--views-bawah-WT-ds').css('background-color', 'rgba(223, 140, 13, 0.8)')
        if(top.$('#gethuk_ds').html()!==''){
            $('.btn__trigger-bawah-WT-ds').css('right', '8.5rem')
            $('.my-nav--list-bawah-WT-ds').css('bottom', '6.5rem')
            $('.my-nav--list-bawah-WT-ds').css('right', '9.5rem')
        }

    $('.btn__trigger-bawah-WT-ds').on('click', function(event){
        var hasClass = $('body').hasClass('sidebar-open');
        if(hasClass){
            $('body').toggleClass('sidebar-open');
        }
    });

}

function showTime(){
    var a_p = "";
    var today = new Date();
    var curr_hour = today.getHours();
    var curr_minute = today.getMinutes();
    var curr_second = today.getSeconds();
//    if (curr_hour < 12) {
//        a_p = "AM";
//    } else {
//        a_p = "PM";
//    }
//    if (curr_hour == 0) {
//        curr_hour = 12;
//    }
//    if (curr_hour > 12) {
//        curr_hour = curr_hour - 12;
//    }
    curr_hour = checkTime(curr_hour);
    curr_minute = checkTime(curr_minute);
    curr_second = checkTime(curr_second);

//        document.getElementById('times').innerHTML=curr_hour + ":" + curr_minute + ":" + curr_second + " " + a_p;
//    document.getElementsByClassName('jam')[0].innerHTML=curr_hour;
//    document.getElementsByClassName('jam')[1].innerHTML=curr_hour;
//    document.getElementsByClassName('menit')[0].innerHTML=curr_minute + " " + a_p;
//    document.getElementsByClassName('menit')[1].innerHTML=curr_minute + " " + a_p;

    if(document.getElementsByClassName('jam')[0]){document.getElementsByClassName('jam')[0].innerHTML=curr_hour;}
    if(document.getElementsByClassName('jam')[1]){document.getElementsByClassName('jam')[1].innerHTML=curr_hour;}
    if(document.getElementsByClassName('menit')[0]){document.getElementsByClassName('menit')[0].innerHTML=curr_minute + " " + a_p;}
    if(document.getElementsByClassName('menit')[1]){document.getElementsByClassName('menit')[1].innerHTML=curr_minute + " " + a_p;}

//        var months = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
    var months = ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agt', 'Sep', 'Okt', 'Nov', 'Des'];
    var myDays = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jum&#39;at', 'Sabtu'];
    var date = new Date();
    var day = date.getDate();
    var month = date.getMonth();
    var thisDay = date.getDay(), thisDay = myDays[thisDay];
    var yy = date.getYear();
    var year = (yy < 1000) ? yy + 1900 : yy;

//    document.getElementsByClassName('hari')[0].innerHTML=thisDay;
//    document.getElementsByClassName('hari')[1].innerHTML=thisDay;
//    document.getElementsByClassName('tanggal')[0].innerHTML= day + ' ' + months[month] + ' ' + year;
//    document.getElementsByClassName('tanggal')[1].innerHTML= day + ' ' + months[month] + ' ' + year;
    if(document.getElementsByClassName('hari')[0]){document.getElementsByClassName('hari')[0].innerHTML=thisDay;}
    if(document.getElementsByClassName('hari')[1]){document.getElementsByClassName('hari')[1].innerHTML=thisDay;}
    if(document.getElementsByClassName('tanggal')[0]){document.getElementsByClassName('tanggal')[0].innerHTML= day + ' ' + months[month] + ' ' + year;}
    if(document.getElementsByClassName('tanggal')[1]){document.getElementsByClassName('tanggal')[1].innerHTML= day + ' ' + months[month] + ' ' + year;}

}

function checkTime(i){
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}
setInterval(showTime, 500);

function confirmLogout(url=''){
    swal({
        title: 'Are you sure?',
        text: "Do you really want to Logout?!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes!',
        cancelButtonText: 'No!'
    }).then((result) => {
        if (result) {
            if(url!==''){
                top.location.href = url
                console.log('do logout');
            }
            else{
                swal('gagal logout')
                console.log('do error logout');
            }
        }
    })
}

var removeCommas = function(i){
    return typeof i === 'string' ?  i.replace(/[\$,]/g, '')*1 : typeof i === 'number' ?  i : 0;
};

function removeCommas_(nStr){
    nStr = String(nStr);
    return parseFloat(nStr.replace(/,/g, ''));
}

function addCommas(nStr){
    //detect penulisan decimal
    var dec;
    nStr += '';
    dec = nStr.split('.');
    nStr = removeCommas(nStr);
    nStr += '';
    x = nStr.split(',');
    x1 = x[0];
    x2 = x.length > 1 ? ',' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    if (dec.length > 1) {
        if (dec[1] == '') {
            return x1 + x2 + '.';
        } else {
    return x1 + x2;
}
    }
    else {
        return x1 + x2;
    }
}

function delay_v2(callback, ms){
    var timer = 0;
    return function() {
        var context = this, args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            callback.apply(context, args);
        }, ms || 0);
    };
}

function replaceText(){
    $('.panel.panel-danger', $('body')).find('.bg-yellow').removeClass('bg-yellow');
    var searchword = $('#searchtxt').val();
    var custfilter = new RegExp(searchword, 'ig');
    var repstr = "<span class='bg-yellow'>" + searchword + '</span>';
    if (searchword != '') {
        $('.panel.panel-danger', $('body')).each(function() {
            $(this).html($(this).html().replace(custfilter, repstr));
        })
    }
}

function just_alert(judul, pesan, btn_yes_str='OK'){
    swal({
        title: judul,
        html: pesan,
        showCancelButton: false,
        confirmButtonColor: '#3085d6',
        confirmButtonText: btn_yes_str
    })
}

// "use strict";
// function loadCoaData(id) {
//     var base_url = $("#base_url").val();
//     // var base_url = $("#baseURL").html();
//     // console.log(base_url + "Tool/coa_selectedform/" + id);
//     $.ajax({
//         url: base_url + "Tool/coa_selectedform/" + id,
//         type: "GET",
//         dataType: "json",
//         success: function (data) {
//             $('#newform').html(data);
//             $('#btnSave').hide();
//         },
//         error: function (jqXHR, textStatus, errorThrown) {
//             alert('Error get data from ajax**2');
//         }
//     });
// }
//
// "use strict";
// function newHeaddata(id) {
//     var base_url = $("#base_url").val();
//     $.ajax({
//         url: base_url + "Tool/coa_newform/" + id,
//         type: "GET",
//         dataType: "json",
//         success: function (data) {
//             var headlabel = data.headlabel;
//             $('#txtHeadCode').val(data.headcode);
//             document.getElementById("txtHeadName").value = '';
//             $('#txtPHead').val(data.rowdata.HeadName);
//             $('#txtHeadLevel').val(headlabel);
//             $('#btnSave').prop("disabled", false);
//             $('#btnSave').show();
//             $('#btnUpdate').hide();
//         },
//         error: function (jqXHR, textStatus, errorThrown) {
//             alert('Error get data from ajax///');
//         }
//     });
// }

// $(document).ready(function () {
//     $('#jstree1').jstree({
//         'core': {
//             'check_callback': true
//         },
//         'plugins': ['types', 'dnd'],
//         'types': {
//             'default': {
//                 'icon': 'fa fa-folder'
//             },
//             'html': {
//                 'icon': 'fa fa-file-code-o'
//             },
//             'svg': {
//                 'icon': 'fa fa-file-picture-o'
//             },
//             'css': {
//                 'icon': 'fa fa-file-code-o'
//             },
//             'img': {
//                 'icon': 'fa fa-file-image-o'
//             },
//             'js': {
//                 'icon': 'fa fa-file-text-o'
//             },
//             'attr': {
//                 'class': 'panel-heading'
//             }
//         }
//     });
// });

var loadQtips = function(){
    $("span[name='qtips']").each(function(){
        $(this).qtip({
            content: {
                text: function(event, api){
                    $.ajax({
                        url: api.elements.target.attr('href')
                    })
                    .then(function(content){
                        api.set('content.text', content);
                    }, function(xhr, status, error){
                        api.set('content.text', status + ': ' + error);
                    });
                    return 'Memuat...';
                }
            },
            position: {
                viewport: $(window)
            },
            hide: {
                fixed: true,
                delay: 300
            },
            style: 'qtip-wiki'
        });
    });
}

function writeProgress(textProgress, group='wp', style='', finish=0, finish_desc='') {

    var now = new Date;
    var humanTime = now.customFormat("#YYYY#-#MM#-#DD# #hh#:#mm#:#ss#")
    var microTime = new Date();

    var wadah_microtime_start = document.getElementById('wadah_microtime_start');
    var wadah_human_time_start = document.getElementById('wadah_human_time_start');
    var wadah_progress = document.getElementById('wadah_progress');
    var header_wadah_progress = document.getElementById('header_wadah_progress');
    var microtime_html;

    if(null!=wadah_microtime_start){
        microtime_html=wadah_microtime_start.innerHTML;
        if(microtime_html<1){
            wadah_microtime_start.innerHTML=microTime;
            wadah_human_time_start.innerHTML=humanTime;
        }
        else{
            var timeStart=wadah_human_time_start.innerHTML;
            var timeNow=now.customFormat("#YYYY#-#MM#-#DD# #hh#:#mm#:#ss#");
            momentDiff=moment.utc(moment(timeNow,"HH:mm:ss").diff(moment(timeStart,"HH:mm:ss"))).format("HH:mm:ss")
            wadah_microtime_start.innerHTML="<span class='text-red text-bold'>"+momentDiff+"</span>"
        }
    }

    if(finish){
        var upload_info = {
            time_mulai: timeStart,
            time_finish: timeNow,
            time_diff: momentDiff,
            desc: finish_desc,
        }
        localStorage.uploadInfo = JSON.stringify(upload_info)
    }

    $('#h_wadah_human_time_start').removeClass('hidden');

    if(group=='wp'){
        if (null != wadah_progress) {
            wadah_progress.innerHTML = textProgress;
            wadah_progress.style.color = '#ab1d1d';
            wadah_progress.style.fontWeight = '700';
        }
        else{
            console.error('TIDAK DITEMUKAN #wadah_progress, log dikeluarkan dibrowser console..');
            console.log('menulis kewadah #wadah_progress' + ' | ' + humanTime);
            console.info(textProgress + ' | ' + humanTime);
        }
    }
    else{
        if(null != header_wadah_progress) {
            header_wadah_progress.innerHTML = textProgress;
            header_wadah_progress.style.color = 'lightcoral';
            header_wadah_progress.style.fontWeight = '700';
        }
        else{
            console.error('TIDAK DITEMUKAN #wadah_progress, log dikeluarkan dibrowser console..');
            console.log('menulis kewadah #wadah_progress' + ' | ' + humanTime);
            console.info(textProgress + ' | ' + humanTime);
        }
    }
}


var countObj=function(obj){
    // console.log('%c Execute countInObject(i)', 'background: #222; color: #bada55');
    var count = 0;
    for(var key in obj) if(obj.hasOwnProperty(key)) count++;
    return count;
}

function pembilang(nilai,rupiah=0){
    nilai = Math.abs(nilai);
    var simpanNilaiBagi=0;
    var huruf = ["", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas"];
    var temp="";

    if (nilai < 12) {
        temp = " "+huruf[nilai];
    }
    else if (nilai <20) {
        temp = pembilang(nilai - 10) + " Belas";
    }
    else if (nilai < 100) {
        simpanNilaiBagi = Math.floor(nilai/10);
        temp = pembilang(simpanNilaiBagi)+" Puluh"+ pembilang(nilai % 10);
    }
    else if (nilai < 200) {
        temp = " Seratus" + pembilang(nilai - 100);
    }
    else if (nilai < 1000) {
        simpanNilaiBagi = Math.floor(nilai/100);
        temp = pembilang(simpanNilaiBagi) + " Ratus" + pembilang(nilai % 100);
    }
    else if (nilai < 2000) {
        temp = " Seribu" + pembilang(nilai - 1000);
    }
    else if (nilai < 1000000) {
        simpanNilaiBagi = Math.floor(nilai/1000);
        temp = pembilang(simpanNilaiBagi) + " Ribu" + pembilang(nilai % 1000);
    }
    else if (nilai < 1000000000) {
        simpanNilaiBagi = Math.floor(nilai/1000000);
        temp =pembilang(simpanNilaiBagi) + " Juta" + pembilang(nilai % 1000000);
    }
    else if (nilai < 1000000000000) {
        simpanNilaiBagi = Math.floor(nilai/1000000000);
        temp = pembilang(simpanNilaiBagi) + " Miliar" + pembilang(nilai % 1000000000);
    }
    else if (nilai < 1000000000000000) {
        simpanNilaiBagi = Math.floor(nilai/1000000000000);
        temp = pembilang(nilai/1000000000000) + " Triliun" + pembilang(nilai % 1000000000000);
    }

    return rupiah==1 ? temp + " Rupiah" : temp;
}

var initWdwNamep;
var kirim = function(url, callback){
    jQuery.ajax({
        url: url,
        dataType: 'json',
        success: callback,
        async: true
    });
}
var genNewTab = function(o=0,u=''){
    var baseURL = top.$('#baseURL').html();
    this.window.name = Date.now();

    if(u!=''){
        baseURL = u;
    }
console.log('baseURL: ' + baseURL);
    kirim(baseURL+'eusvc/NonRest/cacheTab?tab='+this.window.name, function(a){
        console.log('API tab: ', a);
        if(o){
            window.location.href = baseURL + "penjualan/Create/index/582"
        }
        else{
            wdwName()
        }
    });
}



var wdwCheck = function(){
    setTimeout( function(){
        var baseURL = top.$('#baseURL').html();
        if(baseURL!='undefined'){
            kirim(baseURL+'eusvc/NonRest/cacheTabCheck?tab='+this.window.name, function(a){
                console.log('API tab: ',a);
                if(a.active_tab != a.this_tab){
                    console.error("tab tidak sama, kuncil layar ini.. atau tetapkan");
                    window.location.href = baseURL+ "eusvc/lockscreen";
                }
                else{
                    wdwCheck()
                }
            });
        }
        else{
            console.log("halan sudah di lock");
            clearTimeout(initWdwNamep)
        }
    }, 3000)
}

var wdwName = function(){
    if(this.window.name=='undefined'||this.window.name==''){
        genNewTab()
    }
    else{
        console.log("TAB HAS TAB NAME: ",this.window.name);
        wdwCheck()
    }
}


initWdwNamep = setTimeout(function(){
    wdwName();
}, 1000)