
	var sAgent = navigator.userAgent.toLowerCase();

	$ = function (id) {return document.getElementById(id);};

	var j = jQuery.noConflict(true);
	
	j(document).ready(function () {
		j = j.noConflict(true);
		$ = function (id) {return document.getElementById(id);};
	});

	function on_window_load(func) {
		if (isIe()) {
			attachEvent(document, 'readystatechange', createMethodReference({func:func}, function () {
				if (document.readyState == 'complete') {
					$ = function (id) {return document.getElementById(id);};
					this.func();
				}
			}));
		} else {
			attachEvent(window, 'load', createMethodReference({func:func}, function () {
				$ = function (id) {return document.getElementById(id);};
				this.func();
			}));
		}
	}

	function isIe() {
		return (!isPresto() && !isGecko() && document.all) ? true : false;
	}

	function isIe6() {
		return (!isPresto() && !isGecko() && document.all && !/MSIE (7|8)/.test(navigator.userAgent)) ? true : false;
	}

	function isGecko() {
		return sAgent.match(/gecko/i);
	}

	function isPresto() {
		return sAgent.match(/presto/i);
	}

	function createMethodReference(object, method) {
		return function () {
			return method.apply(object, arguments);
		};
	}
	
	function dbg(v) {
		return debug(v);
	}
	
	function debug(v) {
		try {
			if (is_def(console))
				console.info(v);
		} catch (e) {
		}
	}
	
	function replaceAll(strTarget, strSubString, strText) {
		var intIndexOfMatch = strText.indexOf(strTarget);
		
		while (intIndexOfMatch != -1) {
			strText = strText.replace(strTarget, strSubString);
			intIndexOfMatch = strText.indexOf(strTarget);
		}
		
		return strText;
	}

	var IE = (typeof document.all != 'undefined' && !(typeof window.opera == 'Opera'));
	//if (!IE) document.captureEvents(Event.MOUSEMOVE);
	var tempX, tempY;
	
	var attachEvent = function (o, sEventName, oCallback) {
		if (typeof o.addEventListener != 'undefined') {
		  o.addEventListener(
			sEventName,
			oCallback,
			false
		  );
		} else if (typeof o.attachEvent != 'undefined') {
		  o.attachEvent(
			'on' + sEventName,
			oCallback
		  );
		}
	};
	
	var _mouse = {x:0, y:0};
	function getMouseXY() {
		return _mouse;
	}
	
	function getBodyElement() {
		if (document.documentElement) {
			return document.documentElement;
		} else {
			return document.body;
		}
	}
	
	if (document) {
		attachEvent(document, 'mousemove', function (e) {
			if (isIe()) {
				_mouse = {
					x: e.clientX + getBodyElement().scrollLeft,
					y: e.clientY + getBodyElement().scrollTop
				};
			} else if (e && e.pageX) { 
				_mouse = {
					x: e.pageX,
					y: e.pageY
				};
			} else {
				_mouse = {x:0, y:0};
			}
		});
	}
	
	function get_mouse() {
		return getMouseXY();
	}
	
	function getElementsByClass(searchClass,node,tag) {
		if (!node)
			node = document;
			
		if (document.getElementsByClassName) {
			return node.getElementsByClassName(searchClass);
		}
		
		var classElements = new Array();
		if ( node == null )
			node = document;
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		//var pattern = new RegExp("(^|[ 	]*)"+searchClass+"([ 	]*|$)");
		for (i = 0, j = 0; i < elsLen; i++) {
			//if ( pattern.test(els[i].className) ) {
			if (is_subclass_of(els[i], searchClass)) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}

	function is_subclass_of(element, className) {
		return (element.className == className || element.className.indexOf(" "+className) !== -1 || element.className.indexOf(className+" ") !== -1);
		className = new String(className);
		className = className.replace(/-/, '\\-');
		
		var pattern = new RegExp("(^|[ 	]+)"+className+"([ 	]+|$)");
		return pattern.test(element.className);
		
		return (new String(element.className)).match("/(^|[ 	]*)" + className + "([ 	]*|$)/");
	}

	function n(type, id, count) {
		if (count > 0) {
			var res = [];
			for (var i = 0; i < count; i ++) {
				res.push(n(type, id?id+i:null));
			}
			return res;
		}else {
			var o = document.createElement(type);
			if (!id) 
				id = 'object' + (new Date()).getTime();
			o.setAttribute('id', id);
			
			return o;
		}
	}

	function getAC() {
		var res;
		if (window.XMLHttpRequest) {
			try {
				res = new XMLHttpRequest();
		   } catch(e) {
				res = false;
		   }
		} else if (window.ActiveXObject) {
		   try {
			res = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				try {
					res =  new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					res = false;
				}
			}
		}

		return res;
	}

	var TConnection = function (sUrl, fOnData, settings) {
		this.onData = null;
		this.oConn = getAC();
		this.sMethod = 'GET';
		this.sUrl = '';
		this.status = 'none';
		this.aPost = {};
		this.aSettings = {
			timeout: 1000,
			queue: null,
			status_point: null
		};

		this.partialData = null;
		
		if (typeof settings == 'object') {
			for (k in settings) {
				if (typeof this.aSettings[k] != 'undefined') {
					this.aSettings[k] = settings[k];
				}
			}
		}
		
		this.oConn.onreadystatechange = createMethodReference(this, function () {
			if (this.oConn.readyState == 4) {
				_is_loading = false;
				//document.body.style.cursor = 'auto';
				
				try {
					if ((new String(this.oConn.responseText)).indexOf('{') === 0) {
						eval('var data = ' + this.oConn.responseText);
						
						if (data && data.sysMsg && data.sysMsg.length > 0) {
							clear_msg_container();
							this.status = data.sysMsg[0].type;
							for (var i = 0; i < data.sysMsg.length; i ++) {
								if (!data.sysMsg[i].value)
									continue;
									
								if (this.aSettings.status_point) {
									var d = n('div');
									d.className = data.sysMsg[i].type;
									d.innerHTML = '<div style="float:left">' + data.sysMsg[i].value +
										'</div><img src="'+JS_HOST+'view/images/icon_close.png" alt="x" style="margin-left: 20px; float:right; cursor:pointer" onclick="shadeoff_timeout(1, this.parentNode, null, true);" />' +
										'';

									var hint = add_hint_for(null, d);
									hint.appendToElement(this.aSettings.status_point);
									hint.onmove(true);
								} else
									show_message(data.sysMsg[i].type, data.sysMsg[i].value);
							}
						}

						if (data && data.data)
							this.partialData = data.data;
					}
				} catch (E) {
					debug(E);
				}
				
				if (this.onData) 
					this.onData(this.oConn, this);
			}
		});
		
		this.onData = fOnData;
		
		//fast call
		if (sUrl) {
			//sUrl = sUrl.replace(/^http:/, 'https:'); //fix problem with https protection
			this.sUrl = sUrl;
			this.open();
		}
	};
	TConnection.prototype.onData = null;
	TConnection.prototype.sMethod = 'GET';
	TConnection.prototype.sUrl = '';
	TConnection.prototype.status = '';
	TConnection.prototype.bCacheProtection = true;
	TConnection.prototype.aPost = {};

	TConnection.prototype.addPost = function (k, v) {
		this.aPost[k] = v;
	};

	TConnection.prototype.cacheProtect = function () {
		if (this.sUrl.match(/_t=[0-9]+/)) {
			this.sUrl.replace(/_t=[0-9]+/, '_t' + (new Date()).getTime());
		} else {
			this.sUrl += (this.sUrl.match(/\?/) ? '&' : '?') + '_t=' + (new Date()).getTime() ;
		}
	};

	TConnection.prototype.open = function () {
		this.cacheProtect();
		this.oConn.open(this.sMethod, this.sUrl, true);
		if (this.sMethod == 'POST') {
			var parameters = this.getParameters();
			this.oConn.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.oConn.setRequestHeader("Content-length", parameters.length);
			this.oConn.setRequestHeader("Connection", "close");
			this.oConn.send(parameters);
		} else {
			this.oConn.send('');
		}

		//document.body.style.cursor = 'wait';
	};

	TConnection.prototype.getParameters = function () {
		var sRes = '';
		
		for (var k in this.aPost) {
			sRes += urlencode(k) + '=' + urlencode(this.aPost[k]) + '&';
		}
		
		return sRes;
	};
	
	function urlencode( str ) {                                     
		var ret = new String(str);
		
		ret = encodeURIComponent(ret);
		ret = ret.replace(/%20/g, '+');
	 
		return ret;
	}


	function menu(id) {
		var sb = $('sidebar');
		var ul = sb.getElementsByTagName('ul');
		var li = sb.getElementsByTagName('li');
		
		for (var k in li) {
			if ((new String(li[k].id)).match(/^submenu/)) {
				li[k].style.display = 'none';
			}
		}
		for (k in li) {
			if ((new String(li[k].id)).match(/^menu/)) {
				li[k].style.display = '';
			}
		}
		
		for (i = 0; i < arguments.length; i ++) {
			id = arguments[i];

			if (!id || !$('menu_' + id))
				continue;

			var checkis = $('menu_' + id).style.display != 'none';

			if (checkis) {
				$('menu_' + id).style.display = 'none';
				$('submenu_' + id).style.display = '';
			} else {
				$('menu_' + id).style.display = '';
				$('submenu_' + id).style.display = 'none';
			}
		}

		return false;
	}
	
	_registered_interval = {};

	function registerPartialForm(id) {
		if (_registered_interval['fit_' + id]) {
			clearInterval(_registered_interval['fit_' + id]);
		}
		
		_registered_interval['fit_' + id] = setInterval('updatePartialForm("' + id + '")', 5000);
		
		_active_page.intervals.push({
			name: id, 
			callback: 'updatePartialForm("' + id + '")',
			ref: _registered_interval['fit_' + id],
			interval: 10000
		});
	}
	
	function unregisterPartialForm(id) {return;
		clearInterval(_registered_interval['fit_' + id]);
	}

	function updatePartialForm(id) {
		return;
		
		var form = $(id);
		var conn = new TConnection;
		
		if (!form) {
			if (_debug) {
				dbg('Form "'+id+'" not exists');
			}
			return;
		}
		
		view_loading();
		conn.sUrl = form.getAttribute('action') + '&partial_store=1';
		conn.onData = createMethodReference({id:id, form:form}, function (conn) {
			evaluate_jcode();
			hide_loading();
			//alert(conn.responseText);
		});
		conn.sMethod = 'POST';
		
		var ip = form.getElementsByTagName('input');
		
		for (k = 0; k < ip.length; k ++) {
			if (ip[k] && ip[k].getAttribute('name') != null) {
				if (ip[k].getAttribute('type') == 'radio' || ip[k].getAttribute('type') == 'checkbox') {
					if (!ip[k].checked) {
						continue;
					}
				}
				conn.aPost[ip[k].getAttribute('name')] = ip[k].value;
			}
		}
		
		var t = form.getElementsByTagName('textarea');
		for (l = 0; l < t.length; l ++) {
			if (t[l] && t[l].getAttribute('name') != null) {
				conn.addPost(t[l].getAttribute('name'), t[l].value);
			}
		}
		
		t = form.getElementsByTagName('select');
		for (l = 0; l < t.length; l ++) {
			if (t[l] && t[l].getAttribute('name') != null) {
				conn.addPost(t[l].getAttribute('name'), t[l].value);
			}
		}
		
		conn.open();
	}

	var _load_to_con = null;
	
	function loadTo(url, id, onload) {
		view_loading('loading-partial');
		_load_to_con = new TConnection(url, createMethodReference({url:url, id:id, onload:onload}, function (conn) {
			var e = n('div');
			e.innerHTML = conn.responseText;
			
			$(this.id).innerHTML = '';
			$(this.id).appendChild(e);
			
			evaluate_jcode();
			hide_loading();
			
			if (this.onload) {
				this.onload();
			}
		}));
	}
	
	function cancel_loading() {
		if (_load_to_con) {
			_load_to_con.onData = null;
		}
		hide_loading();
	}


	function sendFormAndLoadPage(id, cnt) {
		if (_is_loading) 
			return;
			
		var form = $(id);
		var cnt = $(cnt ? cnt : id + '_container');
		if (_active_page) {
			//_active_page.url = conn.sUrl;
		}
		
		send_form(form, createMethodReference({cnt:cnt}, function (conn) {
			this.cnt.innerHTML = conn;
		}));
	}


	function send_form(form, onload) {
		if (_is_loading) 
			return;
			
		view_loading();
		var conn = new TConnection;
		
		var act = form.getAttribute('action');
		conn.sUrl = get_url(act, {partial: 1});
		
		if (_active_page) {
			//_active_page.url = conn.sUrl;
		}
		
		conn.onData = createMethodReference(onload, function (conn) {
			this(conn.responseText);
			evaluate_jcode();
			hide_loading();
		});
		
		if (form.getAttribute('method') == 'post') {
			conn.sMethod = 'POST';
		}
		
		var ip = get_by_tag(form, 'input', []);
		
		for (k = 0; k < ip.length; k ++) {
			if (ip[k] && ip[k].getAttribute('name') != null) {
				if (ip[k].getAttribute('type') == 'radio' || ip[k].getAttribute('type') == 'checkbox') {
					if (!ip[k].checked) {
						continue;
					}
				}
				
				if (ip[k].getAttribute('name') == 'partial') {
					continue;
				}
				
				if (form.getAttribute('method') == 'post') {
					conn.aPost[ip[k].getAttribute('name')] = ip[k].value;
				} else {
					conn.sUrl += '&' + urlencode(ip[k].getAttribute('name')) + '=' + urlencode(ip[k].value);
				}
			}
		}
		
		var t = form.getElementsByTagName('textarea');
		for (l = 0; l < t.length; l ++) {
			if (t[l] && t[l].getAttribute('name') != null) {
				if (form.getAttribute('method') == 'post') {
					conn.addPost(t[l].getAttribute('name'), t[l].value);
				} else {
					conn.sUrl += '&' + urlencode(t[l].getAttribute('name')) + '=' + urlencode(t[l].value);
				}
			}
		}
		
		t = form.getElementsByTagName('select');
		for (l = 0; l < t.length; l ++) {
			if (t[l] && t[l].getAttribute('name') != null) {
				if (form.getAttribute('method') == 'post') {
					conn.addPost(t[l].getAttribute('name'), t[l].value);
				} else {
					conn.sUrl += '&' + urlencode(t[l].getAttribute('name')) + '=' + urlencode(t[l].value);
				}
			}
		}
		
		conn.open();
	}

	function get_by_tag(e, t, res) {
		if (e.childNodes) {
			for (var i = 0; i < e.childNodes.length; i ++) {
				if (e.childNodes[i].nodeName.toLowerCase() == t) {
					res.push(e.childNodes[i]);
				}
				get_by_tag(e.childNodes[i], t, res);
			}
		}
		return res;
	}

	var _pages = [];
	var _active_page;

	function backward(id) {
		if (_active_page.id == 0) {
			return true; //use normal link
		}
		
		if (!id) id = 'page_container';
		
		for (var i = 0; i < _active_page.intervals.length; i ++) {
			clearInterval(_active_page.intervals[i].ref);
		}
		pid = (_active_page.id - 1);
		_active_page = _pages[pid];
		_url = _active_page.url;
		_urlid = _active_page.urlid;
		
		loadTo(_active_page.url, id);
		
		for (i = 0; i < _active_page.intervals.length; i ++) {
			_active_page.intervals[i].ref = setInterval(_active_page.intervals[i].callback, _active_page.intervals[i].interval);
		}
		
		return false;
	}
	
	function forward(id) {
		if (!id) id = 'page_container';
		
		if (_active_page.id == _pages.length - 1) {
			return true; //use normal link
		}
		
		for (var i = 0; i < _active_page.intervals.length; i ++) {
			clearInterval(_active_page.intervals[i].ref);
		}
		
		_active_page = _pages[_active_page.id + 1];
		_url = _active_page.url;
		_urlid = _active_page.urlid;
		loadTo(_active_page.url, id);
		
		for (i = 0; i < _active_page.intervals.length; i ++) {
			_active_page.intervals[i].ref = setInterval(_active_page.intervals[i].callback, _active_page.intervals[i].interval);
		}
		
		return false;
	}

	function add_page(url, urlid) {
		if (_active_page) {
			for (var i = 0; i < _active_page.intervals.length; i ++) {
				clearInterval(_active_page.intervals[i].ref);
			}
			
			if (_active_page.id != _pages.length-1) {
				_new_pages = [];
				for (var k = 0; k <= _active_page.id ; k ++) {
					_new_pages.push(_pages[k]);
				}
				_pages = _new_pages;
			}
		}
		
		_active_page = {
			intervals: [],
			url: url,
			urlid: urlid,
			id: _active_page ? _active_page.id + 1 : 0
		};
		
		_pages.push(_active_page);
	}

	var _opid = 0;
	function set_opid(v) {
		//_opid = v;
		
		/*_active_page = {
			intervals: [],
			url: get_url_opid(null, {partial: 1}),
			id: 0
		};
		_pages.push(_active_page);*/
	}
	
	function get_url_opid(url, param) {
		//if (!param) param = {};
		//param.opid = _opid;
		
		return get_url(url, param);
	}
	
	function do_partial(aobj, cntid) {
		if (_is_loading) 
			return false;

		var url = aobj;
		if (aobj && aobj.getAttribute) 
			url = aobj.getAttribute('href');

		url = new String(url);
		
		if (!cntid) 
			cntid = 'checkform_container';
		
		window.location.hash = 'L' + encode_s2c(url.replace(/.*?\?/, ''));
		
		var params = {'partial': 1};
		if ($('save_filters') && !$('save_filters').checked) {
			//params['clear_filters'] = 1;
			//params['filter'] = '';
		}
		
		url = get_url(url, params);
		
		view_loading();
		loadTo(url, cntid);
		
		return false;
	}

	function view_loading(sub) {
		j('.loading:hidden, .loading-caption:hidden, .loading-area:hidden').show('slide', 'slow');
	}

	function hide_loading(sub) {
		j('.loading, .loading-caption, .loading-area').hide('slide', 'slow');
	}
	
	function shadeoff(el, stepsize, hideafter) {
		j(el).fadeOut('slow');
	}
	
	function shadeoff_timeout(timeo, el, stepsize, hideafter) {
		var func = createMethodReference({el:el, stepsize:stepsize, hideafter:hideafter}, function () {
			shadeoff(this.el, this.stepsize, this.hideafter);
		});
		
		setTimeout(func, timeo);
	}

	var _pathes = [];
	function reset_pathes() {
//		_pathes = [];
//		$('pathes').innerHTML = '';
	}

	function path_add(name, url) {
//		var li = n('li');
//		var a = n('a');
//
//		a.setAttribute('href', url);
//		a.innerHTML = name;
//
//		li.appendChild(a);
//		$('pathes').appendChild(li);
	}

	var _evaluated = {};
	
	function evaluate_jcode() {
		var jc = getElementsByClass('jcode');
		
		for (var k = 0; k < jc.length; k ++) {
			var s = jc[k].getElementsByTagName('script')[0];
			
			if (s) {
				var ev = new String(s.innerHTML);
				ev = ev.replace('evaluate_jcode();', '');
				ev = ev.replace('<!--', '');
				ev = ev.replace('-->', '');
				
				if (!_evaluated[new String(jc[k].id)]) {
					try {
						eval((new String(ev)).toString());
					} catch (e) {
						debug(e);
					}

					_evaluated[new String(jc[k].id)] = 1;
				}
			}
		}
		
		show_class('js-show');
		hide_class('js-hide');
	}


	function show_confirm(onAccept, onRefuse, text, autohide, onAutohide) {
		var div = n('div');
		div.className = 'confirm';
		
		var placemark = n('div');
		div.appendChild(placemark);
		placemark.style.marginBottom = '5px';
		
		if (text) {
			div.innerHTML = text;
		}
		
		var refuse = n('input');
		var accept = n('input');
		
		refuse.type = accept.type = 'button';
		refuse.className = 'button refusebutton button_medium';
		accept.className = 'button acceptbutton button_medium';
		
		refuse.value = _l['Nie'];
		accept.value = _l['Tak'];
		
		var cfm = {
			onAccept: onAccept,
			onRefuse: onRefuse,
			onAutohide: onAutohide,
			div: div,
			autohide: autohide,
			accept: accept,
			refuse: refuse
		};
		
		attachEvent(refuse, 'click', createMethodReference(cfm, function () {
			this.div.style.display = 'none';
			
			if (this.onRefuse) {
				this.onRefuse();
			}
		}));
		
		attachEvent(accept, 'click', createMethodReference(cfm, function () {
			this.div.style.display = 'none';
			
			if (this.onAccept) {
				this.onAccept();
			}
		}));
		
		if (autohide) {
			setTimeout(createMethodReference(cfm, function () {
				if (this.div.style.display != 'none') {
					this.div.style.display = 'none';
					
					if (this.onAutohide) {
						this.onAutohide();
					}
					
					clearInterval(this.interval);
				}
			}), 1000*autohide);
			
			cfm.interval = setInterval(createMethodReference(cfm, function () {
				this.autohide --;
				this.refuse.value = _l['Nie'] + ' (' + this.autohide + ')';
			}), 1000);			
		}
		
		div.appendChild(refuse);
		div.appendChild(accept);
		
		//~ $('msg_container').innerHTML = '';
		$('msg_container').appendChild(div);
		
		return placemark;
	}

	function clear_msg_container() {
		$('msg_container').innerHTML = '';
	}

	function show_message(type, value, nohide) {
		//clear_msg_container();
		
		var im = '<img src="' + JS_HOST + 'view/images/icon_close.png" style="float:right;cursor: pointer;" onclick="shadeoff_timeout(1, this.parentNode, null, true);" />';
		
		var div = n('div');
		div.className = type;
		div.innerHTML = im + value;
		$('msg_container').appendChild(div);
		$('msg_container').style.display = '';
		var ow = $('msg_container').offsetWidth - 25;
		//$('msg_container').style.position = 'absolute';
		//$('msg_container').style.width = ow + 'px';
		//$('msg_container').className = 'msg_container_dynamic';
		
		attachEvent(div, 'click', createMethodReference(div, function () {
			shadeoff_timeout(1, this, null, true);
		}));
		
		if (!nohide) {
			shadeoff_timeout(10000, div, null, true);
		}
	}
	
	var _is_loading = false;
	function show_loading_msg(msg) {
		clear_msg_container();
		
		var div = n('div');
		div.className = 'loading';
		
		var img = n('img');
		img.src = JS_P + 'images/loading.gif';
		img.className = 'mid';
		
		div.appendChild(img);
		
		var span = n('span');
		span.innerHTML = msg;
		
		div.appendChild(span);
		$('msg_container').appendChild(div);
	}

	var _hook = [];
	setInterval(hook_listener, 500);

	function hook_add(name, callback) {
		var hook = {name: name, callback: callback, state: 0};
		_hook.push(hook);
	}

	function hook_listener() {
		for (var i = 0; i < _hook.length; i ++) {
			if (_hook[i].state == 0) {
				if ($(_hook[i].name)) {
					_hook[i].state = 1;
					var ev = $(_hook[i].name).getElementsByTagName('script')[0].innerHTML;
					eval((new String(ev)).toString());
					_hook[i].callback(data);
				}
			}
		}
	}

	function clear_smallmode() {
		var s = getElementsByClass('nosmallmode');
		for (var k = 0; k < s.length; k ++) {
			s[k].style.display = 'none';
		}
		s = getElementsByClass('onlysmallmode');
		for (k = 0; k < s.length; k ++) {
			s[k].style.display = '';
		}
	}

	function filt_list(formid) {
		var s = getElementsByClass('list-filter');
		var form = $(formid);
		
		var data = [];
		for (var i = 0; i < s.length; i ++) {
			data[s[i].getAttribute('name')] = s[i].value;
		}
		
		var oCon = new TConnection;
		oCon.aPost = data;
		oCon.sUrl = form.getAttribute('action') + '?partial=1&' + oCon.getParameters();
		
		oCon.onData = createMethodReference({form:form}, function (conn) {
			$('list_container').innerHTML = conn.responseText;
		});
		
		oCon.open();
	}

	function select_all_radio_with(name, value) {
		var radio = document.getElementsByTagName('input');
		for (var k = 0; k < radio.length; k ++) {
			if (radio[k].type == 'radio' && strpos(radio[k].id, name) == 0) {
				if ((new String(radio[k].value)).toLowerCase() == (new String(value)).toLowerCase()) {
					radio[k].checked = true; 
				} else {
					radio[k].checked = false;
				}
			}
		}
	}

	function select_all(name, strict, none) {
		if (typeof name == 'object') {
			for (var k = 0; k < name.length; k ++) {
				if (name[k].type == 'checkbox') {
					if (strict)
						name[k].checked = !none; 
					else
						name[k].checked = !name[k].checked; 
				}
			} 
		} else {
			var radio = document.getElementsByTagName('input');
			for (var k = 0; k < radio.length; k ++) {
				if (radio[k].type == 'checkbox' && strpos(radio[k].name, name) === 0) {
					if (strict)
						radio[k].checked = !none;
					else
						radio[k].checked = !radio[k].checked; 
				}
			}
		}
	}

	function get_checked(name) {
		var radio = document.getElementsByTagName('input');
		var res = [];
		for (var k = 0; k < radio.length; k ++) {
			if (radio[k].type == 'checkbox' && strpos(radio[k].name, name) === 0 && radio[k].checked) 
				res.push(radio[k]);
		}
		return res;
	}

	function style_by_class(className, styles) {
		var it = getElementsByClass(className);
		for (var k = 0; k < it.length; k ++) {
			for (var s in styles) {
				it[k].style[s] = styles[s];
			}
		}
	}

	function check_by_class(className, strict) {
		var it = getElementsByClass(className);

		if (it.length > 0)
			var stv = it[0].checked;
			
		for (var k = 0; k < it.length; k ++) 
			it[k].checked = strict ? !stv : !it[k].checked;
	}
	
	function style_by_id(id, styles) {
		var it = $(id);
		for (var s in styles) {
			it.style[s] = styles[s];
		}
	}

	function show_id(cls) {
		style_by_id(cls, {display: ''});
	}

	function hide_id(cls) {
		style_by_id(cls, {display: 'none'});
	}
	

	function show_hint(msg, element) {
		var hint = n('div');
		hint.className = 'hint';
		
		var mouse = get_mouse();
		hint.style.position = 'absolute';
		hint.style.top = mouse.y + 'px';
		hint.style.left = mouse.x + 'px';
		
		hint.innerHTML = msg;
		document.body.appendChild(hint);
		
		attachEvent(element, 'mouseout', createMethodReference(hint, function () {this.parentNode.removeChild(this)}));
	}

	function show_class(cls) {
		j('.' + cls).show();
	}

	function hide_class(cls) {
		j('.' + cls).hide();
	}
	
	var _urlid = 'none'; //id urla
	function set_url(url, id) {
		if (id && _urlid != id) {
			_url = url;
			_urlid = id;
			add_page(url, id);
		}
	}
	
	var _url = new String(window.location);
	
	function get_url(url, arg) {
//		var query = '';
		
		if (!url)
			url = _url;
		
		url = new String(url);
//
//		if (_url.match(/\?/)) {
//			query = _url.replace(/.*\?/, '');
//		}
		
		if (!url.match(/\?/)) 
			url += '?';
		
		for (var k in arg) {
			url = url.replace(new RegExp(k + "(\[.*?\])*=.*?(&|$)", "g"), '');
			url += '&' + encodeURI(k) + '=' + encodeURI(arg[k]);
		}
		url = url.replace(/\?\&+/, "?");
		url = url.replace(/\&+/, "&");
		
		return url;
	}

	function safe(string) {
		string = string.toString();
		
		string = string.replace(/&/g, '&');
		string = string.replace(/</g, '&lt;');
		string = string.replace(/>/g, '&gt;');
		
		string = string.replace(/"/g, '&quot;');
		string = string.replace(/'/g, '&#039;');
		
		return string;
	}

	function strpos( haystack, needle, offset){
		var i = haystack.indexOf( needle, offset );
		return i >= 0 ? i : false;
	}
	
	on_window_load(function () {
		show_class('js-show');
		hide_class('js-hide');
	});
	
	function waiting_button(button, sec) {
		sec --;
		button.value = button.value.replace(/ \([0-9]+\)$/, '');
		
		if (sec <= 0) {
			button.readonly = false;
			button.disabled = false;
			return;
		} else {
			button.readonly = true;
			button.disabled = true;
		}
		
		button.value += ' (' + sec + ')';
		
		setTimeout(createMethodReference({button:button, sec:sec}, function () {
			waiting_button(this.button, this.sec);
		}), 1000);
	}
	
	var in_array = function (search, arr) {
		for (var k in arr) {
			if (arr[k] == search) {
				return true;
			}
		}
		
		return false;
	};
	
	function in_array(needle, haystack) {
		if (haystack.length) {
			for (var k = 0; k < haystack.length; k ++) {
				if (haystack[k] == needle) 
					return true;
			}
			return false;
		}
		
		for (var k in haystack) {
			if (haystack[k] == needle) 
				return true;
		}
		return false;
	}	
	
	function is_def(variable) {
		return typeof(variable) !== 'undefined';
	}
	
	
	var CActionStack = function () {
		this.action = [];
	};
	
	CActionStack.prototype.push = function (callback, context) {
		if (is_def(context)) {
			callback = createMethodReference(context, callback);
		} 
		this.action.push(callback);
	};
	
	CActionStack.prototype.call = function () {
		for (var i = 0; i < this.action.length; i ++) {
			if (this.action[i]() === false) {
				break;
			}
		}
	};
	
	var _active_hint = {};
	function add_hint_for(el, hint, xy, group) {
		return new (function (el, hint, xy, group) {
			this.el = el;
			this.hint = hint;
			this.group = group;
			this.closeOnOut = true;
			this.c = new CElement;
			this.c.setElement(hint);

			if (this.el) {
				this.cel = new CElement;
				this.cel.setElement(el);
			}
			
			this.over = true;
			this.xy = xy;

			this.setXy = function (x, y) {
				this.xy = {x:x, y:y};
			};

			this.appendToElement = function (e) {
				var c = new CElement;
				c.setElement(e);
				this.setXy(c.getAbsoluteLeft() - 20, c.getAbsoluteTop()+15);

				this.cel = new CElement;
				this.cel.setElement(e);
			};
			
			this.onout = function () {
				if (this.closeOnOut && this.over) {
					this.over = false;
					setTimeout(createMethodReference(this, function () {this.close(false);}), 1000);
				}
			};

			this.onin = function () {
				return this.onmove(true);
			};
			
			this.onmove = function (force) {
				if (this.xy)
					this.open(this.xy.x, this.xy.y);
				else
					this.open(get_mouse().x, get_mouse().y);
			};

			this.open = function (x, y) {
				x = Math.min(parseInt(x), document.body.offsetWidth - 200);
				
				this.over = true;

				if (_active_hint[this.group] == this)
					return;

				if (_active_hint[this.group] && _active_hint[this.group] != this)
					_active_hint[this.group].close(true);

				var parent = document.body;

				if (window.parent) {
					parent = window.parent.document.body;
				}

				parent.appendChild(this.hint);

				_active_hint[this.group] = this;
				this.hint.style.display = '';
				this.hint.style.top = (y) + 'px';
				this.hint.style.left = (x) + 'px';
			};
			
			this.close = function (force) {
				if (!force && (this.c.isMouseOver() || (this.cel && this.cel.isMouseOver())))
					return;
					
				this.over = false;
				this.hint.style.display = 'none';

				if (_active_hint[this.group] == this)
					_active_hint[this.group] = null;
			};
			
			this.hint.style.position = 'absolute';
			this.hint.style.top = (get_mouse().y + 10) + 'px';
			this.hint.style.left = (get_mouse().x + 10) + 'px';
			
			if (this.el) {
				attachEvent(this.el, 'mousemove', createMethodReference(this, this.onin));
				attachEvent(this.el, 'mouseout', createMethodReference(this, this.onout));
			}
			
			attachEvent(this.hint, 'mousemove', createMethodReference(this, this.onmove));
			attachEvent(this.hint, 'mouseout', createMethodReference(this, this.onout));
			attachEvent(this.hint, 'mouseup', createMethodReference(this, this.onmove));
			
			attachEvent(document.body, 'mousedown', createMethodReference(this, this.onout));
			attachEvent(document.body, 'mousemove', createMethodReference(this, this.onout));
		})(el, hint, xy, group);
	}
	
	function get_element_absolute(element) {
		var res = {
			top: element.offsetTop,
			left: element.offsetLeft
		}
		
		if (element.offsetParent) {
			var parent = get_element_absolute(element.offsetParent);
			res.top += parent.top;
			res.left += parent.left;
		}
		
		return res;
	}
	
	function register_function(name, cbx) {
		window[name] = cbx;
	}
	
	var carnico = {
		"event": {
			events: {},
			add_listener: function (event, listener) {
				if (!this.events[event]) {
					this.events[event] = [];
				}
				
				this.events[event].push(listener);
			},
			"call": function (event, arg) {
				if (this.events[event]) {
					for (var k = 0; k < this.events[event].length; k ++) {
						this.events[event][k](arg);
					}
				}
			}
		}
	};

	var noptions_group = {};

	function getForm(obj) {
		if (obj.nodeName.toLowerCase() == 'form')
			return obj;
		return getForm(obj.parentNode);
	}
	
	function write_list_for(id, fid, title, s_options) {
		var list = $(id);
		
		var nlist = n('div');
		nlist.className = 'select-imitation';

		var group = 'gen' + (new Date()).getTime();
		var group_initial = false;
		if (s_options.group)
			group = s_options.group;

		if (!noptions_group[group]) {
			var noptions = n('div');
			noptions.style.position = 'absolute';
			noptions.style.display = 'none';
			noptions.className = 'select-imitation-options';

			noptions_group[group] = {
				"noptions": noptions,
				"active": null,
				"defalt": null,
				"no": []
			};

			var form = s_options.absolute ? document.body : getForm($(fid));
			form.appendChild(noptions);
			
			group_initial = true;
		}
		
		$(fid).appendChild(nlist);
		$(fid).className = 'select-imitation-container';
		$(fid).style.display = '';

		if (group_initial) {
			var first = -1;
			var o = list.getElementsByTagName('option');
			first = 0;
			
			nlist.innerHTML = o[first].innerHTML;
			noptions_group[group]["default"] = o[first].innerHTML;
		}
		
		var ndata = {
			num: 0, 
			value: [],
			title: title || "Wybrano", 
			nlist: nlist, 
			noptions: noptions_group[group].noptions,
			"checked": [],
			"focus": false,
			"disabled": false,
			"opened": false,
			"selected": 0,
			"default": noptions_group[group]["default"],
			'list':list,
			'multiple': true,
			'min': 0, 'max': 0,
			'icon_caption': false,
			'icon-height': 0,
			'group': group,
			'group_obj': noptions_group[group],
			'group_initial': group_initial,
			'onchange': function () {},
			'setTitle' : function () {
				if (this.selected == 0) {
					this.nlist.innerHTML = this['default'];
					this.nlist.style.fontWeight = 'normal';
				} else if (this.selected == 1) {
					for (i = 0; i < this.checked.length; i ++) {
						if (this.checked[i]) {
							if (this.icon_caption && this.group_obj.no[i].icon)
								this.nlist.innerHTML = '<img src="' + this.group_obj.no[i].icon.src + '" ' + (this['icon-height'] > 0 ? 'style="height: ' + this['icon-height'] + 'px;"' : '')+'  />';
							else
								this.nlist.innerHTML = ' ' + this.group_obj.no[i].name;

							break;
						}
					}
					this.nlist.style.fontWeight = 'bold';
				} else {
					this.nlist.innerHTML = ' '+this.title+': ' + this.selected;
					this.nlist.style.fontWeight = 'bold';
				}
			}
		};

		if (group_initial)
			list_parse_options(o, first+1, ndata);

		var opt = list.getElementsByTagName('option');
		
		var checked = s_options.checked;
		if (!s_options.checked) {
			checked = [];

			for (i = 0; i < noptions_group[group].no.length; i ++) {
				if (opt[i+1].getAttribute('selected') == "1")
					checked.push(i);
			}
		} else {
			checked = [];

			for (i = 0; i < noptions_group[group].no.length; i ++) {
				if (in_array(opt[i+1].getAttribute('value'), s_options.checked))
					checked.push(i);
			}
		}

		for (i = 0; i < noptions_group[group].no.length; i ++) {
			ndata.checked[i] = false;
			noptions_group[group].no[i].check.checked = false;
		}

		for (i = 0; i < checked.length; i ++) {
			ndata.checked[checked[i]] = 1;
			noptions_group[group].no[checked[i]].check.checked = true;
			ndata.selected ++;
			ndata.value.push(opt[checked[i]+1].getAttribute('value'));
		}

		ndata.setTitle();

		if ((ndata.num) * 26 < 250) {
			noptions_group[group].noptions.style.overflow = '';
			//noptions_group[group].noptions.style.height = 'auto';
		}
		
		if (s_options) {
			for (var k in s_options) {
				var val = s_options[k];
				switch (k) {
					case 'options-width':
						noptions_group[group].noptions.style.width = val + 'px';
						break;
						
					case 'select-width':
						nlist.style.width = val + 'px';
						break;
						
					case 'multiple':
					case 'min':
					case 'max':
					case 'icon_caption':
					case 'icon-height':
					case 'onchange':
						ndata[k] = val;
						break;
				}
			}
		}

		ndata.open = createMethodReference(ndata, function () {
			if (this.disabled)
				return;

			if (this.group)
				noptions_group[this.group].active = this;

			var c = new CElement;
			c.setElement(this.nlist);

			this.noptions.style.left = c.getAbsoluteLeft() + 'px';
			this.noptions.style.top = (c.getAbsoluteBottom()) + 'px';

			for (var i = 0; i < noptions_group[this.group].no.length; i ++) {
				noptions_group[this.group].no[i].check.checked = this.checked[i];
				noptions_group[this.group].no[i].element.className = this.checked[i] ? 'select-imitation-option select-imitation-option-active' : 'select-imitation-option';
			}

			if (this.opened)
				this.noptions.style.display = 'none';
			else
				this.noptions.style.display = '';

			this.focus = true;
			this.opened = !this.opened;
		});
		attachEvent(nlist, 'click', ndata.open);

		if (group_initial) {
			attachEvent(document.body, 'click', createMethodReference(noptions_group[group], function () {
				var ndata = this.active;

				if (ndata && !ndata.focus) {
					ndata.noptions.style.display = 'none';
					ndata.opened = false;
					this.active = null;
				}
			}));
		}
		
		var set_focus = createMethodReference(noptions_group[group], function () {
			var ndata = this.active;
			if (ndata)
				ndata.focus = true;
		});
		var unset_focus = createMethodReference(noptions_group[group], function () {
			var ndata = this.active;
			if (ndata)
				ndata.focus = false;
		});
		
		attachEvent(nlist, 'mouseover', set_focus);
		attachEvent(nlist, 'mousemove', set_focus);
		attachEvent(nlist, 'mouseout', unset_focus);

		if (group_initial) {
			attachEvent(noptions, 'mouseover', set_focus);
			attachEvent(noptions, 'mousemove', set_focus);
			attachEvent(noptions, 'mouseout', unset_focus);
		}
		
		list.style.display = 'none';
		list.name = '';

		return ndata;
	}
	
	function list_parse_options(o, first, ndata) {
		for (var i = first; i < o.length; i ++) {
			var no = n('div');
			var span = n('span');
			var check = n('input');
			
			no.className = 'select-imitation-option';
			
			var table = new CTable(no);
			var no_side = table.createRow(2);
			
			no_side[0].style.width = '28px';
			no_side[0].className = 'select-imitation-option-left';
			no_side[1].className = 'select-imitation-option-right';

			ndata.noptions.appendChild(no);
			
			check.type = ndata.multiple ? 'checkbox' : 'radio';
			check.name = ndata.list.name;
			check.value = o[i].value;
			no_side[0].appendChild(check);
			check.readonly = true;
			check.className = 'no-replace';
			check.style.padding = '0';
			check.style.margin = '0';
			check.style.border = '0';
			check.style.background = 'transparent';
			
			var settings = {};
			
			if ((new String(o[i].getAttribute('title'))).charAt(0) == '{') {
				try {
					eval('var settings = ' + o[i].getAttribute('title') + ';');
				} catch (E) {
					settings = {};
				}
			}
			
			if (o[i].getAttribute('icon'))
				settings.icon = o[i].getAttribute('icon');
			
			var icon = null;
			if (settings.icon) {
				icon = n('img');
				icon.src = settings.icon;
				check.style.display = 'none';
				no_side[0].appendChild(icon);
			}
			
			var nod = {selected: false, element: no, side: no_side, value: o[i].value, name: o[i].innerHTML, last:0, check:check, icon:icon};
			
			span.innerHTML = ' ' + o[i].innerHTML;
			no_side[1].appendChild(span);
			
			noptions_group[ndata.group].no.push(nod);
			ndata.num ++;
			
			var clicked = createMethodReference({group:noptions_group[ndata.group], no:no, check:check, span:span, nod:nod, i:noptions_group[ndata.group].no.length - 1}, function () {
				this.ndata = this.group.active;

				if (this.ndata.disabled)
					return;

				var t = (new Date).getTime();
				if ((t - this.nod.last) < 200) 
					return;
				
				this.nod.last = t;
				
				if (this.ndata['min'] > 0 && this.ndata.checked[this.i] && this.ndata['min'] <= this.ndata.selected)
					return;
				
				if (this.ndata['max'] > 0 && !this.ndata.checked[this.i] && this.ndata['max'] >= this.ndata.selected)
					return;
				
				this.ndata.checked[this.i] = !this.ndata.checked[this.i];
				this.check.checked = this.ndata.checked[this.i];
				
				if (this.check.checked) {
					if (!this.ndata.multiple) {
						for (var i = 0; i < this.ndata.no.length; i ++) {
							if (this.ndata.checked[i] && this.group.no[i].check.id != this.check.id) {
								this.ndata.checked[i] = false;
								this.group.no[i].check.checked = false;
								this.ndata.selected --;
								this.group.no[i].element.className = 'select-imitation-option';
							}
						}
					}
					
					this.ndata.selected ++;
					this.no.className = 'select-imitation-option select-imitation-option-active';
				} else {
					this.ndata.selected --;
					this.no.className = 'select-imitation-option';
				}
				
				this.ndata.setTitle();
				
				if (!this.ndata.multiple) 
					this.ndata.value = [];
				
				if (this.check.checked) {
					this.ndata.value.push(this.check.value);
				} else {
					var ne = [];
					for (var k = 0; k < this.ndata.value.length; k ++) {
						if (this.ndata.value[k] != this.check.value) {
							ne.push(this.ndata.value[k]);
						}
					}
					this.ndata.value = ne;
				}
				
				this.ndata.onchange(!this.ndata.multiple ? this.ndata.value[0] : this.ndata.value);
			});
			
			attachEvent(no, 'click', clicked);
			attachEvent(check, 'click', clicked);
		}
	}
	
	function clone(obj) {
		var cn = {};
		for (p in obj) {
			cn[p] = obj[p];
		}
		return cn;
	}
	
	var _delay_action = {};
	function delay_action(name, delay, action) {
		clearInterval(_delay_action[name]);
		_delay_action[name] = setTimeout(action, delay);
		//debug('delay_action ' + name);
	}
	
	function unregister_delay(name) {
		if (delay_registered(name)) {
			clearInterval(_delay_action[name]);
			_delay_action[name] = null;
			
			//debug('unregister_delay ' + name);
		}
	}
	
	function register_delay(name, handle) {
		if (delay_registered(name)) {
			unregister_delay(name);
		}
		
		_delay_action[name] = handle;
		
		//debug('register_delay ' + name);
	}
	
	function delay_registered(name) {
		return _delay_action[name];
	}
	
	function preventDefault(event) {
		if (event.preventDefault) {
			event.preventDefault();
		} else {
			event.returnValue = false;
		}
	}
	
	function add_search() {
		if (window.external && ("AddSearchProvider" in window.external)) {
			window.external.AddSearchProvider("http://ppd.pl/search.xml");
		} else if (window.sidebar && ("addSearchEngine" in window.sidebar)) {
			window.sidebar.addSearchEngine("http://ppd.pl/search.src", "http://ppd.pl/view/images/favicon.png", "PPD.pl", "");
		} else {
			alert("Korzystasz ze zbyt starej wersji przeglądarki lub Twoja przeglądarka nie obsługuje dodatkowych silników wyszukiwania.");
		}
	}
	
	function rgb2hex(rgb) {
		return (rgb[0] < 16 ? '0' : '') + rgb[0].toString(16)+ (rgb[1] < 16 ? '0' : '')+rgb[1].toString(16)+(rgb[2] < 16 ? '0' : '')+rgb[2].toString(16);
	}
	
	function setcookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function getcookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function encode_s2c(s) {
		var res = '';
		for (var i = 0; i < s.length; i ++) {
			if (s.charCodeAt(i) < 16)
				res += '0';
				
			res += s.charCodeAt(i).toString(16);
		}
		return res;
	}
	
	function decode_s2c(s) {
		var res = '';
		for (var i = 0; i < s.length; i += 2) {
			res += String.fromCharCode(parseInt(s.substr(i, 2), 16));
		}
		return res;
	}

	function get_price(iCent, bCurrency, bCent) {
		iCent = new String(iCent);
		iCent.replace(/^(-)?0+/, '', iCent);
		iCent = new String(parseInt(Math.round(iCent), 10));

		if (parseInt(iCent) >= 100) {
			sPrice = iCent.substr(0, iCent.length - 2) + (bCent ? ',' + iCent.substr(iCent.length-2, 2) : '');
		} else if (parseInt(iCent) >= 10) {
			sPrice = '0' + (bCent ? ',' + iCent : '');
		} else {
			sPrice = '0' + (bCent ? ',0' + iCent : '');
		}

		var sRes = "";
		for (var i = (bCent ? 6 : 3); i < sPrice.length; i += 3) {
			sPrice = substr(sPrice, 0, sPrice.length-i) + " " + substr(sPrice, sPrice.length-i, i);
			i ++;
		}

		return sPrice + (bCurrency !== false ? ' PLN' : '');
	}

	function time_diff_s(mTime, mTime2) {
		if (!(mTime2))
			mTime2 = time();

		iTime = (mTime);
		iTime2 = !(mTime2) ? time() : (mTime2);

		iDiff = Math.abs(iTime - iTime2);

		iYears = Math.floor(iDiff / 31536000);iDiff -= 31536000*iYears;
		iMonths = Math.floor(iDiff / (86400 * 31));iDiff -= 86400*31*iMonths;
		iDays = Math.floor(iDiff / 86400);iDiff -= 86400*iDays;
		iHours = Math.floor(iDiff / 3600);iDiff -= 3600*iHours;
		iMinutes = Math.floor(iDiff / 60);iDiff -= 60*iMinutes;

		sRes = '';
		dsp = 0;
		if (iYears > 0) {
			sRes += l('%0l', iYears);
			dsp ++;
		}

		sRes += ' ';
		if (iMonths > 0) {
			sRes += l('%0m', iMonths);
			dsp ++;
		}

		if (dsp == 2) return trim(sRes);

		sRes += ' ';
		if (iDays > 0) {
			sRes += l('%0d', iDays);
			dsp ++;
		}

		if (dsp == 2) return trim(sRes);

		sRes += ' ';
		if (iHours > 0) {
			sRes += l('%0h', iHours);
			dsp ++;
		}

		if (dsp == 2) return trim(sRes);

		sRes += ' ';
		if (iMinutes > 0) {
			sRes += l('%0m', iMinutes);
			dsp ++;
		}

		if (dsp == 2) return trim(sRes);

		sRes += ' ';
		if (iDiff > 0) {
			sRes += l('%0s', iDiff);
			dsp ++;
		}

		return trim(sRes);
	}

	function time_diff(mTime, mTime2) {
		if (!(mTime2))
			mTime2 = time();

		iTime = (mTime);
		iTime2 = !(mTime2) ? time() : (mTime2);
		
		iDiff = Math.abs(iTime - iTime2);

		iYears = Math.floor(iDiff / 31536000);iDiff -= 31536000*iYears;
		iMonths = Math.floor(iDiff / (86400 * 31));iDiff -= 86400*31*iMonths;
		iDays = Math.floor(iDiff / 86400);iDiff -= 86400*iDays;
		iHours = Math.floor(iDiff / 3600);iDiff -= 3600*iHours;
		iMinutes = Math.floor(iDiff / 60);iDiff -= 60*iMinutes;

		sRes = '';
		dsp = 0;
		if (iYears > 0) {
			if (iYears == 1) {
				sRes += l('1 rok');
			} else if (in_array(substr(iYears, -1), array(2, 3, 4)) && substr(iYears, -1) != 1) {
				sRes += l('%0 lata', iYears);
			} else {
				sRes += l('%0 lat', iYears);
			}
			dsp ++;
		}

		sRes += ' ';
		if (iMonths > 0) {
			if (iMonths == 1) {
				sRes += l('1 miesiąc');
			} else if (in_array(substr(iMonths, -1), array(2, 3, 4)) && substr(iMonths, -1) != 1) {
				sRes += l('%0 miesiące', iMonths);
			} else {
				sRes += l('%0 miesięcy', iMonths);
			}
			dsp ++;
		}

		if (dsp == 2) return trim(sRes);

		sRes += ' ';
		if (iDays > 0) {
			if (iDays == 1) {
				sRes += l('1 dzień');
			} else {
				sRes += l('%0 dni', iDays);
			}
			dsp ++;
		}

		if (dsp == 2) return trim(sRes);

		sRes += ' ';
		if (iHours > 0) {
			if (iHours == 1) {
				sRes += l('1 godzina');
			} else if ((iHours < 10 || iHours > 20) && in_array(substr(iHours, -1), [2, 3, 4]) && substr(iHours, -1) != 1) {
				sRes += l('%0 godziny', iHours);
			} else {
				sRes += l('%0 godzin', iHours);
			}
			dsp ++;
		}

		if (dsp == 2) return trim(sRes);

		sRes += ' ';
		if (iMinutes > 0) {
			if (iMinutes == 1) {
				sRes += l('1 minuta');
			} else if ((iMinutes < 10 || iMinutes > 20) && in_array(substr(iMinutes, -1), [2, 3, 4]) && substr(iMinutes, -1) != 1) {
				sRes += l('%0 minuty', iMinutes);
			} else {
				sRes += l('%0 minut', iMinutes);
			}
			dsp ++;
		}

		if (dsp == 2) return trim(sRes);

		sRes += ' ';
		if (iDiff > 0) {
			if (iDiff == 1) {
				sRes += l('1 sekunda');
			} else if ((iDiff < 10 || iDiff > 20) && in_array(substr(iDiff, -1), [2, 3, 4]) && substr(iDiff, -1) != 1) {
				sRes += l('%0 sekundy', iDiff);
			} else {
				sRes += l('%0 sekund', iDiff);
			}
			dsp ++;
		}

		return trim(sRes);
	}


	function substr(s, st, len) {
		s = new String(s);

		if (st < 0) {
			st += s.length;
		}

		if (len == undefined) {
			len = s.length;
		} else if (len < 0){
			len += s.length;
		} else {
			len += st;
		}

		if (len < st) {
			len = st;
		}

		return s.substring(st, len);
	}

	function trim(s) {
		return ltrim(rtrim(s));
	}

	function ltrim(s) {
		return (new String(s)).replace(new RegExp("^[ \t\r\n]+", "g"), "");
	}

	function rtrim(s) {
		return (new String(s)).replace(new RegExp("[ \t\r\n]+$", "g"), "");
	}

	function l(s) {
		for (var i = 1; i < arguments.length; i ++) {
			s = s.replace('%' + (i-1), arguments[i]);
		}

		return s;
	}

	function time() {
		return Math.round((new Date()).getTime()/1000 - _timediff);
		return _thetime;
	}

	function array() {
		var res = [];
		for (var i = 0; i < arguments.length; i ++)
			res.push(arguments[i]);

		return res;
	}

	function get_html_translation_table(table) {
		var entities = {}, histogram = {}, decimal = 0, symbol = '';

		entities['38'] = '&amp;';
		entities['60'] = '&lt;';
		entities['62'] = '&gt;';

		for (decimal in entities) {
			symbol = String.fromCharCode(decimal)
			histogram[symbol] = entities[decimal];
		}

		return histogram;
	}

	function htmlspecialchars (s, quote_style) {
		var tmp_str = new String(s);

		var histogram = {}, symbol = '', i = 0;

		if (false === (histogram = get_html_translation_table('HTML_SPECIALCHARS', quote_style))) {
			return false;
		}

		for (symbol in histogram) {
			entity = histogram[symbol];
			tmp_str = tmp_str.split(symbol).join(entity);
		}

		return tmp_str;
	}

	function array_unshift(a, val) {
		return a.unshift(val);
	}

	function array_pop(a) {
		return a.pop();
	}
	function array_push(a, val) {
		return a.push(val);
	}


	on_window_load(function () {
		if (typeof(console) == 'undefined') {
			var console = {"log": function () {}};
		}
	});

	function list_changePage(p, loc) {
		window.scroll(0, 0);
		return changePage(p, loc);
	}


	function set_caret(inputEl, selStart, selEnd) {
		if (inputEl.setSelectionRange) {
			inputEl.focus();
			inputEl.setSelectionRange(selStart, selEnd);
		} else if (inputEl.createTextRange) {
			var range = inputEl.createTextRange();
			range.collapse(true);
			range.moveEnd('character', selEnd);
			range.moveStart('character', selStart);
			range.select();
		}
	}

	var dynamic_enabled = false;
	var has_focus = true;
	var last_focus = 0;

	if (isIe()) {
		window.onfocus = function () {
			has_focus = true;
			get_inactive_msg().style.display = 'none';
		};
		document.onclick = function () {
			has_focus = true;
			get_inactive_msg().style.display = 'none';
			last_focus = (new Date).getTime();
		};
		window.onblur = function () {
			if ((new Date).getTime() - last_focus > 200) {
				has_focus = false;
				if (dynamic_enabled) get_inactive_msg().style.display = '';
			}
		};
	} else {
		attachEvent(window, 'focus', function () {
			has_focus = true;
			get_inactive_msg().style.display = 'none';
		});
		attachEvent(window, 'blur', function () {
			has_focus = false;

			if (dynamic_enabled) get_inactive_msg().style.display = '';
		});
	}

	function is_focused() {
		return has_focus;
	}

	function get_inactive_msg() {
		if (im = $('inactive-msg'))
			return im;

		var im = n('div');
		im.id = 'inactive-msg';
		im.className = 'error';
		im.innerHTML = 'Okno zostało uznane za nieaktywne. Dane nie będą odświeżane. <a class="important" onclick="has_focus = true; this.parentNode.style.display=\'none\';">Kliknij, aby aktywować okno</a> (lub kliknij gdziekolwiek na stronie).';
		im.style.display = 'none';

		$('msg_container').appendChild(im);

		return im;
	}



	/*** Events handling ***/

	j(document).ready(function () {

//		j('.desk-item').mouseover(function () {
//			j(this).stop().animate({
//				height: (j(this).children('ul').height() + 40) + 'px'
//			}, 'fast', function () {
//				if (!j(this).hasClass('desk-item-noexpand'))
//					j(this).css('background-image', "url('" + JS_HOST + "view/images/section/arrow-up.png')");
//			});
//		});

//		j('.desk-item').mouseleave(function () {
//			j(this).stop().animate({
//				height: '40px'
//			}, 'fast', function () {
//				if (!j(this).hasClass('desk-item-noexpand'))
//					j(this).css('background-image', "url('" + JS_HOST + "view/images/section/arrow-down.png')");
//			});
//		});

		var _menu_last = null;
		var _menu_on = false;

		j('.desk-item').mouseleave(function () {
			_menu_on = false;
		});
		j('.desk-item').mouseenter(function () {
			_menu_on = true;
		});

		j('div').click(function () {
			if (_menu_last && !_menu_on) {
				var item = _menu_last;
				
				if (item.height() > 45) {
					item.stop().animate({
						height: '40px'
					}, 'fast', function () {
						if (!j(this).hasClass('desk-item-noexpand'))
							j(this).css('background-image', "url('" + JS_HOST + "view/images/section/arrow-down.png')");
					});
				}
			}
		});

		j('.desk-item-label').click(function () {
			if (_menu_last) {
				item = _menu_last;

				if (item.height() > 45) {
					item.stop().animate({
						height: '40px'
					}, 'fast', function () {
						if (!j(this).hasClass('desk-item-noexpand'))
							j(this).css('background-image', "url('" + JS_HOST + "view/images/section/arrow-down.png')");
					});
				}
			}

			var item = j(this).parent();
			_menu_last = item;
			
			if (item.height() > 45) {
				item.stop().animate({
					height: '40px'
				}, 'fast', function () {
					if (!j(this).hasClass('desk-item-noexpand'))
						j(this).css('background-image', "url('" + JS_HOST + "view/images/section/arrow-down.png')");
				});
			} else{
				item.stop().animate({
					height: (item.children('ul').height() + 40) + 'px'
				}, 'fast', function () {
					if (!j(this).hasClass('desk-item-noexpand'))
						j(this).css('background-image', "url('" + JS_HOST + "view/images/section/arrow-up.png')");
				});
			}
		});

		j('.desk-expand a').click(function (e) {
			e.preventDefault();

			if (j(this).text() == 'zwiń') {
				j('.desk-in').css('height', '55px').hide('slide', {direction: "up"}, 'slow', function () {
					j('.desk-imitation').hide();
				});
				j(this).text('rozwiń');
			} else {
				j('.desk-imitation').show();
				j('.desk-in').css('height', '55px').show('slide', {direction: "up"}, 'slow');
				j(this).text('zwiń');
			}
		});

	});