var random_key = getRandomCookie();

function getRandomCookie()
{
	return readCookie("token");	
}

function readCookie(n)
{
	a = document.cookie;
	res = '';
	while(a != '')
 	{
		cookiename = a.substring(0,a.search('='));
		cookiewert = a.substring(a.search('=')+1,a.search(';'));
		if(cookiewert == '')
		{cookiewert = a.substring(a.search('=')+1,a.length);}

		if(n == cookiename){res = cookiewert;}

		i = a.search(';')+1;
		if(i == 0){i = a.length}
		a = a.substring(i,a.length);
	}
	return(res)
}

function writeCookieInput(formname)
{
	cookie = getRandomCookie();
	var inp = document.createElement("input");
	inp.setAttribute('type','hidden');
	inp.setAttribute('name','account_randomkey');
	inp.setAttribute('value',cookie);
	inp.setAttribute('id','account_randomkey');
	document.getElementById(formname).appendChild(inp);	
}
