
var RowHighlighter=Class.create({initialize:function(Row)
{this.rows=new Array(Row);for(var i=1;i<5;i++)
this.rows.push((Row=Row.next()));this.link=this.rows[0].select('a')[0].readAttribute('href');this.rows.each((function(row){Event.observe(row,'mouseover',this.highlight.bind(this));Event.observe(row,'mouseout',this.dehighlight.bind(this));Event.observe(row,'click',this.go.bind(this));}).bind(this));},highlight:function()
{this.rows.each(function(row){row.addClassName('over');});},dehighlight:function()
{this.rows.each(function(row){row.removeClassName('over');});},go:function()
{document.location=this.link;}});var s_county;var s_city;var s_city_part;var d_defaults;function s_is_default(i,v)
{return s_defaults!==null&&s_defaults[i].length>0&&s_defaults[i]==v;}
function update_cities()
{var county_id=$F(s_county);s_city.update();s_city.insert({bottom:new Element('option',{'value':-1})});if(county_id>=0)
{(location_info.get(county_id)).cities.each(function(pair)
{var city_info=pair.value;var city_id=pair.key;var o=new Element('option',{'value':city_id}).update(city_info.name);if(s_is_default(1,city_id))
o.selected=true;s_city.insert({bottom:o});});}
else
{location_info_special.each(function(city_info)
{var o=new Element('option',{'value':city_info.id}).update(city_info.name);s_city.insert({bottom:o});});}
update_city_parts();}
function update_city_parts()
{var county_id=$F(s_county);var city_id=$F(s_city);s_city_part.disable();s_city_part.update();s_city_part.insert({bottom:new Element('option',{'value':-1})});if(city_id==-1)
return;if(county_id==-1)
{var ids;ids=city_id.split('_');if(ids.length!=2)
return;county_id=ids[0];city_id=ids[1];}
if(county_id>=0&&city_id>=0)
{((location_info.get(county_id)).cities.get(city_id)).city_parts.each(function(pair)
{var city_part=pair.value;var city_part_id=pair.key;var o=new Element('option',{'value':city_part_id}).update(city_part);if(s_is_default(2,city_part_id))
o.selected=true;s_city_part.insert({bottom:o});});s_city_part.enable();}}
var sort_popup=null;function toggle_sort_popup(e)
{if(sort_popup==null)
return;if(sort_popup.visible())
sort_popup.hide();else
{var trgt=Event.element(e);var dim=trgt.getDimensions();var off=trgt.cumulativeOffset();sort_popup.setStyle({display:'block',position:'absolute',top:(off.top+dim.height-5)+'px',left:(off.left+dim.width-sort_popup.getWidth())+'px'});}}
Event.observe(window,'load',function()
{($$('#kuulutused .obj_list tr.row')).each(function(he){new RowHighlighter(he);});s_county=$('search_county');s_city=$('search_city');s_city_part=$('search_city_part');s_defaults=($F($('search_location'))).split('_');s_county.disable();s_city.disable();s_city_part.disable();s_county.insert({bottom:new Element('option',{'value':-1})});location_info.each(function(pair)
{var county_info=pair.value;var county_id=pair.key;var o=new Element('option',{'value':county_id}).update(county_info.name);if(s_is_default(0,county_id))
o.selected=true;s_county.insert({bottom:o});});s_county.enable();update_cities();s_city.enable();s_defaults=null;Event.observe(s_county,'change',update_cities);Event.observe(s_city,'change',update_city_parts);sort_popup=($$('#kuulutused .obj_list_sort')).first()
if(sort_popup!=null)
{sort_popup.hide();($$('#kuulutused .obj_list_sort_trigger')).each(function(trig)
{trig.setStyle({cursor:'pointer'});Event.observe(trig,'click',toggle_sort_popup);});}
var gotoField=$('ikodu_id_goto');gotoField.observe('blur',function()
{if(gotoField.value=='')
return;gotoField.form.submit();});});
