translation = {
	lang_smazat	: 'Smazat'
};
/* START POPUP */
function openwindow(link)
{
window.open(link,
	"mywindow","location=0,status=0,scrollbars=1,width=690,height=433,toolbar=0,menubar=0,location=0,directories=0");
}
/* END POPUP */


/* START ZOBRAZENI DIV */
function show_div(id){
el=document.getElementById(id).style;
el.display=(el.display == 'block')?'none':'block';
}

/* END  ZOBRAZENI DIV */

/* alert okno */
function alert_(text){
	document.domwinDesktop.newWindow({
		id: 'alert_window',
		title: 'Upozornění',
		loadMethod: 'html',
		content: '<div style="text-align:center"><strong>' + text + '</strong></div>',
		modal:true,
		width: 250,
		height: 70,
		languages: false
	});
}
/* get file from url*/
String.implement({
	getFile: function(){
		var arr = this.split('\\');
		return arr[arr.length-1];
	}
});


/* pro meni item */
Element.implement({
	depth: function(contain){		
		depth = 0;
		if(this != contain){
			if(this.getTag() != contain.getTag())
				depth++;
			depth += this.getParent().depth(contain);
		}	
 
		return depth;
	},
	
	getUlItems:function(){
		if (this.nodeName != 'UL') alert('Tato metoda lze pouze na UL element');
		var items = [];
		var list = this.getElements('li');
		list.each(function(item){
			if (this == item.parentNode){
				items[items.length] = item;
			}
		},this);
		return items;
	},
	
	getIndex:function(){
		var items = [], list;
		if (this.nodeName != 'LI') alert('Tato metoda lze pouze na LI element');
		list = this.parentNode.getElements('li');
		list.each(function(item,key){
			if (this.parentNode == item.parentNode)
				items[items.length] = item.id
		},this);
		
		if (this.id != undefined)
			return items.indexOf(this.id);
		else 
			return items.length;
	},
	
	getLiText: function(){
		if (this.nodeName != 'LI') alert('Tato metoda lze pouze na LI element');
		var p = this.firstChild;
		if (p.nodeType == 3)
			return p
		else 
			return false;
	},
	
	getParentElements: function(node,endNode){
		var pnode = this, output = [];
		while(pnode.parentNode && pnode.parentNode != endNode)
			pnode = pnode.parentNode;
			if (pnode.nodeName == node)
				output[output.length] = pnode;
		return output;
	},
	
	center: function(){
		/* velikost alert okna */
		var OH = this.getSize().y;
		var OW = this.getSize().x;

			
		/* velikosti window */
		var WH = window.getHeight();
		var WW = window.getWidth();
			
		var top = (WH/2 - OH/2)+window.getScrollTop();
			
		this.setStyles({
			'top'	: 	(top>0)?top:0,
			'left'	:	((WW/2 - OW/2)+window.getScrollLeft())
		});
			
		return this;
	}

});

/* ========= START  FILE BROWSER =========== */
Element.implement({
	setFile: function(elementId){
		this.addEvent('click',function(e){
			new Event(e).stop();
			var win = window.open('../../../../js/ajaxfilemanager/ajaxfilemanager.php?editor=form&elementId='+elementId, 'ajaxFileImageManager', 'width=782,height=440');
		});
	}
});
	
/* ========= END FILE BROWSER =========== */

