// Regularni vyrazy
var REGEXP_IE        = /MSIE/gi;
var REGEXP_IE6 		= /MSIE 6\.0/gi;
var REGEXP_IE7       = /MSIE 7\.0/gi;
var REGEXP_IE8       = /MSIE 8\.0/gi;
var REGEXP_NS        = /Gecko/gi;
var REGEXP_OPERA     = /Opera/gi;
var REGEXP_CHROME    = /Chrome/gi;
var REGEXP_VISTA     = /Windows NT 6\.0/gi;
var REGEXP_NBSP 		= /([\w012345678910111213141516171819202122232425262728293031323334353637])&nbsp;([\w012345678910111213141516171819202122232425262728293031323334353637])/gi;
var REGEXP_EMAIL 		= /^(mailto:)?[a-zA-Z0-9_\.-]{1,50}@([a-z0-9-]{1,63}\.){1,}[a-z]{2,}$/;
var REGEXP_URL 		= /^((http|https|ftp):\/\/)?(([a-z0-9-]+\.)+[a-z]{2,})(\/|\/.+|)$/;

var isIE    	= navigator.userAgent.match(REGEXP_IE);
var isIE6		= navigator.userAgent.match(REGEXP_IE6);
var isIE7 		= navigator.userAgent.match(REGEXP_IE7);
var isIE8 		= navigator.userAgent.match(REGEXP_IE8);
var isNS   		= navigator.userAgent.match(REGEXP_NS);
var isOpera	 	= navigator.userAgent.match(REGEXP_OPERA);
var isChrome   = navigator.userAgent.match(REGEXP_CHROME);
var isVista 	= navigator.userAgent.match(REGEXP_VISTA);
var isXP    	= !isVista;

// klavesy
var KEY_BACKSPACE    = 8;
var KEY_ENTER		 	= 13;
var KEY_SHIFT		  	= 16;
var KEY_CTRL  			= 17;
var KEY_ALT   			= 18;
var KEY_ESC    		= 27;
var KEY_SPACE        = 32;
var KEY_LEFT   		= 37;
var KEY_UP     		= 38;
var KEY_RIGHT			= 39;
var KEY_DOWN			= 40;
var KEY_DEL    		= 46;
var KEY_CONTROL		= [8, 9, 13, 16, 17, 18, 27, 32, 37, 38, 39, 40, 46];
var KEY_AZ    			= [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90];
var KEY_09_S     		= [48, 49, 50, 51, 52, 53, 54, 55, 56, 57];
var KEY_09				= [96, 97, 98, 99, 100, 101, 102, 103, 104, 105];

// property uniqueID pro vsechny prohlizece ================= //																				  
function uId(elm)                                             
{                                                             
	if(!elm.uniqueID)                                          
	{                                                                                                    
	   var date = new Date();                                  
	   elm.uniqueID = 'E' + date.getTime() + (Math.random() * 1000).toString().substring(0, 2);
	}                                                          
																				  
	return elm.uniqueID;                                       
}
// ========================================================== //
if(!isIE)
{
	Node.prototype.moveRow = function()
	{
      if(this && this.nodeName.match(/^(table|t(body|head|foot))$/i))
		{
         try 
			{
         	var one = arguments[0];
            var two = arguments[1];

            // Makes sure the row exists and then makes sure the insertable row isn't greater then the length
            if(!this.rows[one] || two > this.rows.length)
				{
            	var err = new Error();
               throw err;
            }
				   
            var cloneOne = this.rows[one].cloneNode(true);
            var cloneTwo = this.rows[two].cloneNode(true);
            
            this.rows[one].parentNode.replaceChild(cloneTwo, this.rows[one]);
            this.rows[two].parentNode.replaceChild(cloneOne, this.rows[two]);
            
            
         } catch(e) {}
      }
	}
}

if(typeof HTMLElement != 'undefined')
{
	var element = HTMLElement.prototype;
	if(element.__defineGetter__) 
	{
		element.__defineGetter__("outerHTML",
			function () 
			{
            var el = document.createElement('div');
            el.appendChild(this);
            var shtml = el.innerHTML;
            return shtml;
			}
      );
   }
}

Array.prototype.inArray = function(search)
{
	for(var i = 0; i < this.length; i++)
	{
		if(this[i] == search)
			return true;
	}
	
	return false;
}

