var schedule_form = {
    settings: {
        medical_facility_autocomplete_url: '',
        patient_autocomplete_url: '',
        provider_autocomplete_url: '',
    },
    init: function() {
        this.initAutocomplete();
        this.removeParams();
    },
    initAutocomplete: function() {
        global.autocomplete.bind(this.settings.medical_facility_autocomplete_url, '#schedule_health_facility_desc', '#schedule_health_facility', {
            onSelect: function () {
                var params = {
                    healthFacility_id : jQ('#schedule_health_facility').val() !== '' ? jQ('#schedule_health_facility').val() : '',
                };

                jQ('#schedule_provider_fullName').devbridgeAutocomplete('setOptions', {params: params});
            }
        });

        global.autocomplete.bind(this.settings.patient_autocomplete_url, '#schedule_patient_fullName', '#schedule_patient');

        global.autocomplete.bind(this.settings.provider_autocomplete_url, '#schedule_provider_fullName', '#schedule_provider', {
            onSelect: function () {
                var params = {
                    provider_id : jQ('#schedule_provider').val() !== '' ? jQ('#schedule_provider').val() : '',
                };

                jQ('#schedule_health_facility_desc').devbridgeAutocomplete('setOptions', {params: params});
            }
        });

        global.autocomplete.bind(this.settings.provider_autocomplete_url, '#schedule_provider_fullName', '#schedule_provider', {
            onSelect: function () {
                var params = {
                    provider_id : jQ('#schedule_provider').val() !== '' ? jQ('#schedule_provider').val() : '',
                };

                jQ('#schedule_health_facility_desc').devbridgeAutocomplete('setOptions', {params: params});
            }
        });
    },

    removeParams: function () {
        jQ('#schedule_health_facility_desc').unbind('keyup').bind('keyup', function () {
            var params = {
                provider_id : ''
            };
            jQ('#schedule_provider_fullName').devbridgeAutocomplete('setOptions', {params: params});
        });

        jQ('#schedule_provider_fullName').unbind('keyup').bind('keyup', function () {
            var params = {
                healthFacility_id : ''
            };
            jQ('#schedule_health_facility_desc').devbridgeAutocomplete('setOptions', {params: params});
        });
    }
};