function UpdateList(selDD, selMth, selYr)
{
	if (selMth.options[selMth.selectedIndex].value == "4" || 
		selMth.options[selMth.selectedIndex].value == "6" ||
		selMth.options[selMth.selectedIndex].value == "9" ||
		selMth.options[selMth.selectedIndex].value == "11" )
    {
		generateDays(30, selDD);
	}
	else if (selMth.options[selMth.selectedIndex].value == "2")
	{
		if (leapYr(selYr.options[selYr.selectedIndex].value))
			generateDays(29, selDD);
		else
			generateDays(28, selDD);
	}
	else if (selMth.options[selMth.selectedIndex].value == "0")
	{
        generateDD(selDD);
	}
	else
	{
		generateDays(31, selDD);
	}
}

//generate the days of the month
function generateDays(days, objectDay)
{   
	objectDay.options.length =0; //Reset the combo box
	for (i = 1; i < 10; i++)
		objectDay.options[objectDay.length] 
			= new Option("0" + i + "", i, false, false);
	for (i = 10; i <= days; i++)
		objectDay.options[objectDay.length] 
			= new Option("" + i + "", i, false, false);
}
function generateDD(objectDay)
{   
	objectDay.options.length =0; //Reset the combo box
	objectDay.options[objectDay.length] = new Option("DD",0, false, false);

}

//check for leap year
function leapYr(year)
{
	return ( ( year % 4 == 0 ) && ( year % 100 != 0 || year % 400 == 0 ));
}
//-->

