//given discount code element id updates charge cost and recurring charge cost elements
function apply_discount(link_element)
{
  var show_effects = link_element != null
  if (show_effects)
  {
    Element.hide(link_element);
  }
  if (show_effects) {Element.show($('applying'));}
  Element.hide(document.forms[0].commit);
  Element.show($('loading'));
  if ($('order_action_b') && $('order_action_b').checked) {plan = "B"}
  if ($('order_action_w') && $('order_action_w').checked) {plan = "W"}
  if ($('order_action_p') && $('order_action_p').checked) {plan = "P"}
  if ($('order_action_u') && $('order_action_u').checked) {plan = "U"}
  Element.hide($('discount_invalid'))
    new Ajax.Request('/signup/apply_discount',
    {
      method:'get',
      onSuccess: function(transport){
      var response = transport.responseText;
      var results = response.split('|');
      $('charge_price').innerHTML = results[0];
      $('charge_price_recurring').innerHTML = results[1];
      if (results[2] == 'invalid') {Element.show($('discount_invalid'))}
      },
      onFailure: function(){ alert('Something went wrong...') },
      onComplete: function()
      {
        if (show_effects) {Element.show(link_element);}
        Element.hide($('applying'));
        Element.hide($('loading'));
        Element.show(document.forms[0].commit);
      },
      parameters:'plan='+plan+'&discount='+$('discount').value
    });
}