



var layer_geo = new Layer("citySearch", "searchTypeCity");
var layer_address = new Layer("addressSearch", "searchTypeAddress");
var layer_poi = new Layer("poiSearch", "searchTypePOI");
var searchLayerGroup = new LayerGroup();
searchLayerGroup.setLayerGroup(new Array(layer_geo, layer_address, layer_poi));
searchLayerGroup.setClassNames("radiobutton", "radiobutton");

var filter_price_rates = new Layer("filter_price_rates", "link_filter_price_rates");
filter_price_rates.setLayerClassNames("show", "hidden");
filter_price_rates.setTexts("Price range", "Price range");

var filter_characteristics = new Layer("filter_characteristics", "link_filter_characteristics");
filter_characteristics.setLayerClassNames("show", "hidden");
filter_characteristics.setTexts("Characteristics", "Characteristics");

var filter_services = new Layer("filter_services", "link_filter_services");
filter_services.setLayerClassNames("show", "hidden");
filter_services.setTexts("Services", "Services");

var urlCalendarAdvanced_iFrame = '/nh/Layer.Controller?event=3&formName=searchForm&calendarDivName=calendar&fIniVisualInputName=stdate&fIniInputName=fini&fOutVisualInputName=enddate&fOutInputName=fout&twoDates=1&twoMonth=1&dateSelectedID=dateSelected';

var SHORT_MONTH_NAMES = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

function initSearch() {
	var f = document.searchForm;

	// back browser
	var stype = f.stype.value;
	if (stype != 1) {
		searchLayerGroup.showSelectedLayer(stype - 1);
	}

	if(f.country1.selectedIndex > 0)
		changeCountry(f.country1, f.city1, f.hotel1, 'All cities', 'All hotels');

	if(f.country2.selectedIndex > 0)
		changeCountry(f.country2, f.city2, null, 'Select a city', null, jsCitiesSearch);

	if(f.country3.selectedIndex > 0)
		changeCountry(f.country3, f.city3, null, 'Select a city', null, jsCitiesSearch);

	// Init Quick Search Element
	//auto = new AutoSuggest(document.getElementById('stext1'), document.searchForm.country1, document.searchForm.city1, document.searchForm.hotel1, quickSearchResults, "submitAdvancedSearchForm()");
	//document.searchForm.stext1.value = 'City, hotel or point of interest' ;

	// B. Load page
	changeSearchMethod(sType);
	loadAll(country, city, hotel, f.stype.value);

	// C. Preload Calendar Dates
	if (searchParameters_fIni != null && searchParameters_fIni != '') {
		f.stdate.value = createVisualFormattedDate(createDateFromCode(searchParameters_fIni), SHORT_MONTH_NAMES);
		f.fini.value = searchParameters_fIni;
		f.enddate.value = createVisualFormattedDate(createDateFromCode(searchParameters_fOut), SHORT_MONTH_NAMES);
		f.fout.value = searchParameters_fOut;
	}

	// D. Preload filters selected
	initServices();
}

function submitAdvancedSearchForm() {
	var url = submitSearchForm();
	if (url === false) return;

	var servicesString = "";
	var element;
	for(i = 0; i < numServices; i++) {
		element = document.getElementById("service_" + i);
		if(element.checked == true) { servicesString+= element.value + ","; }
	}
	servicesString = servicesString.substring(0, servicesString.length-1);
	if (servicesString != "") { url+= "&services=" + servicesString; }

	var roomsString = "";
	for(i = 0; i < numRooms; i++) {
		element = document.getElementById("room_" + i);
		if(element.checked == true) { roomsString+= element.value + ","; }
	}
	roomsString = roomsString.substring(0, roomsString.length-1);
	if (roomsString != "") { url+= "&rooms=" + roomsString; }

	document.location.href = url;
}

function initServices() {
	for(var i = 0; i < numServices; i++) {
		var check = document.getElementById("service_" + i);
		if (servicesSelected[check.value] != null) {
			check.checked = true;
		}
	}
	for(var i = 0; i < numRooms; i++) {
		var check = document.getElementById("room_" + i);
		if (servicesSelected[check.value] != null) {
			check.checked = true;
		}
	}
}