var patient_form = {
    settings: {
        account_autocomplete_url: '',
        account_user_autocomplete_url: '',
        city_autocomplete_url: '',
        patient_type_autocomplete_url: '',
        postalCode_autocomplete_url: '',
        referring_health_facility_autocomplete_url: '',
        referring_provider_autocomplete_url: '',
        health_facility_autocomplete_url: '',
        patient_autocomplete_url: ''
    },
    init: function() {
        this.initAutocomplete();
        this.redFlagShowReason();

        jQ('#patient_source').unbind('change').bind('change', function () {
            jQ('.referredByText').addClass('hide');
            if(jQ('option:selected',this).text() === 'Referred By Patient'){
                jQ('.referredByText').removeClass('hide');
            }

            jQ('.referredByName').addClass('hide');
            if(jQ('option:selected',this).text() === 'Referred By'){
                jQ('.referredByName').removeClass('hide');
            }
        });
    },
    initAutocomplete: function() {
        global.autocomplete.bind(this.settings.account_autocomplete_url, '#patient_account_desc', '#patient_account');
        global.autocomplete.bind(this.settings.account_user_autocomplete_url, '#patient_endorsed_by');
        global.autocomplete.bind(this.settings.city_autocomplete_url, '#patient_city_desc', '#patient_city');
        global.autocomplete.bind(this.settings.patient_type_autocomplete_url, '#patient_patient_type_desc', '#patient_patient_type');
        global.autocomplete.bind(this.settings.primary_provider_autocomplete_url, '#patient_primary_provider_fullName', '#patient_primary_provider');
        global.autocomplete.bind(this.settings.postalCode_autocomplete_url, '#patient_postalCode_desc', '#patient_postalCode',{
            onSelect: function (c) {
                jQ('#patient_city_desc').val(c.city);
                jQ('#patient_city').val(c.cityId);
            }
        });
        global.autocomplete.bind(this.settings.health_facility_autocomplete_url, '#patient_health_facility_desc', '#patient_health_facility');
        global.autocomplete.bind(this.settings.referring_provider_autocomplete_url, '#patient_referring_provider_desc', '#patient_referring_provider');
        global.autocomplete.bind(this.settings.patient_autocomplete_url, '#patient_referredByPatient_fullName', '#patient_referredBy');
    },
    redFlagShowReason: function(){
        // jQ('#patient_is_red_flag').unbind('click').bind('click', function () {
        //     if(this.checked){
        //         jQ('.red-flag-reason').fadeIn(300);
        //     }else{
        //         jQ('.red-flag-reason').slideUp(300);
        //         jQ('#patient_red_flag_note').val(null);
        //     }
        // });
        //
        // if(jQ('#patient_is_red_flag').prop('checked')){
        //     jQ('.red-flag-reason').fadeIn(300);
        // }

        jQ('#patient_is_endorsed').unbind('click').bind('click', function () {
            if(this.checked){
                jQ('#patient_endorsed_by').fadeIn(300);
            }else{
                jQ('#patient_endorsed_by').slideUp(300);
                jQ('#patient_endorsed_by').val(null);
            }
        });

        if(jQ('#patient_is_endorsed').prop('checked')){
            jQ('#patient_endorsed_by').fadeIn(300);
        }
    }
};