// JavaScript Document
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function showBeaches(action) {
	//loader
	document.getElementById('show_activity').innerHTML = '<p class="lrg_noline"><img src="/img/load_beach.gif" alt="loading" width="35" height="35" align="absmiddle" /> Loading...</p>';
	document.getElementById('map_it').innerHTML = '';
	// Get value of showTrails cookie
	var cookValue = readCookie('showBeaches');
	// if this is the initial load and no cookie has been set, show all trails.
	// if this is the initial load and there is a cookie, show right content
  	if(action == 'load'){
		if(cookValue){
			action = cookValue;
		}else{
			action = 'all';
		}
	}
	
	// Now that we have the right action, we can set the cookie
	createCookie('showBeaches', action, '');
	document.getElementById(action).checked = true;

	showme(action);
}