var mapCookie = "photomaps";	// Name of cookie attribute
var defaultAge  = 1;		// Number of days to keep cookie for

function setCookie(name, value, days) 
{
	if (!days)
		days = 1; // default to 1 day if empty 

	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() + days * 24 * 60 * 60 * 1000); 

	document.cookie = name + "=" + escape(value) + 
		 "; expires=" + expdate.toGMTString() + ";path=/"; 
}

function getCookie(name)
{
	var dc     = document.cookie;
	var cname  = name + "=";
	var clen   = dc.length;
	var cbegin = 0;

	while (cbegin < clen)
	{ 
		var vbegin = cbegin + cname.length;

		if (dc.substring(cbegin, vbegin) == cname)
		{ 
			var vend = dc.indexOf(";", vbegin);
			if (vend == -1)
				vend = clen;

			return unescape(dc.substring(vbegin, vend));
		}
		cbegin = dc.indexOf(" ", cbegin) + 1;

		if (cbegin== 0)
			break;
	}
	return null;
}

function mapEnabled()
{
	if (getCookie(mapCookie) != "no")
		return (1);

	return (0);
}

function showMap(tag)
{
	if (mapEnabled())
		document.write(tag);
}

function toggleMap()
{
	if (mapEnabled())
		setCookie(mapCookie, "no", defaultAge);
	else
		setCookie(mapCookie, "yes", defaultAge);

	document.location.href = document.location.href; // Refresh page
}

function showToggleLink()
{
	var action;

	if (mapEnabled())
		action = "隠す)";
	else
		action = "表示)";
		
	document.write('<a href="javascript:toggleMap()">' +
	    '(地図を' + action + '</a>');
}

function showToggleLinkEn()	// XXX: code duplication
{
	var action;

	if (mapEnabled())
		action = "(Hide";
	else
		action = "(Show";
		
	document.write('<a href="javascript:toggleMap()">' +
	    action + ' Map)' + '</a>');
}
