function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    //alert("Invalid E-mail ID")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    //alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }

	 return true					
}

function LeapYear(year)
{
	if (year % 4 == 0)
	{
		if (year % 100 == 0)
		{
			if (year % 1000 == 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return true;	
		}
	}
}

function LoadDaysCI()
{
	var iyear;
	iyear = document.rf.ciyear.value;

	document.rf.ciday.length = 0;
	
	if ((document.rf.cimonth.selectedIndex == 0) || (document.rf.cimonth.selectedIndex == 2) || (document.rf.cimonth.selectedIndex == 4) || (document.rf.cimonth.selectedIndex == 6) || (document.rf.cimonth.selectedIndex == 7) || (document.rf.cimonth.selectedIndex == 9) || (document.rf.cimonth.selectedIndex == 11)) //jan mar may jul aug oct dec
	{
		document.rf.ciday.length = 31;
		
		for (var i = 1; i < 32; i++)
		{
			if (i < 10)
			{
				document.rf.ciday.options[i-1] = new Option(i.toString(), '0' + i.toString());
			}
			else
			{
				document.rf.ciday.options[i-1] = new Option(i.toString(), i.toString());
			}
		}
	}
	
	if (document.rf.cimonth.selectedIndex == 1)  //feb
	{		
		if (LeapYear(iyear))
		{
			document.rf.ciday.length = 29;
			
			for (var i = 1; i < 30; i++)
			{
				if (i < 10)
				{
					document.rf.ciday.options[i-1] = new Option(i.toString(), '0' + i.toString());
				}
				else
				{
					document.rf.ciday.options[i-1] = new Option(i.toString(), i.toString());
				}
			}			
		}
		else
		{
			for (var i = 1; i < 29; i++)
			{
				if (i < 10)
				{
					document.rf.ciday.options[i-1] = new Option(i.toString(), '0' + i.toString());
				}
				else
				{
					document.rf.ciday.options[i-1] = new Option(i.toString(), i.toString());
				}
			}
		}//*/
	}
	
	if ((document.rf.cimonth.selectedIndex == 3) || (document.rf.cimonth.selectedIndex == 5) || (document.rf.cimonth.selectedIndex == 8) || (document.rf.cimonth.selectedIndex == 10)) //apr jun sep nov
	{
		document.rf.ciday.length = 30;
		
		for (var i = 1; i < 31; i++)
		{
			if (i < 10)
			{
				document.rf.ciday.options[i-1] = new Option(i.toString(), '0' + i.toString());
			}
			else
			{
				document.rf.ciday.options[i-1] = new Option(i.toString(), i.toString());
			}
		}
	}
	
	document.rf.ciday.disabled = false;
}

function LoadDaysCO()
{
	var iyear;
	iyear = document.rf.coyear.value;

	document.rf.coday.length = 0;
	
	if ((document.rf.comonth.selectedIndex == 0) || (document.rf.comonth.selectedIndex == 2) || (document.rf.comonth.selectedIndex == 4) || (document.rf.comonth.selectedIndex == 6) || (document.rf.comonth.selectedIndex == 7) || (document.rf.comonth.selectedIndex == 9) || (document.rf.comonth.selectedIndex == 11)) //jan mar may jul aug oct dec
	{
		document.rf.coday.length = 31;
		
		for (var i = 1; i < 32; i++)
		{
			if (i < 10)
			{
				document.rf.coday.options[i-1] = new Option(i.toString(), '0' + i.toString());
			}
			else
			{
				document.rf.coday.options[i-1] = new Option(i.toString(), i.toString());
			}
		}
	}
	
	if (document.rf.comonth.selectedIndex == 1)  //feb
	{		
		if (LeapYear(iyear))
		{
			document.rf.coday.length = 29;
			
			for (var i = 1; i < 30; i++)
			{
				if (i < 10)
				{
					document.rf.coday.options[i-1] = new Option(i.toString(), '0' + i.toString());
				}
				else
				{
					document.rf.coday.options[i-1] = new Option(i.toString(), i.toString());
				}
			}			
		}
		else
		{
			for (var i = 1; i < 29; i++)
			{
				if (i < 10)
				{
					document.rf.coday.options[i-1] = new Option(i.toString(), '0' + i.toString());
				}
				else
				{
					document.rf.coday.options[i-1] = new Option(i.toString(), i.toString());
				}
			}
		}//*/
	}
	
	if ((document.rf.comonth.selectedIndex == 3) || (document.rf.comonth.selectedIndex == 5) || (document.rf.comonth.selectedIndex == 8) || (document.rf.comonth.selectedIndex == 10)) //apr jun sep nov
	{
		document.rf.coday.length = 30;
		
		for (var i = 1; i < 31; i++)
		{
			if (i < 10)
			{
				document.rf.coday.options[i-1] = new Option(i.toString(), '0' + i.toString());
			}
			else
			{
				document.rf.coday.options[i-1] = new Option(i.toString(), i.toString());
			}
		}
	}
	
	document.rf.coday.disabled = false;
}

function DoCheck()
{
	var mydate = new Date();
	
	var todayday = mydate.getUTCDate(); 
		
	var todaymonth = mydate.getUTCMonth() + 1;
	
	var selectedmonth = document.rf.cimonth.options[document.rf.cimonth.selectedIndex].value;
	
	if (selectedmonth == 'January') { selectedmonth = 1; }
	if (selectedmonth == 'February') { selectedmonth = 2; }
	if (selectedmonth == 'March') { selectedmonth = 3; }
	if (selectedmonth == 'April') { selectedmonth = 4; }
	if (selectedmonth == 'May') { selectedmonth = 5; }
	if (selectedmonth == 'June') { selectedmonth = 6; }
	if (selectedmonth == 'July') { selectedmonth = 7; }
	if (selectedmonth == 'August') { selectedmonth = 8; }
	if (selectedmonth == 'September') { selectedmonth = 9; }
	if (selectedmonth == 'October') { selectedmonth = 10; }
	if (selectedmonth == 'November') { selectedmonth = 11; }
	if (selectedmonth == 'December') { selectedmonth = 12; }
	
	//alert(selectedmonth);
	
	var todayyear = mydate.getUTCFullYear();
	
	var checkindate = new Date(document.rf.cimonth.options[document.rf.cimonth.selectedIndex].value + ' ' + document.rf.ciday.options[document.rf.ciday.selectedIndex].value + ', ' + document.rf.ciyear.options[document.rf.ciyear.selectedIndex].value);
	
	var checkoutdate = new Date(document.rf.comonth.options[document.rf.comonth.selectedIndex].value + ' ' + document.rf.coday.options[document.rf.coday.selectedIndex].value + ', ' + document.rf.coyear.options[document.rf.coyear.selectedIndex].value);
	
	
	if (document.rf.name.value.length == 0)
	{
		alert('Please enter your name.');
		document.rf.name.focus();
	}
	else if (document.rf.email.value.length == 0)
	{
		alert('Please enter a email address.');
		document.rf.email.focus();		
	}
	else if (!echeck(document.rf.email.value))
	{
		alert('Please enter a VALID email address.');
		document.rf.email.focus();
	}
	else if ((document.rf.cellno.value.length == 0) && (document.rf.telno.value.length == 0))
	{
		alert('Please enter at least one contact number.');
		document.rf.cellno.focus();		
	}
	else if ((document.rf.cellno.value.length > 0) && (document.rf.cellno.value.length < 10))
	{
		alert('Please make sure you enter a valid mobile number.');
		document.rf.cellno.focus();
	}
	else if ((document.rf.telno.value.length > 0) && (document.rf.telno.value.length < 10))
	{
		alert('Please make sure you enter a valid telephone number.');
		document.rf.telno.focus();
	}
	else if (document.rf.ciyear.options[document.rf.ciyear.selectedIndex].value == todayyear)
	{
		if (todaymonth > selectedmonth)
		{
			alert('The check in date is in the past.');	
			document.rf.ciday.focus();
		}
		else
		{
			if ((todayday > document.rf.ciday.options[document.rf.ciday.selectedIndex].value) && (todaymonth == selectedmonth))
			{
				alert('The check in date is in the past.');
				document.rf.ciday.focus();
			}
			else
			{
				if (checkoutdate <= checkindate)
				{
					alert('Check out date cannot be before or the same as check in date.');
					document.rf.coday.focus();
				}			
				else if (document.rf.adults.value.length == 0)
				{
					alert('Please specify how many adults.');
					document.rf.adults.focus();		
				}
				else if ((document.rf.children.value.length != 0) && (document.rf.childrenages.value.length == 0))
				{
					alert('Please enter your children ages');
					document.rf.childrenages.focus();
				}
				else
				{
					document.rf.submit();
				}
			}
		}
	}
	else if (checkoutdate <= checkindate)
	{
		alert('Check out date cannot be before or the same as check in date.');
		document.rf.coday.focus();
	}
	else if (document.rf.adults.value.length == 0)
	{
		alert('Please specify how many adults.');
		document.rf.adults.focus();		
	}
	else if ((document.rf.children.value.length != 0) && (document.rf.childrenages.value.length == 0))
	{
		alert('Please enter your children ages');
		document.rf.childrenages.focus();
	}
	else
	{
		document.rf.submit();
	}
}
