function emailDecode(email) {
	email = email.replace(/ \(?zavin\u00e1\u010d\)? /i, '@');
	email = email.replace(/ \(?te\u010dka\)? /gi, '.');
	email = email.replace(/(([^ .@]+\.)*[^ .@]+@([^ .@]+\.)+[^ .@]+)/g,
			'<a href="mailto:$1">$1</a>');
	return email;
}

function emailDecodeByTagName(tagName) {
	var alltags = document.getElementsByTagName(tagName);
	for (i = 0; i < alltags.length; i++) {
			alltags[i].innerHTML = emailDecode(alltags[i].innerHTML);
	}
}

function emailDecodeById(id) {
	element = document.getElementById(id);
	if (element) {
			element.innerHTML = emailDecode(element.innerHTML);
	}
}

function setInputHelp(inputSelector, helpContent) {
	$(inputSelector).css("color", "#AAA").val(helpContent)
		.focus(function() {
			var $this = $(this);
			if ($this.val() == helpContent) {
				$this.val("");
				$this.css("color", "black");
			}
		})
		.blur(function() {
			var $this = $(this);
			if ($this.val() == "") {
				$this.val(helpContent);
				$this.css("color", "#AAA");
			}
		});
}
/**
* AJAX Nette Framework plugin for jQuery
*
* @copyright   Copyright (c) 2009 Jan Marek
* @license MIT
* @link    http://nettephp.com/cs/extras/jquery-ajax
* @version 0.2
*/
jQuery.extend({
   nette: {
       updateSnippet: function(id, html) {
           $("#" + id).html(html);
       },

       success: function(payload) {
           // redirect
           if (payload.redirect) {
               window.location.href = payload.redirect;
               return;
           }

           // snippets
           if (payload.snippets) {
               for (var i in payload.snippets) {
                   jQuery.nette.updateSnippet(i, payload.snippets[i]);
               }
           }
       }
   }
});

// prevzato z JQuery Cookie pluginu
function cookie(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
		}
		// CAUTION: Needed to parenthesize options.path and options.domain
		// in the following expressions, otherwise they evaluate to undefined
		// in the packed version for some reason...
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = cookies[i].replace(/^\s+|\s+$/g, "");
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};

function reloadComponent(anchorOrUrl, callback) {
		$.get((typeof anchorOrUrl == "string" ? anchorOrUrl : anchorOrUrl.href), {}, function(data) {
			$.nette.success(data);
			if(callback != undefined) {
				callback(data);
			}
		}, "json");
		return false;
}

var sklikZoneIds = new Array();
function sklik(divId, zoneId) {
	$.get(
		'/reklama/sklik/?json=1&zoneId=' + encodeURIComponent(zoneId) +
			'&previousZoneIds=' + encodeURIComponent(sklikZoneIds.join(',')) +
			'&url=' + encodeURIComponent(window.location.href) +
			'&referer=' + encodeURIComponent(document.referrer),
		{},
		function(data) {
			if (data["status"] == 200) {
				$("#" + divId).html(data["html"]);
			}
		},
		"json"
	);
	sklikZoneIds.push(zoneId);
}

