var base = 0; var target = 0; var result = 0; var time = ''; var typ = 'CUR'; var timeout_ID_convertCurrency; function hideOrShow(id) { var object = $('#' + id); if (object) { if (object.hasClass('hide')) { $('.hideable').addClass('hide'); object.toggleClass('hide'); object[0].getElementsByTagName('input')[0].focus(); } else { $('.hideable').addClass('hide'); } } } function clearInput(id, head_id){ var searchbox = document.getElementById(id); searchbox.value = ''; filter(searchbox, head_id); } function convertCurrency(){ clearTimeout(timeout_ID_convertCurrency); timeout_ID_convertCurrency = setTimeout(convertCurrencyAsync, 200); } function convertCurrencyAsync(){ var quantity = document.getElementById('quantity_short').value; quantity = parseFloat(quantity.replace(',', '.')); if (base && target && quantity) { var base_value = getLast(base); var target_value = getLast(target); result = base_value / target_value; var result_round = result; if (quantity * result_round >= 1000) { result_round = Math.round(quantity * result_round); } else { result_round = parseFloat(quantity * result_round).toPrecision(3) } document.getElementById('ergebnis_short').value = String(result_round).replace('.', ','); document.getElementById('ergebnis_long').innerHTML = quantity * result; document.getElementById('quantity_long').innerHTML = quantity; } } function changeResult(){ var ergebnis_long = document.getElementById('ergebnis_long'); var quantity_long = document.getElementById('quantity_long'); var ergebnis_short = parseFloat(document.getElementById('ergebnis_short').value.replace(',','.').replace(' ','')); var quantity_short = parseFloat(document.getElementById('quantity_short').value.replace(',','.').replace(' ','')); quantity_long.innerHTML = ergebnis_short / ergebnis_long.innerHTML * quantity_long.innerHTML; if (quantity_long.innerHTML >= 1000) { quantity_short = Math.round(quantity_long.innerHTML).toPrecision(0); } else { quantity_short = parseFloat(quantity_long.innerHTML).toPrecision(3); } ergebnis_long.innerHTML = ergebnis_short; document.getElementById('quantity_short').value = quantity_short.replace('.',','); } function filter(searchbox, head_id) { var head = document.getElementById(head_id); var value = searchbox.value.toLowerCase(); for (var i = head.children.length - 1; i >= 0; i--) { var child = head.children[i]; if (child != searchbox.parentNode) { if (child.innerHTML.toLowerCase().indexOf(value) > -1) { child.style.display = ""; } else { child.style.display = "none"; } } } } function filterByDataset(data, value, hide){ if (hide) { $( "a[data-" + data + "=" + value + "]" ).addClass('hide'); } else { $( "a[data-" + data + "=" + value + "]" ).removeClass('hide'); } } function filterTyp(typ){ this.typ = typ; var callConvertCurrency = false; if (typ == 'CUR') { //Währung filterByDataset('sort', 'hideAll'); filterByDataset('typ', 'CUR'); filterByDataset('typ', 'CCR', true); } else if (typ == 'CCR') { //Krypto filterByDataset('sort', 'hideAll'); filterByDataset('typ', 'CUR', true); filterByDataset('typ', 'CCR'); } else { //Alle filterByDataset('typ', 'CUR'); filterByDataset('typ', 'CCR'); filterByDataset('sort', 'hideAll', true); typ = 'ALL'; } if (callConvertCurrency) { convertCurrency(); $('#bottommenu').find('.active').children().click(); var base_name = document.getElementById('base_dropdown_Head').querySelector('.display-inline').innerHTML; $('#waehrungsrechner_kurstabelle').load('/devisen/waehrungsrechner/_kurstabelle', {'typ': typ, 'base': base, 'base_name': base_name}); } } window.onclick = function(event) { if (!($(event.target).hasClass('hideable')) && !($(event.target).hasClass('noHide'))) { $('.hideable').addClass('hide'); } } function getLast(ag){ var last = '-'; if (ag <= 0) { return 1; //Spezieller Euro fall }; $.ajaxSetup({async: false}); $.getJSON('/api/portal_schnittstelle.m', { 'aic': ag, 'date': time, 'operation': 'get_last' }) .done(function(json) { if (json.is_error == 0) { var length = json.quotes.length; for (var i = 0; i < length; i++) { if (json.quotes[i].last != '-') { last = Number(json.quotes[i].last); break; } } } }); return last; } function setBase(base, noUpdate){ this.base = base; if (noUpdate) { return; } convertCurrency(); $('#bottommenu').find('.active').children().click(); var base_name = document.getElementById('base_dropdown_Head').querySelector('.display-inline').innerHTML; $('#waehrungsrechner_kurstabelle').load('/devisen/waehrungsrechner/_kurstabelle', {'typ': typ, 'base': base, 'base_name': base_name}); } function setTarget(target, noUpdate){ this.target = target; if (noUpdate) { return; } convertCurrency(); $('#bottommenu').find('.active').children().click(); var base_name = document.getElementById('base_dropdown_Head').querySelector('.display-inline').innerHTML; $('#waehrungsrechner_kurstabelle').load('/devisen/waehrungsrechner/_kurstabelle', {'typ': typ, 'base': base, 'base_name': base_name}); } function setTime(time, noUpdate){ if (typeof time == 'string') { var pieces = time.split('.'); time = new Date(pieces[2] + '-' + pieces[1] + '-' + pieces[0]); this.time = time; } if (time > new Date()) { time = new Date(); } this.time = ('0' + time.getDate()).slice(-2) + '.' + ('0' + (time.getMonth()+1)).slice(-2) + '.' + time.getFullYear(); document.getElementById('start').value = this.time; if (noUpdate) { return; } convertCurrency(); } function setForm(url, typ){ event.preventDefault(); var form = document.getElementById('waehrungsrechner_form'); form.action = url; document.getElementById('waehrungsrechner_typ').value = typ; form.submit(); } $(document).ready(function() { setBase(document.getElementById('base_dropdown_Head').dataset.ag, true); setTarget(document.getElementById('target_dropdown_Head').dataset.ag, true); var typ = document.getElementById('waehrungsrechner_typ').value; filterTyp(typ); setTime(new Date()); }); //Wird nicht genutzt function setTimeFree(){}