function validation(form) 
{
	var checking = "Your Form Is unable to be Submitted due to the following errors in the form.\nPlease Correct and Re-Submit\n-----------------------------------------------------------------------------------------\n";
	var check = true;
	
	personal = 1;
	if (form.salutation.selectedIndex == 0)
	{
		if (personal == 1) 
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Salutation\n";
		check = false;
	}		
	
	if (isblank(form.familyname.value))
	{
		if (personal == 1)
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Name\n";
		check = false;
	}		
	
	if (isblank(form.nationality.value))
	{
		if (personal == 1) 
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Nationality \n";
		check = false;
	}		
	
	/******************validate address*************************************/
	if (isblank(form.address1.value))
	{
		if (personal == 1) 
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Address\n";
		check = false;
	}
	
	if (isblank(form.postalcode.value))
	{
		if (personal == 1)
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Postal Code\n";
		check = false;
	}
	else
	{
		if (isNaN(form.postalcode.value))
		{
			if (personal == 1)
			{
				personal = 0;
				checking = checking + "\nMissing Fields In Personal Particulars\n";
			}
			checking = checking + " - Invalid Postal Code\n";
			check = false;
		}			
	}
	
	/******************validate contact numbers*****************************/
	if (isblank(form.contact1.value) && isblank(form.contact2.value))
	{
		if (personal == 1) 
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Contact Number\n";
		check = false;
	}
	
	if (isNaN(form.contact1.value))
	{
		if (personal == 1) 
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Contact Tel must be numeric\n";
		check = false;
	}
		
	if (isNaN(form.contact2.value))
	{
		if (personal == 1) 
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Mobile Tel must be numeric\n";
		check = false;
	}
		
	/******************validate fax****************************************/
	if (isNaN(form.fax.value))
	{
		if (personal == 1) 
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Fax must be numeric\n";
		check = false;
	}
		
	/******************validate email address*******************************/
	if (isblank(form.email.value))
	{
		if (personal == 1) 
		{
			personal = 0;
			checking = checking + "\nMissing Fields In Personal Particulars\n";
		}
		checking = checking + " - Email Address\n";
		check = false;
	}
	else if (!(isblank(form.email.value)))
	{
		var tempadd;
		var tempadd1;
		tempadd = form.email.value;
		tempadd1 = tempadd.indexOf("@");
		tempadd =  tempadd.indexOf(".");
		if (tempadd1 == -1 || tempadd == -1)
		{
			if (personal == 1) 
			{
				personal = 0;
				checking = checking + "\nMissing Fields In Personal Particulars\n";
			}
			checking = checking + " - Invalid Email Address.\n";
			check = false;
		}
	}

	/******************validate departure date*******************************/
	var tempSmonth;
	tempSmonth = form.DepartMonth.value
	//     check for months(April,June,Sep,Nov) with 31 days
	if (tempSmonth == "4" || tempSmonth == "6" || tempSmonth =="9" || tempSmonth =="11")
	{
		if (form.DepartDate.value == "31")
		{
			if (details == 1) 
			{
				details = 0;
				checking = checking + "\nMissing Fields In Booking Details\n";
			}
		checking = checking + " - Invalid Departure Date: Check value of month and day.\n";
		check = false;
		}		
	} 
		
	//      check for the month of Feb
	if (tempSmonth == "2")
	{
		if(form.DepartDate.value > 29)
		{
			if (details == 1) 
			{
				details = 0;
				checking = checking + "\nMissing Fields In Booking Details\n";
			}
		checking = checking + " - Invalid Departure Date: February has only 28 days.\n";
		check = false;
		}
				
		//        check for leap years
		if(form.DepartDate.value == 29 && ((form.DepartYear.value/4)!=parseInt(form.DepartYear.value/4)))
		{
			if (details == 1) 
			{
				details = 0;
				checking = checking + "\nMissing Fields In Booking Details\n";
			}
			checking = checking + " - Invalid Departure Date: Only February of leap years has exactly 29 days.\n";
			check = false;
		}
	}										

	/*************************validate passenger details*******************************************************/

	details = 1;
	tempNoAdult = form.NoAdult.value;
	tempNoChild = form.NoChild.value;
	NumberPassenger = form.NoAdult.value - (-form.NoChild.value);
	if (NumberPassenger  == "")
	{
		checking = checking + "\nNumber of Passenger field is incomplete\n";
	}

	if (form.guest1familyname.value == "" || form.guest1givenname.value=="" || form.guest1salutation.value =="" || form.guestPP1.value =="")
	{
		if (details  == 1)
		{
			details = 0;
			checking = checking + "\nMissing Fields In Guest Particulars";
		}

	checking = checking +  "\n   - 1st Guest personal detail is incomplete";
	check = false;
	
	
	}
	
	if (form.guestage1.value != "")
	{
		if (isNaN(form.guestage1.value))
		{
		if (details == 1) 
		{
			details = 0;
			checking = checking + "\nMissing Fields In Guest Particulars\n";
		}

		checking = checking + "\n - 1st Child age must be numeric\n";
		check = false;
		}
	}	

	if (NumberPassenger >=2 && NumberPassenger <=6)
	{
		if (NumberPassenger >= 2)
		{
			if (form.guest2familyname.value == "" || form.guest2givenname.value=="" || form.guest2salutation.value =="" || form.guestPP2.value =="")
			{

				if (details  == 1)
				{
					details = 0;
					checking = checking + "\nMissing Fields In Guest Particulars";
				}

			checking = checking +  "\n   - 2nd Guest personal detail is incomplete";
			check = false;
			}				
		}
		
		if (form.guestage2.value != "")
		{
			if (isNaN(form.guestage2.value))
			{
				if (details == 1) 
				{
					details = 0;
					checking = checking + "\nMissing Fields In Guest Particulars\n";
				}
				checking = checking + "\n - 2nd Child age must be numeric\n";
				check = false;
			}
		}	

		if (NumberPassenger >=3)
		{
			if (form.guest3familyname.value == "" || form.guest3givenname.value=="" || form.guest3salutation.value =="" || form.guestPP3.value =="")
			{
				if (details  == 1)
				{
					details = 0;
					checking = checking + "\nMissing Fields In Guest Particulars";
				}

			checking = checking +  "\n   - 3rd Guest personal detail is incomplete";
			check = false;
			}
		}
		
		if (form.guestage3.value != "")
		{
			if (isNaN(form.guestage3.value))
			{
			if (details == 1) 
			{
				details = 0;
				checking = checking + "\nMissing Fields In Guest Particulars\n";
			}
			checking = checking + "\n - 3rd Child age must be numeric\n";
			check = false;
			}
		}	
		
		if (NumberPassenger >=4)
		{
			if (form.guest4familyname.value == "" || form.guest4givenname.value=="" || form.guest4salutation.value =="" || form.guestPP4.value =="")
			{
				if (details  == 1)
				{
					details = 0;
					checking = checking + "\nMissing Fields In Guest Particulars";
				}

			checking = checking +  "\n   - 4th Guest personal detail  is incomplete";
			check = false;
			}
		}
		
		if (form.guestage4.value != "")
		{
			if (isNaN(form.guestage4.value))
			{
			if (details == 1) 
			{
				details = 0;
				checking = checking + "\nMissing Fields In Guest Particulars\n";
			}
			checking = checking + "\n - 4th Child age must be numeric\n";
			check = false;
			}
		}	
		
		if (NumberPassenger >=5)
		{
			if (form.guest5familyname.value == "" || form.guest5givenname.value=="" || form.guest5salutation.value =="" || form.guestPP5.value =="")
			{
				if (details  == 1)
				{
					details = 0;
					checking = checking + "\nMissing Fields In Guest Particulars";
				}

			checking = checking +  "\n   - 5th Guest personal detail  is incomplete";
			check = false;
			}
		}
		
		if (form.guestage5.value != "")
		{
			if (isNaN(form.guestage5.value))
			{
				if (details == 1) 
				{
					details = 0;
					checking = checking + "\nMissing Fields In Guest Particulars\n";
				}
				checking = checking + "\n - 5th Child age must be numeric\n";
				check = false;
			}
		}	
		
		if (NumberPassenger >=6)
		{
			if (form.guest6familyname.value == "" || form.guest6givenname.value=="" || form.guest6salutation.value =="" || form.guestPP6.value =="")
			{
				if (details  == 1)
				{
					details = 0;
					checking = checking + "\nMissing Fields In Guest Particulars";
				}
				checking = checking +  "\n   - 6th Guest personal detail  is incomplete";
				check = false;
			}
		}
		
		if (form.guestage6.value != "")
		{
			if (isNaN(form.guestage6.value))
			{
				if (details == 1) 
				{
					details = 0;
					checking = checking + "\nMissing Fields In Guest Particulars\n";
				}
				checking = checking + "\n - 6th Child age must be numeric\n";
				check = false;
			}
		}	
	}

	if (check == false)
	{ 
		alert(checking);
		return false;
	}
		
	if (check == true)
	{  
		form.submit();
		return true; 
	}
}

function isblank(field)
{   
	if (Trim(field) == "" )
	{	
		return true;
	}
	else
	{ 	
		return false;
	}
}

function autoFillin()
{
	var form = document.getElementById('enquiry');
	
	if (form.salutation.value != "")
	{
		form.guest1salutation.value = form.salutation.value; 
	} 
	if (form.familyname.value != "")
	{
		form.guest1familyname.value = form.familyname.value;
	}
	if (form.givenname.value != "")
	{
		form.guest1givenname.value = form.givenname.value;
	}
}

function Trim(iStr)
{
	while (iStr.charCodeAt(0) <= 32)
	{
		iStr=iStr.substr(1);
	}

	while (iStr.charCodeAt(iStr.length - 1) <= 32)
	{
		iStr=iStr.substr(0, iStr.length - 1);
	}

	return iStr;
}
