function loadArgs()
{
	this.tile = getArgument('tile')
	
	this.bw = getArgument('bw')
	if (this.bw==null)
		this.bw='false'
	
	this.culvert= getArgument('culvert')
	if (this.culvert==null)
		this.culvert='true'
	
	this.photo= getArgument('photo')
	if (this.photo==null)
		this.photo='true'
	
	this.instream= getArgument('instream')
	if (this.instream==null)
		this.instream='true'
	
	this.aerial= getArgument('aerial')
	if (this.aerial==null)
		this.aerial='true'
	
	this.fish= getArgument('fish')
	if (this.fish==null)
		this.fish='fish'
	
	this.stream= getArgument('stream')
	if (this.stream==null)
		this.stream='true'
	
	this.ortho= getArgument('ortho')
	if (this.ortho==null)
		this.ortho='true'
	
	this.topo= getArgument('topo')
	if (this.topo==null)
		this.topo='true'
		
	this.pathname=location.pathname
	if (this.pathname.substr(this.pathname.length-1,1)=='l')
		this.pathname = this.pathname.replace(/.html/g,".htm")
	else
		this.pathname = this.pathname.replace(/.htm/g,".html")
}

function copyArgs(myArgs)
{
	this.tile = myArgs.tile
	this.bw = myArgs.bw
	this.culvert= myArgs.culvert
	this.photo= myArgs.photo
	this.aerial= myArgs.aerial
	this.fish= myArgs.fish
	this.instream= myArgs.instream
	this.stream = myArgs.stream
	this.ortho = myArgs.ortho
	this.topo = myArgs.topo 
	this.pathname = myArgs.pathname
}

function getURL(myArgs)
{
	return('?tile='+this.tile+'&bw='+this.bw+'&culvert='+this.culvert+'&aerial='+this.aerial+'&photo='+this.photo+'&fish='+this.fish+'&instream='+this.instream+'&stream='+this.stream+'&topo='+this.topo+'&ortho='+this.ortho)
}

function go()
{
	location.href = (location.protocol+'//'+location.host+this.pathname+this.getURL())
}

function mapArgs(dflt)
{
	this.tile = null
	this.topo = dflt
	this.ortho = dflt
	this.bw = dflt
	this.photo = dflt
	this.culvert = dflt
	this.aerial = dflt
	this.fish = dflt
	this.instream = dflt
	this.stream = dflt
	this.loadArgs = loadArgs
	this.copyArgs = copyArgs
	this.getURL = getURL
	this.go = go
}



/***** Utilities *****/

function plusUnescape(str) { // the unescape function won't convert plus signs
	str = '' + str; // to spaces; like you see in search strings
	while (true) {
		var i = str.indexOf('+');
		if (i == -1) break;
		str = str.substring(0,i) + ' ' + str.substring(i+1,str.length);
	}
	return unescape(str);
}

function getArgument (theKey) {
	var args = new Array ();
	var argstring = window.location.search;
	if (argstring.charAt(0) != '?') return null; // no arguments
	argstring = argstring.substring(1, argstring.length);
	var argarray = argstring.split('&');
	for (var i=0; i < argarray.length; i++) {
		var singlearg = argarray[i].split('=');
		if (singlearg.length != 2) continue; // not a valid argument
		var argsKey = plusUnescape(singlearg[0]);
		var argsValue = plusUnescape(singlearg[1]);
		args [argsKey] = argsValue;
	}
	return args[('' + theKey)]
}


