// Load Script Dinamis
function loadScript(url, callback) {
    const script = document.createElement('script');
    script.src = url;
    script.onload = callback;
    document.body.appendChild(script);
}

// ==============================
// AKSARA CONVERTER CONTROLLER
// ==============================

// Convert ke Aksara Jawa
function JavaneseConvert() {
    var latinText = document.getElementById('aksara_latin').value;

    var jawaText = JavaneseConverter.convert(latinText);

    var el = document.getElementById('aksara_jawa_text');
    if (el) el.value = jawaText;
}

// Convert ke Aksara Sunda
function SundaneseConvert() {
    var latinText = document.getElementById('aksara_latin').value;
    var sundaText = SundaneseConverter.convert(latinText);

    var el = document.getElementById('aksara_sunda_text');
    if (el) el.value = sundaText;
}

// Convert ke Aksara Bugis
function BugineseConvert() {
    var latinText = document.getElementById('aksara_latin').value;
    var bugisText = BugisConverter.convert(latinText);

    var el = document.getElementById('aksara_lontara_text');
    if (el) el.value = bugisText;
}


// Convert ke Aksara Bali
function BalineseConvert() {
    var latinText = document.getElementById('aksara_latin').value;
    var baliText = BaliConverter.convert(latinText);

    var el = document.getElementById('aksara_bali_text');
    if (el) el.value = baliText;
}

// Convert ke Aksara Batak
function BatakConvert() {
    var latinText = document.getElementById('aksara_latin').value;
    var batakText = BatakConverter.convert(latinText);

    var el = document.getElementById('aksara_batak_text');
    if (el) el.value = batakText;
}

// Convert ke Aksara Lampung
function LampungConvert() {
    var latinText = document.getElementById('aksara_latin').value;
    var lampungText = LampungConverter.convert(latinText);
    
    var el = document.getElementById('aksara_lampung_text');
    if (el) el.value = lampungText;
}

// Convert ke Aksara Incung
function IncungConvert() {
    var latinText = document.getElementById('aksara_latin').value;
    var incungText = IncungConverter.convert(latinText);

    var el = document.getElementById('aksara_incung_text');
    if (el) el.value = incungText;
}


// Salin Aksara
function SalinAksara() {
    var aksara_view = $("#aksara-tabContent .tab-pane.active input.aksara_view").attr('id');

    var range = document.createRange();
    range.selectNode(document.getElementById(aksara_view));
    window.getSelection().removeAllRanges(); // clear current selection
    window.getSelection().addRange(range); // to select text
    document.execCommand("copy");
    window.getSelection().removeAllRanges();

    $("#salin_info").fadeIn(1e3, function() {
        setTimeout(function() {
            $("#salin_info").fadeOut(1e3);
            //$("#salin_aksara").hover();
        }, 3e3);
    });
}

