function SelectedHotel( source, eventArgs ) {
   //window.open("propertydetail_v2.aspx?id=" + eventArgs.get_value(),window.name)
   //+ "&" + Utilities.ReviewsURL(dr["hotel_id"].ToString()); 
    hidHotel =  document.getElementById(hidHotelClientId) ;
   hidHotel.value = eventArgs.get_value();
   hidDest =  document.getElementById(hidDestinationClientId) ;
   hidDest.value = ""
   document.forms[0].submit();
   }
function SelectedDestination( source, eventArgs ) {
   //window.open("propertydetail_v2.aspx?id=" + eventArgs.get_value(),window.name)
   //+ "&" + Utilities.ReviewsURL(dr["hotel_id"].ToString()); 
   
   hidDest =  document.getElementById(hidDestinationClientId) ;
   hidDest.value = eventArgs.get_value();
//   if (hidHotelClientId!='undefined')
//   {
//   hidHotel =  document.getElementById(hidHotelClientId) ;
//   hidHotel.value = ""
//   }
   document.forms[0].submit();
   
}
// handles the navigation drop down onChange event
function navChange(selectObj) {
		var quickSearchType = selectObj.options[selectObj.selectedIndex].value;
		var ddListToLoad;

		switch(quickSearchType) {
			case "continent": // By Continent
				ddListToLoad = document.getElementById("ddlContinents");
				toggleDropDownList(document.getElementById("ddlContinents"), true);
				toggleDropDownList(document.getElementById("ddlCountries"), false);
				toggleDropDownList(document.getElementById("ddlStates"), false);
				toggleDropDownList(document.getElementById("ddlDestinations"), false);
				//BLM 20090601 This is breaking FireFox, need getelementbyid
				//toggleDropDownList(usaFilter, false);
				toggleDropDownList(document.getElementById("usaFilter"), false);
				break;
			case "country": // By Country
				ddListToLoad = document.getElementById("ddlCountries");
				toggleDropDownList(document.getElementById("ddlContinents"), false);
				toggleDropDownList(document.getElementById("ddlCountries"), true);
				toggleDropDownList(document.getElementById("ddlStates"), false);
				toggleDropDownList(document.getElementById("ddlDestinations"), false);
				//toggleDropDownList(usaFilter, false);
				toggleDropDownList(document.getElementById("usaFilter"), false);
				break;
			case "state": // By State/Province
				ddListToLoad = document.getElementById("ddlStates");
				toggleDropDownList(document.getElementById("ddlContinents"), false);
				toggleDropDownList(document.getElementById("ddlCountries"), false);
				toggleDropDownList(document.getElementById("ddlStates"), true);
				toggleDropDownList(document.getElementById("ddlDestinations"), false);
				//toggleDropDownList(usaFilter, false);
				toggleDropDownList(document.getElementById("usaFilter"), false);
				break;
			case "destination": // By Desination
				ddListToLoad = document.getElementById("ddlDestinations");
				toggleDropDownList(document.getElementById("ddlContinents"), false);
				toggleDropDownList(document.getElementById("ddlCountries"), false);
				toggleDropDownList(document.getElementById("ddlStates"), false);
				toggleDropDownList(document.getElementById("ddlDestinations"), true);
				//toggleDropDownList(usaFilter, false);
				toggleDropDownList(document.getElementById("usaFilter"), false);
				break;
			default:
				toggleDropDownList(document.getElementById("ddlContinents"), false);
				toggleDropDownList(document.getElementById("ddlCountries"), false);
				toggleDropDownList(document.getElementById("ddlStates"), false);
				toggleDropDownList(document.getElementById("ddlDestinations"), false);
				//toggleDropDownList(usaFilter, false);
				toggleDropDownList(document.getElementById("usaFilter"), false);
				return;
				break;					
		}
		
		loadDropDownList(ddListToLoad, quickSearchType, "", "");						
		
}
			
