Trying to get double calendar to hide when clicking outside

I have a double calendar and I want it to close when you click outside of it. The single calendar does this by default, but for some reason, the double calendar doesn’t. I’ve seen code on this forum that attaches a click event to the body to make it close, but this prevents the double calendar to show up since I have an on click event on an input field. In other words, the calendar is opened and closed immediately. Do I have other options?

figure it out:

dhtmlxEvent(document.body, "mousedown", function()
{ mDCal.hide(); });
dhtmlxEvent(document.getElementById("dateRange1"), "mousedown", function(e)
{ (e||event).cancelBubble=true; });