

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 validateDates()
{	

	//alert("Badre Alam........"); return false;
	var fromDateString = document.getElementById("txtCheck_in").value;
	var toDateString = document.getElementById("txtCheck_out").value;

	if(!validateIndDate(fromDateString))
	{
		alert("Please Enter Valid Check-in Date"); 
		calCheck_in.select(document.forms[0].txtCheck_in,'anchorCheck_in','dd/MM/yyyy'); 
		positionIFrame(); 
		return false;
	}

	if(!validateIndDate(toDateString))
	{
		alert("Please Enter Valid Check-out Date"); 
		callMe();  
		calCheck_out.select(document.forms[0].txtCheck_out,'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.forms[0].txtCheck_in,'anchorCheck_in','dd/MM/yyyy'); 
		positionIFrame(); 
		return false;
	}
	if (fromDateString.length==0)
	{
		alert("Please select a Check-in date.");
		calCheck_in.select(document.forms[0].txtCheck_in,'anchorCheck_in','dd/MM/yyyy'); 
		positionIFrame(); 
		return false;
	}
	if (toDateString.length==0)
	{
		alert("Please select a Check-out date.");
		//document.getElementById("txtCheck_out").focus();
		callMe();  
		calCheck_out.select(document.forms[0].txtCheck_out,'anchorCheck_out','dd/MM/yyyy'); positionIFrame(); 
		return false;
	}

}




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 callMe()
{
	dateValue = document.getElementById('txtCheck_in').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"));
	}
}
