function frmtCurrency(ele,symb,val,code,cls) { // round the currency to the nearest .05 val *= 2.0; val = val.toFixed(1) / 2.0; val = val.toFixed(2); // build the text in the form: '$' '12.35' 'USD' ele.html(symb+' '+val+code ); // add the currency code to the element class. ele.addClass(cls); } function convertCurrency(obj, from_value) { var $this = $(obj); if ($this.attr('rel')) { var prms = $this.attr('rel').split(':'); /*"USD:EUR:€"*/ var fAmnt = from_value; var cCode = ''; // check if the exchange rate has been retrieved today var cookieVal = $.cookie('currencyrate'+prms[0]+prms[1]); if (cookieVal != null) { frmtCurrency($this,prms[2],fAmnt*parseFloat(cookieVal),cCode,prms[1]); } else { try { reqAjax = $.ajax({ type: "POST", url: '/currency-ajax.php', dataType: "json", data: "action=rate" + "&currfrom=" + prms[0] + "&currto=" + prms[1], success: function(json) { switch (json.errcode) { case 'ERR-100': $.cookie('currencyrate'+prms[0]+prms[1],json.result,{expires: 6, path: '/' }); frmtCurrency($this,prms[2],fAmnt*parseFloat(json.result),cCode,prms[1]); break; case 'ERR-200': break; default: break } }, error: function(xhr, msg, ex) { reqAjax = null } }) } catch(e) { } } } }