
var
	c_list = 0,
	hs = 0,
	hsrc = '',	// src скрытого дива с надписью "загружаю..."
	cmodel = 0,
	models_sz = [],
	c_sts = [],
	o_sts = [],
	loaded = [],
	maincity = 0,
	cstr = '<table cellspacing=0 cellpadding=0 border=0 class="f_city_tb" width=174><tr><td><div class="prom_td"></div></td></tr><tr><td class="subtd"><table cellspacing=0 cellpadding=0 border=0><tr><td id="model0" class="city_td">Список загружается...</td></tr></table></td></tr></table><table cellspacing=0 cellpadding=0 class="bottom_tb" width=174><tr><td class="bottom_left_td"></td><td class="bottom_center_td">&nbsp;</td><td class="bottom_right_td"></td></tr></table></div>',
	metros = [],
	salons = [],
	doc = document
;

c_sts['city'] = 0; c_sts['salon'] = 0; c_sts['model'] = 0; c_sts['metro'] = 0;
o_sts['city'] = ''; o_sts['salon'] = ''; o_sts['model'] = ''; o_sts['metro'] = '';
loaded['city']=0; loaded['model']=0; loaded['metro']=0; loaded['salon']=0;

function selectCity(obj, d){if(d){obj.className+='_over';}else{obj.className=obj.className.replace('_over','');}}
function setCityList(){var lst=document.getElementById("city_list_div"); var st='block'; if(c_list){st='none';} lst.style.display=st; c_list=Math.abs(c_list-1);}
function setCity(id){if(!id){return;}document.getElementById("sel_city_div").innerHTML = document.getElementById("hid_city"+id).value; document.sel_city.city_code.value=document.getElementById("hid_city_code"+id).value}
function setReloadCity(){var cit=document.sel_city.city_code.value; if(cit!=''){location.href='/_cities/'+cit+'/';}}
function showSalons(model, city, logo, x, y){
 if(logo){document.getElementById("model_logo").innerHTML = "<img src='"+phs_fold+"/"+logo+"'>";}
 if(!models_sz['id'+model]){return;}

 var dv = document.getElementById("hidsalon");
 dv.style.left = x+3; dv.style.top = y+document.body.scrollTop;
 hs=0;
 if(model!=cmodel){dv.innerHTML = hsrc;}
 dv.style.display = 'block';  if(model!=cmodel){hid_fr.location.href = '/getsalons.php?model='+model+'&city='+city; cmodel=model;}
}
function hideSalons(){if(hs){hideLogo(); document.getElementById("hidsalon").style.display = 'none';}}
function setSalonsInfo(nstr){document.getElementById("hidsalon").innerHTML = nstr;}
function hideLogo(){document.getElementById("model_logo").innerHTML = "&nbsp;";}
function selectFList(obj, d){if(d){obj.className+='_over';}else{obj.className=obj.className.replace('_over','');}}

function setFListStat(v){
	if((v=='metro' || v=='salon') && doc.getElementById("search_city_code").value=='')
		return;
	
	var
		lst = doc.getElementById("f_"+v+"_list_div"),
		st = 'block'
	;
	if(c_list)
		st = 'none';

	//alert('v='+v+', loaded='+loaded[v]+', st='+st);
	if(!loaded[v] && v!='city' && st=='block'){
		lst.style.display = st;
		c_list = Math.abs(c_list-1);
		lst.innerHTML = cstr;
		var uri = '/getList.php?v='+v+(v=='metro'||v=='salon'?'&city='+maincity:'');
		hid_fr.location.href = uri;
	} else {
		var
			lst = doc.getElementById("f_"+v+"_list_div"),
			st = 'block'
		;
		if(c_list)
			st='none';
		
		lst.style.display = st;
		c_list = Math.abs(c_list-1);
	}
	
	//alert(c_list);
}

function setFList(id, v){
 if(o_sts[v]!=''){var obj=document.getElementById(v+'_'+o_sts[v]); if(obj!=null){document.getElementById(v+'_'+o_sts[v]).className = 'city_td';}}
 if(id!=0){document.getElementById(v+'_'+id).className = 'def_city'; o_sts[v] = id;}else{o_sts[v]='';}
 document.getElementById(v+"_value").innerHTML = document.getElementById("hid_"+v+id).value; document.getElementById("search_"+v+"_code").value=document.getElementById("hid_"+v+"_code"+id).value;
 if(v=='city'){setMetros(id); setSalons(id); maincity=id;}
}

function setMetros(cid){
 loaded['metro']=0;
 var msg='---- Неважно ----'; if(cid==0){msg='---- Выберите город ----';}
 document.getElementById("f_metro_list_div").innerHTML = metros['city'+cid];
 document.getElementById("search_metro_code").value='';
 document.getElementById("metro_value").innerHTML=msg;
}

function setSalons(cid){loaded['salon']=0; var msg='---- Неважно ----';if(cid==0){msg='---- Выберите город ----';} document.getElementById("f_salon_list_div").innerHTML = salons['city'+cid]; document.getElementById("search_salon_code").value=''; document.getElementById("salon_value").innerHTML=msg;}
function searchSubm(){
 var s=document.getElementById("search_salon_code").value;
 var c=document.getElementById("search_city_code").value;
 var mo=document.getElementById("search_model_code").value;
 var me=document.getElementById("search_metro_code").value;
 if(c!='' || s!='' || mo!='' || me!=''){document.search_form.submit();}else{alert('Укажите параметры поиска!');}
}
