function idExists(id, target)
{
	select = document.getElementById(target);
	if (select) {
		for (var i=0; i<select.length; i++) {
			if (id == select[i].value) {
				return true;
			}
		}
	}
	return false;
}

function setCountry(country, city, cit_id)
{
	if (city == undefined) {
		city = 'city';
	}
	if (country == undefined) {
		country = 'country';
	}
	var id = document.getElementById(country).value;

	var select = document.getElementById(city);
	select.disabled = true;
	select.innerHTML = '';

	var option = document.createElement("option");
	option.value 		= '';
	option.text 		= 'выбрать ...';
	option.innerText 	= 'выбрать ...';
	select.appendChild(option);

	var items = loadJson("/json/cities/"+id+"/");

	var sel = 0;
	for (var i=0; i<items.length; i++) {
		if (items[i][2]=='city') {
			var option = document.createElement("option");
			option.value 		= items[i][0];
			option.text 		= items[i][1];
			option.innerText 	= items[i][1];
			if (cit_id == items[i][0]) {
				if (option.selected == undefined) {
					sel = i;
				}
				option.selected = 'true';
			}
			optgroup.appendChild(option);

		} else {
			var optgroup = document.createElement("optgroup");
			optgroup.label = items[i][1];
			select.appendChild(optgroup);
		}
	}
	if (sel) {
		select.selectedIndex = sel;
	}
	if (i>0) {
		select.disabled = false;
	}
}