
var cities = new Array();

function addCityOption(searchId, region, cityOption)
{
  if (!cities[searchId]) cities[searchId] = new Array();
  if (!cities[searchId][region]) cities[searchId][region] = new Array();

  cities[searchId][region][cities[searchId][region].length] = cityOption;
}
 
function addCity(searchId, region, city, cityId)
{
  var opt = new Option();
  opt.value = cityId;
  opt.text = city;
  
  addCityOption(searchId, region, opt);
  if (region!="all") addCityOption(searchId, "all", opt);
}

function filterCities(searchId, selectId, region)
{
  var _selectOptions = document.getElementById(selectId).options;
  _selectOptions.length = 0;
  if (region==-1 || region=="-1") region = "all";
  else _selectOptions[_selectOptions.length] = cities[searchId]["all"][0];
  fillOptions(_selectOptions, cities[searchId][region]);
}

function fillOptions(_selectOptions, _arrayOptions)
{
  if (_arrayOptions)
  for (var i=0; i<_arrayOptions.length; i++)
    _selectOptions[_selectOptions.length] = _arrayOptions[i];
}

function clearSelect(searchId)
{
  if (searchId=="sales" || searchId=="etude")
  {
    document.getElementById(searchId+"-regions").options.selectedIndex = 0;
    document.getElementById(searchId+"-cities").options.selectedIndex = 0;
    document.getElementById(searchId+"-etudes").options.selectedIndex = 0;
    if (searchId=="sales") 
    {
      document.getElementById(searchId+"-dates").options.selectedIndex = 0;
      document.getElementById(searchId+"-specs").options.selectedIndex = 0;
    }
    filterCities(searchId, searchId+"-cities", "-1");
  }
  else alert("???"+searchId);
}

function clearTextField(fieldId)
{
  document.getElementById("top-form")[fieldId].value="";
  document.getElementById("search-full-text")[fieldId].value="";
}
