function doSwitchComment()
{
     $('addkomentarz').style.display = 'block';
     $('listkomentarz').style.display = 'none';
}
function switchimg(img,dest)
{
	img.src = 'imgn/tabs/'+dest;
}
function switchimgtop(img,dest)
{
	img.src = 'imgn/menu/'+dest;
}

function switchimgM(img,dest)
{
	img.src = 'imgn/tabs/'+dest;
}

/**
 * @project MavSelectBox (Customizable Select boxes)
 * @author Dustin Hansen
 * @version 0.5.1
 * @url http://fuzecore.com, http://maveno.us
 * @license MIT Style License
 * 
 * @contributions
 * : Container additions for using selectbox in animations and bug fixes
 * : fixed multiselect bug, yayyy! ^_^
 * : Quentin Ambard - http://www.quentin.avricot.com
 */

var MavSelectBox = new Class({
	Implements: [Options, Events],

	options: {
		allowSplit: true,							// depricate for .filter()
		altClass: 'select-box-alt',
		alternate: false,
		alternateOdd: false,
		attachResize: true,
		container: null,
		disableClass: 'disabled',
		elem: null,
		filter: null,
		fxOptions: {},
		groupClass: 'select-box-options-group',
		maxShow: null,
		minShow: 3,
		optionClass: 'select-box-opt',
		selectboxClass: 'select-box',
		selectClass: 'selected',
		selectmenuClass: 'select-box-options',
		separator: '--',							// depricate for .filter()
		showStyles: false,
		size: 1,
		useFx: true,

		onHide: $empty(),
		onOver: $empty(),
		onSelect: $empty(),
		onShow: $empty()
	},

	container: null,
	element: null,
	focused: null,
	length: 0,
	selected: null,
	selectedIndex: 0,
	showing: false,
	textSearch: '',
	version: '0.5.1',

	initialize: function(_options) {
		var opts = ($type(_options) != 'object' ? {'elem':_options} : _options);
		if (!$defined(opts.elem)) return;

		this.setOptions(opts);

		if (this.options.filter) {
			this.filter = this.options.filter;
		}

		this.element = $(this.options.elem);
		this.elementCopy = this.element.clone().set({
			'id':this.element.get('id'),
			'name':this.element.get('name')
		});

		if (!$defined(this.options.container) || (this.container = $(this.options.container)) == null) {
			this.container = null;
		}

		this.optClass = 'li[class*=' + this.options.optionClass + ']';

		this.create_select();
		if (this.options.attachResize) { window.addEvent('resize', function() { if (this.showing) { this.show(); } }.bind(this)); }
	},

	destroy: function(_revert) {
		if (_revert) {
			if (this.selected && $defined(this.selected.retrieve('value'))) {
				$each(this.elementCopy.options, function(_elem) {
					if (_elem.value == this.selected.retrieve('value')) { _elem.selected = true; }
				}, this);
			}

			this.elementCopy.replaces($(this.element.get('id')));
		}

		this.remove_events();
		this.elementSelect.destroy();
	},

	create_select: function() {
		var wh = this.element.getSize();
		this.eid = this.element.get('id');

		// create the select element
		this.elementSelect  = new Element('div', {
			'class': this.options.selectboxClass, 
			'styles': { 'width': wh.x, 'height': '18px' }
		}).inject(this.element, 'after');

		// create display element for selectbox
		this.elementDisplay = new Element('a', {'href':'javascript:void(0)'}).inject(this.elementSelect, 'top');
		if (this.elementCopy.get('tabindex') != 0) {
			this.elementDisplay.set('tabindex', this.elementCopy.get('tabindex'));
		}

		this.elementDisplay.setStyles({'height': (wh.y-5), 'line-height': (wh.y-5)});
		this.add_events();

		// create the options element
		this.elementOptions = new Element('ul', {
			'styles': { 'width': wh.x },
			'opacity': (this.options.useFx ? 0 : 1),
			'class': this.options.selectmenuClass
		}).inject(this.elementSelect);

		// create the fx object if useFx is set
		this.fx = this.options.useFx ? new Fx.Tween(this.elementOptions, $merge({
			'duration': '200', 
			'link': 'cancel'
		}, this.options.fxOptions)) : null;

		// loop thru existing options and recreate
		$each(this.element.getChildren(), this.create_option.bind(this));

		// set alternating
		if (this.options.alternate) {
			this.elementOptions.getElements(this.optClass + ':' + (this.options.alternateOdd ? 'odd': 'even')).addClass(this.options.altClass);
		}

		// set default selected option and dislpay value
		(this.selected = this.elementOptions.getElement('li.' + this.options.selectClass)).removeClass(this.options.selectClass);
		this.selectedIndex = this.selected.retrieve('idx');

		this.elementDisplay.set({
			'html': this.selected.get('html'),
			'class': (this.options.showStyles ? this.selected.get('class') : ''),
			'style': (this.options.showStyles ? this.selected.get('style') : '')
		});

		// store option menu coords info
		this.elementOptions.store('coords', this.elementOptions.getCoordinates()).setStyles({'visibility':'','display':'none'});

		// replace select element with hidden input by same id/name
		this.element = new Element('input', {
			'type': 'hidden',
			'value': this.element.get('value'),
			'id': this.element.get('id'),
			'name': this.element.get('name')
		}).replaces(this.element).set('id', this.eid);
	},

	create_option: function(_opt, _idx, _group) {
		// get option information
		var val = _opt.get('value'), selected = !!(_opt.selected);
		var text = (_opt.get('label') ? _opt.get('label') : (_opt.get('text') || '&nbsp;'));

		// determine class for option
		var opt_class = (_opt.get('tag')=='optgroup'?' optgroup unselectable':' ' + this.options.optionClass) + (selected&&!_opt.disabled?' '+this.options.selectClass:'') +
						(_opt.disabled?' '+this.options.disableClass:'');

		// create li replacement for select option
		var new_option = new Element('li', {
			'id': this.eid + '_opt' + _idx,
			'html': this.filter(text, null, '<span>%s</span>'),
			'style': _opt.get('style'),
			'class': _opt.get('class') + opt_class
		}).store('value', _opt.get('value'))
		  .store('idx', (_opt.get('tag')!='optgroup'?(++this.length):''))
		  .addEvents({
			'mouseover': this.over.bind(this),
			'mousedown': this.select.bind(this)
		}).inject(($(_group) || this.elementOptions));

		new_option.store('coords', new_option.getCoordinates());
		
		if (_opt.get('tag') == 'optgroup') {
			var optgroup = new Element('ul', {'class': this.options.groupClass}).inject(new_option);
			$each(_opt.getChildren(), function(_sopt, _sidx) {
				this.create_option(_sopt, (_idx + '' + _sidx), optgroup);
			}, this);
		}

		// THIS TO BE REPLACED WITH this.filter()
		// if option.text matches this.options.separator split and go left / right with text
		if (this.options.allowSplit && text.match(new RegExp(this.options.separator))) {
			text = text.split(this.options.separator);
			this.elementOptions.lastChild.set('html', '<span><span class="goleft">' + text[0].trim() + '</span><span class="goright">' + text[1].trim() + '</span><br style="clear:both" /></span>');
		}
	},
	
	filter: function(_str, _regx, _tmplt) {
		return _tmplt.replace(/\%s/i, _str);
	},
	
	inject: function(_option, _where) {
		
	},
	
	dispose: function(_elem) {
		
	},
	
	add_events: function() {
		this.elementDisplay.addEvents({
			'click': this.show.bind(this),
			'keydown': this.key_option.bind(this),
			'blur': this.hide.bind(this)
		});
	},
	
	remove_events: function() {
		this.elementDisplay.removeEvents({
			'click': this.show.bind(this),
			'keydown': this.key_option.bind(this),

			'blur': this.hide.bind(this)
		});
	},

	key_option: function(e) {
		e = new Event(e);
		if (e.key != 'tab') {
			e.stop();
			switch(e.key) {
				case 'esc':
					this.hide();
					break;

				case 'enter':
					this.select(this.selected);
				case 'tab':
					this.hide();
					break;
				
				case 'up': case 'down':
					if (e.alt) { this.show(); }
					this.select(e.key);
					break;
				
				case 'shift': case 'control': case 'alt':
					break;

				default:
					this.search(e.key);
			}
		}
	},

	search: function(_key, _retrying) {
		this.textSearch += _key;
		var option_elems = this.get_options(), str_found=false, elem = false;
		// var option_elems = this.get_options('li[text^=' + this.textSearch +']'), str_found=false, elem = false;

		for(var i=0; i<option_elems.length; i++) {
			var elem = option_elems[i]
			if ((elem.get('text')).match(new RegExp('^' + this.textSearch, 'i'))) {
				if (this.selected != elem) { this.select(elem); }
				str_found = true;
				break;
			}
		}

		if (str_found === false) {
			this.textSearch = '';
			if (!_retrying) { this.search(_key, true); }
		}
	},

	get_options: function(_selector) {
		return this.elementOptions.getElements((_selector || this.optClass));
	},

	// is there a better way to do this?
	determine: function(_elem) {
		var elem = ($type(_elem) == 'element' ? (_elem.get('tag') != 'li' ? _elem.getParent('li') : _elem) : this.get_options());

		if ($type(_elem) != 'element') {
			var fromIdx = ((this.focused && this.focused != this.selected) ? this.focused : this.selected).retrieve('idx');

			elem = elem.filter(function(_el) {
						return (!$(_el).hasClass(this.options.disableClass) && 
								((_elem == 'up' && $(_el).retrieve('idx') < fromIdx ) ||
								 (_elem == 'down' && $(_el).retrieve('idx') > fromIdx)));
			}, this);

			elem = elem[0] ? (_elem == 'up' ? elem.reverse() : elem)[0] : elem;
		}

		return elem;
	},

	over: function(e) {
		e = new Event(e);
		var elem = ($(e.target).get('tag') != 'li' ? $(e.target).getParent('li') : $(e.target));

		if (!elem.hasClass(this.options.disableClass) && !elem.hasClass('unselectable')) {
			if ($type(this.focused) == 'element') { this.focused.removeClass(this.options.selectClass); }
			(this.focused = elem).addClass(this.options.selectClass);
			this.fireEvent('over');
		}
	},

	select: function(_elem) {
		var elem = ($type(_elem) == 'event' ? new Event(_elem).target : _elem);
		elem = this.determine(elem);
		
		if (elem && !elem.hasClass(this.options.disableClass) && !elem.hasClass('unselectable')) {
			if (this.focused) { this.focused.removeClass(this.options.selectClass); }
			if (this.showing === true) {
				(this.focused = this.selected = elem).addClass(this.options.selectClass);
				this.scroll();
			} else {
				this.selected = elem;
			}

			this.element.set('value', this.selected.retrieve('value'));
			this.selectedIndex = this.selected.retrieve('idx');

			this.elementDisplay.set({
				'html': this.selected.get('html'),
				'class': (this.options.showStyles ? this.selected.get('class') : ''),
				'style': (this.options.showStyles ? this.selected.get('style') : '')
			}).removeClass(this.options.selectClass).removeClass(this.options.altClass);

			this.fireEvent('select', this.selected);
		}
	},

	scroll: function() {
		var sElem = this.elementOptions.getCoordinates();
		var selElem = this.selected.getCoordinates();
		var elScrollTop = this.elementOptions.scrollTop;

		if ((elScrollTop + sElem.height) < (selElem.top - sElem.top + 5)) {
			this.elementOptions.scrollTop = (selElem.top - sElem.top - sElem.height + selElem.height);
		}
		else if ((selElem.top - sElem.top + selElem.height) < (elScrollTop + 5)) {
			this.elementOptions.scrollTop = (selElem.top - sElem.top);
		}
	},

	show: function() {
		var coords = this.elementOptions.retrieve('coords');
		var sElem = this.elementSelect.getCoordinates(), sElem_top = (sElem.top + sElem.height);

		if (this.container) {
			sElem_top -= this.container.getStyle('top');
			sElem.left -= this.container.getStyle('left');
		}

		var h = ((window.getSize().y + window.getScroll().y) - sElem_top);
		var height = (coords.height >= h ? 0 : 'auto'), showing = 0;

		if (coords.height >= h) {
			$each(this.get_options(), function(_elem) {
				var eH = _elem.retrieve('coords').height;
				if (height < h && (height + eH) < h) { height += eH; showing++; }
			}, this);

			if (showing < this.options.minShow) {
				height = (sElem.top < coords.height ? sElem.top - 10 : coords.height);
				sElem_top = sElem.top - height - 1;
			}
		}

		this.elementOptions.setStyles({
			'display': '', 
			'height': height, 
			'top': sElem_top, 
			'left': sElem.left,
			'margin': 0
		});
		this.scroll();

		this.showing = true;
		this.focused = this.selected;
		this.focused.addClass(this.options.selectClass);
		this.fireEvent('show');

		if (this.options.useFx) { this.fx.start('opacity', 0, 1); }
		
		// fixes chrome/safari focus bug
		this.elementDisplay.focus();
	},

	hide: function(e) {
		if (this.showing) {
			if (this.options.useFx) {
				this.fx.start('opacity', 1, 0).chain(function() {
					this.elementOptions.scrollTop = 0;
					this.elementOptions.setStyle('display', 'none');

					if (this.focused) {
						this.focused.removeClass(this.options.selectClass);
					}
					this.showing = this.focused = false;
				}.bind(this));
			} else {
				this.elementOptions.setStyle('display', 'none');

				if (this.focused) {
					this.focused.removeClass(this.options.selectClass);
				}
				this.showing = this.focused = false;
			}

			this.fireEvent('hide');
		}

		this.textSearch = '';
	}
});


