﻿
function atm_rearangeResultsList(){
	var resholder = $('atm_results');
	var divs = resholder.getElementsByTagName('div');
	var div;
	var yb,yt;
	var hasLabel = false;
	var str;
	for(i=0;i<divs.length;i++){
		div = divs[i];
		yt = div.offsetTop - resholder.scrollTop;
		yb = yt + div.offsetHeight;
		if((yt <= -14) && (yb>=0)){
			hasLabel = true;
			str = div.getAttribute('City').bold();
			if($('atm_results_header').innerHTML!=str){
				Element.update('atm_results_header', str);
			}
		}
	}
	if(!hasLabel) Element.update('atm_results_header', '');
}

function atm_show(atmid){
	//DEPRICATED
}

function atm_cityChange(){
	var _select = $('atm_cities_list');
	
	if($('MapIconsHolder').CurrentIcon)
		$('MapIconsHolder').CurrentIcon.src = "/uploads/map/fiblogo_gray_small.gif";
	if($(_select.options[_select.selectedIndex].value))
		$(_select.options[_select.selectedIndex].value).src = "/uploads/map/fiblogo_small.gif";	
	
	_select.style.color = _select.options[_select.selectedIndex].style.color;
	$('atm_filters').CurrentKey = _select.options[_select.selectedIndex].value;
	atm_loadResults();
}

function atm_loadResults(){
	if($('atm_filters').CurrentKey == 'NONE') return;
	var _url = '/bg/server/show/operate/atm_results/key/';
	_url += $('atm_filters').CurrentKey + '/addkey/' + encodeURIComponent($('atm_additional_key').value);
	new Ajax.Updater(
		'atm_results', 
		_url, 
		{
				asynchronous:true, 
				evalScripts:true, 
				onComplete:function(){map_changeIndicatorState(false);}, 
				onLoading:function(){map_changeIndicatorState(true);}
		}
	);
}

// These functions are cross related with map module
function map_afterIconClick(imgID){
	$('atm_filters').CurrentKey = imgID;
	$('atm_cities_list').selectedIndex = $('city'+imgID).index;
	atm_cityChange();
	//new Ajax.Updater('atm_results', '/bg/server/show/operate/atm_results/key/'+img.id, {asynchronous:true, evalScripts:true, onComplete:function(){map_changeIndicatorState(false);}, onLoading:function(){map_changeIndicatorState(true);}}); 
}
function map_afterRegionClick(regID){
	$('atm_filters').CurrentKey = $(regID).getAttribute('Region');
	$('atm_cities_list').selectedIndex = $('opt_'+regID).index;
	atm_cityChange();
}
