//Function creates a cookie
function createCookie(){
	//Create cookies
	wert = 'logged-in=1;';

	//Writes the cookie
	document.cookie = wert;

	//Alert the user
	alert('Cookie erstellt');
}

//Function deletes cookie 
function logout(){
	//Delete cookie
	document.cookie = 'logged-in=1; expires=Thu, 01-Jan-70 00:00:01 GMT;';

	//Alert the user
	//alert('Login Cookie gelöscht');
}

//Function changes the div
function changeContent(div){
	testvalue = fetchCookie('logged-in');
	ao_kennung = fetchCookie('ao-kennung');
	//alert(testvalue);
	if( testvalue == '1'){
		//alert('Nur am testen, ignoriere mich einfach :)');
		document.getElementById(div).innerHTML = '<ul><li class="ao-log-in">Angemeldet als: </li><li>'+ao_kennung+'</li><li class="ao-log-out"><a href="/mein-aspectonline/logout/" onclick="logout();">Abmelden</a></li></ul>';
		//document.getElementById(div).innerHTML = 'Logout';
	}
}

//Function checks if a cookie exists and reads its value
function fetchCookie(name){
	i=0;  //Searchposition
	suche = name+"=";
	while (i<document.cookie.length){
		if (document.cookie.substring(i, i+suche.length)==suche){
			ende = document.cookie.indexOf(";", i+suche.length);
			ende = (ende>-1) ? ende : document.cookie.length;
			cook = document.cookie.substring(i+suche.length, ende);
			return unescape(cook)
		}
		i++
	}
	return null
}

//changeContent('myao');