var patient_schedule_form = {
    settings: {
        medical_facility_autocomplete_url: '',
        provider_autocomplete_url: '',
        patient_referring_provider_autocompleteUrl: '',
        patient_referring_health_facility_autocompleteUrl: '',
        patient_insurance_autocompleteUrl: '',
        chartType_autocompleteUrl: '',
        patientId: '',
        scheduleId: '',
        axn: '',
        appointmentNoticeFax_ajaxUrl: ''
    },
    init: function() {
        this.initAutocomplete();
        this.initDataTable();
    },
    initAutocomplete: function() {
        global.autocomplete.bind(this.settings.medical_facility_autocomplete_url, '#patient_schedule_health_facility_desc', '#patient_schedule_health_facility');
        global.autocomplete.bind(this.settings.provider_autocomplete_url, '#patient_schedule_provider_fullName', '#patient_schedule_provider');
        global.autocomplete.bind(this.settings.chartType_autocompleteUrl, '#patient_schedule_chartType_desc', '#patient_schedule_chartType');
        var
            params = {
                patient_id : this.settings.patientId,
                schedule_id: this.settings.scheduleId
            };
        global.autocomplete.bind(this.settings.patient_referring_provider_autocompleteUrl, '#appointment_notice_fax_patient_referring_provider_desc', '#appointment_notice_fax_patient_referring_provider', {});
        global.autocomplete.bind(this.settings.patient_referring_health_facility_autocompleteUrl, '#appointment_notice_fax_patient_referring_health_facility_desc', '#appointment_notice_fax_patient_referring_health_facility');
        global.autocomplete.bind(this.settings.patient_insurance_autocompleteUrl, '#appointment_notice_fax_patient_insurance_desc', '#appointment_notice_fax_patient_insurance');
        jQ('#appointment_notice_fax_patient_referring_provider_desc').devbridgeAutocomplete('setOptions', {params: params});
        jQ('#appointment_notice_fax_patient_referring_health_facility_desc').devbridgeAutocomplete('setOptions', {params: params});
        jQ('#appointment_notice_fax_patient_insurance_desc').devbridgeAutocomplete('setOptions', {params: params});

        jQ("#appointment_notice_fax_affiliate_type").unbind('change').bind('change',function () {
            if(jQ(this).val() === 'Insurance'){
                jQ('#affiliate-Insurance').removeClass('hide');
                jQ('#create-new-appointment-notice-save').removeClass('hide');
                jQ('#affiliate-Referring-HealthFacility, #affiliate-Referring-Provider').addClass('hide');
                jQ('#appointment_notice_fax_patient_referring_health_facility_desc, #appointment_notice_fax_patient_referring_health_facility, #appointment_notice_fax_patient_referring_provider_desc, #appointment_notice_fax_patient_referring_provider').val(null);
            }else if(jQ(this).val() === 'Referring Affiliate'){
                jQ('#affiliate-Referring-HealthFacility').removeClass('hide');
                jQ('#create-new-appointment-notice-save').removeClass('hide');
                jQ('#affiliate-Referring-Provider, #affiliate-Insurance').addClass('hide');
                jQ('#patient_letter_patient_insurance_desc, #patient_letter_patient_insurance, #appointment_notice_fax_patient_referring_provider_desc, #appointment_notice_fax_patient_referring_provider').val(null);
            }else if(jQ(this).val() === 'Referring Physician'){
                jQ('#affiliate-Referring-Provider').removeClass('hide');
                jQ('#create-new-appointment-notice-save').removeClass('hide');
                jQ('#affiliate-Referring-HealthFacility, #affiliate-Insurance').addClass('hide');
                jQ('#appointment_notice_fax_patient_insurance_desc, #appointment_notice_fax_patient_insurance, #appointment_notice_fax_patient_referring_health_facility_desc, #appointment_notice_fax_patient_referring_health_facility').val(null);
            }else{
                jQ('#affiliate-Referring-HealthFacility, #affiliate-Referring-Provider').addClass('hide');
                jQ('#affiliate-Referring-Provider, #affiliate-Insurance').addClass('hide');
                jQ('#affiliate-Referring-HealthFacility, #affiliate-Insurance').addClass('hide');
                jQ('#create-new-appointment-notice-save').addClass('hide');
                jQ('#appointment_notice_fax_patient_insurance_desc, #appointment_notice_fax_patient_insurance, #appointment_notice_fax_patient_referring_health_facility_desc, #appointment_notice_fax_patient_referring_health_facility').val(null);
            }
        });
    },
    initDataTable: function() {
        var callBack = function() {
        };

        var dataList = jQ('#appointmentNoticeFax-datalist').DataTable({
            'processing': true,
            'serverSide': true,
            'ajax': {
                'url': this.settings.appointmentNoticeFax_ajaxUrl,
                'data': function(d) {
                    d.url = global.settings.url;
                    d.patient_id = patient_schedule_form.settings.patientId;
                    d.scheduleId = patient_schedule_form.settings.scheduleId;
                }
            },
            'deferRender': true,
            'columnDefs': [
                { 'orderable': false, 'targets': 4 },
                { 'searchable': false, 'targets': 4 }
            ],
            drawCallback: function() {
                callBack();
            },
            responsive: {
                details: {
                    renderer: function( api,rowIdx ) {
                        return global.dataTableResponsiveCallBack(api, rowIdx, callBack);
                    }
                }
            }
        });
    }
};