function uir_change(value, fillElement, type, ondata)
{	
	select_empty(fillElement);

	//alert(value+" to " + type);
	//alert("../uir.php?"+type+"="+value);
	
	json.init();	
	json.ondata=function() { uir_changed(fillElement); ondata(); };
	json.url="../uir.php?"+type+"="+value;
	json.open();
}

function uir_changed(fillElement)
{
	select_empty(fillElement);
	select_addOption(fillElement, 0, "---");
	
	for (var k in json.data)
		select_addOption(fillElement, k, json.data[k]);
}


function select_empty(selectElement)
{
	while(selectElement.length>0)
		selectElement.remove(0);
}


function select_addOption(selectElement, value, label)
{
	var optionElement=document.createElement("option");
	optionElement.text=label;
	optionElement.value=value;
	
	try
	{
		selectElement.add(optionElement, null); // standards compliant
	}
	catch(ex)
	{
		selectElement.add(optionElement); // IE only
	}
}



function uir_fillCityNCircuit(value, fillElementCity, fillElementCircuit)
{
	uir_change(value, fillElementCity, 'obec', null);
	uir_change(value, fillElementCircuit, 'mcast', null);	
	
}

function uir_setObecObvod(okres, obce, obvody, obceParent, obvodyParent)
{

	var onObvody=function()
	{
		obceParent.style.display='none';
		obvodyParent.style.display='';
	}
	
	var onOobce=function()
	{
		obceParent.style.display='';
		obvodyParent.style.display='none';
		
		var c=0;
		for(var k in json.data)
			c++;			
		
		if(c==1) //jen jedna obec v okresu
		{
			uir_change(k, obvody, 'mcast', onObvody);
		}
	}
	
	uir_change(okres, obce, 'obec', onOobce);
	
	
	//mesta.style.display='';
	
}
