var currentId = '';

function show(targetId)
{	if(targetId!='')
	{	if(document.all)
		{	target = document.all(targetId);
			hide(currentId);
			currentId=targetId;
			target.style.display='';
			writeCookie('hpCookies', 'activemenu', targetId);
		}
	}		
}

function hide(id)
{	if(id!='')
	 document.all(id).style.display='none';
}

function toggle(targetId)
{	if(document.all)
	{	target = document.all(targetId);
		if(target.style.display=='none')
		{	hide(currentId);
			currentId=targetId;
			target.style.display='';
			writeCookie('hpCookies', 'activemenu', targetId);
		}
		else
		{	currentId='';
			target.style.display='none';
			writeCookie('hpCookies', 'activemenu', '');
		}
	}
}

function showActive()
{	var a = getCookie('hpCookies','activemenu');
	if (a=='')
		writeCookie('hpCookies', 'activemenu','');
	else
		show(a);
}
	

function getCookie(cookiename,item)
{
	//alert(document.cookie);
	var m = document.cookie.indexOf(cookiename + "=");
	if (m != -1)
	{	var cookiearray = document.cookie.substr(m +cookiename.length + 1)
		cookiearray = cookiearray.split("#")
	
		for (var i = 0; i < cookiearray.length; i++)
		{	var string2check = cookiearray[i].split("-")
			if (string2check[0] == item)
				return(string2check[1]);
		}
	}
	return '';
}

function writeCookie(cookiename,item,newvalue)
{	
	//retrieve the value of the cookie with name: cookiename and convert it to an array, we use # as delilimitor for the dummycookies, the minus sign divided the identifier and the value
	//if cookiename not found, we have to create a new one
	var m = document.cookie.indexOf(cookiename+'=');
	if(m != -1)
	{//we have a cookie with this name already
		//alert('have');
		var cookiearray = (document.cookie.substr(m + cookiename.length + 1));
		// alert(cookiearray);
		cookiearray=cookiearray.split("#");
		var cookiefound = false;
		
		//loop through the array and checks or the identifier equals the item paramater if yes replace the current value for the newvalue parameter 
		for (var i = 0; i < cookiearray.length; i++)
		{	var string2check = cookiearray[i].split("-");
			if (string2check[0] == item)
				{	cookiearray[i] = string2check[0] + "-" + newvalue;
					cookiefound = true;
				}
		}
		
		//Add new value to the array
		if (cookiefound == false)
			cookiearray[cookiearray.length] = item + "-" + newvalue;
		
		//Build a new cookiestring
		var newcookie = "";
		
		for (var i = 0; i < cookiearray.length; i++)
		{	if (cookiearray[i] != "")
				newcookie = newcookie +  cookiearray[i]	+ "#";
		}
		document.cookie = cookiename + "=" + newcookie + ";path=/highlandpark";
		//alert(document.cookie);
	}
	else
	{//no cookie with this name.
		//alert('none');
		document.cookie = cookiename + "=" + item + "-" + newvalue + "#" + ";path=/highlandpark";
		//alert(document.cookie);
	}
}