<%= javascript_include_tag 'plans_widget.js' %>
<%= stylesheet_link_tag 'plans_widget.css' %>

<% id = id || "choose-plan-#{contract.id}" %>
<% wizard = wizard || false %>

<%= javascript_tag do %>
  $(document).ready(function(){

    function updateForm(name, planID){
      $('#selected-plan em').text(name);
      $('input#cinstance_plan_id').val(planID);
    }

    $("#<%= id %>").click(function(){
      <%- if contract.new_record? %>
        var planID = $('input#cinstance_plan_id').val();
        PlanWidget.loadPreview(planID, updateForm, '<%= admin_service_plans_widget_path(@service) %>');
      <%- else -%>
        var planID = '<%= contract.plan.id %>';
        PlanWidget.loadPreview(planID, updateForm, '<%= admin_service_plans_widget_path(contract.service, wizard: wizard) %>', '<%= contract.id %>' );
       <%-end-%>
      return false;
    });
  });
<% end %>