function newWin(url, contentWidth, contentHeight, params, target, returnVoid)
{
	var winWidth = contentWidth + 0;
	var winHeight = contentHeight + 0;

	if(params)
		params = ','+params;
	else
		params = '';

	posX = screen.width / 2 - (winWidth + 10) / 2;
	posY = screen.height / 2 - (winHeight + 10) / 2;

	var win = window.open(url, target ? target : '_blank', 'width='+winWidth+',height='+winHeight+params);
	win.moveTo(posX, posY);

	if(!returnVoid)
		return false;
}

function getElementsByClassName(clsName, type)
{
	var elements = new Array();
	var regExp = new RegExp('/(^|\\s)' + clsName + '(\\s|$)/');
	var result = document.getElementsByTagName(type || '*');
	
	for(i = 0; i < result.length; i++)
	{
		if(regExp.test(result[i].className))
			elements.push(result[i]);
	}
	
	return elements;
}

var $$ = function(elmId) {	return document.getElementById(elmId); }

U = {
	
	getKey : function(ev)
	{
		return ev.keyCode ? ev.keyCode : ev.charCode;
	},

	getFncName : function(fnc)
	{
		var fncString = fnc.toString();
		var match = /^function ([^\(]+)\(/.exec(fncString);

		if(typeof(match[1]) != 'undefined')
		   return match[1];
		else
		   return '';
	},

	getInt : function(val)
	{
 		try {
			val = parseInt(val.toString().replace(/^0*/, ''));
		} catch(e) {
			val = 0;
		}

		return isNaN(val) ? 0 : val;
	},
	
	getFloat : function(val)
	{
	   try {
			val = parseFloat(val.toString().replace(/^0*/, ''));
		} catch(e) {
			val = 0;
		}

		return isNaN(val) ? 0 : val;
	},

	setEvent : function(obj, event, fnc)
	{
		try {
			return obj.attachEvent(event, fnc);
		} catch (e) {
			return obj.addEventListener(event.replace(/^on/, ''), fnc, false);
		}
	},

	resetEvent : function(obj, event, fnc)
	{
	   try {
	      obj.detachEvent(event, fnc);
	   } catch (e) {
	      obj.removeEventListener(event.replace(/^on/, ''), fnc, false);
	   }
	},
	
	getCookie : function(name)
	{
		var value = null;

		cookies = document.cookie.split(/; ?/);
		for(id in cookies)
		{
			try
			{
				var pair = cookies[id].split(/=/);
		      if(pair[0] == name)
				   return pair[1];
			}catch(e) {}
		}

		return null;
	},
	
	rgb2hex : function(rgb)
	{
		var dec2hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];

		var hex = '#';
		var tmp;

		if(rgb[0] > 255 || rgb[1] > 255 || rgb[2] > 255)
		   return null;

		for(i = 0; i < 3; i++)
		{
	 	   tmp = dec2hex[Math.floor(rgb[i] / 16)].toString();
		   tmp += dec2hex[rgb[i] % 16].toString();
			hex += tmp;
		}

		return hex;
	},
	
	// ziska sirku elementu
	getWidth : function(elm)
	{
	   try {
      	var w = document.defaultView.getComputedStyle(elm, '').getPropertyValue('width');
		}
	   catch(e) {
	   	var w = elm.offsetWidth;
		}

		return this.getInt(w);
	},

	// ziska vysku elementu
	getHeight : function(elm)
	{
	   try {
      	var h = document.defaultView.getComputedStyle(elm, '').getPropertyValue('height');
		}
	   catch(e) {
	   	var h = elm.offsetHeight;
		}

		return this.getInt(h);
	},
	
	getWindowWidth : function()
	{
		if(window.innerWidth)    /* NN4 a kompatibilni prohlizece */
	      return window.innerWidth;
	   else if(document.documentElement && document.documentElement.clientWidth) /* >= MSIE6 v std. rezimu */
	      return document.documentElement.clientWidth;
	   else if(document.body && document.body.clientWidth) /* starsi MSIE + MSIE6 v quirk rezimu */
	      return document.body.clientWidth;
	   else
	      return 0;
	},
	
	getWindowHeight : function()
	{
		if(window.innerHeight)    /* NN4 a kompatibilni prohlizece */
	      return window.innerHeight;
	   else if(document.documentElement && document.documentElement.clientHeight) /* >= MSIE6 v std. rezimu */
	      return document.documentElement.clientHeight;
	   else if(document.body && document.body.clientHeight) /* starsi MSIE + MSIE6 v quirk rezimu */
	      return document.body.clientHeight;
	   else
	      return 0;
	},
	
	isChildrenOf : function(object, parentTag, returnElement)
	{
		$parent = $(object).parents(parentTag);
		
		if($parent.size() > 0)
			return returnElement ? $parent.eq(0).get() : true;
		else
			return returnElement ? document.body : false;
	},
	
	centerElement : function(elm)
	{
	   width = U.getWindowWidth();
	   height = U.getWindowHeight();
	
	   elm.style.left = Math.round(width / 2 - this.getWidth(elm) / 2) + 'px';
	   elm.style.top = Math.round(height / 2 - this.getHeight(elm) / 2) + 'px';
	},

	showChildren : function(elm)
	{
		if(elm.childNodes.length)
		{
		   for(i = 0; i < elm.childNodes.length; i++)
		   {
		      if(elm.childNodes[i].childNodes.length)
					this.showChildren(elm.childNodes[i]);
				else
				{
				   try {
						elm.childNodes[i].style.display = '';
					} catch(e) {}
				}
		   }
		}
		
		elm.style.display = '';
	},
	
	hideChildren : function(elm)
	{
		if(elm.childNodes.length)
		{
		   for(i = 0; i < elm.childNodes.length; i++)
		   {
		      if(elm.childNodes[i].childNodes.length)
					this.hideChildren(elm.childNodes[i]);
				else
				{
				   try {
						elm.childNodes[i].style.display = 'none';
					} catch(e) {}
				}
		   }
		}

		elm.style.display = 'none';
	},
	
	disableDefault : function(e)
	{
		if(e.preventDefault)
			e.preventDefault();
		else
			e.returnValue = false;
	},
	
	cancleBubble : function(e)
	{
		if(e && e.stopPropagation)
			e.stopPropagation();
		else
			e.cancleBubble = true;
	}, 
	
	arrayUnset : function(array, value)
	{
		var newArray = new Array();
		for(i = 0; i < array.length; i++)
		{
			if(array[i] != value)
				newArray.push(array[i]);
		}
		
		return newArray;
	},
	
	clearSelection : function() 
	{
		if(document.selection && document.selection.empty)
		{
			document.selection.empty();
		}
		else if(window.getSelection) 
		{
			var sel=window.getSelection();
			if(sel && sel.removeAllRanges)
				sel.removeAllRanges();
		}
},
	
	getParent : function(elm)
	{
		return elm.parentElement || elm.parentNode;
	},
	
	pasteHTML : function(document, selection, html)
	{
		try {
			selection.pasteHTML(html);
		} catch(e) {
			document.execCommand('insertHTML', null, html);
		}		
	},
	
	removeNode : function(node)
	{
		try {
			node.removeNode(true);
		} catch(e) {
			this.getParent(node).removeChild(node);
		}
	},
	
	getSelectedItem : function(selection)
	{
		if(isIE)
		{	
			return selection.item ? selection.item() : null;
		}
		else
		{
			var range = selection.getRangeAt(0);
			var node = range.cloneContents();
			
			var tmpDiv = document.createElement('DIV');
			tmpDiv.appendChild(node);
			
			return tmpDiv.children[0];
		}
	}
}

var Interval = {

	interval : 0,
	counter : 0,
	state : 'stoped',
	
	list : {},
	count : 0,
	
	add : function(id, callback, everyX)
	{
	   if(!id || !callback || typeof Interval.list[id] != 'undefined')
	      return;
	      
		if(!everyX) everyX = 1;
		
		Interval.list[id] = {
		   callback : callback,
		   everyX : everyX
		}
		
		Interval.count++;
		if(Interval.state == 'stoped')
		{
		   if(Interval.interval != 0)
		      window.clearInterval(Interval.interval);

			Interval.state = 'running';
			Interval.interval = window.setInterval('Interval.run()', 25);
		}
	},
	
   remove : function(id)
   {
   	if(typeof Interval.list[id] != 'undefined')
      {
	      delete Interval.list[id];
	      Interval.count--;
	   }
   },
	
	run : function()
	{
	   if(!Interval.count)
	   {
	      Interval.end(Interval.interval);
		}
		else
		{
		   Interval.counter++;
		   var ix;
		   for(ix in Interval.list)
		   {
				if(!(Interval.counter % Interval.list[ix].everyX))
		         eval(Interval.list[ix].callback);
		   }
		}
	},
	
	end : function(interval)
	{
		Interval.list = {};
	   Interval.count = 0;
	   Interval.couter = 0;
	   Interval.state = 'stoped';
	   
	   window.clearInterval(interval);
	   Interval.interval = 0;
	}
}

var xmlHttp;

Ajax = {

	'noAjaxSupport' : false,
	'overlay' : null,

	'init' : function()
	{
		try {
			xmlHttp = new XMLHttpRequest();
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					this.noAjaxSupport = true;
				}
			}
		}
	},

	'sendRequest' : function(url, returnResult, callback, counter)
	{
		if(!xmlHttp && !this.noAjaxSupport)
			this.init();
			
		if(this.noAjaxSupport)
			return null;
	
		if (xmlHttp.readyState != 0)
		{ 
			if(!counter)
				counter = 0;
		
			if(counter == 5000)
			{
				xmlHttp.abort();
			}
			else
			{
				setTimeout("Ajax.sendRequest('" + url + "', " + (returnResult ? 'true' : 'false') + ", '" + callback + "', " + (counter + 25) + ")", 25);
				return;
			}				
		}
		
      xmlHttp.open ('GET', url, true);
      xmlHttp.onreadystatechange = function()
		{
      	if(xmlHttp.readyState == 4 && Ajax.isSuccess())
			{
				if(xmlHttp.responseText)
				{
					if(callback)
					{
						eval(callback.replace(/\[data\]/g, xmlHttp.responseText)); 
					}
				   else if(returnResult)
				   {
					   return xmlHttp.responseText;
					}
					else
					{
						eval(xmlHttp.responseText);
					}
				}
				
				xmlHttp.abort();
        	}
      }
   	xmlHttp.send(null);
   	return true;
	},
	
	'postRequest' : {

		'data' : '',
		'initialized' : false,

		'prepare' : function(url, data, callback, counter)
		{
			this.initialized = false;
			
			if(!xmlHttp && !this.noAjaxSupport)
				Ajax.init();
			
		   if (xmlHttp.readyState != 0)
			{ 
				if(!counter)
					counter = 0;
			
				if(counter == 5000)
				{
					xmlHttp.abort();
				}
				else
				{
					setTimeout("Ajax.postRequest.prepare('" + url + "', '" + data + "', '" + callback + "', " + (counter + 25) + ")", 25);
					return;
				}				
			}
		   
		   xmlHttp.open ('POST', url, true);
		   xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		   
         xmlHttp.onreadystatechange = function()
			{
      		if(xmlHttp.readyState == 4 && Ajax.isSuccess())
				{
					if(xmlHttp.responseText)
					{
						if(callback)
						{
							eval(callback.replace(/\[data\]/g, xmlHttp.responseText)); 
						}
					   else
						{
							eval(xmlHttp.responseText);
						}
					}
				
					xmlHttp.abort();
	        	}
      	}
      	this.data = data;
      	this.initialized = true;
		},
		
		'send' : function(counter)
		{
			if(!this.initialized)
			{ 
				if(!counter)
					counter = 0;
			
				if(counter == 5000)
				{
					return false;
				}
				else
				{
					setTimeout("Ajax.postRequest.send(" + (counter + 25) + ")", 25);
					return;
				}				
			}
		
			xmlHttp.send(this.data);
		}
	},
	
	'isSuccess' : function()
	{
		try {
		   return !xmlHttp.status && location.protocol == 'file:' ||
		      (xmlHttp.status >= 200 && xmlHttp.status < 300) ||
		         xmlHttp.status == 304 ||
		            navigator.userAgent.indexOf('Safari') >= 0 && typeof xmlHttp.status == 'undefined';
		} catch(e) {}

		return false;
	}
}
// ============================================================== //



