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;
	details = 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 hotel name*******************************/
	if (isblank(form.PackageTitle.value))
	{
		if (details == 1) 
		{
			details = 0;
			checking = checking + "\nMissing Fields In Booking Details\n";
		}
		checking = checking + " - Invalid hotel name: please select.\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 return date*******************************/
	var tempSmonth;
	tempSmonth = form.ReturnMonth.value
	//     check for months(April,June,Sep,Nov) with 31 days
	if (tempSmonth == "4" || tempSmonth == "6" || tempSmonth =="9" || tempSmonth =="11")
	{
		if (form.ReturnDate.value == "31")
		{
			if (details == 1) 
			{
				details = 0;
				checking = checking + "\nMissing Fields In Booking Details\n";
			}

		checking = checking + " - Invalid Return Date: Check value of month and day.\n";
		check = false;
		}		
	} 

	//      check for the month of Feb
	if (tempSmonth == "2")
	{
		if(form.ReturnDate.value > 29)
		{
			if (details == 1) 
			{
				details = 0;
				checking = checking + "\nMissing Fields In Booking Details\n";
			}
		checking = checking + " - Invalid Return Date: February has only 28 days.\n";
		check = false;
		}
			
	//        check for leap years
		if(form.ReturnDate.value == 29 && ((form.ReturnYear.value/4)!=parseInt(form.ReturnYear.value/4)))
		{
			if (details == 1) 
			{
				details = 0;
				checking = checking + "\nMissing Fields In Booking Details\n";
			}	
			checking = checking + " - Invalid Return Date: Only February of leap years has exactly 29 days.\n";
			check = false;
		}
	}	

// Departure date, Return date
				var indate = returnMonth(form.DepartMonth.value)+" "+form.DepartDate.value+","+" "+form.DepartYear.value;
				var outdate = returnMonth(form.ReturnMonth.value)+" "+form.ReturnDate.value+","+" "+form.ReturnYear.value;
				//month date, year
				//alert("The departure date is "+indate);
				var ONE_DAY = 1000 * 60 * 60 * 24
				var inD = new Date(indate);
				var outD = new Date(outdate);
				var d = new Date();
			    var TodayDate = d.getDate();
				var ThisMonth = d.getMonth()+1;
				var ThisYear = d.getFullYear();
				var currentdate = returnMonth(ThisMonth)+" "+TodayDate+", "+ThisYear;
				var curD = new Date(currentdate);
				var difference;
				if(inD<curD) {
					if (details  == 1)
					{
						details = 0;
						checking = checking + "\nMissing Fields In Guest Particulars \n";
					}
					checking = checking +  " - Departure date is incomplete\n";
					check = false;
				}else{
					difference = ((outD - inD)/ONE_DAY)
					if(difference<1){
						if (details  == 1)
						{
							details = 0;
							checking = checking + "\nMissing Fields In Guest Particulars \n";
						}
						checking = checking +  " - Selected Return date must be at least 1 day from the Departure date\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";
	//}
	NumberPassenger=1;
	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 \n";
		}

	checking = checking +  " - 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 (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 returnMonth(value){
	var st='';
	switch(parseInt(value))
	{
	case 1:
		return "Jan";
		break
	case 2:
		return "Feb";
		break		
	case 3:
		return "Mar";
		break
	case 4:
		return "Apr";
		break
	case 5:
		return "May";
		break		
	case 6:
		return "Jun";
		break					
	case 7:
		return "Jul";
		break
	case 8:
		return "Aug";
		break		
	case 9:
		return "Sep";
		break					
	case 10:
		return "Oct";
		break
	case 11:
		return "Nov";
		break		
	case 12:
		return "Dec";
					break										
				}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->

function Isdate(datevalue){// mm/dd/yyyy
	var mo, day, yr;
    var entry = datevalue;
    var reLong = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
    var reShort = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{2}\b/;
    var valid = (reLong.test(entry)) || (reShort.test(entry));
    if (valid) {
        var delimChar = (entry.indexOf("/") != -1) ? "/" : "-";
        var delim1 = entry.indexOf(delimChar);
        var delim2 = entry.lastIndexOf(delimChar);
        mo = parseInt(entry.substring(0, delim1), 10);
        day = parseInt(entry.substring(delim1+1, delim2), 10);
        yr = parseInt(entry.substring(delim2+1), 10);
        // handle two-digit year
        if (yr < 100) {
            var today = new Date();
            // get current century floor (e.g., 2000)
            var currCent = parseInt(today.getFullYear() / 100) * 100;
            // two digits up to this year + 15 expands to current century
            var threshold = (today.getFullYear() + 15) - currCent;
            if (yr > threshold) {
                yr += currCent - 100;
            } else {
                yr += currCent;
            }
        }
        var testDate = new Date(yr, mo-1, day);
        if (testDate.getDate() == day) {
            if (testDate.getMonth() + 1 == mo) {
                if (testDate.getFullYear() == yr) {
                    // fill field with database-friendly format
                    //fld.value = mo + "/" + day + "/" + yr;
                    return true;
                } else {
                    alert("There is a problem with the year.");
                }
            } else {
                alert("There is a problem with the month.");
            }
        } else {
            alert("There is a problem with the date.");
        }
    } else {
        alert("Incorrect date format as mm/dd/yyyy.");
    }
    return false;
	
}

function CheckCurrentDate(datevalue){ // mm/dd/yyyy
	//month date, year
	var inD = new Date(datevalue);
	var d = new Date();
	var TodayDate = d.getDate();
	var ThisMonth = d.getMonth()+1;
	var ThisYear = d.getFullYear();
	var currentdate = (d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear();
	var curD = new Date(currentdate);
	if(inD<curD) {
		return false;
	}else{
		return true;
	}
}

function CompareDate(indate, outdate, numday){
	var ONE_DAY = 1000 * 60 * 60 * 24;
	var inD = new Date(indate);
	var outD = new Date(outdate);
	var difference = ((outD - inD)/ONE_DAY);
	if(difference>=numday){
		return true;
	}else{
		return false;	
	}
}

function CheckDateValue(){
	var date=document.getElementById('DepartMonth').value+'/'+document.getElementById('DepartDate').value+'/'+document.getElementById('DepartYear').value;
	if (!CheckCurrentDate(date)){
		alert('Departure date is incomplete');
		return false;
	}
	if (!Isdate(date)){
		return false;
	}
	var dateout=document.getElementById('ReturnMonth').value+'/'+document.getElementById('ReturnDate').value+'/'+document.getElementById('ReturnYear').value;
	if (!CompareDate(date, dateout, 1)){
		alert('Selected Departure date must be at least 1 day from the Return date');
		return false;
	}
}

