function validateCheck()
{
	var ArrivalDay = document.checkrate.ArriveDay;
	var ArrivalMonth = document.checkrate.ArriveMonth;
	var ArrivalYear = document.checkrate.ArriveYear;
	var DepartureDay = document.checkrate.DepartDay;
	var DepartureMonth = document.checkrate.DepartMonth;
	var DepartureYear = document.checkrate.DepartYear;
	

	if (ArrivalDay.selectedIndex == 0)
	{
		alert('Please select the Day of your Check-in Date.');
		return false;
	}

	if (ArrivalMonth.selectedIndex == 0)
	{
		alert('Please select the Month of your Check-in Date.');
		return false;
	}

	if (ArrivalYear.selectedIndex == 0)
	{
		alert('Please select the Year of your Check-in Date.');
		return false;
	}

	if (((ArrivalDay[ArrivalDay.selectedIndex].value > 29) && (ArrivalMonth[ArrivalMonth.selectedIndex].value == 2) && ((ArrivalYear[ArrivalYear.selectedIndex].value % 4) == 0)) || ((ArrivalDay[ArrivalDay.selectedIndex].value > 28) && (ArrivalMonth[ArrivalMonth.selectedIndex].value == 2) && ((ArrivalYear[ArrivalYear.selectedIndex].value % 4) > 0)) || ((ArrivalDay[ArrivalDay.selectedIndex].value > 30) && ((ArrivalMonth[ArrivalMonth.selectedIndex].value == 4) || (ArrivalMonth[ArrivalMonth.selectedIndex].value == 6) || (ArrivalMonth[ArrivalMonth.selectedIndex].value == 9) || (ArrivalMonth[ArrivalMonth.selectedIndex].value == 11))))
	{
		alert('Please select a valid Check-in Date.');
		return false;
	}
	
	

	today = new Date();

	var arrday = today.getDate();
	var arrmonth = today.getMonth() + 1;
	var arryear = today.getFullYear();
	var dayincrease = 0;

	if ((arrmonth == 1) || (arrmonth == 3) || (arrmonth == 5) || (arrmonth == 7) || (arrmonth == 8) || (arrmonth == 10) || (arrmonth == 12))
	{
		if ((arrday + dayincrease) > 31)
		{
			theDay = arrday + dayincrease - 31;
			if (arrmonth == 12)
			{
				theMonth = 1;
				theYear = arryear + 1;
			}
			else
			{
				theMonth = arrmonth + 1;
				theYear = arryear;
			}
		}		
		else
		{
			theDay = arrday + dayincrease;
			theMonth = arrmonth;
			theYear = arryear;
		}
	}
	else if ((arrmonth == 4) || (arrmonth == 6) || (arrmonth == 9) || (arrmonth == 11))
	{
		theYear = arryear;
		if ((arrday + dayincrease) > 30)
		{
			theDay = arrday + dayincrease - 30;
			theMonth = arrmonth + 1;
		}
		else
		{
			theDay = arrday + dayincrease;
			theMonth = arrmonth;
		}
	}
	else
	{
		theYear = arryear;
		LeapYear = theYear % 4;
		if (LeapYear == 0)
		{
			if ((arrday + dayincrease) > 29)
			{
				theDay = arrday + dayincrease - 29;
				theMonth = arrmonth + 1;
			}
			else
			{
				theDay = arrday + dayincrease;
				theMonth = arrmonth;
			}
		}
		else if (LeapYear > 0)
		{
			if ((arrday + dayincrease) > 28)
			{
				theDay = arrday + dayincrease - 28;
				theMonth = arrmonth + 1;
			}
			else
			{
				theDay = arrday + dayincrease;
				theMonth = arrmonth;
			}
		}
	}

	if (theDay < 10)
		theDay = '0' + theDay;
	if (theMonth < 10)
		theMonth = '0' + theMonth;
	var AdvanceDate = '' + theYear + theMonth + theDay;
	
	if (ArrivalDay[ArrivalDay.selectedIndex].value < 10)
		NewArrivalDay = '0' + ArrivalDay[ArrivalDay.selectedIndex].value;
	else
		NewArrivalDay = ArrivalDay[ArrivalDay.selectedIndex].value;
	if (ArrivalMonth[ArrivalMonth.selectedIndex].value < 10)
		NewArrivalMonth = '0' + ArrivalMonth[ArrivalMonth.selectedIndex].value;
	else
		NewArrivalMonth = ArrivalMonth[ArrivalMonth.selectedIndex].value;
	var CheckinDate = ArrivalYear[ArrivalYear.selectedIndex].value + NewArrivalMonth + NewArrivalDay;

	if (parseInt(CheckinDate) < parseInt(AdvanceDate))
	{
//		alert('The Check-in Date has to be a least ' + dayincrease + ' days ahead from today.');
		alert('The Check-in Date you select is earlier than today.');
		return false;
	}

	if (DepartureDay.selectedIndex == 0)
	{
		alert('Please select the Day of your Check-out Date.');
		return false;
	}

	if (DepartureMonth.selectedIndex == 0)
	{
		alert('Please select the Month of your Check-out Date.');
		return false;
	}

	if (DepartureYear.selectedIndex == 0)
	{
		alert('Please select the Year of your Check-out Date.');
		return false;
	}

	if (((DepartureDay[DepartureDay.selectedIndex].value > 29) && (DepartureMonth[DepartureMonth.selectedIndex].value == 2) && ((DepartureYear[DepartureYear.selectedIndex].value % 4) == 0)) || ((DepartureDay[DepartureDay.selectedIndex].value > 28) && (DepartureMonth[DepartureMonth.selectedIndex].value == 2) && ((DepartureYear[DepartureYear.selectedIndex].value % 4) > 0)) || ((DepartureDay[DepartureDay.selectedIndex].value > 30) && ((DepartureMonth[DepartureMonth.selectedIndex].value == 4) || (DepartureMonth[DepartureMonth.selectedIndex].value == 6) || (DepartureMonth[DepartureMonth.selectedIndex].value == 9) || (DepartureMonth[DepartureMonth.selectedIndex].value == 11))))
	{
		alert('Please select a valid Check-out Date.');
		return false;
	}

	var edstotal = ArrivalYear[ArrivalYear.selectedIndex].value;
	if (parseInt(ArrivalMonth[ArrivalMonth.selectedIndex].value) < 10)
		edstotal = edstotal + '0' + ArrivalMonth[ArrivalMonth.selectedIndex].value;
	else
		edstotal += ArrivalMonth[ArrivalMonth.selectedIndex].value;
	if (parseInt(ArrivalDay[ArrivalDay.selectedIndex].value) < 10)
		edstotal = edstotal + '0' + ArrivalDay[ArrivalDay.selectedIndex].value;
	else
		edstotal += ArrivalDay[ArrivalDay.selectedIndex].value;

	var edetotal = DepartureYear[DepartureYear.selectedIndex].value;
	if (parseInt(DepartureMonth[DepartureMonth.selectedIndex].value) < 10)
		edetotal = edetotal + '0' + DepartureMonth[DepartureMonth.selectedIndex].value;
	else
		edetotal += DepartureMonth[DepartureMonth.selectedIndex].value;
	if (parseInt(DepartureDay[DepartureDay.selectedIndex].value) < 10)
		edetotal = edetotal + '0' + DepartureDay[DepartureDay.selectedIndex].value;
	else
		edetotal += DepartureDay[DepartureDay.selectedIndex].value;

	if (parseInt(edstotal) > parseInt(edetotal))
	{
		alert('The Check-in Date is later than the Check-out Date. Please re-check the dates.');
		return false;
	}

	var CheckoutDate = DepartureYear[DepartureYear.selectedIndex].value + DepartureMonth[DepartureMonth.selectedIndex].value + DepartureDay[DepartureDay.selectedIndex].value;

	if (parseInt(CheckinDate) == parseInt(CheckoutDate))
	{
		alert('The Check-out Date cannot be the same as the Check-in Date.');
		return false;
	}
	
	if ((document.checkrate.NumOfRoom.value == '') || (document.checkrate.NumOfRoom.value == 0) || (isNaN(document.checkrate.NumOfRoom.value) == true))
	{
		alert('Please enter the number of rooms.');
		return false;
	}
	
	if ((document.checkrate.NumOfAdult.value == '') || (document.checkrate.NumOfAdult.value == 0) || (isNaN(document.checkrate.NumOfAdult.value) == true))
	{
		alert('Please enter the number of adults.');
		return false;
	}
	
	if ((document.checkrate.hotelid.value == '') || (document.checkrate.hotelid.value == 0))
	{
		alert('Please select the hotel.');
		return false;
	}
	
	if ((document.checkrate.NumOfChild.value == '') || (isNaN(document.checkrate.NumOfChild.value) == true))
	{
		alert('Please enter the number of children.');
		return false;
	}

	return true;
}


