function ajaxCustom(stranka, idecko)
{
	$.ajax({
		url: stranka,
		success: function(data) {
			$('#'+idecko).html(data);
		}
	});
}

function pridajFilter(filter)
{
	if( filter == '' ) return;

	url = unescape(self.document.location.hash.substring(1));
	url_div = $('#ajax_url').html();
	
	filter = filter + ';;';
	
	url = url.replace('&lt;', '<');
	url = url.replace('&gt;', '>');
	filter = filter.replace('&lt;', '<');
	filter = filter.replace('&gt;', '>');

	if( url.search(filter) >= 0 ) {
		url = url.replace(filter, '');
	} else {
		url = url + filter;
	}

	self.document.location.hash = url;
	ajaxCustom(url_div + zmazIdecka(url), 'vypis_domov');
}

function refreshFiltre(filtre)
{
	url = unescape(self.document.location.hash.substring(1));
	url_div = $('#ajax_url').html();
	
	var zvoleneFiltre;
	
	if( filtre.length > 1 ) {
		zvoleneFiltre = zmazIdecka(filtre);
		oznacFiltre(filtre);
	} else {
		zvoleneFiltre = zmazIdecka(url);
		oznacFiltre(url);
	}
	ajaxCustom(url_div + zvoleneFiltre, 'vypis_domov');
}

function zmazIdecka(hash)
{
	hash_ex = hash.split(";;");
	var navrat = "";
	for( var i = 0; i < hash_ex.length; i++ ) {
		if( hash_ex[i] != "" ) {
			hash_ex_ex = hash_ex[i].split("--");
			if( hash_ex_ex[1] != "" ) {
				navrat = navrat + hash_ex_ex[1] + ";;";
			}
		}
	}
	return navrat;
}
function oznacFiltre(hash)
{
	clear_filter();
	hash_ex = hash.split(";;");
	var navrat = "";
	for( var i = 0; i < hash_ex.length; i++ ) {
		if( hash_ex[i] != "" ) {
			hash_ex_ex = hash_ex[i].split("--");
			if( hash_ex_ex[0] != "" ) {
				$("#filter_"+hash_ex_ex[0]).addClass("active");
			}
		}
	}
}

function zmazFiltre()
{
	clear_filter();
	url_div = $('#ajax_url').html();
	self.document.location.hash = '';
	ajaxCustom(url_div, 'vypis_domov');
}

function prepniOdkaz(idecko)
{
	var staryHref = $('#tlacidlo_vyber'+idecko).attr('href');

	if( staryHref.search('odober_z_vyberu') > 0 ) {
		novyHref = staryHref.replace('odober_z_vyberu', 'pridaj_do_vyberu');
	} else {
		novyHref = staryHref.replace('pridaj_do_vyberu', 'odober_z_vyberu');
	}

	$('#tlacidlo_vyber'+idecko).attr('href', novyHref);
}

