function changeHrefs ( szukaj, ref, z ) {
	var isAdv = ( null == ref || ( -1 == ref.indexOf ( 'zaawansowane.html' ) && -1 == ref.indexOf ( 'zaawansowanef.html' ) ) ) ? false : true;
	var h = szukaj.href;
	if ( 'pr' != z && -1 == h.indexOf ( '?' ) ) {
		h += '?';
	}

	if ( ! isAdv ) {	
		var q = '';
		if ( $( 'szukaj' ) != null ) {
			q = $( 'szukaj' ).value;
		}

		if ( 'pr' != z && q.length > 0 && -1 == h.indexOf ( 'szukaj=' ) ) {
			h += '&szukaj=' + q;
		}			
		h = h.replace ( /(szukaj=[^&]*)/, 'szukaj=' + q );
		if ( h.indexOf ( '?&' ) > -1 ) {
			h = h.replace ( '?&', '?' );
		}
		if ( ( h.indexOf ( '/?' ) > -1 || h.indexOf ( 'index.html' ) > -1 ) && ( 'undefined' == z || null == z ) ) {
			z = 'p';
		} 

		if ( 'p' == z || 'f' == z || 'm' == z || 'e' == z || 'pr' == z || 'wp' == z ) {
			if ( q.length > 0 ) {
				switch ( z ) {
					case 'p':
						var s = ( h.indexOf ( 'index.html' ) > -1 ) ? 'index.html' : '/?';
						var r = ( h.indexOf ( 'index.html' ) > -1 ) ? 'szukaj.html' : '/szukaj.html?';
						h = h.replace ( s, r );
						break;
					case 'f':
						h = h.replace ( 'http://firmy.wp.pl/?', 'http://firmy.wp.pl/szukajf.html?' );
						break;	
					case 'm':
						h = h.replace ( 'obrazki.html?', 'szukaj.html?z=m&' );
						break;
					case 'e':
						h = h.replace ( 'http://slowniki.wp.pl/?', 'http://slowniki.wp.pl/szukaj.html?lang=plen&' );
						break;
					case 'pr':
						h = 'http://tanio.pl/nazwa,' + q + ',szukaj.html';
						break;
					case 'wp':
						h = h.replace ( /[^\/]*$/, q );
						break;
				}				
			}	
		}
	} else {
		var szukaj_and = ''
		if ( $( 'szukaj_and' ) != null ) {
			szukaj_and = $( 'szukaj_and' ).value;
			if ( undefined == szukaj_and ) {
				szukaj_and = '';
			}
		}
		var szukaj_or = '';	
		if ( $( 'szukaj_or' ) != null ) {
			szukaj_or = $( 'szukaj_or' ).value;
			if ( undefined == szukaj_or ) {
				szukaj_or = '';
			}
		}
		var szukaj_not = ''
		if ( $( 'szukaj_not' ) != null ) {
			szukaj_not = $( 'szukaj_not' ).value;
			if ( undefined == szukaj_not ) {
				szukaj_not = '';
			}
		}
		var szukaj_phr = ''
		if ( $( 'szukaj_phr' ) != null ) {
			szukaj_phr = $( 'szukaj_phr' ).value;
			if ( undefined == szukaj_phr ) {
				szukaj_phr = '';
			}
		}

		h = ( h.indexOf ( 'szukaj_and' ) > -1 ) ? h.replace ( /(szukaj_and=[^&]*)/, 'szukaj_and=' ) : h + '&szukaj_and=';
		h += szukaj_and;
		h = ( h.indexOf ( 'szukaj_or' ) > -1 ) ? h.replace ( /(szukaj_or=[^&]*)/, 'szukaj_or=' ) : h + '&szukaj_or=';
		h += szukaj_or;
		h = ( h.indexOf ( 'szukaj_not' ) > -1 ) ? h.replace ( /(szukaj_not=[^&]*)/, 'szukaj_not=' ) : h + '&szukaj_not=';
		h += szukaj_not;
		h = ( h.indexOf ( 'szukaj_phr' ) > -1 ) ? h.replace ( /(szukaj_phr=[^&]*)/, 'szukaj_phr=' ) : h + '&szukaj_phr=';
		h += szukaj_phr;
		
		h = h.replace ( /(szukaj=[^&]*)/, 'szukaj=' );
		if ( h.indexOf ( 'zaawansowane.html?&' ) > -1 ) {
			h = h.replace ( 'zaawansowane.html?&', 'zaawansowane.html?' );
		} else if ( h.indexOf ( 'zaawansowanef.html?&' ) > -1 ) {
			h = h.replace ( 'zaawansowanef.html?&', 'zaawansowanef.html?' );
		}
	
		if ( szukaj_and.length > 0 ) {	
			if ( 'pr' == z ) {
				h = 'http://tanio.pl/nazwa,' + szukaj_and + ',szukaj.html';
			} else if ( 'wp' == z ) {
				h = 'http://szukaj.wp.pl/wp/' + szukaj_and;
			}
		}
	}

	var len = h.length;
	if ( h.indexOf ( '?' ) == len - 1 || h.indexOf ( '&' ) == len -1 ) {
		h = h.substr ( 0, len - 1 );
	}

	szukaj.href = h;
}
function advHref ( els ) {
	var q = '';
	if ( $( 'szukaj' ) != null ) {
		q = $( 'szukaj' ).value;
	}
	
	els.href = els.href.replace ( /(szukaj_and=[^&]*)/, 'szukaj_and=' + q ); 
}

