jq(function() {

    if (jq("#fr_newsletter").length == 1) {
          $el = jq("input#newsletter-email");
          $el.focus(function() {
              if (jq(this).val() == 'Votre email') {
                  jq(this).val("");
                  jq(this).css('color', 'black');
              }
          });
          $el.blur(function() {
              if (jq(this).val() == '') {
                  jq(this).val("Votre email");
                  jq(this).css('color', 'gray');
              }
          });

          if ($el && $el.val() == "") {
              $el.val("Votre email");
              $el.css('color', 'gray');
          }
    }
    if (jq("#fr_sponsorship").length == 1) {
          // This part is for "other amount" fields of the Sponsorship LP
          if ( jq("div#real_amount input#amountx:checked").length == 0 ) {
            jq("div#real_amount").find("div.other").hide(); 
          }
          jq("div#real_amount").find("input:radio").click(function() {
                if( jq(this).attr('id')=="amountx" ){                                                  
                    jq("div#real_amount").find("div.other").show(); 
                }else   
                    jq("div#real_amount").find("div.other").hide();
          })
          jq("div#real_amount input#other-amount").focus(function() {
              if (jq(this).val() == 'A partir de 25') {
                  jq(this).val("");
                  jq(this).css('color', 'black');
              }
          });
          jq("div#real_amount input#other-amount").blur(function() {
              if (jq(this).val() == '') {
                  jq(this).val("A partir de 25");
                  jq(this).css('color', 'gray');
              }
          });

          $other = jq("div#real_amount input#other-amount");
          if ($other && $other.val() == "") {
              $other.val("A partir de 25");
              $other.css('color', 'gray');
          }
    }
    if (jq("#fr_donation").length == 1) {
          // This part is for "other amount" fields of the donation LP
          if ( jq("div#m_amount input.other_amount:checked").length == 0 ) {
            jq("div#m_amount").find("div.other").hide(); 
          };
          jq("div#m_amount").find("input:radio").click(function() {
                jq("div#o_amount").find("div.other").hide(); 
                if( jq(this).attr('id')=="amountmx" ){
                    jq("div#m_amount").find("div.other").show(); 
                }else {   
                    jq("div#m_amount").find("div.other").hide();
                }
          });
          jq("input#m-other-amount").focus(function() {
              if (jq(this).val() == 'A partir de 5') {
                  jq(this).val("");
                  jq(this).css('color', 'black');
                  jq("input#amountmx").attr('checked', 'checked');
              }
          });
          jq("input#m-other-amount").blur(function() {
              if (jq(this).val() == '') {
                  jq(this).val("A partir de 5");
                  jq(this).css('color', 'gray');
              }
          });
          // one-off specific
          if ( jq("div#o_amount input.other_amount:checked").length == 0 ) {
            jq("div#o_amount").find("div.other").hide(); 
          };
          jq("div#o_amount").find("input:radio").click(function() {
                jq("div#m_amount").find("div.other").hide(); 
                if( jq(this).attr('id')=="amountox" ){
                    jq("div#o_amount").find("div.other").show(); 
                }else {   
                    jq("div#o_amount").find("div.other").hide();
                }
          });
          jq("input#o-other-amount").focus(function() {
              if (jq(this).val() == 'A partir de 1') {
                  jq(this).val("");
                  jq(this).css('color', 'black');
                  jq("input#amountox").attr('checked', 'checked');
              }
          });
          jq("input#o-other-amount").blur(function() {
              if (jq(this).val() == '') {
                  jq(this).val("A partir de 1");
                  jq(this).css('color', 'gray');
              }
          });

          // initial setup
          var $other = jq("input#m-other-amount");
          if ($other && $other.val() == "") {
              $other.val("A partir de 5");
              $other.css('color', 'gray');
          }
          var $other = jq("input#o-other-amount");
          if ($other && $other.val() == "") {
              $other.val("A partir de 1");
              $other.css('color', 'gray');
          }
    }
    if (jq("#co_es-co_hagasedonante").length == 1) {
          // This part is for "other amount" fields
          if ( jq("div#real_amount input#amountx:checked").length == 0 ) {
            jq("div#real_amount").find("div.other").hide(); 
          }
          jq("div#real_amount").find("input:radio").click(function() {
                if( jq(this).attr('id')=="amountx" ){                                                  
                    jq("div#real_amount").find("div.other").show(); 
                }else   
                    jq("div#real_amount").find("div.other").hide();
          })
    }

    jQuery('.accordion > div').hide();
    jQuery('.accordion > div:first').show().prev('h5').addClass('open');

    jQuery('.accordion h5').click(function(event) {

        event.preventDefault();
        if( !jQuery(this).hasClass('open') ) {

            jQuery('.accordion > h5').removeClass('open');
            var $nextDiv = jQuery(this).next();
            var $visibleSiblings = $nextDiv.siblings('div:visible');
            if ($visibleSiblings.length ) {
                $visibleSiblings.slideUp('normal', function() {
                    $nextDiv.slideToggle('normal').prev().addClass('open');
                });
            } else {
                $nextDiv.slideToggle('normal');
            }
        }
    }); 
    
    jQuery('.checklist ul li ul').hide();
    jQuery('.checklist ul li input').focus(function() {
        jQuery(this).parent('li').find('ul').slideDown();
    });

});