// toggles the visibility of a dropdown
function toggleDropDownList(ddList, display) {
	
	if(display) {
		ddList.style.visibility = "visible";
		ddList.style.display = "block";
	}
	else {
		ddList.style.visibility = "hidden";
		ddList.style.display = "none";
	}
}
function LeftStr(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

var g_requestObj = null;			
// load a dropdown list using data from ListPopulator.aspx
function loadDropDownList(dropdownList, listType, filter, param, firstOptionText) {
	try {	
				
		if(g_requestObj == null)
			g_requestObj = getXmlHttpRequestObject();
			
		if (param.length > 0)
		{
			if(param.substring(1,6) == "select")
				param="";			
		}	
		
		var _undefined; // allows us to test for javascript "undefined" value
		if(firstOptionText == _undefined) {
			firstOptionText = 'Select ' + listType;
		}
		
		var url = "ListPopulator.aspx?type=" + listType + "&filter=" + filter + "&param=" + param;
		g_requestObj.open("GET", url, false);
		g_requestObj.send(null);
		
		if(g_requestObj.status == 200) {
		    x=g_requestObj.getResponseHeader("Content-Type");
		    x=LeftStr(x,8);
			if(x == "text/xml") {
				var doc = g_requestObj.responseXML;
				var rows = doc.getElementsByTagName("list_item");
				
				resetDropDownList(dropdownList, firstOptionText);				
				
				for(i = 0; i < rows.length; i++) {
					
					var opt = new Option(rows[i].getAttribute("item_value"), rows[i].getAttribute("item_id"));								
					
					dropdownList.options[dropdownList.options.length] = opt;								
				}
			}
		}
		else { // error
			throw new Error("Error getting list data.");
		}
	}
	catch(e) {
		alert("Error loading drop down list: " + e.description);
	}
}

// handles the onchange event for Country select
function handleCountryDropDown_onChange(selectObj) {
    if (document.getElementById("ddlCountries"))
    {	
	ddlCountry = document.getElementById("ddlCountries");
	}
	else
	{
	ddlCountry = document.getElementById(ddlCountriesClientId);
	}
	//ddlCountry=selectObj;
	filter = document.getElementById("usaFilter");
	
	if(ddlCountry.options[ddlCountry.selectedIndex].text == 'USA')
	{
		document.getElementById("optDestination").checked = true;
		toggleDropDownList(filter, true);
		loadDestinations(ddlCountry,'country');
	}
	else {
		toggleDropDownList(filter, false);
		if (document.getElementById("ddlStates"))
		{
		toggleDropDownList(document.getElementById("ddlStates"), false);
		}
		else
		{
		toggleDropDownList(document.getElementById(ddlStatesClientId), false);
		}
		loadDestinations(ddlCountry,'country');
	}	
	
}

function resetDropDownList(dropDownList, firstOptionText) {
	dropDownList.options.length = 0;				
	dropDownList.options[dropDownList.options.length] = new Option(firstOptionText, "-1");
}

//can't get search page to properly pass client id of control so it can be referenced properly
//hardcoding control names for now
function handleAdvancedSearchState_onChange(selectObj) {
	try {
		var ddlCountry = document.getElementById(ddlDestinationCountryClientId);
		var ddlState = document.getElementById(ddlStateClientId);
		var ddlDest = document.getElementById(ddlDestinationClientId);

		var param =  (selectObj.value == '-1') ? '' : selectObj.value;
		var optText = (selectObj.value == '-1') ? 'All Destinations' : 'Select Destination';
		
		loadDropDownList(ddlDest, 'destination', 'state', param, optText);
	}
	catch(e) {
		alert('handleAdvancedSearchState_onChange error:' +  e.description);
	}
}

function handleAdvancedSearchCountry_onChange(selectObj) {
	try {
		var ddlCountry = document.getElementById(ddlDestinationCountryClientId);
		var ddlState = document.getElementById(ddlStateClientId);
		var ddlDest = document.getElementById(ddlDestinationClientId);
		 
		if(selectObj.value == '-1')  {
			loadDropDownList(ddlDest, 'destination', '', '', 'All Destinations');
			loadDropDownList(ddlState, 'state', '', '', 'All States');
		}
		else {
			var param = selectObj.value;
			loadDropDownList(ddlDest, 'destination', 'country', param, 'Select Destination');
			loadDropDownList(ddlState, 'state', 'country', param, 'Select State');
		}
	}
	catch(e) {
		alert('handleAdvancedSearchCountry_onChange error: ' + e.description);
	}
}

function handleAdvancedSearchContinent_onChange(selectObj) {
	try {
		var ddlCountry = document.getElementById(ddlDestinationCountryClientId);
		var ddlState = document.getElementById(ddlStateClientId);
		var ddlDest = document.getElementById(ddlDestinationClientId);
				
		if(selectObj.value == "-1") {
			
			loadDropDownList(ddlCountry, 'country', '', '', 'All Countries');
			loadDropDownList(ddlDest, 'destination', '', '', 'All Destinations');
			loadDropDownList(ddlState, 'state', '', '', 'All States');
		}
		else {
		    var param = selectObj.value;
			loadDropDownList(ddlCountry, 'country', 'continent', param, 'Select Country');
			loadDropDownList(ddlDest, 'destination', 'continent', param, 'Select Destination');
			loadDropDownList(ddlState, 'state', 'continent', param, 'Select State');
		}	
	}
	catch(e) {
		alert("handleAdvancedSearchContinent_onChange error: " + e.description);
	}
}

// display UI control for USA based on radio selection
function filterUsa(radioObj) {	
    var ddlCountry;
	if (document.getElementById("ddlDestinations"))
	{
		ddlCountry = document.getElementById("ddlCountries");
		var ddlState = document.getElementById("ddlStates");
		var ddlDest = document.getElementById("ddlDestinations");
	}
	else
	{
	    ddlCountry = document.getElementById(ddlDestinationCountryClientId);
		var ddlState = document.getElementById(ddlStateClientId);
		var ddlDest = document.getElementById(ddlDestinationClientId);
	}
	
	if(radioObj.value == 'state') {
		toggleDropDownList(ddlDest, false);
		toggleDropDownList(ddlState, true);
		loadDropDownList(ddlState, 'state', 'country', ddlCountry.options[ddlCountry.selectedIndex].text, 'Select State');
	}
	else {
		toggleDropDownList(ddlState, false);
		toggleDropDownList(ddlDest, true);
		loadDestinations(ddlCountry,'country');
	}
}
			
// populates the destinations dropdownlist
function loadDestinations(selectObj, filter) {
	//desObj = document.getElementById(ddlDestinationClientId);
//	desObj = document.getElementById("ddlDestinations");
	if (document.getElementById("ddlDestinations"))
	{
	desObj = document.getElementById("ddlDestinations");
	}
	else
	{
	desObj = document.getElementById(ddlDestinationClientId);
	}
	toggleDropDownList(desObj, true);
	
	loadDropDownList(desObj, "destination", filter, selectObj.options[selectObj.selectedIndex].text, 'Select Destination');				
}
			
// handles the onchange event of ddlDestinations
function showDestination(selectObj) {
	if(selectObj.options[selectObj.selectedIndex].value == "-1")
		return;
		
	document.forms[0].submit();
}
			
// creates browser specific XMLHttpRequest object 
function getXmlHttpRequestObject() {
	
	var obj;
	
	if(typeof ActiveXObject != "undefined") { // IE
		obj = new ActiveXObject("Msxml2.XMLHTTP");	
	}
	else { // Mozilla
		obj = new XMLHttpRequest();
	}
	
	if(obj) {
		return obj;
	}
	else {
		throw new Error("XMLHttpRequest not supported");
	}
}
			
// code to execute when the page is loaded
//function startUp() {
//	navObj = document.getElementById("ddlNavType");
//	if(navObj != null )
//	    navObj.selectedIndex = 0;
//}