function callMe()
{
    dateValue = document.getElementById('ctl00_ContentPlaceHolder1_TxtCheckin').value;    
    var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

    if(	objRegExp.test(dateValue))
    {
        var now = new Date();
        now.setDate(now.getDate()+2);
        calCheck_out = new CalendarPopup("testdiv1");

        calCheck_out.setCssPrefix("TEST");

        var arrayDate = dateValue.split("/"); 
        start = new Date(arrayDate[2]+"/"+(arrayDate[1])+"/"+arrayDate[0]);	
        calCheck_out.addDisabledDates(null,formatDate(start,"yyyy-MM-dd"));
    }
}
function positionIFrame()
{
	var div = document.getElementById("testdiv1");
	var frm = document.getElementById("theframe");

	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		frm.style.left = div.style.left;
		frm.style.top = div.style.top;
		frm.style.height = div.offsetHeight;
		frm.style.width = div.offsetWidth;
		frm.style.display = "block";	
	}
}
function validateIndDate( strValue ) 
{	
    var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
 
    if(!objRegExp.test(strValue))
        return false; //doesn't match pattern, bad date
    else
    {
        if(strValue.length < 10)
        {
	        return false;
        }
        var strSeparator = strValue.substring(2,3) 
        var arrayDate = strValue.split(strSeparator); 
        var intDay = parseInt(arrayDate[0],10); 

        //create a lookup for months not equal to Feb.
        var arrayLookup = { '01' : 31,'03' : 31, 
					        '04' : 30,'05' : 31,
					        '06' : 30,'07' : 31,
					        '08' : 31,'09' : 30,
					        '10' : 31,'11' : 30,'12' : 31}

        // check if month value and day value agree
        if(arrayLookup[arrayDate[1]] != null) 
        {
	        if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
	        return true; //found in lookup table, good date
        }
    
        var intMonth = parseInt(arrayDate[1],10);

        if (intMonth == 2) 
        { 
	        var intYear = parseInt(arrayDate[2]);
	        if (intDay > 0 && intDay < 29) 
	        {
		        return true;
	        }
	        else if (intDay == 29) 
	        {
		        if ((intYear % 4 == 0) && (intYear % 100 != 0) || (intYear % 400 == 0))
		        {
			        // year div by 4 and ((not div by 100) or div by 400) ->ok
			        return true;
		        }   
	        }
        }
    }
    return false; //any other values, bad date
}        
function validatecheckInDates(sender,args)
{	
    var fromDateString = document.getElementById("ctl00_ContentPlaceHolder1_TxtCheckin").value;
    if(!validateIndDate(fromDateString))
    {
        alert("Please Enter Valid Check-in Date"); 
        calCheck_in.select(document.aspnetForm.ctl00$ContentPlaceHolder1$TxtCheckin,'anchorCheck_in','dd/MM/yyyy'); 
        positionIFrame(); 
        return false;
    }
        
    if (fromDateString.length==0)
    {
        alert("Please select a Check-in date.");
        calCheck_in.select(document.aspnetForm.ctl00$ContentPlaceHolder1$TxtCheckin,'anchorCheck_in','dd/MM/yyyy'); 
        positionIFrame(); 
        return false;
    }	        
 }
 
function validatecheckOutDates(sender,args)
{
    var fromDateString = document.getElementById("ctl00_ContentPlaceHolder1_TxtCheckin").value;
    var toDateString = document.getElementById("ctl00_ContentPlaceHolder1_TxtCheckout").value;     
    if(!validateIndDate(toDateString))
    {
        alert("Please Enter Valid Check-out Date"); 
        callMe();  
        calCheck_out.select(document.aspnetForm.ctl00$ContentPlaceHolder1$TxtCheckout,'anchorCheck_out','dd/MM/yyyy'); 
        positionIFrame(); 
        return false;
    }
    if (toDateString.length==0)
    {
        alert("Please select a Check-out date.");
        //document.getElementById("ctl00$ContentPlaceHolder1$txtCheck_out").focus();
        callMe();  
        calCheck_out.select(document.aspnetForm.ctl00$ContentPlaceHolder1$TxtCheckout,'anchorCheck_out','dd/MM/yyyy'); positionIFrame(); 
        return false;
    }
    
   if (fromDateString.length==0 && toDateString.length==0)
   {		
       alert("Please select Check-in and Check-out dates.");
       calCheck_in.select(document.aspnetForm.ctl00$ContentPlaceHolder1$TxtCheckin,'anchorCheck_in','dd/MM/yyyy'); 
       positionIFrame(); 
       return false;
   }
   
    /////////  Difference of checkIn and checkOut date using JAVASCRIPT  /////////////
    var days = 0;
    var difference = 0;

    var tomorrow_date =  new Date();

    tomorrow_date.setDate( tomorrow_date.getDate() + 2 );

    var chkInDate = document.getElementById("ctl00_ContentPlaceHolder1_TxtCheckin").value;
    var strSeparator = chkInDate.substring(2,3);
    var arrchkInDate = chkInDate.split(strSeparator);
    chkInDate = new Date(arrchkInDate[1]+"/"+arrchkInDate[0]+"/"+arrchkInDate[2]);

    var chkOutDate = document.getElementById("ctl00_ContentPlaceHolder1_TxtCheckout").value;
    var strSeparator = chkOutDate.substring(2,3);
    var arrchkOutDate = chkOutDate.split(strSeparator);
    chkOutDate = new Date(arrchkOutDate[1]+"/"+arrchkOutDate[0]+"/"+arrchkOutDate[2]);

    difference =  chkOutDate - chkInDate;
    days = difference/(1000*60*60*24);

    if(chkInDate <= tomorrow_date)
    {
        alert("Check-In date should be atleast 2 day later than current date!!!"); 
        return false;
    }
	
    if(days<0)
    {
        alert("The Check-in date cannot be after the Check-out date.");
        return false;
    }
    if(days==0)
    {
        alert("Check-In and Check-Out dates cannot be same....");
        return false;
    }

    if(days>15)
    {
        alert( "The Check-out date needs to be within 15 days from the Check-in date.");
        return false;
    }
   
}