/**
 * Multiple file upload element (Mootools 1.1 version)
 *  by Stickman
 *  http://the-stickman.com
 *  with thanks to:
 *   Luis Torrefranca -- http://www.law.pitt.edu
 *   and
 *   Shawn Parker & John Pennypacker -- http://www.fuzzycoconut.com
 *   ...for Safari fixes in the original version
 *
 * Licence:
 *  You may use this script as you wish without limitation, however I would 
 *  appreciate it if you left at least the credit and site link above in 
 *  place. I accept no liability for any problems or damage encountered 
 *  as a result of using this script. 
 *
 * Requires:
 *  Mootools 1.1 [ http://mootools.net ]
 *  ...with at least:
 *   Window.DomReady and its dependencies
 *   [ Download this release here: http://tinyurl.com/25ksor ]
 * Supports:
 *  All browsers supported by Mootools (see Mootools site for details)
 *
 * Usage:
 *  Include this file (or the packed version) and your mootools.js release in 
 *  your HTML file. To  convert a standard file input element into a multiple 
 *  file input element, add the following code to your HTML:
 * 
 *    window.addEvent('domready', function(){
 *      new MultiUpload( $( 'my_form' ).my_file_input_element );
 *    });
 *
 *  ...where 'my_form' is the ID of your form and 'my_file_input_element' is 
 *  the name of the file input element to be converted (or use whichever other
 *  method you prefer for finding the target file input element).
 *
 *  I've also included a simple CSS file (Stickman.MultiUpload.css) which
 *  you can include, although it's very basic (see 'Styling the element'),
 *  below.
 *
 * Optional parameters:
 *  There are four optional parameters (null = ignore this parameter):
 *
 *  - maximum number of files (default = 0)
 *    An integer to limit the number of files that can be uploaded using the 
 *    element. A value of zero means 'no limit'.
 *
 *  - File name suffix template (default '_{id}'
 *    By default, the script will take the name of the original file input 
 *    element and append an underscore followed by a number to it, eg. if the 
 *    input's name is 'file' then the elements will be numbered sequentially: 
 *    file_0, file_1, file_2... 
 *    You can change the format of the suffix by passing in a template. This 
 *    can be any string, but the sequence '{id}' will be replaced by the 
 *    sequential ID of the element. So if the element is called 'file' and you
 *    pass in the template '[{id}]' then the elements will be named file[0], 
 *    file[1], file[2]...
 *    To remove the suffix entirely, simply pass an empty string.
 *
 *  - Remove file path (default = false)
 *    By default, the entire path of the file is shown in the list of files. 
 *    If you would prefer to show only the file name, set this option to 
 *    'true'.
 *
 *  - Remove empty file input element (default = false)
 *    Because an extra (empty) element is created every time a file is 
 *    chosen, this means that there will always be one empty file input 
 *    element when the form is submitted. By default this is submitted with 
 *    the form (exactly as it would be with a 'normal' file input element, in 
 *    most browsers) but setting this option to 'true' will cause the element 
 *    to be disabled  (and therefore ignored) when the form is submitted.
 * 
 * Styling the element
 *  I didn't spend a lot of time making this look pretty. I've included an
 *  example CSS file (Stickman.MultiUpload.css) which is very basic but shows
 *  the parts that make up the element. These are:
 *   - div.multiupload
 *     When instaniated, the script places a container DIV around the file
 *     element, which also includes the files list
 *   - div.list
 *     Container DIV for the list of files
 *   - div.item
 *     Each item in the files list
 *   - div.item img
 *     The delete button image
 *  If changing the appearance of the element is not enough, you can alter the
 *  structure of the container and list elements in the initialize() method, 
 *  or the file list elements in the addRow() method.
 * 
 * Handling the uploaded files
 *  This is purely a client-side script -- I have not included any code for
 *  handling the uploaded files when they reach your server. This is because
 *  I don't know what platform you're using, or what you want to do with the
 *  files. When I posted the original version of this script, a lot of people 
 *  went on to submit support code for various platforms. So you might find
 *  what you need in the comments one of these pages:
 *   http://tinyurl.com/8yp53
 *   http://tinyurl.com/wrc8p
 *
 * Other notes
 *  Because it's not possible to  set the value of a file input element
 *  dynamically (for good security reasons), this script works by hiding the 
 *  file input element when a file is selected, then immediately replacing
 *  it with a new, empty one. This happens so quickly that it looks as if
 *  there's only ever one file input element. 
 *  Although ideally the extra elements would be hidden using the CSS setting
 *  'display:none', this causes Safari to ignore the element completely when
 *  the form is submitted. So instead, elements are moved to a position 
 *  off-screen.
 *  And no, it's not 'Ajax' -- it doesn't upload the files in the background
 *  or anything clever like that. Its sole purpose is cosmetic: to remove the 
 *  need for multiple file input elements in a form.
 */

