

	/*****************************************************************/
	/* Globalni javascriptove funkce 								 */
	/*****************************************************************/
	function new_window( mypage, myname, w, h, scroll, resize,posAddon)
	{
		if (posAddon == null) posAddon = 0;

		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		var res = (resize==null)? "auto" : resize;
		var winprops = 'height='+h+', width='+w+', top='+wint+', left='+(winl+posAddon)+', scrollbars='+scroll + ', resizable=' + res+', dependent=yes';
		var win = null;
		try
		{	
					
			if ( (window != null) && (window.open != null) && ((typeof(window.open) == 'object') || (typeof(window.open) == 'function')) )
				win = 	window.open(mypage, ""+myname, winprops);
			else
			{
				win = top.window.open(mypage, "" + myname, winprops);
			}
			win.opener = self;
			if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
		}
		catch (e)
		{
			alert(e + "/" +   e.message)
		}
	}

	function trimAll(sString) 
	{ 
		return sString.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	} 
	
	function getBrowserName() 
	{ 
		var browserName = ""; 

		var ua = navigator.userAgent.toLowerCase(); 
		if ( ua.indexOf( "opera" ) != -1 ) { 
			browserName = "opera"; 
		} else if ( ua.indexOf( "msie" ) != -1 ) { 
			browserName = "msie"; 
		} else if ( ua.indexOf( "safari" ) != -1 ) { 
			browserName = "safari"; 
		} else if ( ua.indexOf( "mozilla" ) != -1 ) { 
			if ( ua.indexOf( "firefox" ) != -1 ) { 
				browserName = "firefox"; 
			} else { 
				browserName = "mozilla"; 
			} 
		} 

		return browserName; 
	};
	
	// Vraci element podle zadaneho ID
	function _getById(_id)
	{
		return document.getElementById(_id);
	}
	
	// Vraci elementy podle zadaneho css className
	function _getByCss(_className)
	{
		var elements = document.getElementsByTagName('*');
		var index = 0;
		var result = new Array();
		
		for(var i=0, ln=elements.length; i<ln; i++)
		{
			if(elements[i].className == _className)
			{
				result[index++] = elements[i];
			}
		}
		
		return result;
	}
	
	// Vraci elementy podle zadaneho tagu
	function _getByTag(_parentNode, _tagName)
	{
		return _parentNode.getElementsByTagName(_tagName);
	}
	
	// Vraci elementy podle zadaneho jmena
	function _getByName()
	{
	
	}
	
	// Vraci nove vytvoreny element
	function _create(_tagName)
	{
		return document.createElement(_tagName);
	}
	
	// Vytvori pojmenovany element ("INPUT", "deviceIds", "checkbox", 1) vs ("SELECT", "deviceIds")
	function _createNamed(_tagName, _name, _type, _value)
	{
		var element = null;
		
		try 
		{
		 	element = document.createElement('<' + _tagName + ' name="' + _name + '"' + (typeof _value != 'undefined' ? (' value="' + _value + '"') : '') + (typeof _type != 'undefined' ? (' type="' + _type + '"') : '') + '>');
		} 
		catch (e) {}
		
		if (!element || element.nodeName != _tagName.toUpperCase()) 
		{
			element = document.createElement(_tagName);
			element.name = _name;
			
			if(_type)
			{
				element.type = _type;
			}
			
			if(_value)
			{
				element.value = _value;
			}
		}
		
		return element;
	}
	
	// Vraci element ze skupiny radio buttonu (zadanych jmenem), ktery je zaskrtnuty
	function _getRadio(_radioName)
	{
		var inputs = _getByTag(document, 'INPUT');
		
		for(var i=0, ln=inputs.length; i<ln; i++)
		{
			var input = inputs[i];
			
			if(input.name == _radioName && input.type == 'radio' && input.checked)
			{
				return input;
			}
		}
		
		return null;
	}

	// Vraci vybrany option element selectu, ktery je zadany budto odkazem na samotny elementem nebo jeho ID
	function _getOpt(_param)
	{
		var opt = (typeof _param == 'string' ? _getById(_param) : _param);
		if(opt != null){
			if ((opt.tagName == 'INPUT') || (opt.tagName == 'input'))
				return opt;
			
		}
		return opt ? opt.options[opt.selectedIndex] : null;
	}

	function _setRadio(radioObj, newValue) {
		if(!radioObj)
			return;
		var radioLength = radioObj.length;
		if(radioLength == undefined) {
			radioObj.checked = (radioObj.value == newValue.toString());
			return;
		}
		for(var i = 0; i < radioLength; i++) {
			radioObj[i].checked = false;
			if(radioObj[i].value == newValue.toString()) {
				radioObj[i].checked = true;
			}
		}
	}	
	// Nastavi option selectu (zadany budto odkazem na samotny elementem nebo jeho ID) podle zadane hodnoty jako selected
	function _setOpt(_param, _value)
	{
		var opt = (typeof _param == 'string' ? _getById(_param) : _param);
		
		if(opt)
		{
			if ((opt.tagName == 'INPUT') || (opt.tagName == 'input'))
				opt.value = _value;
			else
			for(var i=0, ln=opt.options.length; i<ln; i++)
			{
				if(opt.options[i].value == _value)
				{
					opt.selectedIndex = i;
					break;
				}
			}
		}
	}
	
	// Vraci pozici elementu od shora
	function _getTop(_element)
	{
		var curTop = 0;
		
		if (_element.offsetParent) 
		{
			curTop = _element.offsetTop;
			
			while (_element = _element.offsetParent)
			{
				curTop += _element.offsetTop;
			}
		}
		
		return curTop;
	}
	
	// Vraci pozici elementu z leva
	function _getLeft(_element)
	{
		var curLeft = 0;
		
		if (_element.offsetParent) 
		{
			curTop = _element.offsetLeft;
			
			while (_element = _element.offsetParent)
			{
				curLeft += _element.offsetLeft;
			}
		}
		
		return curLeft;
	}
	
	// Vraci sirku okna
	function _getWindowWidth()
	{
		return this.innerWidth ? this.innerWidth : document.body.offsetWidth;
	}
	
	// Vraci vysku okna
	function _getWindowHeight()
	{
		return this.innerHeight ? this.innerHeight : document.body.offsetHeight;
	}
	
	// Vraci element, ktery byl zdrojem udalosti
	function _getSource(_event)
	{
		if (window.event)
		{
    		return window.event.srcElement;
    	}
 		else if (_event)
 		{
    		return _event.target;
    	}
    	else
    	{
    		return null;
    	}
	}
	
	// Vraci hodnotu nodu, ktery ma najit ve strukture (Pocita i s CDATA)
	function _getNodeValue(_parentNode, _nodeName)
	{
		return _extractNodeValue(_getNode(_parentNode, _nodeName));
	}
	
	// Vraci hodnotu nodu (Pocita i s CDATA)
	function _extractNodeValue(_node)
	{
		if(_node)
		{
			if (_node.firstChild != null)
			{		
				return _node.firstChild.nodeValue;
			}
			else
			{
				return _node.nodeValue;
			}
		}
		else
		{
			return '';
		}
	}
	
	// Vraci element udany jmenem (prvni v poradi, pokud jich je vic)
	function _getNode(_parentNode, _tagName)
	{
		var elements = _getByTag(_parentNode, _tagName);
		return elements.length > 0 ? elements[0] : null;
	}
	
	// Vraci string orezany o mezery z obou stran
	function _trim(_string)
	{
		var i;
		
		for(i = 0, ln = _string.length; i < ln; ++i)
		{
			if(_string.charAt(i) != ' ')
			{
				break;
			}
		}
		
		if(i > 0)
		{
			_string = _string.substring(i);
		}
		
		i = 0;
		
		for(i = (_string.length - 1); i >= 0; --i)
		{
			if(_string.charAt(i) != ' ')
			{
				break;
			}
		}
		
		if(i < (_string.length - 1))
		{
			_string = _string.substring(0, i + 1);
		}
		
		return _string;
	}
	
	// Vraci podrobnosti o danem elementu/objektu - hlavne kvuli IE a jeho [OBJECT]
	function _explain(_element)
	{
		var result = '';
		
		
		return result;
	}
	
	// Loguje text (budto do FireBug konzole nebo do alertu)
	function _log(_message)
	{
		//console ? console.log(_message) : alert(_message);
	}
	
	// AJAX volani
	function _XHR(_url, _query, _callback, _errorCallback)
	{
		var request = XHRFactory.getInstance();
		request.open('POST', _url, true);
		request.onreadystatechange = function(){
			if(request.readyState == 4)
			{
				if ((request.status == 200) || (request.status == 0))
				{
					_callback(request.responseXML);
					XHRFactory.release(request);
				}
				else if(_errorCallback)
				{
					_errorCallback();
				}
			}
		};
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset:UTF-8");
		request.send(_query);
	}
	
	// AJAX volani, vraci JSON objekt
	function _JSON(_url, _query, _callback)
	{
		var request = XHRFactory.getInstance();
		request.open('POST', _url, true);
		request.onreadystatechange = function(){
			if(request.readyState == 4 && request.status == 200)
			{
				if(_callback)
				{
					_callback(eval('(' + request.responseText + ')'));
				}
				
				XHRFactory.release(request);
			}
		};
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset:UTF-8");
		request.send(_query);
	}

	// AJAX volani, vraci JSON objekt
	function _JSON2(_url, _query, _callback, link)
	{
		var request = XHRFactory.getInstance();
		request.open('POST', _url, true);
		request.onreadystatechange = function(){
			if(request.readyState == 4 && request.status == 200)
			{
				if(_callback)
				{
					_callback(request.responseXML,link);
				}
				
				XHRFactory.release(request);
			}
		};
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset:UTF-8");
		request.send(_query);
	}
	
	// AJAX volani
	function _XHRGet(_url, _query, _callback, _errorCallback, async)
	{
		var request = XHRFactory.getInstance();
		if(_query != null && _query.length > 0){
			request.open('GET', _url+"?"+_query, async);
		} else {
			request.open('GET', _url, async);
		}
		request.onreadystatechange = function(){
			if(request.readyState == 4)
			{
				if ((request.status == 200) || (request.status == 0))
				{
					_callback(request.responseXML);
					XHRFactory.release(request);
				}
				else if(_errorCallback)
				{
					_errorCallback();
				}
			}
		};
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset:UTF-8");
		// request.send(_query);
		request.send("");
	}
	
	// Zobrazi popup okno podle zadanych parametru (string, string, int, int, boolean, boolean)
	function _window(_url, _name, _width, _height, _resize, _scroll)
	{
		var left = (screen.width - _width) / 2;
		var top = (screen.height - _height) / 2;
		
		if(!_resize)
		{
			_resize = 'auto';
		}
		
		if(!_scroll)
		{
			_scroll = 'no';
		}
		
		var properties = 	'height=' + _height + ', width=' + _width + ', top=' + top + ', left=' + left + 
							', scrollbars=' + (scroll ? 'yes' : 'no') + ', resizable=' + (_resize ? 'yes' : 'no') + ', dependent=yes, toolbar=no';

		try
		{
			var win = null;
				
			if (window != null && window.open != null && (typeof(window.open) == 'object' || typeof(window.open) == 'function'))
			{
				win = 	window.open(_url, "" + _name, properties);
			}
			else
			{
				win = top.window.open(_url, "" + _name, properties);
			}
			
		    win.opener = self;
		    
			if (win.window.focus)
			{
				win.window.focus();
			}
		}
		catch (error)
		{
			alert(error.message)
		}
	}
	
	// Chybejici DOM funkce
	function _insertAfter(_newElement, _targetElement) 
	{
		var parent = _targetElement.parentNode;
		
		if(parent.lastchild == _targetElement)
		{
			parent.appendChild(_newElement);
		}
		else
		{
			parent.insertBefore(_newElement, _targetElement.nextSibling);
		}
	}
	
	// Ziska hodnoty vsech pojmenovanych prvku formulare a vrati query string
	function _getFormQuery(form,ignoreEmpty)
	{
		try
		{
			var inputs = form.getElementsByTagName('INPUT');
			var selects = form.getElementsByTagName('SELECT');
			var texts = form.getElementsByTagName('TEXTAREA');
			var result = '';
			
			//select
			for(var i=0, ln=selects.length; i<ln; i++)
			{
				var select = selects[i];
				
				if(select.name != '')
					result += '&' + select.name + '=' + _getOpt(select).value;
				else if(select.id != '')
					result += '&' + select.id + '=' + _getOpt(select).value;
			}
			
			//textara
			for(var i=0, ln=texts.length; i<ln; i++)
			{
				var text = texts[i];
				if (ignoreEmpty && (text.value == '')) continue;
				
				if(text.name != '')
					result += '&' + text.name + '=' + text.value;
				else if(text.id != '')
					result += '&' + text.id + '=' + text.value;
			}
			
			//input
			for(var i=0, ln=inputs.length; i<ln; i++)
			{
				var input = inputs[i];
				
				if ((input.name != '') || (input.id != ''))
				{
					var name = (input.name != '') ? input.name : input.id;
					var type = input.type.toLowerCase();
					
					if (type == 'text' || type == 'password' || type == 'hidden')
					{
						if (ignoreEmpty && (input.value == '')) continue;
						result += '&' + name + '=' + input.value;
						
						if (input.cable && typeof(input.cable == 'string'))
						{
							result += '&' + name + '.fdi=' + input.cable.substring(0,14);
						}
					}
					else if ((type == 'checkbox' ) && input.checked)
					{
						result += '&' + name + '=' + input.value;
					}
					else if ((type == 'radio') && input.checked)
					{
						result += '&' + name + '=' + input.value;
					}
				}
			}
			
			return result.length > 0 ? result.substring(1) : '';
		}
		catch (e)
		{
			alert(e);
		}
	}
	
	// Vraci parent nod vybraneho typu
	function _getParent(node, tagName)
	{
		var node = node.parentNode;
		
		while(node)
		{
			if(node.tagName && node.tagName == tagName)
			{
				return node;
			}
			
			node = node.parentNode;
		}
		
		return null;
	}
	
	// Vraci child nod vybraneho typu
	function _getChild(node, tagName)
	{
		var node = node.firstChild;
		
		while(node)
		{
			if(node.tagName && node.tagName == tagName)
			{
				return node;
			}
			
			node = node.firstChild;
		}
		
		return null;
	}

	function setAddNewItemBehaviourFor(_obj, defaultVal, increment)
	{
		var obj = null;
		if (typeof(_obj) == "string" )
			obj = _getById(_obj);
		else
			obj = _obj;
		if (obj == null) return;
		
		obj.value = defaultVal;
		obj.defValue = defaultVal;
		obj.style.color =  "#B7B7B7";
		
		
		obj.onfocus = function()
		{
			if(this.value == defaultVal)
			{
				this.value = "";
				this.style.color = "#000000";
			}
		}
		
		obj.onblur = function()
		{
			if(this.value == "")
			{
				this.value = defaultVal;
				this.style.color = "#B7B7B7";
			}
		}
		
		if (increment == null) return;
		
		var ESC = 27;
		var KEYUP = 38;
		var KEYDN = 40;
		
		obj.onkeydown = function(ev)
		{
			var key = (window.event) ? window.event.keyCode : ev.keyCode;

			switch(key)
			{
				case ESC:
				obj.value = "";
				break;

				case KEYUP:
				obj.value = modifyTime(obj.value,increment)
				break;

				case KEYDN:
				obj.value = modifyTime(obj.value,-increment)
				break;
			}

		}; 
		
	}

	function showMoreOrLess(what)
	{
		var hr = this;
		var ob = _getEl(what);
		if ((hr == null) || (ob == null)) return;
		
		if (hr.innerHTML != "[show less]")
		{
			ob.style.display = "inline";
			hr.innerHTML = "[show less]";
		}
		else
		{
			ob.style.display = "none";
			hr.innerHTML = "[show more]";
		}
		
		resizeHeight();
	}
	
	function reverseVisibility(what)
	{
		var el = _getEl(what);
		if (!el) return;
		if (el.style.display != "block")
			el.style.display = "block";
		else
			el.style.display = "none";
		resizeHeight();
	}
	
	
	function nl2br(text)
	{
		text = escape(text);
		if(text.indexOf('%0D%0A') > -1){
			re_nlchar = /%0D%0A/g ;
		}else if(text.indexOf('%0A') > -1){
			re_nlchar = /%0A/g ;
		}else if(text.indexOf('%0D') > -1){
			re_nlchar = /%0D/g ;
		}
		return unescape( text.replace(re_nlchar,'<br />') );
	}	
	
	
	/**
	*
	*  AJAX IFRAME METHOD (AIM)
	*  http://www.webtoolkit.info/
	*
	**/
	 
	AIM = {
	 
		frame : function(c) {
	 
			var n = 'f' + Math.floor(Math.random() * 99999);
			var d = document.createElement('DIV');
			d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
			document.body.appendChild(d);
	 
			var i = document.getElementById(n);
			if (c && typeof(c.onComplete) == 'function') {
				i.onComplete = c.onComplete;
			}
	 
			return n;
		},
	 
		form : function(f, name) {
			f.setAttribute('target', name);
		},
	 
		submit : function(f, c) {
			AIM.form(f, AIM.frame(c));
			if (c && typeof(c.onStart) == 'function') {
				return c.onStart();
			} else {
				return true;
			}
		},
	 
		loaded : function(id) {
			var i = document.getElementById(id);
			if (i.contentDocument) {
				var d = i.contentDocument;
			} else if (i.contentWindow) {
				var d = i.contentWindow.document;
			} else {
				var d = window.frames[id].document;
			}
			if (d.location.href == "about:blank") {
				return;
			}
	 
			if (typeof(i.onComplete) == 'function') {
				i.onComplete(d.body.innerHTML);
			}
		}
	 
	}	

	function goTo(href)
	{
		document.location.href = href;
	}
	
