function loadLOBForm() {

    var HDFORMID = "1b2cbe28-74b5-48a9-9187-4568b0852b0e";
    var HBFORMID = "6b9bedc8-de6c-458a-862e-438da6ee1d1f";
    var ROFORMID = "924f3759-91e8-415c-a3c7-7f283e94eef7";
    var NCCHVFORMID = "6ed0e345-cd03-4ad9-937b-b8642b3f521c";
    
    if (Xrm.Page.ui.getFormType() != 1) {
        var currentFormName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();
        var currentFormId = Xrm.Page.ui.formSelector.getCurrentItem().getId();

        var lob = Xrm.Page.getAttribute("DNS_lobid").getValue();
        var formId = ROFORMID;

        switch (lob[0].name) {
            case "Help Desk":
                if (Xrm.Page.ui.formSelector.items.get(HDFORMID) != null) {
                    formId = HDFORMID;
                }
                break;
            case "Health Benefits":
                if (Xrm.Page.ui.formSelector.items.get(HBFORMID) != null) {
                    formId = HBFORMID;
                }
                break;
            case "HRC":
                if (Xrm.Page.ui.formSelector.items.get(ROFORMID) != null) {
                    formId = HBFORMID;
                }
                break;
            case "NCCHV":
                if (Xrm.Page.ui.formSelector.items.get(NCCHVFORMID) != null) {
                    formId = NCCHVFORMID;
                }
                break;
            default:
                formId = ROFORMID;
                break;
        }

        if (Xrm.Page.ui.formSelector.items.get(formId) != null && currentFormId != formId) {
            Xrm.Page.ui.formSelector.items.get(formId).navigate();
        }
    }
}

var refresh = {
    firstname_OnChange: function() {
        refreshMVI();
    },

    lastname_OnChange: function() {
        refreshMVI();
    },

    dob_OnChange: function () {
        refreshMVI();
    },

    ssn_OnChange: function () {
        refreshMVI();
    },

    edipi_OnChange: function () {
        refreshMVI();
    },

    gender_OnChange: function () {
        refreshMVI();
    },

    daytimePhone_OnChange: function () {
        refreshMVI();
    },
}

function refreshMVI() {
    try { 
        var webResArea = Xrm.Page.ui.controls.get("WebResource_mvisearch");
        webResArea.setSrc(webResArea.getSrc());
    }
    catch (e) {
        alert('Error in refreshMVI(): ' + e.Message);
    }
}

var mvi = {
    personSelected: function (id, name) {
        var veteran = new Array();
        veteran[0] = new Object();
        veteran[0].id = id;
        veteran[0].name = name;
        veteran[0].entityType = "contact";
        Xrm.Page.getAttribute("bah_veteranid").setValue(veteran);

        Xrm.Page.getAttribute("bah_veteranid").fireOnChange();
    }
}