function toggleview(item) {
	if (document.getElementById(item+"content").style.display == "none") {
		document.getElementById(item+"content").style.display="block";
		document.getElementById(item+"status").innerHTML="-";
	} else {
		document.getElementById(item+"content").style.display="none";
		document.getElementById(item+"status").innerHTML="+";
	}
}

function getCities(aForm, anArray) {
   var selIndex = aForm.country.value;

   if (selIndex != 0) {
      aForm.cityname.options.length = 0;
      aForm.property.options.length = 0;
      if(!anArray[selIndex]) {
         return;
      }
      for(var i = 0, n = 0; i < anArray[selIndex].length; i++) {
         aForm.cityname.options[n++] = new Option(anArray[selIndex][i][1], anArray[selIndex][i][0]);
      }
      aForm.cityname.selectedIndex = 0;
   }
}

function getProperties(aForm, anArray) {
   var selIndex = aForm.cityname.value;
   if (selIndex != 0) {
      aForm.property.options.length = 0;
      if(!anArray[selIndex]) {
         return;
      }
      for (var i = 0, n = 0; i < anArray[selIndex].length; i++) {
         aForm.property.options[n++] = new Option(anArray[selIndex][i][1], anArray[selIndex][i][0]);
      }
      aForm.property.selectedIndex = 0;
   }
}

function visitURL(aForm) {
	if(aForm.country.options.selectedIndex != 0) {
		if(aForm.cityname.options[aForm.cityname.options.selectedIndex].value != 0) {
			window.open(aForm.property.options[aForm.property.options.selectedIndex].value);
		} else {
			alert('You must select a City first!');	
		}
	} else {
		alert('You must select a Country first!');	
	}
}

function getsubcategories(aForm, anArray) {
   var selIndex = aForm.country.selectedIndex;
   aForm.Hotelnames.options.length = 0;

   if (!anArray[selIndex]) {
      return;
   }
   for (var i = 0, n = 0; i < anArray[selIndex].length; i++) {
      aForm.Hotelnames.options[n++] = new Option(anArray[selIndex][i][1], anArray[selIndex][i][0]
      );
   }
   aForm.Hotelnames.selectedIndex = 0;
}

function checkSelections() {
   if (document.idForm.country.value.length == 0) {
      alert('Please select a country.');
      return false;
   } else {
      return true;
   }
}

/* added on 27th March 2009 */
/* this function will set the txtCities and Hotelnames drop down menus to the default city and property */
function defaultCityAndProperty(f, defaultCity, defaultConnectname, arrPropertyList) {
	//first, let's get the size of the txtCities drop down menu
	var intCitiesLength = f.txtCities.options.length;
	var boolSelected = false;
	for(intCitiesCounter = 0; intCitiesCounter < intCitiesLength; intCitiesCounter++) {
		if(f.txtCities.options[intCitiesCounter].text == defaultCity) {
			f.txtCities.options[intCitiesCounter].selected = true;
			
			f.Hotelnames.options.length = 0;   //reset the drop down menu to nothing
			for(intPropertiesCounter = 0; intPropertiesCounter < arrPropertyList[intCitiesCounter].length; intPropertiesCounter++) {
				if(arrPropertyList[intCitiesCounter][intPropertiesCounter][0] == defaultConnectname) {
					boolSelected = true;
				} else {
					boolSelected = false;
				}
				f.Hotelnames.options[intPropertiesCounter] = new Option(arrPropertyList[intCitiesCounter][intPropertiesCounter][1], arrPropertyList[intCitiesCounter][intPropertiesCounter][0], boolSelected, boolSelected);
			}
		}
	}
}

