function setCookie(cookieName, cookieValue, cookieExp)
{
	document.cookie = cookieName + '=' + escape(cookieValue)+(cookieExp?'; expires='+new Date(+new Date()+cookieExp*864e5).toGMTString():'')+'; path=/'
}
function getCookie(N,x)
{
	if((x=document.cookie)&&(N=(';'+x).match(new RegExp('(;| )'+N+'=[^;]+')))) 
	return unescape(N[0].split(/=/g)[1])
}

var calendar_view;
function calendarView(series)
{
	var prev_series = (series=="mprc") ? "merc" : "mprc";
	
	if ( calendar_view != series )
	{
		setCookie("calendar", series, "365");
		document.getElementById(series).className = "active";
		if (calendar_view)
		{
			document.getElementById(calendar_view).className = "";
			document.getElementById("entry_" + calendar_view).style.display = "none";
		}
		document.getElementById("entry_" + series).style.display = "";
		calendar_view = series;
	}
}


function photo(url, title, width, height)
{
	window.open('/apps/photo?img=' + url + ';title=' + title, 'photo','titlebar=no,toolbar=no,resizable=no,scrollbars=no,status=no,menubar=no,width=' + width + ',height=' + height);
}
function profile(user_id)
{
	var param = (typeof user_id != "undefined") ? "?id="+user_id : "";
	window.open('/apps/profile' + param, 'profile','titlebar=no,toolbar=no,resizable=no,scrollbars=yes,status=no,menubar=no,width=630,height=410');
}
function help(topic_id)
{
	var param = (typeof topic_id != "undefined") ? "?id="+topic_id : "";
	window.open('/apps/help' + param, 'Help','titlebar=no,toolbar=no,resizable=no,scrollbars=yes,status=yes,menubar=no,width=760,height=590');
}
function sendmail(title, url)
{
	window.open('/apps/sendmail?title=' + title + ';url=' + url,'sendmail','toolbar=no,scrollbars=no,resizable=no,status=no,location=no,directories=no,width=580,height=490,menubar=no')
}
function page(url)
{
	window.open(url);
}

function emoticons()
{
	window.open('/static/emoticons.html','','toolbar=no,scrollbars=yes,resizable=no,status=no,location=no,directories=no,width=525,height=410,menubar=no');
}


function poll(poll_id)
{
	var param = (typeof poll_id != "undefined") ? "?results="+poll_id : "";
	window.open('/apps/poll' + param, 'poll','titlebar=no,toolbar=no,resizable=no,scrollbars=yes,status=no,menubar=no,width=630,height=410');
}

var pollAnswerCurrent = 0;
function pollAnswer(answer_id)
{
	if ( pollAnswerCurrent > 0 )
		document.getElementById("answer"+pollAnswerCurrent).className = "false";
	
	if ( pollAnswerCurrent != answer_id )
		document.getElementById("answer"+answer_id).className = "true";
	else
		answer_id = 0;
	
	document.getElementById("answer_id").value = answer_id;
	pollAnswerCurrent = answer_id;
}

function pollEvent(event, answer_id)
{
	if ( pollAnswerCurrent != answer_id )
		document.getElementById("answer"+answer_id).className = event;
}

function pollVoting(poll_id)
{
	if ( pollAnswerCurrent == 0 )
	{
		alert("Zaznacz odpowied¼!");
		return false;
	}
	poll(poll_id);
	return true;
}

function set_page(id)
{
	var el = document.getElementById(id);
	var y=0;
	for( var node=el; node; node=node.offsetParent)
	{
		y += node.offsetTop;
	}
	window.scrollTo(0, y);
}

function do_submit(form_id)
{
	document.getElementById(form_id).submit();
}
