jQuery.fn.extend({
	highlight: function(search, insensitive, klass){
		var regex = new RegExp('(<[^>]*>)|('+ search.replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1") +')', insensitive ? 'ig' : 'g');
		return this.html(this.html().replace(regex, function(a, b, c){
			return (a.charAt(0) == '<') ? a : '<strong class="'+ klass +'">' + c + '</strong>'; 
		}));
	}
});

function fSearch(params, q)
{
	document.location.href = '/paieska/?'+params+'&q='+q;
}
/*
function searchShow(c)
{
	if(c=='all')
	{
		$('.foundInGroupName').show();
		$('.foundInSongName').show();
		$('.foundInLyricsName').show();
		
	} else if(c='foundInGroupName')
	{
		$('.foundInGroupName').show();
		$('.foundInSongName').hide();
		$('.foundInLyricsName').hide();
		
	} else if(c='foundInSongName')
	{
		$('.foundInGroupName').hide();
		$('.foundInSongName').show();
		$('.foundInLyricsName').hide();
		
	} else if(c='foundInLyrics')
	{
		$('.foundInGroupName').hide();
		$('.foundInSongName').hide();
		$('.foundInLyricsName').show();
	}
}
*/

function formatSearchCheckboxes(groups, songs, lyrics)
{
	g = document.getElementById('chk1');
	s = document.getElementById('chk2');
	l = document.getElementById('chk3');

	if(groups>0)
		g.checked = true;
	else
		g.checked = false;
	
	if(songs>0)
		s.checked = true;
	else
		s.checked = false;
	
	if(lyrics>0)
		l.checked = true;
	else
		l.checked = false;
}

function checkSearchForm(form)
{
	if(form.q.value.length < 4)
	{
		alert('Tekstas turi būti bent 4 simbolių ilgio'); 
		return false;
	} 
	
	if(!form.groups.checked && !form.songs.checked && !form.lyrics.checked)
	{
		alert('Būtina pasitrinkti bent vieną kategoiją'); 
		return false;
	}
	
	return true;
}