/* ========= START POUZE CISLA =========== */
Element.implement({
	onlyNumeric: function(){
		this.addEvent('keypress',function(e){
			
			var event = new Event(e);
			var key = event.key;
			var code = event.code;
			if ((code==null) || (code==0) || (code==8) || (code==9) || (code==13) || (code==27) )
				return true;
			else if (("0123456789").indexOf(key) != -1)
				return true;
			else
				return false;
		});
		return this;
	}
});
 /* ========= END POUZE CISLA =========== */

 /* ========= START CLANKY SPRAVA DOPLNKU / PRILOH =========== */
  Element.implement({
	initAddons: function(options){	
		this.addEvent('click',(function(e,options){
			var input = $(options.input);
			var file = $(options.file);
			var ul = $(options.ul);
			var name = options.hidden;
			new Event(e).stop();
			if (input.value =='') { alert('Nebyla zadána hodnota'); return;}
		
			if (file){
				var newLi = new Element('li').setHTML('<strong>Název:</strong> ' + input.value + ' | <strong>Soubor:</strong> '+file.value).inject(ul);
				new Element('input',{'name':name,'type':'hidden','class':'hidden','value':input.value + ';;' + file.value}).inject(newLi);
			} else{
				var newLi = new Element('li').setHTML('<strong>URL:</strong> '+input.value).inject(ul);				
				new Element('input',{'name':name,'type':'hidden','class':'hidden','value':input.value}).inject(newLi);
			}
			new Element('img',{src:'/css/admin/icons/system/delete.gif','alt':translation.lang_smazat,'class':'icon'})
				.addClass('browse')
				.addEvent('click',function(){
					this.parentNode.remove();
  				})
				.inject(newLi);
		}).bindWithEvent(this,options));
	}
 });
 /* ========= END CLANKY SPRAVA DOPLNKU / PRILOH =========== */
 /* ========= START SPRAVA OBRAZKU =========== */
  function	initPhotos(options){	
	var file = options.file;
	var ul = $(options.ul);
	var name = options.hidden;
	var newLi = new Element('li').setHTML('<strong>Soubor:</strong> ' + file).inject(ul);				
	new Element('input',{'name':name,'type':'hidden','class':'hidden','value':file}).inject(newLi);
	new Element('img',{src:'/css/admin/icons/system/delete.gif','alt':translation.lang_smazat,'class':'icon'})
		.addClass('browse')
		.addEvent('click',function(){
			this.parentNode.remove();
  		})
		.inject(newLi);
	var infolink = new Element('a',{style:'position:relative'})
		.addEvent('mouseover',function(){
			this.getElement('.hower').setStyle('display','block');
		})
		.addEvent('mouseout',function(){
			this.getElement('.hower').setStyle('display','none');
		})
		.inject(newLi);
	new Element('img',{src:'/css/admin/icons/system/info.gif','class':'icon'}).addClass('browse').inject(infolink);
	new Element('img',{src:'/uploaded/ubytovani/small/'+file,'class':'hower'}).setStyles({'display':'none','position':'absolute','left':30,'top':4}).inject(infolink);

 }
 /* ========= END SPRAVA OBRAZKU =========== */
 
 
/* ========= START CHECK ALL INPUT  =========== */
 Element.implement({
	checkAll:function(selector){
		var parent = this.getElement('.' + selector).getElement('input[type=checkbox]');
		parent.addEvent('click',(function(parent){
			if (parent.checked)
				this.getElements('input[type=checkbox]').setProperty('checked','checked');
			else
				this.getElements('input[type=checkbox]').removeProperty('checked');
		}).bind(this,parent));
	}
 });