function submitFormCheck(PostURL)
{
	if (!validateCheck())
		return false;
	document.checkrate.action = PostURL;
	document.checkrate.submit();
}


function displayinfo(infoid)
{
	window.open("hotel-reserve-roominfo.asp?infoid=" + infoid, "RoomInfo", config="width=600,height=360,scrollbars=1,resizable=0");
}


function checkRoomType()
{
	if (document.reserveroom.roomtypeid.length > 0 ){
	
	
	
		for (var i=0; i < document.reserveroom.roomtypeid.length; i++)
		{
			if (document.reserveroom.roomtypeid[i].checked == true)
				return true;
		}

		alert('Please select a type of room.');
		return false;
	}else{
		if (document.reserveroom.roomtypeid.checked == true)
		{		
			return true;
		}
		alert('Please select a type of room.');
		return false;
	
	}
}


function doContinueReserve(PostURL)
{
	if (!checkRoomType())
		return false;
	document.reserveroom.action = PostURL;
	document.reserveroom.submit();
}


function extractDigits(mixedString) {
   var digitsOnly = '';
   var thisDigit = '';
   for (var i = 0; i < mixedString.length; i++) {
      thisDigit = mixedString.charAt(i);
      if (thisDigit >= '0' && thisDigit <= '9')
         digitsOnly = digitsOnly + thisDigit;
   }
   return digitsOnly;
}


