// загрузка списка районов для текущего региона
function load_areas_list(region_id, res_fld){
	set_select_options(res_fld, '0::Загрузка...');
	ajax_lookup('/LIBRARY/realty/ajax/areas.php?region=' + region_id, function(res){show_regions_list(res, res_fld);});
}

function show_regions_list(res, res_fld){
	set_select_options(res_fld, res);
}

function set_types_list(action, res_fld, value){
	if(action == 'rent')
		set_select_options(res_fld, ':://condominium::Студио//flat::Квартиры//house::Дома//vip::VIP', value);
	else
		set_select_options(res_fld, ':://condominium::Студио//flat::Квартиры//house::Дома//land::Земля//commercial::Коммерческая недвижимость', value);

	search_quick_from_builders();
}


// быстрый поиск: отображение опции "Недвижимость от застройщиков"
function search_quick_from_builders(){
	if(!document.getElementById('action_buy') || !document.getElementById('quick_search_types')) return;	var action = document.getElementById('action_buy').checked ? 'buy' : 'rent';
	var type = document.getElementById('quick_search_types').value;

	if(action == 'buy' && (type == 'condominium' || type == 'flat' || type == 'house')){
		document.getElementById('from_builders_block').style.display = 'block';
	}else{
		document.getElementById('from_builders_block').style.display = 'none';
	}
}



// быстрый поиск: смена диапазонов цен
function change_cost_ranges(act){	if(act == 'rent'){
		document.getElementById('q_search_cost_from1').style.display = '';
		document.getElementById('q_search_cost_to1').style.display = '';
		document.getElementById('q_search_cost_from2').style.display = 'none';
		document.getElementById('q_search_cost_to2').style.display = 'none';
		document.getElementById('q_search_cost_from3').style.display = 'none';
		document.getElementById('q_search_cost_to3').style.display = 'none';
	}else if(act == 'buy'){
		document.getElementById('q_search_cost_from1').style.display = 'none';
		document.getElementById('q_search_cost_to1').style.display = 'none';
		document.getElementById('q_search_cost_from2').style.display = '';
		document.getElementById('q_search_cost_to2').style.display = '';
		document.getElementById('q_search_cost_from3').style.display = 'none';
		document.getElementById('q_search_cost_to3').style.display = 'none';
	}else{
		document.getElementById('q_search_cost_from1').style.display = 'none';
		document.getElementById('q_search_cost_to1').style.display = 'none';
		document.getElementById('q_search_cost_from2').style.display = 'none';
		document.getElementById('q_search_cost_to2').style.display = 'none';
		document.getElementById('q_search_cost_from3').style.display = '';
		document.getElementById('q_search_cost_to3').style.display = '';
	}
}






// изменение формы поиска в зависимости от выбранных параметров
var r_params = new Array();
r_params['flat'] = new Array('square', 'bedrooms', 'status', 'sea_distance', 'cost_buy', 'cost_rent', 'features',		'drawing_rooms', 'bathrooms', 'conditioners', 'kitchen', 'view_of');
r_params['condominium'] = new Array('sea_distance', 'cost_buy', 'cost_rent', 'features',								'drawing_rooms', 'bathrooms', 'conditioners', 'kitchen', 'view_of');
r_params['house'] = new Array('square', 'bedrooms', 'square_land', 'sea_distance', 'cost_buy', 'cost_rent', 'features',	'drawing_rooms', 'bathrooms', 'conditioners', 'kitchen', 'view_of');
r_params['land'] = new Array('square_land', 'a_type_l', 'cost_buy');
r_params['commercial'] = new Array('square', 'a_type_c', 'cost_buy');
r_params['vip'] = new Array('vip_types');

var all_params = new Array('square', 'square_land', 'bedrooms', 'status', 'a_type_l', 'a_type_c', 'sea_distance', 'cost_buy', 'cost_rent', 'features',	'drawing_rooms', 'bathrooms', 'conditioners', 'kitchen', 'view_of', 'vip_types');
function config_search_form(){
	var type = document.getElementById('s_quick_search_types').value;
	for(i in all_params) document.getElementById(all_params[i] + '_block').style.display = in_array(all_params[i], r_params[type]) ? 'block' : 'none';

	if(type == 'flat') document.getElementById('status_block').style.display = document.getElementById('s_action_rent').checked ? 'none' : 'block';

	if(document.getElementById('s_action_rent').checked){
		document.getElementById('cost_rent_block').style.display = 'block';
		document.getElementById('cost_buy_block').style.display = 'none';
	}else if(document.getElementById('s_action_buy').checked){
		document.getElementById('cost_rent_block').style.display = 'none';
		document.getElementById('cost_buy_block').style.display = 'block';
	}else{
		document.getElementById('cost_rent_block').style.display = 'block';
		document.getElementById('cost_buy_block').style.display = 'block';
	}

	search_form_builders();
}

function search_form_builders(){	var action = document.getElementById('s_action_buy').checked ? 'buy' : 'rent';
	var type = document.getElementById('s_quick_search_types').value;

	if(action == 'buy' && (type == 'condominium' || type == 'flat' || type == 'house')){
		document.getElementById('s_from_builders_block').style.display = '';
	}else{
		document.getElementById('s_from_builders_block').style.display = 'none';
	}
}