/* ========= END CHECK ALL INPUT  =========== */
/* ========= START PRESUN MEZI 2-MI LISTY  =========== */
Element.implement({
	list_find_selected: function(){
		var output = false
		var options = this.getElements('option');
		options.each(function(option){
			if (option.getProperty('selected'))
				output =  option;
		},this);

		return output;
	},
	list_move_one:function(start,end){
		var list1 = $(start);
		var list2 = $(end);
		var selOption = list1.list_find_selected();
		if (!selOption) {alert('Není vybrána položka'); return;}
		list2.options[list2.length] = new Option(selOption.text, selOption.value);
		selOption.remove();
	},
	
	list_move_all: function(start,end){
		var list1 = $(start);
		var list2 = $(end);
		var options = list1.getElements('option');
		options.each(function(option){
			list2.adopt(option);
		});
  	},
	list_select_all:function(){
		this.getElements('option').setProperty('selected','selected');
	},
	findIndexAndRemove: function(list,value){
		$(list).adopt(this.getElement('option[value=' + value + ']'));
	}
});
/* ========= END PRESUN MEZI 2-MI LISTY  =========== */
/* ========= START FUNKCE PRO UPDATE SELECT {STAT,MESTO,KRAJ,...} =========== */
Element.implement({
	setValue: function(value,append){ 
		if(value) { 
			value = value.toString(); 
			value = value.replace(/%25/g,"%"); 
			value = value.replace(/%26/g,"&"); 
			value = value.replace(/%2b/g,"+"); } 
			switch(this.getTag()){ 
				case 'select': 
				case 'select-one': 
					this.value = value; 
					break; 
				case 'hidden': 
				case 'text': 
				case 'textarea': 
				case 'input': 
					if(['checkbox', 'radio'].indexOf(this.type) != -1) { 
						if(['1', 'checked', 'on', 'true', 'yes'].indexOf(value) != -1) 
							this.checked = true; 
						else 
							this.checked = false; 
					} else { 
						
						if(append) 
							this.value += value; 
						else 
							this.value = value; 
					} 
					break; 
				case 'img': 
					this.src = value; 
					break; 
				default: 
					if(append) 
						this.innerHTML += value; 
					else 
						this.innerHTML = value; 
						if(append && this.scrollHeight) 
							this.scrollTop = this.scrollHeight; 
					break; 
			} 
		return this; 
	},
	clearSelect: function(){
		var clearSelect = new Element('select',{'class':'select'});
		var id = this.id;
		clearSelect.setProperties({
			'class'		:	this.getProperty('class'),
			'tabindex'	:	this.getProperty('tabindex'),
			'class'	:	this.getProperty('class'),
			'name'	:	this.getProperty('name'),
			'style'	:	this.getProperty('style'),
			'id'	:	this.getProperty('id')
		});
		clearSelect.cloneEvents(this);
		clearSelect.replaces(this);
		clearSelect.id = id;
	
		//this.getElements('option').each(function(itm){itm.remove()});
		//this.setHTML('');
		//while (this.options.length !=0){
		//	if (this.options[0])
		//		this.options[0].remove();
		//}
		// var i;
		//for(i=this.options.length-1;i>=0;i--){
		//	this.options[i] = null;
		//}
		//this.options.each(function(itm){itm.remove()});
		//this.innerHTML += '';
		//select_innerHTML(this,'');
	},
	
	addOptions: function(json,key,caltion){
		//this.clearSelect(); /* vyprazdni select od options */
		new Element('option',{value:''}).setHTML('').inject(this);
		json.each(function(json_option) {
			
			new Element('option',{value:json_option['key']})
				.setHTML(json_option['caption'])
				.inject(this);
		},this);
	},
	
	addOptionsSpec: function(json){
		new Element('option',{value:''}).setHTML('').inject(this);
		json.each(function(caption,key) {
			new Element('option',{value:key})
				.setHTML(caption)
				.inject(this);
		},this);
	}

	
});
/* ========= END FUNKCE PRO UPDATE SELECT {STAT,MESTO,KRAJ,...} =========== */
/* ========= START FUNKCE IKON ADMIN=========== */
Element.implement({
	window:function(window_id,title,size,modal,languages){
		this.addEvent('click',function(e){
			new Event(e).stop();
			document.domwinDesktop.newWindow({
				id: window_id,
				title: title,
				loadMethod: 'xhr',
				contentURL: this.href,
				modal:modal,
				width: size[0],
				height: size[1],
				languages: languages,
				onBeforeLoad: function(){
					document.preloader.add('menu_data_detail','Stránka se načítá');
				},
				onContentLoaded: function(){
					document.preloader.remove('menu_data_detail');
				}
			});
		});
	},
	requestTop:function(update,form){
		this.addEvent('click',function(e){
			new Event(e).stop();
			document.preloader.add('comunation_DB','Probíhá komunikaces DB');
			new Request.HTML({
				url 		: 	this.href,
				method		:	'post',
				update		:	$(update),
				onComplete	:	function(){
					document.preloader.remove("comunation_DB");
					document.permission.run(update);
				}
			}).post($(form));
		});
	},
	request:function(update){
		this.addEvent('click',function(e){
			new Event(e).stop();
			document.preloader.add('comunation_DB','Probíhá komunikaces DB');
			new Request.HTML({
				url 		: 	this.href,
				method		:	'post',
				update		:	$(update),
				onComplete	:	function(){
					document.preloader.remove("comunation_DB");
				}
			}).send();
		});
	},
	filtr: function(url,update,param){
		this.addEvent('change',function(){
			var h = new Hash({});
			h[param] = this.value
			document.preloader.add('comunation_DB','Probíhá komunikaces DB');
			new Request.HTML({
				url :url,
				method: 'get',
				update: update,
				evalScripts: true,
				onComplete: function(){
					document.preloader.remove('comunation_DB');
					document.permission.run(update);
				}
			}).get(h);
		});
	}
});
/* ========= START FUNKCE IKON ADMIN=========== */
  Element.implement({
	setHTMLTd: function(text){
		new Element('td',{'class':this.getProperty('class'),'id':this.getProperty('id')})
			.setHTML(text)
			.replaces(this);
	}
 });
 
 
 
 
