var glb_cookExp = new Date();
glb_cookExp.setTime(glb_cookExp.getTime() + 365 * 24 * 60 * 60 * 1000);


function hodnoceni_produktu(link)
{
	var w = 600;
	var h = 650;
	var lp = (screen.width - w) / 2;
	var tp = (screen.height - h) / 2;
	var wo = null;

	params = 'toolbar=no,scrollbars=yes,resizable=no,menubar=no,status=no,directories=no,location=no,width='+w+',height='+h+',left='+lp+',top='+tp;
	wo = window.open(link, 'hodnoceni_produktu', params);

	if (window.focus)
		wo.focus();
	return false;
}

function reload_opener_and_close(id)
{
	if (window.opener)
	{
		//setCookie(id, '1', glb_cookExp, '/');
		window.opener.location.reload(true);
		
	}
	self.close();
}

/* nastav cookies */
function setCookie(name, value, expires, path, domain, secure)
{
	document.cookie= name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
 
function showDivByCheckBox(elm, id)
{
	if (elm)
	{
		var checked = elm.checked;
		var elm2 = document.getElementById(id);
		if (elm2)
			elm2.style.display = checked ? '' : 'none';
	}
}

// prepina zalozky nove a nejctenejsi zpravy
function setNewsFolder(type)
{
	var elmTop = document.getElementById('divtoparticles');
	var elmNew = document.getElementById('divnewarticles');
	var elmtmp1 = document.getElementById('topreadarticles');
	var elmtmp2 = document.getElementById('topnewarticles');
	
	if (elmTop && elmNew)
	{
		if (type == 'top')
		{
			elmTop.style.display = '';
			elmNew.style.display = 'none';
			if (elmtmp1) elmtmp1.className = 'active';
			if (elmtmp2) elmtmp2.className = '';
		}
		if (type == 'new')
		{
			elmTop.style.display = 'none';
			elmNew.style.display = '';
			if (elmtmp1) elmtmp1.className = '';
			if (elmtmp2) elmtmp2.className = 'active';
		}
	}
}

// prepina zalozky poslednich diskuzi
function setForumsFolder(type)
{
	var elmAll = document.getElementById('divallforums');
	var elmArt = document.getElementById('divartforums');
	var elmProd = document.getElementById('divprodforums');
	var elmtmp1 = document.getElementById('topallforums');
	var elmtmp2 = document.getElementById('topartforums');
	var elmtmp3 = document.getElementById('topprodforums');
	
	if (elmAll || elmArt || elmProd)
	{
		if (type == 'all')
		{
			elmAll.style.display = '';
			elmArt.style.display = 'none';
			elmProd.style.display = 'none';
			if (elmtmp1) elmtmp1.className = 'active';
			if (elmtmp2) elmtmp2.className = '';
			if (elmtmp3) elmtmp3.className = '';
		}
		if (type == 'art')
		{
			elmAll.style.display = 'none';
			elmArt.style.display = '';
			elmProd.style.display = 'none';
			if (elmtmp1) elmtmp1.className = '';
			if (elmtmp2) elmtmp2.className = 'active';
			if (elmtmp3) elmtmp3.className = '';
		}
		if (type == 'prod')
		{
			elmAll.style.display = 'none';
			elmArt.style.display = 'none';
			elmProd.style.display = '';
			if (elmtmp1) elmtmp1.className = '';
			if (elmtmp2) elmtmp2.className = '';
			if (elmtmp3) elmtmp3.className = 'active';
		}
	}
}

function getwidth()
{
	if (window.innerWidth)
		ret = window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		ret = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		ret = document.body.clientWidth;
	return ret;
}

	// zjisteni horniho okraje
	function getScrollTop() {
		return f_filterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}

	function f_filterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}

/* zjisti vysku od zacatku dokumentu */
function getElmDistTop(el) {
	var top = 0;

	if (!el)
		return false;

	while(el) {
		top += el.offsetTop;
		el = el.offsetParent;
	}
	return top;
}



function change_pos() {
	var x = getwidth();
	x = x / 2;
	var elm = document.getElementById('skyscraper');
	if (elm)
	{
		elm.style.left = 1002;
		// automaticke posunuti
		var t = getScrollTop();
		if (t < 141) t = 100;
		elm.style.top = t;
	}
}


window.onresize = function() {
	change_pos();
}
window.onscroll = function() {
	change_pos();
}

$(document).ready(
	function() {
		var loadProgramInterval = 1000 * 60 * 1; // 1 minuta
		var renewSessionInterval = 1000 * 60 * 5; // 5 minut
	
		function loadProgramFFOnline () {
			$('#ff-online-program-container').load('ajax/financni-forum-online-program.php', function() {
	  			setTimeout(loadProgramFFOnline, loadProgramInterval);
				}
			);	
		}
		$('#ff-online-program-container').ready(function () {
			setTimeout(loadProgramFFOnline, loadProgramInterval);
			}
		);
		
		
		function renewSession()
		{
			$.ajax({
   				url: "ajax/renew-session.php",
				success: function(msg){
   				}
 			});			
  			setTimeout(renewSession, renewSessionInterval);
		}
		$('#renew-session-container').ready(function() {
  			setTimeout(renewSession, renewSessionInterval);
			}
		);
		
		$('#online-help-icon').click(function() {
			$('#online-help').toggle();
		});
		$('#online-help').click(function() {
			$('#online-help').toggle();
		});
		
	}
);
