/* sets cookie with a 1-year expiry */
function setCookie(property, value)
{
	var expr_date = new Date;

	// set expiration date 1 year in the future
	expr_date.setFullYear(expr_date.getFullYear() + 1);

	// set cookie
	document.cookie = property + "=" + value + "; path=/; expires="
		+ expr_date.toGMTString();
}

/* returns the value of a cookie or null for no value */
function getCookie(property)
{
	var start_idx, end_idx;
	var value;


	// find start of cookie
	//  (might be at beginning of string => no preceding semicolon)
	start_idx = document.cookie.search(new RegExp("^(.*; )?" + property + "="));
	
	// check if cookie exists
	if (start_idx != -1)
	{
		// find next equals (char before value)
		start_idx = document.cookie.indexOf("=", start_idx);

		// find next semicolon (char that might be after value)
		end_idx = document.cookie.indexOf(";", start_idx);

		// check if there even is a semicolon after the cookie
		if (end_idx != -1)
			// this cookie is somewhere in the middle
			value = document.cookie.slice(++start_idx, end_idx);
		else
			// this cookie is at the end
			value = document.cookie.slice(++start_idx);
	}
	else
		// cookie not found
		value = null;

	return value;
}

/* set cookie that poll has been taken and submit poll */
function submitPoll(poll_name)
{
	// set cookie
	setCookie(poll_name, 1);

	// submit
	document.PollForm.submit();
}