function checkMod10(ccNumber) {
   var translateMap = '0246813579';
   var digitSum = 0;
   var translateFlag = ((ccNumber.length % 2) == 0);
   for (var i = 0; i < ccNumber.length; i++) {
       digitSum += parseInt(translateFlag ?
            translateMap.charAt(ccNumber.charAt(i)) :
            ccNumber.charAt(i) , 10)
      translateFlag = !translateFlag;
   }
   return (digitSum % 10) == 0;
}
 

function validCardType(ccNumber) {
   var cardLengths = new Array (
         'v', 13, 'v', 16, 'm', 16,
         'a', 15, 'c', 14, 'd', 16);
   var cardDigits = new Array (
         'v', '4', 'm', '51', 'm', '52', 'm', '53' ,
         'm', '54', 'm', '55', 'a', '34', 'a', '37',
         'c', '300', 'c', '301', 'c', '302', 'c', '303',
         'c', '304', 'c', '305', 'c', '36', 'c', '38',
         'd', '6011');
   var validCard = false;
   var correctLength = false;
   var cardType = '' ;
   for (var i = 0; i < cardDigits.length - 1; i += 2) {
      if (cardDigits[i + 1] == ccNumber.substr(0, cardDigits[i + 1].length)) {
         validCard = true;
         cardType = cardDigits[i];
         break;
      }
   }
   if (validCard) {
      var cardLen = ccNumber.length;
      for (var i = 0; i < cardLengths.length - 1; i += 2) {
         if ((cardType == cardLengths[i]) && (cardLen == cardLengths[i + 1])) {
            correctLength = true;
            break;
         }
      }
      validCard = correctLength;
   }
   return validCard;
}
 

function validateCollectInfo()
{
	if (document.reserveform.Surname.value == '')
	{
		alert('Please enter your Surname');
		return false;
	}

	if (document.reserveform.GivenName.value == '')
	{
		alert('Please enter your Given Name');
		return false;
	}

	if (document.reserveform.TelephoneNumber.value == '')
	{
		alert('Please enter your Telephone Number');
		return false;
	}

	if (document.reserveform.MobilePhone.value == '')
	{
		alert('Please enter your Mobile Phone Number');
		return false;
	}

	if (document.reserveform.EmailAddress.value == '')
	{
		alert('Please enter your e-mail address.');
		return false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.reserveform.EmailAddress.value)))
	{
		alert("Invalid e-mail address! Please re-enter.")
		return false;
	}

	if (document.reserveform.AddressLine1.value == '')
	{
		alert('Please enter your Street Address');
		return false;
	}

	if (document.reserveform.AddressCity.value == '')
	{
		alert('Please enter your City');
		return false;
	}

	if (document.reserveform.AddressState.value == '')
	{
		alert('Please enter your State');
		return false;
	}
	
	if (document.reserveform.AddressZip.value == '')
	{
		alert('Please enter your Postal/Zip Code');
		return false;
	}

	if (document.reserveform.AddressCountry.value == '')
	{
		alert('Please enter your Country');
		return false;
	}
/*
	if (document.reserveform.ccType.value == '')
	{
		alert('Please select the type of your credit card');
		return false;
	}

	if (document.reserveform.ccNumber.value == '')
	{
		alert('Please enter your Credit Card Number');
		return false;
	}

	var ccDigits = extractDigits(document.reserveform.ccNumber.value);
	if (!checkMod10(ccDigits) && !validCardType(ccDigits))
	{
      		alert('Invalid credit card number');
		return false;
	}

	if (document.reserveform.ccExpMonth.value == '')
	{
		alert('Please enter the Credit Card Expiration Month');
		return false;
	}

	if (document.reserveform.ccExpYear.value == '')
	{
		alert('Please enter the Credit Card Expiration Year');
		return false;
	}

	if (document.reserveform.ccNameOnCard.value == '')
	{
		alert('Please enter the name printed on the credit card');
		return false;
	}
*/
	return true;
}


function doReserve()
{
	if (!validateCollectInfo())
		return false;
	document.reserveform.action = 'hotel-reserve-process.asp';
	document.reserveform.submit();
}


