var currencyRates = new Array(); var selectedCurrency = false; var multiplier = 1; currencyRates['usd'] = new Array(); currencyRates['usd']['symbol'] = '$'; currencyRates['usd']['rate'] = '1.27180'; currencyRates['gbp'] = new Array(); currencyRates['gbp']['symbol'] = '£'; currencyRates['gbp']['rate'] = '0.82590'; currencyRates["eu"] = new Array(); currencyRates["eu"]["symbol"] = "€"; currencyRates["eu"]["rate"] = 1; function convertRates(element) { var currency = element.get("id"); var symbol = selectedCurrency = currencyRates[currency]["symbol"]; var xrate = currencyRates[currency]["rate"]; multiplier = xrate; $$(".price").each( function(td) { if(td.get("dir")) { if(td.get("dir") > 0) td.set("html", symbol + floatFix(parseFloat(td.get("dir")) * parseFloat(xrate), 2)); } } ); } function floatFix (Val, Places) { var Res = "" + Math.round(Val * Math.pow(10, Places)); var Dec = Res.length - Places; if (Places != 0) { var x = Res.substring(0, Dec); if (x.length > 0) { OutString = x + "." + Res.substring(Dec, Res.length); } else { OutString = "0." + Res.substring(Dec, Res.length); } } else { OutString = Res; } return (OutString); } function currencyEvents() { $$("img.currency").each( function(img) { img.addEvent("click", function(event) { $$("img.currency").each( function(i) { i.removeClass("selected"); }); event.target.addClass("selected"); convertRates(event.target); }); } ); } window.addEvent("domready", function() { currencyEvents(); });