/* this function will update the Hotelnames list based on the selection in txtCities */
function updateProperties(f, defaultConnectname, arrPropertyList) {
	var txtSelectedCity = f.txtCities.options[f.txtCities.selectedIndex].value;
	var boolSelected = false;
	
	f.Hotelnames.options.length = 0;   //reset the drop down menu to nothing
	for(i=0; i<arrPropertyList[txtSelectedCity].length; i++) {
		if(arrPropertyList[txtSelectedCity][i][0] == defaultConnectname) {
			boolSelected = true;
		} else {
			boolSelected = false;
		}
		f.Hotelnames.options[i] = new Option(arrPropertyList[txtSelectedCity][i][1], arrPropertyList[txtSelectedCity][i][0], boolSelected, boolSelected);
	}
}
/* added on 27th March 2009 */
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function validateEnquiry(f) {
   //declare some variables here first
   var strErrMsg = "";
   var regExp1 = /[^a-zA-Z0-9 ]/
   var regstr1 = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
   var regstr2 = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
   var regEmail1 = new RegExp(regstr1);
   var regEmail2 = new RegExp(regstr2);
   var regEmail3 = /[^a-zA-Z0-9\-_.@]/;

   //reset all the fields to #FFFFFF
   f.txtFirstName.style.backgroundColor = '#FFFFFF';
   f.txtLastName.style.backgroundColor = '#FFFFFF';
   f.txtEmailAddress.style.backgroundColor = '#FFFFFF';
   f.captcha.style.backgroundColor = '#FFFFFF';
   f.numPhoneCountryCode.style.backgroundColor = '#FFFFFF';
   f.txtAddress.style.backgroundColor = '#FFFFFF';
   f.txtEnquiryContents.style.backgroundColor = '#FFFFFF';

   if(!f.txtFirstName.value) {
      strErrMsg = strErrMsg + "- First Name/Given Name is required\n";
      f.txtFirstName.style.backgroundColor = '#FF0000';
   } else {
      if(window.RegExp) {
         if(regExp1.test(f.txtFirstName.value)) {
            strErrMsg = strErrMsg + "- Family Name is invalid\n";
            f.txtFirstName.style.backgroundColor = '#FF0000';
         }
      }
   }

   if(!f.txtLastName.value) {
      strErrMsg = strErrMsg + "- Last Name/Family Name is required\n";
      f.txtLastName.style.backgroundColor = '#FF0000';
   } else {
      if(window.RegExp) {
         if(regExp1.test(f.txtLastName.value)) {
            strErrMsg = strErrMsg + "- Given Name is invalid\n";
            f.txtLastName.style.backgroundColor = '#FF0000';
         }
      }
   }

   if(!f.txtEmailAddress.value) {  //for the Email Address field
      strErrMsg = strErrMsg + "- Email Address is required\n";
      f.txtEmailAddress.style.backgroundColor = "#FF0000";
   } else {
      if(window.RegExp) {
         if(!(!regEmail1.test(f.txtEmailAddress.value) && regEmail2.test(f.txtEmailAddress.value) && !regEmail3.test(f.txtEmailAddress.value)) || !(f.txtEmailAddress.value.indexOf("@")>=0)) {
            strErrMsg = strErrMsg + "- Invalid Email Address\n";
            f.txtEmailAddress.style.backgroundColor = '#FF0000';
         }
      }
   }

   if(!f.numPhoneCountryCode.value){
      strErrMsg = strErrMsg +"- Country Code is required\n";
      f.numPhoneCountryCode.style.backgroundColor = '#FF0000';
   }

   if(!f.numPhoneNumber.value){
      strErrMsg = strErrMsg +"- Phone Number is required\n";
      f.numPhoneNumber.style.backgroundColor = '#FF0000';
   }

   if(!f.txtAddress.value){
      strErrMsg = strErrMsg +"- Address is required\n";
      f.txtAddress.style.backgroundColor = '#FF0000';
   }

   if(!f.txtEnquiryContents.value){
      strErrMsg = strErrMsg +"- Enquiry / Feedback is required\n";
      f.txtEnquiryContents.style.backgroundColor = '#FF0000';
   }

   if(!f.captcha.value) {
      strErrMsg = strErrMsg + "- Anti Spam Code is required\n";
      f.captcha.style.backgroundColor = '#FF0000';
   } else {
      if(window.RegExp) {
         if(regExp1.test(f.captcha.value)) {
            strErrMsg = strErrMsg + "- Please enter the Anti Spam Code shown in the image shown on the left \n";
            f.captcha.style.backgroundColor = '#FF0000';
         }
      }
   }

   if(strErrMsg != "") {
      alert(strErrMsg);
      return false;
   } else {
      return true;
   }
}

function validateFeedback(f) {
   var strErrMsg = "";
   var regExp1 = /[^a-zA-Z0-9 ]/
   var regstr1 = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
   var regstr2 = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
   var regEmail1 = new RegExp(regstr1);
   var regEmail2 = new RegExp(regstr2);
   var regEmail3 = /[^a-zA-Z0-9\-_.@]/;

   //reset all the fields to #FFFFFF
   f.txtFirstName.style.backgroundColor = '#FFFFFF';
   f.txtLastName.style.backgroundColor = '#FFFFFF';
   f.txtEmailAddress.style.backgroundColor = '#FFFFFF';
   f.txtComments.style.backgroundColor = '#FFFFFF';
   f.captcha.style.backgroundColor = '#FFFFFF';

   if(!f.txtFirstName.value) {
      strErrMsg = strErrMsg + "- First Name is required\n";
      f.txtFirstName.style.backgroundColor = '#FF0000';
   } else {
      if(window.RegExp) {
         if(regExp1.test(f.txtFirstName.value)) {
            strErrMsg = strErrMsg + "- First Name is invalid\n";
            f.txtFirstName.style.backgroundColor = '#FF0000';
         }
      }
   }

   if(!f.txtLastName.value) {
      strErrMsg = strErrMsg + "- Last Name is required\n";
      f.txtLastName.style.backgroundColor = '#FF0000';
   } else {
      if(window.RegExp) {
         if(regExp1.test(f.txtLastName.value)) {
            strErrMsg = strErrMsg + "- Last Name is invalid\n";
            f.txtLastName.style.backgroundColor = '#FF0000';
         }
      }
   }

   if(!f.txtEmailAddress.value) {  //for the Email Address field
      strErrMsg = strErrMsg + "- Email Address is required\n";
      f.txtEmailAddress.style.backgroundColor = "#FF0000";
   } else {
      if(window.RegExp) {
         if(!(!regEmail1.test(f.txtEmailAddress.value) && regEmail2.test(f.txtEmailAddress.value) && !regEmail3.test(f.txtEmailAddress.value)) || !(f.txtEmailAddress.value.indexOf("@")>=0)) {
            strErrMsg = strErrMsg + "- Invalid Email Address\n";
            f.txtEmailAddress.style.backgroundColor = '#FF0000';
         }
      }
   }

   if(!f.txtComments.value) {
      strErrMsg = strErrMsg + "- Comments is required\n";
      f.txtComments.style.backgroundColor = '#FF0000';
   }

   if(!f.captcha.value) {
      strErrMsg = strErrMsg + "- Anti Spam Code is required\n";
      f.captcha.style.backgroundColor = '#FF0000';
   } else {
      if(window.RegExp) {
         if(regExp1.test(f.captcha.value)) {
            strErrMsg = strErrMsg + "- Please enter the Anti Spam Code shown in the image shown on the left \n";
            f.captcha.style.backgroundColor = '#FF0000';
         }
      }
   }

   if(strErrMsg != "") {
      alert(strErrMsg);
      return false;
   } else {
      return true;
   }
}