/* getHighestZIndex */
	function getHighestIndex(){				
		var allElems = document.getElementsByTagName?document.getElementsByTagName("*"): document.all; 
		var maxZIndex = 0;
		for(var i=0;i<allElems.length;i++) {
			var elem = allElems[i];
			var cStyle = null;
			if (elem.currentStyle) {cStyle = elem.currentStyle;
			} else if (document.defaultView && document.defaultView.getComputedStyle){
				cStyle = document.defaultView.getComputedStyle(elem,"");
			}
			var sNum;
			if (cStyle) {
				sNum = Number(cStyle.zIndex);
			} else {
				sNum = Number(elem.style.zIndex);
			}
			if (!isNaN(sNum)) {
				maxZIndex = Math.max(maxZIndex,sNum);
			}
		}
		return maxZIndex;
	} 
/* ============ START doporuceni na stranku =================== */
function doporuceni_init(){
	var slide_doporuceni = new Fx.Slide('doporuceni_form');
	var slide_doporuceni_text = new Fx.Slide('doporuceni_link');
	slide_doporuceni.hide();
	
	$("doporuceni_link").addEvent('click', function(e){
		e = new Event(e);
		slide_doporuceni_text.toggle();
		$('footer_navigace').fade();
		slide_doporuceni.toggle();
		e.stop();
		return false;
	});
	
	$('send_doporuceni_form').addEvent('click',function()	{
		if (document.validation.valideAll('SendPageFormSend')){
			document.preloader.add('send_to_db','Probíhá komunikace');
			new Request.JSON({
				url:'/system/doporuceni/',
				onComplete:function(text){
					document.preloader.remove('send_to_db');
					$('SendPageVaseJmeno').value = '';
					$('SendPageEmailZnameho').value = '';
					new alert_('Doporučení bylo odesláno');
					slide_doporuceni.toggle();
					(function(){
						slide_doporuceni_text.show();
						$('footer_navigace').setStyles({opacity:1,visibility:'visible'});
					}).delay(1000);
				}
			}).post($('SendPageFormSend'));	
		}
		
	});
	
	$('doporuceni_close').addEvent('click',function(e){
		new Event(e).stop();
		$('SendPageVaseJmeno').value = '';
		$('SendPageEmailZnameho').value = '';
		slide_doporuceni.toggle();
		
		(function(){
			slide_doporuceni_text.show();
			$('footer_navigace').setStyles({opacity:1,visibility:'visible'});
		}).delay(1000);
		return false;
	});
	
	document.validation.load('SendPage');
}

/* ============ END doporuceni na stranku =================== */