//validate date
function checkdate(bdDay, dbMonth, dbYear)
{
	if(!IsValidDate(bdDay, dbMonth, dbYear)) 
	{
			return false;
	}
	return true;
}
function DaysInMonth(CMonth,CYear)
{
	 var intMonth = parseInt(CMonth);

	 var intYear = parseInt(CYear);

	 if ((intMonth == 4) ||

	  (intMonth == 6) ||

	  (intMonth == 9) ||

	  (intMonth == 11))

	  return 30;

	 if (intMonth==2) {  // Leap year stuff

	  if ((intYear % 400)==0) return 29;

	  if ((intYear % 100)==0) return 28;

	  if ((intYear % 4)==0) return 29;

	  return 28;

	 }

	 return 31;

}


function IsDate(CDay, CMonth, CYear)
{

	if ((CDay <= 0) || (CDay > 31) ||

	(CMonth <= 0) || (CMonth > 12) ||

	(CYear <= 0))

	return false;

	var intDay = parseInt(CDay);

	var intMonth = parseInt(CMonth);

	var intYear = parseInt(CYear);

	if (intDay <= DaysInMonth(intMonth, intYear)) return true;

	return false;

}
function IsValidDate(CDay, CMonth, CYear)
{
	if(!IsDate(CDay, CMonth, CYear)) 
	{
		alert("Please select valid date");
		return false;
	}
	Today = new Date();
	DayBeforeYesterday = new Date((Today.getTime() - 172800000));
	Hours = Today.getHours();
	Minutes = Today.getMinutes()+1;
	Seconds = Today.getSeconds();
	StartDate= new Date(CYear,(CMonth - 1),CDay,Hours,Minutes,Seconds);
	if (StartDate<Today) 
	{ 
		alert("Date must be above current date!");
		return false;
	}
	return true;
}

function checkEmail(mf)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mf.email.value))
	{
		return (true);
	}
	alert("Invalid e-mail address! please re-enter");
	return (false);
}
function checkReservationRequest(mf)
{	
	if(mf.name.value=="")
	{
		alert("Please enter your name");
		mf.name.focus();
		return false;
	}
	if(mf.email.value=="")
	{
		alert("Please enter email address");
		mf.email.focus();
		return false;
	}
	if(checkEmail(mf)==false)
	{
		mf.email.focus();
		return false;
	}
	if(mf.city.value=="")
	{
		alert('Please enter your city');
		mf.city.focus();
		return false;
	}	
	if(mf.phone.value=="")	
	{
		alert("Please enter phone number");	
		mf.phone.focus();	
		return false;	
	}
	var valid= "+-()1234567890 ";
	if (mf.phone.value !="")
	{
		var string=mf.phone.value
		var length=string.length;
		for(var i=0;i<=length;i++)
		{
			var substring =string.substr(i,1);
			if(valid.indexOf(substring)== -1)
			{
				alert("Please enter valid phone number");
				mf.phone.focus();
				return false;
			}
		}
	}
	if(mf.mobile.value=="")	
	{
		alert("Please enter mobile number");	
		mf.mobile.focus();	
		return false;	
	}
	var valid= "+-()1234567890 ";
	if (mf.mobile.value !="")
	{
		var string=mf.mobile.value
		var length=string.length;
		for(var i=0;i<=length;i++)
		{
			var substring =string.substr(i,1);
			if(valid.indexOf(substring)== -1)
			{
				alert("Please enter valid mobile number");
				mf.mobile.focus();
				return false;
			}
		}
	}	
	if(mf.arrivaldate.value=="")
	{
		alert("Please enter date of arrival");
		mf.arrivaldate.focus();
		return false;
	}
	var arrival_date=mf.arrivaldate.value;
	var arr1 = arrival_date.split("-");
	var m1= arr1[1];
	var d1 = arr1[0];
	var y1 = arr1[2];	
	if(!checkdate(d1,m1,y1))
	{
		mf.arrivaldate.focus();
		return false;
	}
	if(mf.departuredate.value=="")
	{
		alert("Please enter date of departure");
		mf.departuredate.focus();
		return false;
	}
	var departure_date=mf.departuredate.value;
	var arr1 = departure_date.split("-");
	var m1= arr1[1];
	var d1 = arr1[0];
	var y1 = arr1[2];	
	if(!checkdate(d1,m1,y1))
	{
		mf.departuredate.focus();
		return false;
	}
	if(mf.arrivaldate.value > mf.departuredate.value)
	{
		alert('Please enter valid date of departure');
		mf.departuredate.focus();
		return false;
	}
	if(mf.room_type.value=="")	
	{
		alert("Please select room type");	
		mf.room_type.focus();	
		return false;	
	}
	if(mf.adult.value=="")
	{
		alert ("Please enter number of adult" );
		mf.adult.focus();
		return false;
	}
	if(isNaN(mf.adult.value))
	{
		alert('Please enter valid number of adult');
		mf.adult.focus();
		return false;
	}
	if(mf.child.value=="")
	{
		alert ("Please enter number of child" );
		mf.child.focus();
		return false;
	}
	if(isNaN(mf.child.value))
	{
		alert('Please enter valid number of child');
		mf.child.focus();
		return false;
	}
	if(mf.travel_plan.value=="")
	{
		alert ("Please enter your description" );
		mf.travel_plan.focus();
		return false;
	}
	if(mf.security_code.value=="")
	{
		alert ("Please enter security code" );
		mf.security_code.focus();
		return false;
	}	
	return true;
}

