$(document).ready(function(){
	$('a[rel*=external]').click(linkExternal);
	$('#typ, #subtyp, #kraj, #okres, #status').change(searchReload);
});

function linkExternal(){
	window.open(this.href);
	return false;
}

function searchReload(){
	var typ = $('#typ option:selected').val();
	var subtyp = ($(this).attr('id') == 'typ') ? 0 : $('#subtyp option:selected').val();
	var kraj = $('#kraj option:selected').val();
	var okres = ($(this).attr('id') == 'kraj') ? 0 : $('#okres option:selected').val();
	var status = ($('#status').length) ? $('#status option:selected').val() : 0;
	$.get(HOME_URL + "xml", { typ: typ, subtyp: subtyp, kraj: kraj, okres: okres, status: status },
		function(data){
			$(data).find('select').each(function(){
				$("#" + $(this).attr('id')).html($(this).text());
				if ($(this).attr('disabled'))
				{
					$("#" + $(this).attr('id')).attr('disabled', 'disabled');
				}
				else
				{
					$("#" + $(this).attr('id')).removeAttr('disabled');
				}
			});
		}
	);
}

function popup(url,name,windowWidth,windowHeight){
  myleft=(screen.width)?(screen.width-windowWidth)/2:100;
  mytop=(screen.height)?(screen.height-windowHeight)/2:100;
  properties = "scrollbars=no,resizable=no,width="+windowWidth+",height="+windowHeight+",top="+mytop+",left="+myleft;
  winPop = window.open(url,name,properties)
  if(winPop)return false;
}
