var valuta_arfolyamok = {'USD' : 309.65, 'EUR' : 356.38};var current_currency = 'EUR';
// most frissitettuk utoljara
var valuta_arfolyamok_last_refresh = new Date();
// volt frissitve az ar?
var valuta_arfolyamok_refreshed = 0;
var current_valuta_wrapper_parent = null;
// most nem adminban vagyunk
_ajax_subpath = '';
jQuery(document).ready(function() {
var rates_text = get_exchange_rates_list();
jQuery("body").append("
");
// jQuery('#valuta_valaszto_wrapper').show();
});
// arfolyam kivalaszto mutatasa
function show_currency_select(e) {
//latszik vagy nem?
if ( jQuery('#valuta_valaszto_wrapper').is(':visible') && current_valuta_wrapper_parent && e == current_valuta_wrapper_parent ) {
jQuery('#valuta_valaszto_wrapper').fadeOut().hide();
} else {
current_valuta_wrapper_parent = e;
if ( valuta_arfolyamok_refreshed ) {
// frissitsuk a listat, hatha kozben frissult az ar
jQuery('#valuta_valaszto_content').html(get_exchange_rates_list());
valuta_arfolyamok_refreshed = 0;
}
// es mutassuk meg
jQuery('#valuta_valaszto_wrapper').css({ top: jQuery(e).offset().top+jQuery(e).height()+'px', left: jQuery(e).offset().left - 90 +'px'}).fadeIn().show();
}
}
function change_current_currency(c) {
// kell valtani, vagy csak birka volt?
if ( current_currency == c ) {
// console.log('Nincs frissites. ['+current_currency+'|'+c+']');
jQuery('#valuta_valaszto_wrapper').fadeOut().hide();
return;
}
var most = new Date();
// 5 perces frissites - 300 * 1000
most.setTime(most.getTime() - ( 300*1000 ) );
current_currency = c;
if ( most > valuta_arfolyamok_last_refresh ) {
// console.log("Updating rates. Last update time: "+valuta_arfolyamok_last_refresh+' Now: '+most);
ajax_call('func=update_exchange_rates','update_foreign_prices()');
} else {
update_foreign_prices();
}
//menstuk le, hogy mit valasztott
ajax_call('func=update_used_foreign_currency¤cy='+c,'',true,false);
}
// befrissiti az arakat
function update_foreign_prices() {
jQuery('.exchanged_price').each(function() {
var huf = this.id.split('_').pop();
// console.log('Using '+current_currency+' with rate '+valuta_arfolyamok[current_currency]+' to update: '+huf);
var new_price = parseFloat(huf) / valuta_arfolyamok[current_currency];
jQuery(this).html(format_number(new_price,2,'.',',')+' '+current_currency);
});
jQuery('#valuta_valaszto_wrapper').hide();
}
// osszeallitja a listat
function get_exchange_rates_list() {
var rates_text = '';
for ( var k in valuta_arfolyamok ) {
rates_text += " ";
rates_text += '
';
rates_text += k+"";
rates_text += " - aktuális MNB árfolyam: "+valuta_arfolyamok[k]+"
";
}
return rates_text;
}
function format_number (n, decimals, decimal_sep, thousands_sep) {
if (isNaN(n)) { return 0};
if (n=='') { return 0};
//var n = this,
c = isNaN(decimals) ? 2 : Math.abs(decimals), //if decimal is zero we must take it, it means user does not want to show any decimal
d = decimal_sep || ',', //if no decimal separetor is passed we use the comma as default decimal separator (we MUST use a decimal separator)
/*
according to [http://stackoverflow.com/questions/411352/how-best-to-determine-if-an-argument-is-not-sent-to-the-javascript-function]
the fastest way to check for not defined parameter is to use typeof value === 'undefined'
rather than doing value === undefined.
*/
t = (typeof thousands_sep === 'undefined') ? '.' : thousands_sep, //if you don't want ot use a thousands separator you can pass empty string as thousands_sep value
sign = (n < 0) ? '-' : '',
//extracting the absolute value of the integer part of the number and converting to string
i = parseInt(n = Math.abs(n).toFixed(c)) + '',
j = ((j = i.length) > 3) ? j % 3 : 0;
return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
}