(function($) {
    $( document ).ready(function() {
        var payment_menthod = $('.payment_method');
        var $credit_box = $('#credit_card');
        var credit_open = false;

        if (typeof first_credit_open === "undefined") {
            first_credit_open = false;
        }

        if (first_credit_open){
            $credit_box.css('display', 'block');
            credit_open = true;
            $('#creditCardNumber').addClass('inputbox required numeric');
            $('#cvv2Number').addClass('inputbox required numeric');
        }


        payment_menthod.each(function(index, item){
            $(item).on('change', function(){
                if (typeof credit_method === "undefined"){
                    return;
                }

                if (credit_method.contains(this.getProperty('id'))){
                    if (!credit_open){
                        $credit_box.slideToggle('fast');
                        credit_open = true;
                        $('#creditCardNumber').addClass('inputbox required numeric').attr('aria-required',"true").attr('required','required');
                        $('#cvv2Number').addClass('inputbox required numeric').attr('aria-required',"true").attr('required','required');
                    }
                }else{
                    if (credit_open ){
                        $credit_box.slideToggle('fast');
                    }

                    credit_open = false;
                    $('#creditCardNumber').removeClass('inputbox required numeric').removeAttr('aria-required').removeAttr('required');
                    $('#cvv2Number').removeClass('inputbox required numeric').removeAttr('aria-required').removeAttr('required');
                }
            });
        });


    });
})(jQuery);
