var options = {
	//script: "ajax/getLocationSuggestions.php?",
	script: function (input) { return url+"ajax/getLocationSuggestions.php?location="+input+"&country=all"; },
	//varname: "hotelLocationHF",
	callback: function (obj) { byId('hotelSelectedLocation').value = obj.id; storedHotelSearchText = byId('hotelLocation').value; },
	json: true,
	maxresults: 35,
	timeout: -1,
	minchars: 3
};
var as;

function hostelCountryChanged(){
	var countrySel = byId('hostelCountry');
	var selectedCountry = countrySel.options[countrySel.selectedIndex].value;
	
	rebuildHostelCitySB(selectedCountry);
}

function rebuildHostelCitySB(selectedCountry){
	var citySB = byId('hostelCity');
	
	//var first = false;
	
	//var html = '<select name="hostelCity" id="hostelCity"><option value="top">-Choose city-</option>';
	var newSB = citySB.cloneNode(false);
	newSB.appendChild(citySB.options[0].cloneNode(true));
	
	//var first = byId('hostelCitySelectCountryFirst'+selectedCountry.replace(' ', '_')).value;
	//var first = byId('hbFirst'+selectedCountry.replace(' ', '_')).value;
	
	/*for(i=first, selectedSet=false, endFound=false; !endFound; i++){
		//if(valsSel = byId('hostelCitySelectVals'+i)){
		if(valsSel = byId('hbVals'+i)){
			vals = valsSel.value.split('*');
			
			selCountry = vals[0];
			selCityID = vals[1];
			selCityName = vals[2];
		}
		else{
			selCountry = '';	
		}
		if(selCountry == selectedCountry){
			opt = document.createElement('option');
			opt.setAttribute('value', selCityID);
			
			opt.appendChild(document.createTextNode(selCityName));
			
			newSB.appendChild(opt);	
		}
		else{
			endFound = true;
		}			
	}*/

	eval('var cities = hbCityArray.'+selectedCountry.replace(' ', '_')+';');
	
	for(var i=0; i < cities.length; i++){
		//if(valsSel = byId('hostelCitySelectVals'+i)){
		//if(valsSel = byId('hbVals'+i)){
			vals = cities[i].split('*');
			
			//selCountry = vals[0];
			selCityID = vals[0];
			selCityName = vals[1];
		//}
		//else{
		//	selCountry = '';	
		//}
		//if(selCountry == selectedCountry){
			opt = document.createElement('option');
			opt.setAttribute('value', selCityID);
			
			opt.appendChild(document.createTextNode(selCityName));
			
			newSB.appendChild(opt);	
		//}
		//else{
		//	endFound = true;
		//}			
	}	
	//html += '</select>';
	//alert('yes');
	//byId('hostelSelectContainer').innerHTML = html;;
	citySB.parentNode.replaceChild(newSB, citySB);
	newSB.selectedIndex = 1;
};

function doHostelSearch(){
	with(document.hostelSearchForm){
		var citySel = byId('hostelCity');
		
		var temp = citySel.options[citySel.selectedIndex].value;//.split('*')[1];
		
		if(temp == 'top'){
			alert('Please select a city');
			return false;
		}
		else{
			//byId('hostelCity').value = temp.split('*')[1];
			submit();
		}	
	}
};

var storedHotelSearchText = '';

function doHotelSearch(){
	with(document.hotelSearchForm){
		var hiddenSB = byId('hotelSelectedLocation');
		var textSB = byId('hotelLocation');
		
		textSB.value = trim(textSB.value);
		
		if(storedHotelSearchText != textSB.value){
			byId('hotelSelectedLocation').value = '';	
		}
		
		if(hiddenSB.value == '' && textSB.value == ''){
			alert('Please enter a location');
			textSB.select();
			
			return false;
		}
		//alert(byId('hotelSelectedLocation').value);
		/*
		var citySel = byId('hostelCity');
		
		var temp = citySel.options[citySel.selectedIndex].value;//.split('*')[1];
		
		if(temp == 'top'){
			alert('Please select a city');
			return false;
		}
		else{
			//byId('hostelCity').value = temp.split('*')[1];
			submit();
		}	*/
		submit();
	}
};

function changeSearchForm(formToShow){
	if(formToShow == 'hostel'){
		document.hostelSearchForm.className = '';
		document.hotelSearchForm.className = 'noDisplay';
	}
	else{
		document.hotelSearchForm.className = '';
		document.hostelSearchForm.className = 'noDisplay';
	}		
};