var MultiUpload = new Class(
{

	/**
	 * Constructor
	 * @param		HTMLInputElement		input_element				The file input element
	 * @param		int						max							[Optional] Max number of elements (default = 0 = unlimited)
	 * @param		string					name_suffix_template		[Optional] Template for appending to file name. Use {id} to insert row number (default = '_{id}')
	 * @param		boolean					show_filename_only			[Optional] Whether to strip path info from file name when displaying in list (default = false)
	 * @param		boolean					remove_empty_element		[Optional] Whether or not to remove the (empty) 'extra' element when the form is submitted (default = true)
	 */
	initialize:function( input_element, max, name_suffix_template, show_filename_only, remove_empty_element ){

		// Sanity check -- make sure it's  file input element
		if( !( input_element.tagName == 'INPUT' && input_element.type == 'file' ) ){
			alert( 'Error: not a file input element' );
			return;
		}

		// List of elements
		this.elements = [];
		// Lookup for row ID => array ID
		this.uid_lookup = {};
		// Current row ID
		this.uid = 0;

		// Maximum number of selected files (default = 0, ie. no limit)
		// This is optional
		if( $defined( max ) ){
			this.max = max;
		} else {
			this.max = 0;
		}

		// Template for adding id to file name
		// This is optional
		if( $defined( name_suffix_template ) ){
			this.name_suffix_template = name_suffix_template;
		} else {
			this.name_suffix_template= '_{id}';
		}

		// Show only filename (i.e. remove path)
		// This is optional
		if( $defined( show_filename_only ) ){
			this.show_filename_only = show_filename_only;
		} else {
			this.show_filename_only = false;
		}
		
		// Remove empty element before submitting form
		// This is optional
		if( $defined( remove_empty_element ) ){
			this.remove_empty_element = remove_empty_element;
		} else {
			this.remove_empty_element = false;
		}

		// Add element methods
		$( input_element );

		// Base name for input elements
		this.name = input_element.name;
		// Set up element for multi-upload functionality
		this.initializeElement( input_element );

		// Files list
		var container = new Element(
			'div',
			{
				'class':'multiupload'
			}
		);
		this.list = new Element(
			'div',
			{
				'class':'list'
			}
		);
		container.injectAfter( input_element );
		container.adopt( input_element );
		container.adopt( this.list );
		
		// Causes the 'extra' (empty) element not to be submitted
		if( this.remove_empty_element){
			input_element.form.addEvent(
				'submit',function(){
					this.elements.getLast().element.disabled = true;
				}.bind( this )
			);
		}
	},

	
	/**
	 * Called when a file is selected
	 */
	addRow:function(){
		if( this.max == 0 || this.elements.length <= this.max ){
		
			current_element = this.elements.getLast();

			// Create new row in files list
			var name = current_element.element.value;
			// Extract file name?
			if( this.show_filename_only ){
				if( name.contains( '\\' ) ){
					name = name.substring( name.lastIndexOf( '\\' ) + 1 );
				}
				if( name.contains( '//' ) ){
					name = name.substring( name.lastIndexOf( '//' ) + 1 );
				}
			}
			var item = new Element(
				'span'
			).setText( name );
			var delete_button = new Element(
				'img',
				{
					'src':'_p/cross_small.gif',
					'alt':'Delete',
					'title':'Delete',
					'events':{
						'click':function( uid ){
							this.deleteRow( uid );
						}.pass( current_element.uid, this )
					}
				}
			);
			var row_element = new Element(
				'div',
				{
					'class':'item'
				}
			).adopt( delete_button ).adopt( item );
			this.list.adopt( row_element );
			current_element.row = row_element;
			
			// Create new file input element
			var new_input = new Element
			(
				'input',
				{
					'type':'file',
					'disabled':( this.elements.length == this.max )?true:false
				}
			);
			// Apply multi-upload functionality to new element
			this.initializeElement(new_input);

			// Add new element to page
			current_element.element.style.position = 'absolute';
			current_element.element.style.left = '-1000px';
			new_input.injectAfter( current_element.element );
		} else {
			alert( 'You may not upload more than ' + this.max + ' files'  );
		}
		
	},

	/**
	 * Called when the delete button of a row is clicked
	 */
	deleteRow:function( uid ){
	
		// Confirm before delete
		deleted_row = this.elements[ this.uid_lookup[ uid ] ];
		if( confirm( 'Czy napewno chcesz usunąć \r\n' +  deleted_row.element.value + '\r\nz listy plików do załadowania?' ) ){
			this.elements.getLast().element.disabled = false;
			deleted_row.element.remove();
			deleted_row.row.remove();
			// Get rid of this row in the elements list
			delete(this.elements[  this.uid_lookup[ uid ] ]);
			
			// Rewrite IDs
			var new_elements=[];
			this.uid_lookup = {};
			for( var i = 0; i < this.elements.length; i++ ){
				if( $defined( this.elements[ i ] ) ){
					this.elements[ i ].element.name = this.name + this.name_suffix_template.replace( /\{id\}/, new_elements.length );
					this.uid_lookup[ this.elements[ i ].uid ] = new_elements.length;
					new_elements.push( this.elements[ i ] );
				}
			}
			this.elements = new_elements;
		}
	},

	/**
	 * Apply multi-upload functionality to an element
	 *
	 * @param		HTTPFileInputElement		element		The element
	 */
	initializeElement:function( element ){

		// What happens when a file is selected
		element.addEvent(
			'change',
			function(){
				this.addRow()
			}.bind( this )
		);
		// Set the name
		element.name = this.name + this.name_suffix_template.replace( /\{id\}/, this.elements.length );

		// Store it for later
		this.uid_lookup[ this.uid ] = this.elements.length;
		this.elements.push( { 'uid':this.uid, 'element':element } );
		this.uid++;
	
	}
}
);

