/* Orszag- es varosvalaszto
** 2 selectet kezel, miutan kivalasztottuk az orszaglistabol az egyik orszagot, a masodik listaban csak a hozzatartozo varosokbol valaszthatunk.
** Orszag es varos lista a locationlist,js-ben van, hogy ez mukodjon, azt is be kell huzni.
** Kiirt ertekek szerint abc sorrendben rendez, ezert szukseg van a dropdownsorter.js-re.
*/


function TString(s) {
  if ( s ) {
    s = s.replace( /^\s+/g, "" );
    return s.replace( /\s+$/g, "" );
  }
}

// feltolti az orszaglistat
function populateCountry(defaultCountry) {
  var countryLineArray = country.split(',');  // a bemeneti country stringbol a varosokat egy tombbe rakja, majd ABC szerint rendezi
  var selObj = document.getElementById('countrySelect');
  selObj.options[0] = new Option(getLocString("profileedit.locationselector.selectcountry"),'');
  selObj.selectedIndex = 0;
  for (var i = 0; i < countryLineArray.length; i++) {
    countryCode  = TString(countryLineArray[i]);
    if ( countryCode != '' ) {
      selObj.options[i + 1] = new Option(countryCode, countryCode);
    }
    if ( defaultCountry == countryCode ) {
      selObj.selectedIndex = i + 1;
    }
  }
  DropDownSelectSort(selObj,1);
  for (var i = 0; i < selObj.length; i++) {
	if (selObj.options[i].value==defaultCountry)selObj.selectedIndex = i;
  }
  selObj.options[selObj.length] = new Option(getLocString("profileedit.locationselector.other"),'');
}

function populate(defaultCity) {
  var orszagertek = document.getElementById('countrySelect').value 
  
  if (city[orszagertek]!=null) {
     var cityLineArray = city[orszagertek].split(',');  // a bemeneti country stringbol a varosokat egy tombbe rakja, majd ABC szerint rendezi
  }
  else{
      var cityLineArray=null;
  }
  

  var selObj = document.getElementById('citySelect');
  for (var i = 0; i < selObj.options.length; i++) {
    selObj.options[i] = null;
  }
  selObj.options.length=null;
  selObj.options[0] = new Option(getLocString("profileedit.locationselector.selectcity"),'');
  selObj.selectedIndex = 0;
  if (cityLineArray !=null){
	  for (var i = 0; i < cityLineArray.length; i++) {
	    cityCode  = TString(cityLineArray[i]);
	    if ( cityCode != '' ) {
	      selObj.options[i + 1] = new Option(cityCode, cityCode);
	    }
	    if ( defaultCity == cityCode ) {
	      selObj.selectedIndex = i + 1;
	    }
	  }
	}
	DropDownSelectSort(selObj,1);
	for (var i = 0; i < selObj.length; i++) {
		if (selObj.options[i].value==defaultCity)selObj.selectedIndex = i;
	}
	selObj.options[selObj.length] = new Option(getLocString("profileedit.locationselector.other"),'');
}

//inicializalas, elobb a countryt kell, aztan a cityt
function initCountry(country,city) {
  populateCountry(country);
  populate(city);
}



