        Object.extend(Number.prototype, {
            numberFormat : function(decimals) {

                decimals = decimals || 0;
                var pow = Math.pow(10, decimals);
                var nStr = (parseFloat(Math.round(this*pow)) / pow).toString();
                
                var x = nStr.split('.');
                var x1 = x[0];
                var x2 = x.length > 1 ? x[1] : '';
                
                while(x2.length < decimals) {
                    x2 += '0';
                }
                x2 = '.' + x2;

                var rgx = /(\d+)(\d{3})/;
                while (rgx.test(x1)) {
                    x1 = x1.replace(rgx, '$1' + ',' + '$2');
                }
                return x1 + x2;

            }
        });


        goldUpdater = {
            xhrUrl: '../site_includes/xhr_goldprices.php',
            prices : {},
            getPrices : function(interval) {
				//alert('here');
                new Ajax.Request(this.xhrUrl, {
                    method    : 'post',
                    evalJSON  : true,
                    onSuccess : function(t) {
                        this.prices = t.responseJSON;
                        
                        this.updatePage();

                        if(interval > 500) {
                            setTimeout('goldUpdater.getPrices('+interval+')', interval);
                        }

                    }.bind(this)
                });


            },

            updatePage : function() {

                //console.log($H(this.prices));
                var items;
                $H(this.prices).each(function(item, value)  {
                    //console.log(label[0]);

                    items = item;
                    var el = $(item[0].toLowerCase());
                    var frm = $('frm' + item[0].toLowerCase());
                    if(el || frm) {
                        //var new_price = parseFloat(Math.round(item[1]*100))/100;
                        var new_price = parseFloat(item[1]);
						var new_price_pretty = new_price;
						if (item[0].toLowerCase() != 'exchangerate') {
							new_price_pretty = new_price.numberFormat(2);
						}

						var old_price = 0;
                        if(frm && frm.elements['price']) {
							old_price = parseFloat(Math.round(parseFloat(frm.elements['price'].value)*100))/100;
						}

                        if(old_price != new_price) {
							if(el) {
	                            el.update('<small>Updating...</small>');
	                            el.newPrice = new_price_pretty;
                                var pound = item[0].toLowerCase().substring(0, 5)=='price' ? '&pound;' : '';
	                            setTimeout("$('" + el.id + "').update('"+pound+"'+$('" + el.id + "').newPrice)", 1000);
							}
                            if(frm) {
								frm.elements['price'].value = new_price;
							}
                        }
                    }
                });
            }
        }

        document.observe('dom:loaded', function() {
            
            var interval = 15000;
            setTimeout('goldUpdater.getPrices('+interval+');', interval);

        });