$(function()
{
	$("select#gyors_megye").change(function()
	{
		$("#gyors_telepules").html('');
		$("#gyors_varosresz").html('');
		$.getJSON("/kereso_megye_json.php",{id: $(this).val(), cat: "selTelepules", elkuld: "elkuld"}, function(j)
		{
			var options = '';
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			$("#gyors_telepules").html(options);
			//$('#selTelepules option:first').attr('selected', 'selected');
		});
	});
	
	$("select#gyors_telepules").change(function()
	{
		$("#gyors_varosresz").html('');
		$.getJSON("/kereso_megye_json.php",{id: $(this).val(), cat: "selVarosresz", elkuld: "elkuld"}, function(j)
		{
			var options = '';
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			$("#gyors_varosresz").html(options);
			//$('#selVarosresz option:first').attr('selected', 'selected');
		});
	});
});

function setByLastIdGY($varosreszId, $telepulesId, $megyeId)
{
	//$varosreszId = '5';

	var i_megyeId = 0;
	var i_telepulesId = 0;
	var i_varosreszId = 0;
		
	$.getJSON("/kereso_megye_json.php",{id: $varosreszId, telepulesId: $telepulesId, megyeId: $megyeId, cat: "setByLast", elkuld: "elkuld"}, function(k)
	{
		i_megyeId = k[0].megyeId;
		i_telepulesId = k[0].telepulesId;
		i_varosreszId = $varosreszId;

		$.getJSON("/kereso_megye_json.php",{id: "1", cat: "selMegye", elkuld: "elkuld"}, function(j)
		{
			var options = '';
			for (var i = 0; i < j.length; i++) {
				options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			}
			$("#gyors_megye").html(options);
			$("#gyors_megye").val(i_megyeId).attr('selected', true);
			
			$.getJSON("/kereso_megye_json.php",{id: i_megyeId, cat: "selTelepules", elkuld: "elkuld"}, function(l)
			{
				var options = '';
				for (var i = 0; i < l.length; i++) {
					options += '<option value="' + l[i].optionValue + '">' + l[i].optionDisplay + '</option>';
				}
				$("#gyors_telepules").html(options);
				$("#gyors_telepules").val(i_telepulesId).attr('selected', true);
				
				$.getJSON("/kereso_megye_json.php",{id: i_telepulesId, cat: "selVarosresz", elkuld: "elkuld"}, function(m)
				{
					var options = '';
					for (var i = 0; i < m.length; i++) {
						options += '<option value="' + m[i].optionValue + '">' + m[i].optionDisplay + '</option>';
					}
					$("#gyors_varosresz").html(options);
					$("#gyors_varosresz").val(i_varosreszId).attr('selected', true);
				});
			});
		});
	});
}
