
    $(document).ready(function() {
            "use strict"

        $("#manage_client_show_hide_password a").on('click', function(event) {
            common_helper.globalPasswordView('#manage_client_show_hide_password',event);
        });

        common_helper.formValidate('#payment-report_form',
            {'card_number': 'required', 'expiry': 'required', 'cvv': 'required'},
            {
                'card_number': {required: "Please enter your card number"},
                'expiry': {required: "Please enter expire date"},
                'cvv': {required: "Please enter your card code"}
            }
        );
    });

    $('#client_form').validate({
        rules: {
            'creditreport[first_name]': 'required',
            'creditreport[last_name]': 'required',
            'creditreport[birth_date]': 'required',
            'creditreport[street_no]' : 'required',
            'creditreport[street_name]' : 'required',
            'creditreport[city]' : 'required',
            'creditreport[state]' : 'required',
            'creditreport[zip_code]' : 'required',
            'creditreport[phone]' : 'required',
            'creditreport[ssn]' : {'required': true,'minlength':4,'maxlength':4},
            'creditreport[password]': 'required',
            'creditreport[credit_report_company_type]': 'required',
        },
        messages: {
            'creditreport[first_name]': {
                required: "Please enter your first name"
            },
            'creditreport[last_name]': {
                required: "Please enter your last name"
            },
            'creditreport[birth_date]': {
                required: "Please enter your birth date",
            },
            'creditreport[street_no]': {
                required: "Please enter your street number"
            },
            'creditreport[street_name]': {
                required: "Please enter your street name"
            },
            'creditreport[state]': {
                required: "Please enter your state"
            },
            'creditreport[city]': {
                required: "Please enter your city"
            },
            'creditreport[zip_code]': {
                required: "Please enter your zip code"
            },
            'creditreport[phone]': {
                required: "Please enter your zip code"
            },
            'creditreport[ssn]': {
                required: "Please enter last 4 digit of your ssn",
                minlength:"Please enter last 4 digit of your ssn",
                maxlength:"Please enter last 4 digit of your ssn"
            },
            'creditreport[password]': {
                required: "Please enter your password"
            },
            'creditreport[credit_report_company_type]': {
                required: "Please enter your source type"
            },
        },
        highlight: function (element) {
            $(element).parent().addClass("has-error");
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
    $('input[name=isReceiveNotificationEmail]').click(function () {
        $('#alternate-email').attr('required', false);
        $('#alternate-email').attr('disabled', true);
        if ($(this).prop('checked')) {
            $('#alternate-email').attr('required', true);
            $('#alternate-email').attr('disabled', false);
        }
    })
    $('input[name=is_letterstream_return_address]').click(function () {
        $('#client-city').attr('required', false);
        $('#client-zip-code').attr('required', false);
        $('#client-address').attr('required', false);
        $('#client-state').attr('required', false);
        $('#client-country').attr('required', false);
        $('.letter-stream-check').removeClass('required')
        // $('#alternate-email').attr('disabled',true);
        if ($(this).prop('checked')) {
            $('#client-city').attr('required', true);
            $('#client-zip-code').attr('required', true);
            $('#client-address').attr('required', true);
            $('#client-state').attr('required', true);
            $('.letter-stream-check').addClass('required')
            //$('#alternate-email').attr('disabled',false);
        }
    });
    function firstTimeLoginUserUpdate(){
        $('#first_time_login_modal').modal('hide');
        $('#first_time_login_view_modal').modal('show');
        $('#btn_first_time_login').click((e)=>{
            $(`#first_time_login_view_modal`).modal('hide');
            var scrollpanel =  $("#upload-document-panel").offset().top;
            $(window).scrollTop(scrollpanel);
            $('#upload-document-panel').focus();
        });
    }

    $("#show_hide_answer1 a").on('click', function(event) {
        common_helper.globalPasswordView('#show_hide_answer1',event);
    })
    $("#show_hide_answer2 a").on('click', function(event) {
        common_helper.globalPasswordView('#show_hide_answer2',event);
    })
    $("#show_hide_answer3 a").on('click', function(event) {
        common_helper.globalPasswordView('#show_hide_answer3',event);
    })
    const birthDateCompleted=()=>{
        let birth_date=$("[name='creditreport[birth_date]']").val();
        if(birth_date.length===2){
            birth_date+='/';
        }
        else if(birth_date.length===5){
            birth_date+='/';
        }
        $("[name='creditreport[birth_date]']").val(birth_date);
    }
    const sourceTypeConfigUnset = () => {
        $('#ok-btn').remove()
        $('#common_confirmation_modal .modal-footer button').removeClass('btn2')
        $('#common_confirmation_modal .modal-footer button').removeAttr('onclick')
    }
    const sourceTypeConfigSetup = (current_source_type) => {
        $('#common_confirmation_modal .modal-footer button').addClass('btn2')
        $('#common_confirmation_modal .modal-footer button').attr('onclick',`setPrevious(${current_source_type})`)
        $('#common_confirmation_modal .modal-footer').prepend(sourceTypeSelectBtn())
    }
    const setPrevious = (value) => {
        $("select[name='credit_report_company_type']").val(value);
    }
    const sourceTypeSelectBtn = (value) =>{

        let html = `
                    <button id="ok-btn" type="button" class="btn btn-secondary btn2 btn-lg" data-dismiss="modal">Ok</button>
            `;

        return html
    }
    const callbackfromreportprovider =(response)=>{
                console.log('test result',response);
                if(response.status) {
                      $('#client_form').submit();
                }else {
                    sourceTypeConfigUnset()
                    let html = response.message;
                    $('#common_message_text').text(html);
                    $('#common_confirmation_modal').modal('show');
                }
    }
    const file_upload = (title,image,type,nameatrr)=>{

        let encoded = encodeURIComponent(image);
        $('#pic_header').text(title);
        $('#doc_type').val(type);
        $("#uploaded_doc").attr("src",decodeURIComponent(encoded));
        $('input[id="profile_pic"]').attr('name', nameatrr);

        $('#upload_pic_modal').modal('show');
    }

