var maxValidDate = '';
var minValidDate = '';

function IsBrowserIE6OrBelow()
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }    
  if(rv > 1 && rv < 7) //-1 for non-IE browsers
    return true;
  else
   return false; 
}
var _isBrowserIE6OrBelow = IsBrowserIE6OrBelow();

document.write('<script src="/javascripts/GetScript.aspx?name=ScreenPosition" type="text/javascript"></script>');

document.write('<div id="_popupCalendarHolderLeanBox" style="position:absolute;display:none;">');
document.write("<div style='border:solid 1px #01194c;background:#c0d1e8;position:absolute;padding:1px;'>")
document.write("<div style='background:#c0d1e8;padding:3px;'>");
document.write('<iframe id="_popupCalIFrameLeanBox" src="/calendar/processing.html" frameborder="0" scrolling="no" style="width:167px;height:172px;"></iframe>');
document.write('</div>');
document.write('<div style="text-align:center;padding:3px;"><a href="javascript:HideCalendar();" style="font-family:Verdana; font-size:9px; color:#01194C; font-weight:bold;">Close</a></div>');
document.write('</div>');
document.write('</div>');

//This dummy iframe prevents IE6 to show slect boxes through the popup div
document.write('<iframe id="_dummyIframeForPopupCalendar" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute;display:none;width:180px; height:202px;"></iframe>');

function OpenCalendar2(targetControlId, targetControlId2, anchorId, xOffset, yOffset, isFormletMode, minDate, maxDate)
{      
	maxValidDate = maxDate; 
	minValidDate = minDate;  			
	OpenCalendar(targetControlId, targetControlId2, anchorId, xOffset, yOffset, isFormletMode); 	
	
}

function OpenCalendar(targetControlId, targetControlId2, anchorId, xOffset, yOffset, isFormletMode) 
{         
    var anchorElement = document.getElementById(anchorId);    
    var targetControl = document.getElementById(targetControlId);       		
	
    var popupCalendarDiv;
    var posXofPopupCal;
    var posYofPopupCal;		
    var dummyIframe;
    var calUrl;			
    var currDate;    
    
	posYofPopupCal = GetObjectPosition(anchorElement).y
	posXofPopupCal = GetObjectPosition(anchorElement).x
	
    if (isNaN(xOffset)){ xOffset = 0;}
    if (isNaN(yOffset)){ yOffset = 0;}
                   
    if(isFormletMode)
    {//override x, y positions for formlets 
     posXofPopupCal = 1;      
     posYofPopupCal = posYofPopupCal + 18;  
    }
    else
    {
        posXofPopupCal = posXofPopupCal + xOffset;
        posYofPopupCal = posYofPopupCal + yOffset;          
    }
        
    var randomnumber=Math.floor(Math.random()*1000000)
    if(targetControl != null)
        currDate = targetControl.value;
    
    calUrl = "/calendar/DatePickerCalendar.aspx?formlet="+isFormletMode+"&target="+targetControlId+"&target2="+ targetControlId2 +"&minDate="+minValidDate+"&maxDate="+maxValidDate + "&currDate=" + currDate + "&" + randomnumber;            
            
    popupCalendarDiv = document.getElementById("_popupCalendarHolderLeanBox");  	
    document.getElementById("_popupCalIFrameLeanBox").src = calUrl;              
      	      	
    popupCalendarDiv.style.top = posYofPopupCal + "px";
    popupCalendarDiv.style.left = posXofPopupCal + "px";
    popupCalendarDiv.style.zIndex = 1200;        
    popupCalendarDiv.style.display = "block";    
               
    if(_isBrowserIE6OrBelow)
    {            
        dummyIframe = document.getElementById("_dummyIframeForPopupCalendar");	            
	    dummyIframe.style.top = (posYofPopupCal - 1) + "px";  	    
	    dummyIframe.style.left = (posXofPopupCal - 1) + "px"; 	    
	    dummyIframe.style.zIndex = popupCalendarDiv.style.zIndex - 1; 		    
	    dummyIframe.style.display = "block";  	    	       	    
    }
	
}

function HideCalendar()
{		
	var popupDivCal = document.getElementById("_popupCalendarHolderLeanBox");
	var dummyIframe = document.getElementById("_dummyIframeForPopupCalendar");	 
	    
    if (popupDivCal != null){ popupDivCal.style.display = "none";}	
    if (dummyIframe != null){ dummyIframe.style.display = "none";}
}

function SetSelectedDate(selectedDate, targetControlId, targetControlId2)
{					   
        var targetObject = document.getElementById(targetControlId);
        var targetObject2 = document.getElementById(targetControlId2);
        
        if(targetObject != null)
            targetObject.value = selectedDate;
        
        if(targetObject2 != null)
            targetObject2.value = selectedDate;
    		
	HideCalendar();
}

