function ChangeCountry(country_id, id_city_select, mode, id_loading, default_name)
{
 default_name = default_name || '---';
 if (country_id == 1)
 {
   document.getElementById(id_city_select).disabled = true;
   if (document.getElementById(id_loading))
     document.getElementById(id_loading).style.display = 'inline-block';
   var xmlhttp_request;
   xmlhttp_request = createRequest();
   xmlhttp_request.onreadystatechange = function(){_get_country_request(xmlhttp_request, country_id, id_city_select, mode, id_loading, default_name);};
   xmlhttp_request.open("GET", 'http://'+location.host+'/auto/_load_cities.php?mode='+mode+'&country_id='+country_id, true);
   xmlhttp_request.send(null);
 }
 else if (country_id == 0)
 {
   document.getElementById(id_city_select).disabled = 1;
   document.getElementById(id_city_select).options.length = 1;
   document.getElementById(id_city_select).options[0].text = 'âûáåðèòå ñòðàíó';
   document.getElementById(id_city_select).options[0].value = 0;
   document.getElementById(id_city_select).selectedIndex = 0;
 }
 else
 {
   document.getElementById(id_city_select).disabled = 1;
   document.getElementById(id_city_select).options.length = 1;
   document.getElementById(id_city_select).options[0].text = 'íå âàæíî';
   document.getElementById(id_city_select).options[0].value = 0;
   document.getElementById(id_city_select).selectedIndex = 0;
 }
}

function _get_country_request(xmlhttp_request, country_id, id_city_select, mode, id_loading, default_name)
{
  if (xmlhttp_request.readyState == 4)// "complete"
  {
    if (xmlhttp_request.status == 200) // "OK"
    {
      var cities_str;
      cities_str = xmlhttp_request.responseText.substr(0, xmlhttp_request.responseText.length-1);
      var i;
      var city_select = document.getElementById(id_city_select);
      cities_str = '0,'+default_name+';' + cities_str;
      if (cities_str)
      {
        var city_list = cities_str.split(';');
        city_select.options.length = city_list.length;
        for (i = 0; i < city_list.length; i++) {
          city_select.options[i].text = (city_list[i]).split(',')[1];
          city_select.options[i].value = (city_list[i]).split(',')[0];
        }
      }
      city_select.selectedIndex = 0;
      city_select.disabled = false;
    }
    if (document.getElementById(id_loading))
      document.getElementById(id_loading).style.display = 'none';
  }
}


