.top
  %h2 Solidaires avec le peuple animal et la planète


.desc
  %p
    %strong C’est vous qui assurez le futur des animaux et de la planète 
  %p
    Nous analysons chaque problématique, nous enquêtons, nous révélons la vérité, nous proposons des alternatives, nous mobilisons l’opinion publique, nous luttons avec des partenaires sur le terrain. 
  %p
    Nous refusons toute subvention venant d’un lobby, d’un gouvernement, ou d’un parti politique. Vous seuls financez One Voice. Ainsi, dans la continuité et l’innovation, One Voice peut faire bouger les lignes en toute liberté de parole et d’action.

=render :partial => "menu" 
    
= semantic_form_for [:public,@donator_transaction] do |f| 
  =f.inputs do 
    =f.hidden_field :donator_id
    
    
    
    =f.input :recurrent, :as => :radio, :collection => [ ["Don mensuel",true], ["Don ponctuel",false]], :label => false, :input_html => {:onchange => "don_amount();"}
    =f.semantic_fields_for :particular_bill do |f| 
      =f.hidden_field :skip_validation
    .donate_grid
      %span#don_reccurent
        -[15,25,35,50,60].each do |amount|
          .amount{:data => {:amount => amount}}
            .price
              =amount
              €
           
        
      %span#don_ponctuel
        -[25,50,100,150,250].each do |amount|
          .amount{:data => {:amount => amount}}
            .price
              =amount
              €
            
            
      .personalized_amount_container
        =text_field_tag :personalised_amount, "", :placeholder => "Autre montant", :class => "personalized_amount", :id => "personalized_amount"
        
        
    =f.semantic_fields_for :transaction_items do |f| 
      =f.hidden_field :amount, :id => "transaction_amount"
      =f.hidden_field :transaction_content_type
      
      - transaction_content_type = f.object.transaction_content_type
      =f.semantic_fields_for :transaction_content do |f| 
        -if transaction_content_type == "TransactionDonate"
          =#f.input :donate_destination, :collection => DonateDestination.all
    
  .donate_infos
    %p
      Un don de 
      %span.personalized_amount
      € vous reviendra à 
      %span.personalized_fiscal
      € après déduction fiscale.
    %p
      66% de votre don est déductible de vos impôts dans la limite de 20% de vos revenus imposables.
      
      
  .actions=f.submit "Suite >", :class => "btn btn-primary"
  
:coffeescript
  amount =  $("#transaction_amount").val()
  if $("#donator_transaction_recurrent_true").is(':checked')
    elements = $("#don_reccurent}").find("[data-amount='"+amount+"']")
  else
    elements = $("#don_ponctuel}").find("[data-amount='"+amount+"']")
  
  if elements.length > 0
    $(".personalized_amount_container .fiscal").css("opacity", 0)
    elements.addClass("active")
    
  else
    $("#personalized_amount").val(amount)
    $(".personalized_amount_container").addClass("active")
    $(".personalized_amount_container .fiscal").css("opacity", 1)
    $("#personalized_fiscal").html (amount*0.34).toFixed(2)
    
    
:coffeescript
  @personalized_infos = ->
    
    p_amount =  $("#transaction_amount").val()
    
    $(".personalized_amount").html p_amount
    p_fiscal =  ($("#transaction_amount").val()*0.34)
    $(".personalized_fiscal").html p_fiscal.toFixed(2)
    
  @don_amount = ->

    if $("#donator_transaction_recurrent_true").is(':checked')
      $('#don_reccurent').show()
      $('#don_ponctuel').hide()
  
    else
      $('#don_reccurent').hide()
      $('#don_ponctuel').show()
  $(".amount").click ->
    $("#personalized_amount").val('')
    $("#transaction_amount").val($(this).data('amount'))
    $(".amount").removeClass("active")
    $(".personalized_amount_container").removeClass("active")
    $(".personalized_amount_container .fiscal").css("opacity", 0)
    $(this).addClass("active")
    personalized_infos()
  
  update_transaction_amount = ->
    $("#transaction_amount").val($("#personalized_amount").val())
    $("#personalized_fiscal").html ($("#personalized_amount").val()*0.34).toFixed(2)
    $(".amount").removeClass("active")
    $(".personalized_amount_container").addClass("active")
    $(".personalized_amount_container .fiscal").css("opacity",1)
  
    
  $("#personalized_amount").bind 'keydown', ->
    update_transaction_amount()
    personalized_infos()
  $("#personalized_amount").bind 'keyup', ->
    update_transaction_amount()
    personalized_infos()
  $("#personalized_amount").bind 'change', ->
    update_transaction_amount()
    personalized_infos()
    
    
  
    
:javascript
  don_amount();
  personalized_infos();