function checkReservation(mf)
{	
	if(mf.checkin_date.value=="")
	{
		alert('Please select check in date');
		mf.checkin_date.focus();
		return false;
	}
	var checkindate=mf.checkin_date.value;
	var arr1 =checkindate.split("-");
	var m1= arr1[1];
	var d1 = arr1[0];
	var y1 = arr1[2];	
	if(!checkdate(d1,m1,y1))
	{
		mf.checkin_date.focus();
		return false;
	}
	if(mf.checkout_date.value=="")
	{
		alert('Please select check out date');
		mf.checkout_date.focus();
		return false;
	}
	var checkoutdate=mf.checkout_date.value;
	var arr1 = checkoutdate.split("-");
	var m1= arr1[1];
	var d1 = arr1[0];
	var y1 = arr1[2];	
	if(!checkdate(d1,m1,y1))
	{
		mf.checkout_date.focus();
		return false;
	}
	if(mf.checkin_date.value >mf.checkout_date.value)
	{
		alert('Please select valid date');
		mf.checkin_date.focus();
		return false;
	}	
	if(mf.name.value=="")
	{
		alert("Please enter your name");
		mf.name.focus();
		return false;
	}
	if(mf.email.value=="")
	{
		alert("Please enter email address");
		mf.email.focus();
		return false;
	}
	if(checkEmail(mf)==false)
	{
		mf.email.focus();
		return false;
	}
	if(mf.address.value=="")
	{
		alert('Please enter your address');
		mf.address.focus();
		return false;
	}	
	if(mf.phone.value=="")	
	{
		alert("Please enter phone number");	
		mf.phone.focus();	
		return false;	
	}
	var valid= "+-()1234567890 ";
	if (mf.phone.value !="")
	{
		var string=mf.phone.value
		var length=string.length;
		for(var i=0;i<=length;i++)
		{
			var substring =string.substr(i,1);
			if(valid.indexOf(substring)== -1)
			{
				alert("Please enter valid phone number");
				mf.phone.focus();
				return false;
			}
		}
	}	
	if(mf.feed_back.value=="")
	{
		alert ("Please enter your feed back" );
		mf.feed_back.focus();
		return false;
	}
	if(mf.reservation_security_code.value=="")
	{
		alert ("Please enter security code" );
		mf.reservation_security_code.focus();
		return false;
	}	
	return true;
}

function checkBookHotel(mf)
{
	if(!checkdate(mf.checkin_day.value, mf.checkin_month.value, mf.checkin_year.value))
	{
		mf.checkin_day.focus();
		return false;
	}
	if(!checkdate(mf.checkout_day.value, mf.checkout_month.value, mf.checkout_year.value))
	{
		mf.checkout_day.focus();
		return false;
	} 
	var checkin_date=mf.checkin_day.value+"-"+mf.checkin_month.value+"-"+mf.checkin_year.value;

	var checkout_date=mf.checkout_day.value+"-"+mf.checkout_month.value+"-"+mf.checkout_year.value;
	if(checkin_date>checkout_date)
	{
		alert('check out must be above check in date!')
		mf.checkin_day.focus();
		return false;
	}
}

