//var ld2 = new net.ContentLoader();

function getCountry2()
{
  nulc = 1;
  url = HTTP_FULL_PATH + '/callback/cb_getcountry.php?getcountry&nulc='+nulc;
  ajaxChainLoaderGet(url, getCountry_callback2);
}
function getCountry_callback2()
{
  var nl = null;
  if (this.req.responseXML) { nl = this.req.responseXML.getElementsByTagName('country'); }
  if (nl)
  {
    clearSelect('id-country-2');
    if (M_COUNTRY_ID) { sel_country_id = M_COUNTRY_ID; } else { sel_country_id = 0; }
    var sel_country = byID('id-country-2');
    for( var i=0; i<nl.length; i++ )
    {
      var nli = nl.item(i);
      var country_id = parseInt(nli.getAttribute('country_id'));
      var country_rus = nli.getAttribute('country_rus');
      if (country_id == sel_country_id) { selected = true; } else { selected = false; }
      newOption = newopt(country_id,country_rus,selected);
			sel_country.appendChild(newOption);
			newOption = null;
    }
    getRegion2();
  }
}

function getRegionForCountry2()
{
  disable('id-region-2');
  disable('id-city-2');
  sel = byID('id-country-2');
  var id = sel.options[sel.selectedIndex].value;
  M_COUNTRY_ID = id;
  M_REGION_ID = 0;
  M_CITY_ID = 0;
  nulc = 1;
  url = HTTP_FULL_PATH + '/callback/cb_getcountry.php?getregion&country_id='+id+'&nulc='+nulc;
  ajaxChainLoaderGet(url, getRegion_callback2);
}
function getRegion2()
{
  disable('id-region-2');
  disable('id-city-2');
  if (M_COUNTRY_ID) { id = M_COUNTRY_ID; } else { id = 0; }
  nulc = 1;
  url = HTTP_FULL_PATH + '/callback/cb_getcountry.php?getregion&country_id='+id+'&nulc='+nulc;
  ajaxChainLoaderGet(url, getRegion_callback2);
}
function getRegion_callback2()
{
  var nl = null;
  if (this.req.responseXML) { nl = this.req.responseXML.getElementsByTagName('region'); }
  if (nl)
  {
    clearSelect('id-region-2');
    disable('id-region-2');
    if (M_REGION_ID) { sel_region_id = M_REGION_ID; } else { sel_region_id = 0; }
    var sel_region = byID('id-region-2');
    for( var i=0; i<nl.length; i++ )
    {
      var nli = nl.item(i);
      var region_id = parseInt(nli.getAttribute('region_id'));
      var region_rus = nli.getAttribute('region_rus');
      if (region_id == sel_region_id) { selected = true; } else { selected = false; }
      newOption = newopt(region_id,region_rus,selected);
			sel_region.appendChild(newOption);
			newOption = null;
    }
    enable('id-region-2');
    if (M_CITY_ID != 0) { getCity2(); } else { getCityForRegion2(); }
  }
}

function getCityForRegion2()
{
  disable('id-city-2');
  sel = byID('id-region-2');
  var id = sel.options[sel.selectedIndex].value;
  M_REGION_ID = id;
  M_CITY_ID = 0;
  nulc = 1;
  url = HTTP_FULL_PATH + '/callback/cb_getcountry.php?getcity&region_id='+id+'&nulc='+nulc;
  ajaxChainLoaderGet(url, getCity_callback2);
}
function getCity2()
{
  disable('id-city-2');
  if (M_REGION_ID) { id = M_REGION_ID; } else { id = 0; }
  nulc = 1;
  url = HTTP_FULL_PATH + '/callback/cb_getcountry.php?getcity&region_id='+id+'&nulc='+nulc;
  ajaxChainLoaderGet(url, getCity_callback2);
}
function getCity_callback2()
{
  var nl = null;
  if (this.req.responseXML) { nl = this.req.responseXML.getElementsByTagName('cities'); }
  if (nl)
  {
    clearSelect('id-city-2');
    disable('id-city-2');
    if (M_CITY_ID) { sel_city_id = M_CITY_ID; } else { sel_city_id = 0; }
    var sel_city = byID('id-city-2');
    for( var i=0; i<nl.length; i++ )
    {
      var nli = nl.item(i);
      var city_id = parseInt(nli.getAttribute('city_id'));
      var city_rus = nli.getAttribute('city_rus');
      if (city_id == sel_city_id) { selected = true; } else { selected = false; }
      newOption = newopt(city_id,city_rus,selected);
			sel_city.appendChild(newOption);
			newOption = null;
    }
    enable('id-city-2');

  }
}

//var ld2 = new net.ContentLoader();


addLoadEvent(getCountry2);