function showoffset(offset) {
	displayoffset=offset;
	if (displayoffset < 0)
	{
			displayoffset=0;
	};
	document.variablepassing.offset.value=displayoffset;
	querymap(map);
	navigate();
}

function showgroupolder(gid) {
	if (document.variablepassing.groupsearch.value!=gid) {
		document.variablepassing.offset.value=0;
	} else {
		document.variablepassing.offset.value=Number(document.variablepassing.offset.value)+Number(itemstodisplay);
	};
	document.variablepassing.groupsearch.value=gid;
	document.variablepassing.drawnewmap.value=1;
	loadednewpage=false;
	menuidtoshow='m'+gid;
	querymap(map);
	navigate();
	checkshowmap('m'+gid)
};
function showgroupnewer(gid) {
	if ((document.variablepassing.groupsearch.value!=gid) || (document.variablepassing.offset.value <= itemstodisplay)) {
		document.variablepassing.offset.value=0;
	} else {
		document.variablepassing.offset.value=Number(document.variablepassing.offset.value)-Number(itemstodisplay);
	};
	document.variablepassing.groupsearch.value=gid;
	document.variablepassing.drawnewmap.value=1;
	loadednewpage=false;
	menuidtoshow='m'+gid;
	querymap(map);
	navigate()
	checkshowmap('m'+gid)
};

function showflagged() {
	var maptoshow="mapcache/caching.php?flagged=1&";
	maptoshow=maptoshow+"lastx="+itemstodisplay+"&lastxoff="+displayoffset;
	genericmap( maptoshow, mainmap );
}
function addcountvalue(value){
	var output='<option value="'+value+'"';
	if (itemstodisplay==value){
	output+=' selected';
	};
	output+='>'+value+'</option>';
	return output;
}

function navigate() {
	var count='<form name="toshowform" style="display:inline;padding-left:0px"><select name="toshowvalue" onChange="setitemstodisplay();" style="padding-left:0px">';
	count+=addcountvalue(1);
	count+=addcountvalue(5);
	count+=addcountvalue(10);
	count+=addcountvalue(15);
	count+=addcountvalue(20);
	count+=addcountvalue(25);
	count+=addcountvalue(50);
	count+=addcountvalue(100);
	count+='<\/select><\/form>';
	var clearsearch='<a href="javascript:clearsearches();"><img src="images/home_img/clear-map.gif" border=0 style="padding-right:2px"></a>';
	var latest='<a href="javascript:displaylatestroutes();"><img src="images/home_img/latest.gif" border=0 style="padding=left:0px; padding-right:0px"></a> ';
	var oldoff=Number(displayoffset)+Number(itemstodisplay);
	var newoff=Number(displayoffset)-Number(itemstodisplay);

	if (newoff < 0) {
		newoff=0;
	};
	var older='<a href="javascript:showoffset('+oldoff+');"><img src="images/home_img/previous.gif" border=0 style="padding-right:0px"></a> ';
	var newer='<a href="javascript:showoffset('+newoff+');"><img src="images/home_img/newer.gif" border=0></a> ';

	document.getElementById("navigation").innerHTML = latest;
	document.getElementById("navigation").innerHTML += clearsearch;

	if (displayoffset>0) {
		var newer='<a href="javascript:showoffset('+newoff+');"><img src="images/home_img/next.gif" border=0></a> ';
	} else {
		var newer='<a><img src="images/home_img/next-off.gif" border=0></a> ';
	};
	document.getElementById("navigation").innerHTML += older;
	document.getElementById("navigation").innerHTML += count;
	document.getElementById("navigation").innerHTML += newer;	

//	document.getElementById("navigation").innerHTML += '<a href="javascript:histprevious();"><img src="images/buttons/histolder.png" border=0></a> ';
//	if (currentmaphist>0) {
//		document.getElementById("navigation").innerHTML += '<a href="javascript:histnext();"><img src="images/buttons/histnewer.png" border=0></a> ';
//	} else {
//		document.getElementById("navigation").innerHTML += '<a><img src="images/buttons/histnewergreyed.png" border=0></a> ';
//	};
	if (parseInt(document.variablepassing.admin.value)==1) {
		var flagged='<a href="javascript:showflagged();">show flagged items</a> ';
		document.getElementById("navigation").innerHTML += flagged;
	};
	var mapurl=window.location.href.substr(0,window.location.href.length-window.location.search.length)
	if (mapurl.substr(mapurl.length-1,1)=='#') {
		mapurl=mapurl.substr(0,mapurl.length-1)
	};
	if (mapurl.substr(mapurl.length-1,1)=="?") {
		mapurl=mapurl.substr(0,mapurl.length-1)
	};
	mapurl+=currentmap.substr(28,currentmap.length-28);
	document.getElementById("navigation").innerHTML += '<a href="'+mapurl+'" style="float:right;">link to this map</a>'
}
function clearsearches() {
	document.variablepassing.offset.value=0;
	document.variablepassing.commentsearch.value='';
	document.variablepassing.tagsearch.value='';
	document.variablepassing.groupsearch.value='';
	document.variablepassing.searchlat.value='';		
	document.variablepassing.searchlong.value='';
	document.variablepassing.searchlatsize.value='';
	document.variablepassing.searchlongsize.value='';
	menuidtoshow=false;
	uid=0;
	genericmap( "mapcache/caching.php?lastx="+itemstodisplay , map) ;
};
function displaylatestroutes() {
	document.variablepassing.offset.value=0;
	selectedname='';
	uid=0;
	document.getElementById('updateinfo').value ='';
	hide('updatedropdown');
	tagsearch='';
	commentsearch='';
	displayoffset=0;
	querymap(map);
	navigate();
}
function setitemstodisplay() {
	itemstodisplay = parseInt(document.toshowform.toshowvalue.options[document.toshowform.toshowvalue.selectedIndex].value);
	document.variablepassing.todisplay.value=itemstodisplay;

	querymap(map);
	navigate();
}

function histprevious() {
	currentmaphist=currentmaphist+1;
	navigate()
	genericmap('maphist'+currentmaphist, map);
};
function histnext() {
	currentmaphist=currentmaphist-1;
	navigate()
	if (currentmaphist <= 0) {
		genericmap('maphist'+currentmaphist, map);
	};
};
