var accountUser_form = {
    settings: {
        salesAgent_autocompleteUrl: '',
        accountStaff_autocompleteUrl: '',
        accountUserBilling_autocompleteUrl: '',
        provider_autocompleteUrl: '',
        marketingStaff_autocompleteUrl: '',
    },
    init: function() {
        accountUser_form.bindElements();
        accountUser_form.bindAutoComplete();
        if(jQ("#accountUser_account_user_type option:selected").text() === 'Sales Agent'){
            jQ('.sales-agent').removeClass('hide');
        } else {
            jQ('.sales-agent').addClass('hide');
        }

        if(jQ("#accountUser_account_user_type option:selected").text() !=  'Sales Agent' && jQ("#accountUser_account_user_type option:selected").text() !=  'Clinician' && jQ("#accountUser_account_user_type option:selected").text() !=  'Billing' && jQ("#accountUser_account_user_type option:selected").text() !=  'Marketing Staff' && jQ("#accountUser_account_user_type option:selected").text() !=  'Admin'){
            jQ('.account-staff').removeClass('hide');
        } else {
            jQ('.account-staff').addClass('hide');
        }
    },
    bindElements : function () {
        jQ('#accountUser_account_user_type').unbind('change').bind('change', function () {
            if(jQ("#accountUser_account_user_type option:selected").text() === 'Sales Agent'){
                jQ('.sales-agent').removeClass('hide');
            } else {
                jQ('.sales-agent').addClass('hide');
                jQ('#accountUser_first_name').val('');
                jQ('#accountUser_middle_name').val('');
                jQ('#accountUser_last_name').val('');
            }

            if(jQ("#accountUser_account_user_type option:selected").text() !=  'Sales Agent' && jQ("#accountUser_account_user_type option:selected").text() !=  'Clinician' && jQ("#accountUser_account_user_type option:selected").text() !=  'Billing' && jQ("#accountUser_account_user_type option:selected").text() !=  'Marketing Staff' && jQ("#accountUser_account_user_type option:selected").text() !=  'Admin'){
                jQ('.account-staff').removeClass('hide');
            } else {
                jQ('.account-staff').addClass('hide');
                jQ('#accountUser_first_name').val('');
                jQ('#accountUser_middle_name').val('');
                jQ('#accountUser_last_name').val('');
            }

            if(jQ("#accountUser_account_user_type option:selected").text() === 'Clinician'){
                jQ('.provider').removeClass('hide');
            } else {
                jQ('.provider').addClass('hide');
                jQ('#accountUser_first_name').val('');
                jQ('#accountUser_middle_name').val('');
                jQ('#accountUser_last_name').val('');
            }

            if(jQ("#accountUser_account_user_type option:selected").text() === 'Billing'){
                jQ('.billing').removeClass('hide');
            } else {
                jQ('.billing').addClass('hide');
                jQ('#accountUser_first_name').val('');
                jQ('#accountUser_middle_name').val('');
                jQ('#accountUser_last_name').val('');
            }

            if(jQ("#accountUser_account_user_type option:selected").text() === 'Marketing Staff'){
                jQ('.marketing-staff').removeClass('hide');
            } else {
                jQ('.marketing-staff').addClass('hide');
                jQ('#accountUser_first_name').val('');
                jQ('#accountUser_middle_name').val('');
                jQ('#accountUser_last_name').val('');
            }
        });
    },
    bindAutoComplete : function () {
        global.autocomplete.bind(accountUser_form.settings.salesAgent_autocompleteUrl, '#accountUser_sales_agent_fullname', '#accountUser_sales_agent', {
            onSelect: function(e) {
                jQ('#accountUser_first_name').val(e.first_name);
                jQ('#accountUser_middle_name').val(e.middle_name);
                jQ('#accountUser_last_name').val(e.last_name);
            }
        });
        global.autocomplete.bind(accountUser_form.settings.accountStaff_autocompleteUrl, '#accountUser_account_staff_fullname', '#accountUser_account_staff', {
            onSelect: function(a) {
                jQ('#accountUser_first_name').val(a.first_name);
                jQ('#accountUser_middle_name').val(a.middle_name);
                jQ('#accountUser_last_name').val(a.last_name);
            }
        });
        global.autocomplete.bind(accountUser_form.settings.accountUserBilling_autocompleteUrl, '#accountUser_account_user_billing_fullname', '#accountUser_account_user_billing', {
            onSelect: function(aub) {
                jQ('#accountUser_first_name').val(aub.first_name);
                jQ('#accountUser_middle_name').val(aub.middle_name);
                jQ('#accountUser_last_name').val(aub.last_name);
            }
        });
        global.autocomplete.bind(accountUser_form.settings.provider_autocompleteUrl, '#accountUser_provider_fullname', '#accountUser_provider', {
            onSelect: function(c) {
                jQ('#accountUser_first_name').val(c.first_name);
                jQ('#accountUser_middle_name').val(c.middle_name);
                jQ('#accountUser_last_name').val(c.last_name);
            }
        });
        global.autocomplete.bind(accountUser_form.settings.marketingStaff_autocompleteUrl, '#accountUser_marketingStaff_fullname', '#accountUser_marketingStaff', {
            onSelect: function(c) {
                jQ('#accountUser_first_name').val(c.first_name);
                jQ('#accountUser_middle_name').val(c.middle_name);
                jQ('#accountUser_last_name').val(c.last_name);
            }
        });
    }
};