function GetCountry(b){if(isNaN(b)){return null}for(var a=0;a<countries.length;a++){if(countries[a].Id==b){return countries[a]}}return null}function GetRegion(b){if(isNaN(b)){return null}for(var a=0;a<regions.length;a++){if(regions[a].Id==b){return regions[a]}}return null}function GetHotel(b){if(isNaN(b)){return null}for(var a=0;a<hotels.length;a++){if(hotels[a].Id==b){return hotels[a]}}return null}function SelectAssociatedCountry(c,a){var b=GetRegion(c);if(b==null){return}jQuery("#"+a.id).find("option").each(function(){var d=jQuery(this);d.attr("selected",d.attr("value")==b.CountryId)})}function SelectAssociatedRegion(b,a){var c=GetHotel(b);if(c==null){return}jQuery("#"+a.id).find("option").each(function(){var d=jQuery(this);d.attr("selected",d.attr("value")==c.RegionId)})}function GetOptionGroupLabelText(b,a){return b+" - "+a}function FilterHotelsByRegion(c,b,a){if(b==null){return}if(c==null){for(index=0;index<c.AssociatedHotels.length;index++){if(c.AssociatedHotels[index].Title==""){continue}AddDropDownOption(b,c.AssociatedHotels[index].Title,c.AssociatedHotels[index].Id,GetOptionGroupLabelText(c.AssociatedHotels[index].CountryName,c.AssociatedHotels[index].RegionName))}}else{for(index=0;index<hotels.length;index++){if(hotels[index].Title==""||hotels[index].RegionId!=c.Id){continue}AddDropDownOption(b,hotels[index].Title,hotels[index].Id,null)}if(c.AssociatedHotels==null||c.AssociatedHotels.length==0){b.selectedIndex=0;return}}jQuery("#"+b.id).find("option").each(function(){var d=jQuery(this);d.attr("selected",d.attr("value")==a)})}function FilterHotelsByCountry(c,b,a){if(b==null){return}if(c==null){for(index=0;index<hotels.length;index++){if(hotels[index].Title==""){continue}AddDropDownOption(b,hotels[index].Title,hotels[index].Id,GetOptionGroupLabelText(hotels[index].CountryName,hotels[index].RegionName))}}else{for(index=0;index<hotels.length;index++){if(hotels[index].Title==""||hotels[index].CountryId!=c.Id){continue}AddDropDownOption(b,hotels[index].Title,hotels[index].Id,GetOptionGroupLabelText(hotels[index].CountryName,hotels[index].RegionName))}if(c.AssociatedRegions==null||c.AssociatedRegions.length==0){b.selectedIndex=0;return}}jQuery("#"+b.id).find("option").each(function(){var d=jQuery(this);d.attr("selected",d.attr("value")==a)})}function FilterRegions(b,a){var c=GetCountry(b);if(a==null||a==undefined){return}ClearDropDownOptionGroups(a);ClearDropDownOptions(a);if(c==null){for(index=0;index<regions.length;index++){if(regions[index].Title==""){continue}AddDropDownOption(a,regions[index].Title,regions[index].Id,regions[index].CountryName)}}else{for(index=0;index<regions.length;index++){if(regions[index].Title==""||regions[index].CountryId!=c.Id){continue}AddDropDownOption(a,regions[index].Title,regions[index].Id,null)}}a.selectedIndex=0}function SelectHotelRegionAndCountry(e,d,c,b){countryControl=document.getElementById(e);regionControl=document.getElementById(d);hotelControl=document.getElementById(c);hotelSelectedValueControl=document.getElementById(b);var a=parseInt(hotelControl.options[hotelControl.selectedIndex].value);var f=GetHotel(a);if(f==null){return}hotelSelectedValueControl.value=a.toString();jQuery("#"+regionControl.id).find("option").each(function(){var g=jQuery(this);g.attr("selected",g.attr("value")==f.RegionId.toString())});FilterHotels(e,d,c,b,true,true);SelectAssociatedCountry(f.RegionId,countryControl)}function FilterHotels(l,j,k,a,h,f){countryControl=document.getElementById(l);regionControl=document.getElementById(j);hotelControl=document.getElementById(k);hotelSelectedValueControl=document.getElementById(a);var i;if(f){i=hotelSelectedValueControl.value}else{i=""}var b,g;if(f){var e=GetHotel(i);if(e!=null){b=GetCountry(e.CountryId);g=GetRegion(e.RegionId);SelectAssociatedCountry(e.RegionId,countryControl);FilterRegions(e.CountryId,regionControl);SelectAssociatedRegion(e.Id,regionControl)}else{if(regionControl.options[regionControl.selectedIndex].value!=null&&regionControl.options[regionControl.selectedIndex].value!=""){var d=parseInt(regionControl.options[regionControl.selectedIndex].value);g=GetRegion(d);b=GetCountry(g.CountryId);SelectAssociatedCountry(g.Id,countryControl);FilterRegions(b.Id,regionControl);jQuery("#"+regionControl.id).find("option").each(function(){var m=jQuery(this);m.attr("selected",m.attr("value")==g.Id)})}else{if(countryControl.options[countryControl.selectedIndex].value!=null&&countryControl.options[countryControl.selectedIndex].value!=""){var c=parseInt(countryControl.options[countryControl.selectedIndex].value);b=GetCountry(c);FilterRegions(b.Id,regionControl)}}}}else{if(h&&regionControl.options[regionControl.selectedIndex].value!=null&&regionControl.options[regionControl.selectedIndex].value!=""){var d=parseInt(regionControl.options[regionControl.selectedIndex].value);g=GetRegion(d);b=GetCountry(g.CountryId);SelectAssociatedCountry(g.Id,countryControl)}else{if(countryControl.options[countryControl.selectedIndex].value!=null&&countryControl.options[countryControl.selectedIndex].value!=""){var c=parseInt(countryControl.options[countryControl.selectedIndex].value);b=GetCountry(c);FilterRegions(b.Id,regionControl);SelectAssociatedRegion(i,regionControl)}else{if(!h){FilterRegions(null,regionControl)}}}}ClearDropDownOptionGroups(hotelControl);ClearDropDownOptions(hotelControl);if(g!=null){FilterHotelsByRegion(g,hotelControl,i)}else{if(b!=null){FilterHotelsByCountry(b,hotelControl,i)}else{for(index=0;index<hotels.length;index++){if(hotels[index].Title==""){continue}AddDropDownOption(hotelControl,hotels[index].Title,hotels[index].Id,GetOptionGroupLabelText(hotels[index].CountryName,hotels[index].RegionName))}}}}function FilterRegionsWithoutHotel(j,i,f,h,e){countryControl=document.getElementById(j);regionControl=document.getElementById(i);regionSelectedValueControl=document.getElementById(f);var d;if(e){d=regionSelectedValueControl.value}else{d=""}var a,g;if(e){g=GetRegion(d);if(regionControl.options[regionControl.selectedIndex].value!=null&&regionControl.options[regionControl.selectedIndex].value!=""){a=GetCountry(g.CountryId);SelectAssociatedCountry(d,countryControl);FilterRegions(a.Id,regionControl);jQuery("#"+regionControl.id).find("option").each(function(){var k=jQuery(this);k.attr("selected",k.attr("value")==d)})}else{if(countryControl.options[countryControl.selectedIndex].value!=null&&countryControl.options[countryControl.selectedIndex].value!=""){var c=parseInt(countryControl.options[countryControl.selectedIndex].value);a=GetCountry(c);FilterRegions(a.Id,regionControl)}}}else{if(h&&regionControl.options[regionControl.selectedIndex].value!=null&&regionControl.options[regionControl.selectedIndex].value!=""){var b=parseInt(regionControl.options[regionControl.selectedIndex].value);g=GetRegion(b);a=GetCountry(g.CountryId);SelectAssociatedCountry(g.Id,countryControl)}else{if(countryControl.options[countryControl.selectedIndex].value!=null&&countryControl.options[countryControl.selectedIndex].value!=""){var c=parseInt(countryControl.options[countryControl.selectedIndex].value);a=GetCountry(c);FilterRegions(a.Id,regionControl)}else{if(!h){FilterRegions(null,regionControl)}}}}};
