function form_onSave() {
    if (Xrm.Page.getAttribute("vhacrm_ispromptedcall_bool") != null) {
        Xrm.Page.getAttribute("vhacrm_ispromptedcall_bool").setSubmitMode("always");
    }
}

function isvethomeless_onChange(){
// clear associated fields when Is Veteran Homeless response changes
	if (Xrm.Page.getAttribute("vhacrm_isvethomeless_code") != null) {
	    Xrm.Page.getAttribute("vhacrm_isathomelessrisk_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_ifnothomelessstaying_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_homelesshowlong_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_ifhomelessstaying_code").setValue(null);
    }
}

//instantiate global variable for a setinterval call later
var _intervalVar = null;

function ribbon_SaveAndClose() {
    Xrm.Page.data.save(); 
    _intervalVar = setInterval(function () { if (Xrm.Page.getAttribute("vhacrm_name").getValue() && !Xrm.Page.data.entity.getIsDirty()) { checkforsave(); } }, 50);
 
}

//this gets called once we know the save completed
function checkforsave() {
    //stop the setinterval loop
    clearInterval(_intervalVar);
    window.top.close();
}
