document.getElementById('searchsubmit').onmouseover	= function() { this.style.backgroundPosition = '0 -23px' }
document.getElementById('searchsubmit').onmouseout	= function() { this.style.backgroundPosition = '0 0' }
document.getElementById('searchsubmit').onmousedown	= function() { this.style.backgroundPosition = '0 -46px' }
document.getElementById('searchsubmit').onmouseup	= function() { this.style.backgroundPosition = '0 -23px' }
document.getElementById('searchsubmit').onfocus		= function() { this.blur(); }
document.getElementById('searchinput').onfocus		= function() { document.getElementById('searchsubmit').style.backgroundPosition = '0 -23px' }
document.getElementById('searchinput').onblur		= function() { document.getElementById('searchsubmit').style.backgroundPosition = '0 0' }

	function trimAll(sString) 
	{
		while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
	}
	
	function channelsSelectAll( state )
	{
		var form = document.forms['searchForm'];
	
		for (i = 0; i < form.length; i++)
		{
			if ( form[i].name.substring(0,2) == 'ch' )
			{
				form[i].checked = state;
			}
			
		}
	}
		
	function channelsVisibility()
	{
		if (document.getElementById('searchchannels').style.display != 'none')
		{
		document.getElementById('searchchannels').style.display = 'none';
		document.getElementById('showchannels').style.display = 'block';
		document.getElementById('hidechannels').style.display = 'none';
		}
		else
		{
		document.getElementById('searchchannels').style.display = 'block';
		document.getElementById('showchannels').style.display = 'none';
		document.getElementById('hidechannels').style.display = 'block';
		}		
	}
		
	function search(link_url, search_no_text, url_query, url_channels, url_all_channels, check_at_least_one_channel, url_search_in, url_search_name, url_search_tags, url_search_authors, check_at_least_one_search, url_sort, link_order, url_view, link_view)
	{
		var form = document.forms['searchForm'];
		
		var link = link_url + ',';
		
		/************************* TEKST ***************************/
		var tekst = trimAll( form.s.value.replace(/,/g, ' ') );
		
		if ( tekst == '')
		{
			alert(search_no_text);
			return false;
		}
		
		link += url_query + ',' + tekst + ',';
			
		/************************* KANALY **************************/
		link += url_channels + ',';
		var add = '';
		
		var chcount = 0;
		var chall = 0;
			for (i = 0; i < form.length; i++)
			{
				if ( form[i].name.substring(0,2) == 'ch' )
				{
					chall++;
					
					if ( form[i].checked )
					{
					add += form[i].name.substr(2,8)+';'
					chcount++;
					}
				}
				
			}
		
		if (chcount < chall)
		{
		link += add;
		link = link.substr(0, link.length-1);
		}
		else
		{
		link += url_all_channels;
		}
		
		link += ',';
		
			if (chcount == 0)
			{
			alert(check_at_least_one_channel);
			return false;
			}
			
		/************************* IN *******************************/
		link += url_search_in + ',';
		incount = 0;
			
			if (form.sall.checked)
			{
			incount++;
			link += url_search_name + ';' + url_search_tags + ';' + url_search_authors;
			}
			else
			{
			link += '';
			}
			
			if (form.sname.checked)
			{
			incount++;
			link += url_search_name;
			}
			else
			{
			link += '';
			}
			
			if (form.stags.checked)
			{
			if(incount)
			{
				link += ';';
			}
			link += url_search_tags;
			incount++;
			}
			else
			{
			link += '';
			}
			
			if (form.sauthors.checked)
			{
			if(incount)
			{
				link += ';';
			}
			incount++;
			link += url_search_authors;
			}
			else
			{
			link += '';
			}
		
			if (incount == 0)
			{
			alert(check_at_least_one_search);
			return false;
			}
		
		link += ',';
		
		/************************* NON FORM *************************/
		
		link += url_sort + ',' + link_order + ',' + url_view + ',' + link_view;
		location.href = link;
		return false;
	}

