function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
    num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
    cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + '$' + num + '.' + cents);
}
var SelectDeliveryOption = Behavior.create({
  initialize: function(amount, paypal_button_id) {
    this.amount = amount;
    this.paypal_button_id = paypal_button_id;
  },
  onclick: function() {
    $('postage').update('A' + formatCurrency(this.amount));
    if ($('hosted_button_id'))
    {
      $('hosted_button_id').value = this.paypal_button_id;
    }
    if ($('order_total'))
    {
      $('order_total').update('A' + formatCurrency((29.95 + this.amount)*$F('qty')));
    }
  }
});
Event.addBehavior({
  '#order_option_australia':SelectDeliveryOption(8.00,'1878445'),
  '#order_option_newzealand':SelectDeliveryOption(12.00,'1878477'),
  '#order_option_other':SelectDeliveryOption(15.00,'1878494'),
  '#qty:change' : function(e){
      $('order_total').update('A' + formatCurrency((29.95 + Number($$('.oo').detect(function(o){return o.checked}).value))*$F('qty')));
    },
   '#print_button:click' : function(e){
     this.replace('');
     $$('#order_form input, #order_form select, #order_form textarea').each(function(e){
       e.replace(e.value + '&nbsp;')
     });
     window.print();
   }
  
})

