scrl=null; spa_menu_h=null;
spa_menu_h=readCookie('spa_menu_h');
spa_path='/';

function spa_menu_show(){
	if(spa_menu_h=='1' || spa_menu_h==null){
		spa_menu_h='0';
		document.getElementById('spa_menu').style.display='none';
		document.getElementById('menu_hide_txt').innerHTML='Показать разделы СПА-энциклопедии';
		document.getElementById('menu_hide_txt').className='hide hide_p';

		createCookie('spa_menu_h', spa_menu_h, 0);
	}
	else{
		spa_menu_h='1';
		document.getElementById('spa_menu').style.display='';
		document.getElementById('menu_hide_txt').innerHTML='Скрыть разделы СПА-энциклопедии';
		document.getElementById('menu_hide_txt').className='hide hide_m';

		createCookie('spa_menu_h', spa_menu_h, 0);
	}
}

function spa_menu_init(){
	if(spa_menu_h=='0'){
		spa_menu_h='1';
		spa_menu_show();
	}
}

// SPA-menu
var spa_blocks=[];
function spa_change_img(block_id, img){
	if(img=='') document.getElementById('spa_img_'+block_id).src=spa_blocks[block_id];
	else document.getElementById('spa_img_'+block_id).src=img;
}

function spa_scroll2act(par_elm, elm){
	if(elm=document.getElementById(elm)){
		par_elm=document.getElementById(par_elm);
		if(elm.offsetTop>(par_elm.offsetHeight-100))
			par_elm.scrollTop=elm.offsetTop-100;
	}
}

function spa_scroll_hide(elm, elm_ul, b1, b2){
	elm=document.getElementById(elm);
	elm_ul=document.getElementById(elm_ul);
	if(elm_ul.offsetHeight<elm.offsetHeight){
		document.getElementById(b1).style.display='none';
		document.getElementById(b2).style.display='none';
	}
}

function spa_loaded(){
	// preloading images
	tmp_img=new Image();
	tmp_img.src=spa_path+'img/site/spa/menu_a.gif';
	tmp_img.src=spa_path+'img/site/spa/hide_menu_p.gif';

	if(scrl==null) return;
	// scroll sub-menu to current position
	spa_scroll2act('scroll_list', 'spa_sub_active');
	scrl.init();
	spa_scroll_hide('scroll_list', 'scroll_list_ul', 'scroll_btn_1', 'scroll_btn_2');
}

var spa_indication=[];
function spa_hide_ind(){
	for(i in spa_indication){
		for(n=1; n<=spa_indication[i]; n++)
			document.getElementById('spa_indication_'+i+'-'+n).style.display='none';
	}
}

function spa_htl_search(countries, cities){
	this.countries=countries; this.cities=cities;
	this.countries_elm=null; this.cities_elm=null;
	this.lst_countries=[]; this.lst_cities=[]; this.city2url=[];

	this.host='';
	this.new_win=false;

	this.init=function(){
		this.countries_elm=document.getElementById(this.countries);
		this.cities_elm=document.getElementById(this.cities);
		for(i in this.lst_countries)
			this.countries_elm.options.add(new Option(this.lst_countries[i], i));
		this.countries_elm.onchange();
	};

	this.add=function(country, country_id, city, city_id, url){
		this.lst_countries[country_id]=country;
		this.city2url[city_id]=url;
		if(this.lst_cities[country_id]==undefined) this.lst_cities[country_id]=[];
		this.lst_cities[country_id][city_id]=city;
	};

	this.loadCities=function(country_id){
		ClearSelectElements(this.cities_elm)
		for(i in this.lst_cities[country_id])
			this.cities_elm.options.add(new Option(this.lst_cities[country_id][i], i));
	};

	this.submit=function(){
		this.open(this.city2url[this.cities_elm.value]);
	};

	this.open=function(url){
		if(this.new_win) window.open(this.host+url);
		else window.location=this.host+url;
	};
}
