
function DPRIS_onChange(){
// clear associated fields when DPRIS changes
	if (Xrm.Page.getAttribute("vhacrm_dpris_bool").getValue() != true) {
	    Xrm.Page.getAttribute("vhacrm_verifiedindpris_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_dprisdate_date").setValue(null);
    }
	else{
	Xrm.Page.getAttribute("vhacrm_dprisdate_date").setValue(Date.now());
	}
}

function VIS_onChange(){
// clear associated fields when VIS changes
	if (Xrm.Page.getAttribute("vhacrm_vis_bool").getValue() != true) {
	    Xrm.Page.getAttribute("vhacrm_verifiedinvis_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_visdate_date").setValue(null);
    }
	else{
	Xrm.Page.getAttribute("vhacrm_visdate_date").setValue(Date.now());
	}
}

function SHARE_onChange(){
// clear associated fields when SHARE changes
	if (Xrm.Page.getAttribute("vhacrm_share_bool").getValue() != true) {
	    Xrm.Page.getAttribute("vhacrm_verifiedinshare_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_sharedate_date").setValue(null);
    }
	else{
	Xrm.Page.getAttribute("vhacrm_sharedate_date").setValue(Date.now());
	}
}

function HINQ_onChange(){
// clear associated fields when HINQ changes
	if (Xrm.Page.getAttribute("vhacrm_hinq_bool").getValue() != true) {
	    Xrm.Page.getAttribute("vhacrm_verifiedinhinq_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_hinqdate_date").setValue(null);
    }
	else{
	Xrm.Page.getAttribute("vhacrm_hinqdate_date").setValue(Date.now());
	}
}

function VBMS_onChange(){
// clear associated fields when VBMS changes
	if (Xrm.Page.getAttribute("vhacrm_vbms_bool").getValue() != true) {
	    Xrm.Page.getAttribute("vhacrm_verifiedinvbms_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_vbmsdate_date").setValue(null);
    }
	else{
	Xrm.Page.getAttribute("vhacrm_vbmsdate_date").setValue(Date.now());
	Xrm.Page.getAttribute("vhacrm_vbmsdate_date").setSubmitMode("always");
	}
}

function DD214_onChange(){
// clear associated fields when DD214 changes
	if (Xrm.Page.getAttribute("vhacrm_dd214_bool").getValue() != true) {
	    Xrm.Page.getAttribute("vhacrm_verifieddd214_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_dd214date_date").setValue(null);
    }
	else{
	Xrm.Page.getAttribute("vhacrm_dd214date_date").setValue(Date.now());
	}
}

function ORDERS_onChange(){
// clear associated fields when ORDERS changes
	if (Xrm.Page.getAttribute("vhacrm_orders_bool").getValue() != true) {
	    Xrm.Page.getAttribute("vhacrm_verifiedinorders_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_ordersdate_date").setValue(null);
    }
	else{
	Xrm.Page.getAttribute("vhacrm_ordersdate_date").setValue(Date.now());
	}
}

function Other_onChange(){
// clear associated fields when Other changes
	if (Xrm.Page.getAttribute("vhacrm_other_bool").getValue() != true) {
	    Xrm.Page.getAttribute("vhacrm_verifiedinother_code").setValue(null);
        Xrm.Page.getAttribute("vhacrm_otherdate_date").setValue(null);
        Xrm.Page.getAttribute("vhacrm_othertext_text").setValue(null);
    }
	else{
	Xrm.Page.getAttribute("vhacrm_otherdate_date").setValue(Date.now());
	}
}

//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();
}
