MaskInput = function(f, m){
	if(!f || !m) return;
    function mask(e){
        var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
        function accept(c, rule){
            for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
                if(r & i && patterns[i].test(c))
                    break;
                return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
        addEvent(f, i, mask);
};

function setAdPressLink(obj, hid, bid, url) {
	obj.href = '/_ads/press/'+hid+'/'+bid+'/'+url;
}

/*
 * Pomocné funkce pro OverLayout, animace a JS efekty
 */

function getStyle( node, name) {
	if(!node) return null;
	if (node.style[name]) {
		return node.style[name];
	} else if (node.currentStyle) {
		return node.currentStyle[name];
	} else if (document.defaultView && document.defaultView.getComputedStyle) {
		name = name.replace(/([A-Z])/g, "-$1");
		name = name.toLowerCase();

		var s = document.defaultView.getComputedStyle(node,"");
		return s && s.getPropertyValue(name);
	} else {
		return null;
	}
}

// level [0 .. 100]%
// node - DOM Object
function setOpacity(node, level) {
	if (node.filters) {
		node.style.filters = 'alpha(opacity=' + level + ')';
	} else {
		node.style.opacity = level / 100;
	}
	node.$opacity = level;
}

function hide ( node ) {

	var actualDisplay = getStyle(node, "display");

	if(actualDisplay != 'none') {
		node.$oldDisplay = actualDisplay;
	}

	node.style.display = 'none';
}

function show ( node ) {
	if(!node) return;
	node.style.display = node.$oldDisplay || 'block';
}

function getWidth ( node ) {
	return parseInt ( getStyle(node, "width"));
}

function getHeight ( node ) {
	return parseInt ( getStyle(node, "height"));
}

function getMaxWidth (node) {
	if(!node) return 0;
	if (getStyle (node, 'display') != 'none') {
		return node.offsetWidth || getWidth(node);
	}

	var old = setCSS( node, {
		display: '',
		visibility: 'hidden',
		position: 'absolute'
	});

	var s = node.clientWidth || getWidth(node);

	resetCSS (node, old);
	return s;
}

function getMaxHeight (node) {
	if(!node) return 0;

	if (getStyle (node, 'display') != 'none') {
		return node.offsetHeight || getHeight(node);
	}

	var old = setCSS( node, {
		display: 'block',
		visibility: 'hidden',
		position: 'absolute'
	});

	var s = node.clientHeight || getHeight(node);

	resetCSS (node, old);
	return s;
}

function setCSS (node, attributes) {
	var old = {};

	for (var i in attributes) {
		old[i] = node.style[i];
		node.style[i] = attributes[i];
	}

	return old;
}

function resetCSS ( node, attributes ) {

	for ( var i in attributes ) {
		node.style[ i ] = attributes[ i ];
	}

}

function getPageWidth () { return document.body.scrollWidth; }
function getPageHeight () { return document.body.scrollHeight; }

function getWindowWidth() {
	var de = document.documentElement;
	return self.innderWidth || (de && de.clientWidth) || document.body.clientWidth;
}

function getWindowHeight() {
	var de = document.documentElement;
	return self.innderHeight || (de && de.clientHeight) || document.body.clientHeight;
}

function getScreenWidth() {
	return screen.availWidth || screen.width || getWindowWidth();
}

function getScreenHeight() {
	return screen.availHeight || screen.height || getWindowHeight();
}

function id(name) {
	return document.getElementById(name);
}

//prekryti stranky

function overlayInit() {
	var overlay = document.createElement('div');
	overlay.id = "overlayout";
	var old = setCSS(overlay, {
		background: '#000',// url(/media/img/overlay.gif)',
		opacity: '0.25',
		filter: 'alpha(opacity=25)',
		display: 'none',
		position: 'absolute',
		position: 'fixed',
		top: '0',
		left: '0',
		width: '100%',
		height: '100%',
		zIndex: '1000',
		cursor: 'pointer'
	});
	document.body.appendChild(overlay);
}

function showOverlay(show_method, close_method) {
	var overlay = document.getElementById('overlayout');
	if(!overlay) overlayInit();
	overlay.onclick = hideOverlay;
	if(close_method) overlay.onclick = close_method;
	overlay.style.width = Math.max(getPageWidth(), getWindowWidth()) + "px";
	overlay.style.height = Math.max(getPageHeight(), getWindowHeight()) + "px";
	window.onresize = overlayResize;
//	overlay.$opacity = 0;
//	if(show_method) {
//		fadeIn(overlay, 0 ,50, 7, show_method);
//	} else {
//		fadeIn(overlay, 0 ,50);
//	}
	show(overlay);
//	if(show_method) window.setTimeout(show_method, 300);
//	window.setTimeout(function() {show(overlay); if(show_method) show_method();}, 350);
	if(show_method) show_method();
}

function overlayResize() {
	var overlay = document.getElementById('overlayout');
	overlay.style.width = Math.max(getPageWidth(), getWindowWidth()) + "px";
	overlay.style.height = Math.max(getPageHeight(), getWindowHeight()) + "px";
}

function hideOverlay() {
	var overlay = document.getElementById('overlayout');
	overlay.onclick = null;
	hide(overlay);
//	fadeOut(overlay, overlay.$opacity, 0, 5);
}

window.onload = function() { overlayInit(); };
window.$overlay = overlayInit;
// konec prekryti

/* dialog confirm*/

function showConfirm(message, title, yes_func, no_func) {

	var cdia = id('confirmDialog');
	var cdia_h = null;
	var cdia_b = null;
	var msg_trg = null;
	var ybut = null;
	var nbut = null;

	if(!cdia) {
		cdia = document.createElement('div');
		cdia_h = document.createElement('div');
		cdia_b = document.createElement('div');
		cdia.appendChild(cdia_h);
		cdia.appendChild(cdia_b);

		cdia.id = 'confirmDialog';
		setCSS(cdia, {
			position: 'absolute',
			display: 'none',
			width: '300px',
			background: '#fff',
			padding: '3px',
			top: '90px',
			left: (getWindowWidth() / 2) - 150 + 'px',
			zIndex: 1002,
			border: '2px solid #c00'
		});

		setCSS(cdia_h, {
			height: '20px',
			background: '#c00',
			color: '#fff',
			fontSize: '11px',
			paddingLeft: '8px',
			lineHeight: '20px',
			marginBottom: '5px'
		});

		setCSS(cdia_b, {
			padding: '5px 8px',
			lineHeight: '120%',
			fontSize: '12px',
			color: '#000',
			fontWeight: 'normal'
		});

		msg_trg = document.createElement('p');
		cdia_b.appendChild(msg_trg);

		ybut = document.createElement('input');
		ybut.type = 'button';
		ybut.id = 'ybut';
		ybut.value = 'Ano';
		ybut.className = 'button';

		nbut = document.createElement('input');
		nbut.type = 'button';
		nbut.id = 'nbut';
		nbut.value = 'Storno';
		nbut.className = 'button';

		dv = document.createElement('div');

		setCSS(nbut, {margin: '0 20px'});
		setCSS(ybut, {margin: '0 20px'});
		setCSS(dv, {
			textAlign: 'center',
			padding: '5px 0'
		});

		dv.appendChild(ybut);
		dv.appendChild(nbut);

		cdia_b.appendChild(dv);

		document.body.appendChild(cdia);
	} else {
		hide(cdia);
		cdia_h = DOM_firstChild(cdia);
		cdia_b = DOM_next(cdia_h);
		msg_trg = cdia_b.getElementsByTagName('p')[0]
		ybut = id('ybut');
		nbut = id('nbut');
	}

	ybut.onclick = function() {
		hideConfirm();
		return yes_func();
	};

	nbut.onclick = (!no_func ? function() { hideConfirm(); } : function() { return no_func(); hideConfirm(); });

	cdia_h.innerHTML = title;
	msg_trg.innerHTML = message;
	showOverlay(function() {show(cdia); }, hideConfirm);
}

function hideConfirm() {
	hide(id('confirmDialog'));
	hideOverlay();
}

/* /dialog confirm*/

/*  Animace  */

function rollDown( node , speed) {
	if(isNaN(speed)) speed = 10;
	var v = getMaxHeight(node);
	node.style.height = 0;
	show(node);

	for (var i = 0; i <= 100; i += 5) {
		(function() {
			var pos = i;
			setTimeout(function(){
					node.style.height = (( pos / 100 ) * v ) + 'px';
				}, ( pos + 1 ) * speed);
		})();
	}
	return node;
}

function fadeIn( node, start, finish, speed, last_method) {
	if(isNaN(start)) start = 0;
	if(isNaN(finish)) finish = 100;
	if(isNaN(speed)) speed = 10;

	setOpacity( node, start );
	show(node);
	if(last_method) {
		setTimeout(function(){last_method();}, (finish+5) * speed );
	}
	for(var i = start; i <= finish; i+= 5) {
		last = i;
		(function(){
			var pos = i;
			setTimeout(function(){
				setOpacity(node, pos);
			}, (pos + 1) * speed );
		})();
	}
	return node;
}

function fadeOut( node, start, finish, speed, last_method ) {
	if(isNaN(start)) start = 100;
	if(isNaN(finish)) finish = 0;
	if(isNaN(speed)) speed = 10;

	setOpacity( node, start );
	show(node);
	if(last_method) {
		setTimeout(function(){last_method(); }, (start-finish + 3) * speed );
	}
	for(var i = start; i >= finish; i -= 5) {
		(function(){
			var pos = i;
			var st = start;
			setTimeout(function(){
				setOpacity(node, pos);
			}, ((st-pos)+1) * speed );
		})();
	}
	setTimeout(function(){hide(node);}, (start+2)*speed);
}

function DOM_next(node) {
	if(!node) return null;
	do {
		node = node.nextSibling;
	} while (node && node.nodeType != 1);
	return node;
}

function DOM_prev(node) {
	if(!node) return null;
	do {
		node = node.previousSibling;
	} while (node && node.nodeType != 1);
	return node;
}

function DOM_firstChild(node) {
	if(!node) return null;
	node = node.firstChild;
	if(node.nodeType != 1) node = DOM_next(node);
	return node;
}

function DOM_lastChild(node) {
	if(!node) return null;
	node = node.lastChild;
	if(node.nodeType != 1) node = DOM_prev(node);
	return node;
}

function DOM_allChildren(node) {
	buffer = new Array();
	child = DOM_firstChild(node);
	while(child != null) {
		buffer.push(child);
		child = DOM_next(child);
	}
	return buffer;
}

function DOM_childrenByTag(node, tag) {
	buffer = new Array();
	child = DOM_firstChild(node);
	while(child != null) {
		if(child.tagName == tag) buffer.push(child);
		child = DOM_next(child);
	}
	return buffer;
}

function DOM_parentIdentification(node, recur) {
	parent = node.parentNode;
	if(!recur) return "-- max recursion --";
	if (parent == document.body) return "BODY";
	return parent.id || parent.className || (parent.tagName + ": " + parent.innerHTML.substr(0, 30) + "\n" + DOM_parentIdentification(parent, recur-1));
}

function DOM_remNode(node) {
	if(!node) return;
	return node.parentNode.removeChild(node);
}

function DOM_swapNode(node, new_node) {
	par = node.parentNode;
	next = DOM_next(node);

	DOM_remNode(node);
	par.insertBefore(new_node, next);
}

//funkce pro kaskadove nastaveni vysky obsahu elementu
function doResize(node) {
	if(!node) return;
//	prev = node.offsetHeight || 0;
	if(!node.$skip && (node.parentNode != null)) {
		setCSS(node, {
			height: getMaxHeight(node.parentNode) - (node.$diff || 0) + 'px'
		});
	}

	//user resize function for node
	if(node.$resize) node.$resize();
//	alert("Resize\n" + (node.id || node.className || node.tagName) + ": " + prev + " -> " + node.offsetHeight + "\n\n"+ (node.$resizeObjects || '(empty)'));

	//call doResize to collection of slaved objects
	if(node.$resizeObjects) {
//		if(node.$resizeObjects.length == 1) node.$resizeObjects[0] = node.$resizeObjects;
		for(var i=node.$resizeObjects.length-1; i>=0; i--) {
			doResize(node.$resizeObjects[i]);//, false);
		}
	}

	//user resize function for node
//	if(node.$post_resize) node.$post_resize();
}

//registruje node do kolekce objektu pro resize u rodice
function resReg(object) {
	par = object.parentNode;
//	alert("ResReg: " + (object.id || object.className || object.tagName) + "\nParent: "+ DOM_parentIdentification(object, 15));
	if(!par.$resizeObjects) par.$resizeObjects = new Array();
	par.$resizeObjects.push(object);
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function range ( low, high, step, key_start ) {
    var matrix = [];
    var inival, endval, plus;
    var walker = step || 1;
    var chars  = false;
    var key = key_start || false;

    if ( !isNaN ( low ) && !isNaN ( high ) ) {
        inival = low;
        endval = high;
    } else if ( isNaN ( low ) && isNaN ( high ) ) {
        chars = true;
        inival = low.charCodeAt ( 0 );
        endval = high.charCodeAt ( 0 );
    } else {
        inival = ( isNaN ( low ) ? 0 : low );
        endval = ( isNaN ( high ) ? 0 : high );
    }

    plus = ( ( inival > endval ) ? false : true );
    if ( plus ) {
        while ( inival <= endval ) {
        	if(key == false) {
            	matrix.push ( ( ( chars ) ? String.fromCharCode ( inival ) : inival ) );
        	} else {
        		matrix[key++] = ( ( chars ) ? String.fromCharCode ( inival ) : inival );
        	}
            inival += walker;
        }
    } else {
        while ( inival >= endval ) {
        	if(key == false) {
	        	matrix.push ( ( ( chars ) ? String.fromCharCode ( inival ) : inival ) );
        	} else {
            	matrix[key++] = ( ( chars ) ? String.fromCharCode ( inival ) : inival );
        	}
            inival -= walker;
        }
    }

    return matrix;
}

