How to close CalendarExtender on lost focus or mouse out

CalendarExtender control will not close automatically once opened without selecing a date. This small code snippets helps to achive the control to close once its loses the focus.

  1. <script language="javascript" type="text/javascript">  
  2.    var blnflag = false;  
  3.    document.onmouseout = function(sender, args)   
  4.    {  
  5.       if (event.srcElement.tagName.toLowerCase() == "div" && event.srcElement.outerHTML.indexOf("ajax__calendar") > 0) blnflag = true;  
  6.       if (blnflag && event.srcElement.tagName.toLowerCase() != "div")   
  7.       {  
  8.          blnflag = false;  
  9.          $find("CEBID1").hide();  
  10.       }  
  11.    }  
  12. </script>  
  13.   
  14.   
  15.   
  16.   
  17.   
  18.   
  19. <asp:TextBox id="txtFrom" onkeypress="return false;" onkeydown="return false;" onmouseover="return false;" runat="server" style="width: 100px" />  
  20. <img id="img1" runat="server" alt="Date" src="images/cal.gif" temp_src="images/cal.gif" />  
  21. <cc1:CalendarExtender BehaviorID="CEBID1" runat="server" ID="cl1" TargetControlID="txtFrom" PopupButtonID="img1" Format="dd-MMM-yyyy"></cc1:CalendarExtender>