function calculate() {
	var HotelPrice = new Array();
	HotelPrice[0] = new Array(740, 740, 740, 740, 1260);
	HotelPrice[1] = new Array(700, 700, 700, 820, 1060);
	HotelPrice[2] = new Array(600, 600, 600, 720, 1080);
	HotelPrice[3] = new Array(600, 600, 600, 780, 1200);
	HotelPrice[4] = new Array(480, 480, 480, 600, 820);
	
	var PackagePrice = new Array();
	PackagePrice[0] = new Array(0,0,0,0,3350, 4050);
	PackagePrice[1] = new Array(0,0,0,0,3150, 3800);
	PackagePrice[2] = new Array(0,0,0,0,2900, 3450);
	PackagePrice[3] = new Array(0,0,0,0,3050, 3650);
	PackagePrice[4] = new Array(0,0,0,0,2300, 2750);
	
	obj = document.frmBooking;
	var TotalPrice, NoOfNights, i;
	TotalPrice = 0;
	NoOfNights = obj.selCheckOut.selectedIndex - obj.selCheckIn.selectedIndex + 1;
	if (NoOfNights < 1) {
		//alert ("Check Out date shold be later than Check In date");
		NoOfNights = 1;
		obj.txtNoOfNights.value = 1;
		obj.selCheckOut.options[obj.selCheckIn.selectedIndex].selected = true;
		//calculate();
	}
	
	//if (NoOfNights < 4) {
		obj.txtNoOfNights.value = NoOfNights;
		/*for (i=obj.selCheckIn.selectedIndex; i<obj.selCheckIn.selectedIndex+NoOfNights; i++) {
			TotalPrice += HotelPrice[obj.selHotel.selectedIndex][i];
		}
	} else {
		TotalPrice = PackagePrice[obj.selHotel.selectedIndex][NoOfNights];
		obj.txtNoOfNights.value = NoOfNights + "-nights package";
	}*/
	
	obj.txtTotal.value = "HKD" + (TotalPrice * (obj.selNoOfRooms.selectedIndex+1));
}

function toggle(noOfNames) {
	var i=1;
	for (i=1; i<=noOfNames; i++) {
		document.getElementById('divName' + i).style.display = "block";
	}
	for (i=3; i>noOfNames; i--) {
		document.getElementById('divName' + i).style.display = "none";
	}
	
}

function validateForm() {
	var error = "";
	var obj = document.frmBooking;
	if (obj.txtFirstName1.value == "" || obj.txtLastName1.value == "") error += "\n- Room 1";
	if (obj.selNoOfRooms.selectedIndex > 0 && (obj.txtFirstName2.value == "" || obj.txtLastName2.value == "")) error += "\n- Room 2";
	if (obj.selNoOfRooms.selectedIndex > 1 && (obj.txtFirstName3.value == "" || obj.txtLastName3.value == "")) error += "\n- Room 3";
	if (obj.txtCompany.value == "") error += "\n- Company";
	if (isNumeric(obj.txtCountryCode.value) == false || isNumeric(obj.txtTelephone.value) == false) error += "\n- Contact Number";
	if (validateEmail(obj.txtEmail.value) == false) error += "\n- E-mail Address";
	
	if (error != "") {
		alert("Please fill in the information below:" + error);
		return false;
	} else {
		document.frmBooking.submit();
	}
}

function validateEmail(email)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return true;
	} else {
		return false;
	}
}

function toInteger(n) {
	return (n < 0 ? - 1 : + 1) * Math.floor(Math.abs(n) + 0.5);
}

function isNumeric(n) {
	var validChars = "0123456789";
	var isNumber=true;
	var char;

	if (n == "") isNumber = false;
	for (i = 0; i < n.length && isNumber == true; i++) { 
		char = n.charAt(i); 
		if (validChars.indexOf(char) == -1) isNumber = false;
	}
	return isNumber;
}