function isNumberKey(evt) {
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57)) {
      return false;
   }
   return true;
}

//function to automatically populate the form fields in the booking engine with the current date
function todayDate(f) {
	//var f = document.idForm;
	var intNumDays = 1;
	f.nbdays.value = intNumDays;   //set nbdays to be 1 day
	
   var now = new Date();
	var dteArrivalDate = new Date(now.getTime() + (7*24*60*60*1000));   //set the Arrival Date to be 7 days after the current date
	f.txtArrivalDate.value = dteArrivalDate.getDate() + "/" + (dteArrivalDate.getMonth() + 1) + "/" + dteArrivalDate.getFullYear();
   f.fromday.value = dteArrivalDate.getDate();
   f.frommonth.value = dteArrivalDate.getMonth() + 1;
   f.fromyear.value = dteArrivalDate.getFullYear();

   var dteDepartureDate = new Date(now.getTime() + (8*24*60*60*1000));   //set the Departure Date to be 1 day after the Arrival Date
   f.txtDepartureDate.value = dteDepartureDate.getDate() + "/" + (dteDepartureDate.getMonth() + 1) + "/" + dteDepartureDate.getFullYear();
	f.endday.value = dteDepartureDate.getDate();
   f.endmonth.value = dteDepartureDate.getMonth() + 1;
   f.endyear.value = dteDepartureDate.getFullYear();
}

//similar to the function above but it handles a set start date
function setStartDate(f, intStartDate, intStartMonth, intStartYear) {
	//var f = document.idForm;
	var intNumDays = 1;
	f.nbdays.value = intNumDays;   //set nbdays to be 1 day
	
   var now = new Date();   //current date
	var myDate = new Date();
	myDate.setFullYear(intStartYear, intStartMonth, intStartDate);  //the specific Start Date
	
	if(myDate > now) {
		var dteArrivalDate = myDate;
		var dteDepartureDate = new Date(intStartYear, intStartMonth, (intStartDate + intNumDays));
	} else { 
		var dteArrivalDate = new Date(now.getTime() + (7*24*60*60*1000));   //set the Arrival Date to be 7 days after the current date
		var dteDepartureDate = new Date(now.getTime() + ((7 + intNumDays)*24*60*60*1000));   //set the Departure Date
	}
	f.txtArrivalDate.value = dteArrivalDate.getDate() + "/" + (dteArrivalDate.getMonth() + 1) + "/" + dteArrivalDate.getFullYear();
	f.fromday.value = dteArrivalDate.getDate();
	f.frommonth.value = dteArrivalDate.getMonth() + 1;
	f.fromyear.value = dteArrivalDate.getFullYear();
	
	f.txtDepartureDate.value = dteDepartureDate.getDate() + "/" + (dteDepartureDate.getMonth() + 1) + "/" + dteDepartureDate.getFullYear();
	f.endday.value = dteDepartureDate.getDate();
	f.endmonth.value = dteDepartureDate.getMonth() + 1;
	f.endyear.value = dteDepartureDate.getFullYear();
}

//added on 30th May 2008
function GoogleLocationMapPopUp() {
	window.open("location_map_google.php", "", "width=670, height=520, resizable=no");	
}

function NormalLocationMapPopup() {
	window.open("location_map_normal.php", "", "width=800, height=650, resizable=no, scrollbars=yes");	
}

//added on 9th December 2009 as an extra layer of validation for the More Options
function checkMoreOptions(f) {
	var strClustername = f.Clusternames.value;
	if(f.Hotelnames.value != 'All') {
		strClustername = f.Hotelnames.value;
	}
	hhotelSearch(strClustername, f.langue.value, '', '', '', '', '');
}