function toggleCities()
{
  $("#cities-list").toggle();
  $('.under-element').toggle();
  $("#search-cities").toggleClass('search-cities-open');
}

function autocomplete_select_city(culture)
{
  if ($("#datex_path_filters_city").val())
  {	  
    closeCities($("#datex_path_filters_city").val(), culture);
    $('#cities-error').html('');
    clear_autocomplete_city();
  }
  else
  {
	clear_autocomplete_city()
	$('#cities-error').html(('bg' == culture ? 'Моля изберете град от списъка!' : 'Please select city from the list!'));
	return false;
  }
}

function clear_autocomplete_city()
{
  $("#autocomplete_datex_path_filters_city").val("");
  $("#datex_path_filters_city").val("");
}
function closeCities(city, culture)
{
  city = city.toUpperCase();
  l = ('БЪЛГАРИЯ' == city || 'BULGARIA' == city) ? 0 : 3;
  
  $("#search_location").val(city);
  $("#search_level").val(l);
  
  if ('bg' == culture)
  {
	prefix = ('В' == city.substr(0,1) || 'Ф' == city.substr(0,1)) ? 'във' : 'в';
    city = prefix + ' ' + city;  
  }
  
  if ('en' == culture)
  {
	city = 'in ' + city;  
  }
  
  $("#city-title").html(city);
  toggleCities();
  // TODO: more actions about selected city
}
function closeCitiesOnOut()
{
  $("#cities-list").hide();
  $('.under-element').show();
  $("#search-cities").removeClass('search-cities-open');
}
function showSearch(type, ob)
{
  if (type == 'product')
  {
    $("#input-product").show();
    $("#input-business").hide();
    $("#input-business input").val('');
    $("#product-tab").addClass('active');
    $("#business-tab").removeClass('active');
  }
  else
  {
    $("#input-business").show();
    $("#input-product").hide();
    $("#input-product input").val('');
    $("#business-tab").addClass('active');
    $("#product-tab").removeClass('active');
  }
}

document.onclick = function(e)
{ 
  var exclude = [ 'menu-element', 'under-element', 'over', 'cities-top', 'cities-list', 'ac_input', 'ac_select_city'];
  var ref = document.all ? window.event.srcElement : e.target;

	if (jQuery.inArray(ref.className, exclude) == -1)
	{
	  closeCitiesOnOut(); 	
	}
};

function resultMapToggle(button)
{
  if (button == 'map')
  {
    $('#Results').hide();
    $('#GMap').show();
    
  }
  else
  
  {
    $('#Results').show(); 
    $('#GMap').hide();
  }
  $('#Content .active').removeClass('active');
  $('#' + button + '-button').addClass('active');
}

function ShowHideBlock(blockID)
{
  var itemsBlock = document.getElementById(blockID);

  if (itemsBlock.style.display == "")
  {
    itemsBlock.style.display = "none";
  }

  if (itemsBlock.style.display == "none")
  {
	itemsBlock.style.display = "block";
  }
  else
  {
    itemsBlock.style.display = "none";
  }
}