/****************************************************************************************
Script to take the variables from a location bar and turn them into JavaScript variables
                      Written by Mark Wilton-Jones, 13/9/2001
*****************************************************************************************

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use

To use this script, simply add the lines
<script type="text/javascript">
<!--
var useArray = true; //Or false
//-->
</script>
<script src="PATH TO SCRIPT/locvar.js" type="text/javascript"></script>
into your page before any scripts that need the variables

The line 'var useArray = true;' tells the script whether or not you want it to put the
variables into an array as well as create them as variables.

eg 1.
if the URL ends with '?vara=help_me&varb=now_please' and useArray = true, the script will
create the following:
vara = 'help_me';
varb = 'now_please';
getVars['vara'] = 'help_me';
getVars['1'] = 'help_me';
getVars['varb'] = 'now_please';
getVars['2'] = 'now_please';

eg 2.
if the URL ends with '?vara=help_me&varb=now_please' and useArray = false, the script will
create the following:
vara = 'help_me';
varb = 'now_please';

_______________________________________________________________________________________*/

function locclean( locvarcl, loctrue ) {
	//convert stuff like:
	//%21%22%A3%24%25%5E%26*%28%29-_%3D%2B%7E%23%7B%7D%5B%5D%3A@%3B%27%3C%3E%3F%2C
	//into normal characters
	//I need to do these few myself because I need a different response to unescape
	var locvarar = new Array("+","%27","%5C","%0D","%0A"), varlocar = new Array(" ","\\'","\\\\","","\\n"), x;
	if( loctrue ) { locvarar.length = 0; } //If I'm not using eval(), I only need to convert the +
	for( x = 0; x < locvarar.length ; x++ ) {
		while( locvarcl.indexOf( locvarar[x] ) != -1 ) {
			locvarcl = locvarcl.replace( locvarar[x], varlocar[x] );
		}
	}
	return unescape( locvarcl );
}

var locvartemp = self.location.href + '&', getVars = new Array(), locvarx;
//eg locvartemp = 'http://www.blah.com/test.html?var1=carp&var2=carp2&myvar=sugar&'
//I need that last & in there so the script knows where the end of the last variable is
if( locvartemp.indexOf( "?" ) != -1 ) {
	//there are variables, what are they?
	locvartemp = locvartemp.substr( locvartemp.indexOf( "?" ) + 1 );
	//eg locvartemp = 'var1=carp&var2=carp2&myvar=sugar&'
	for( locvarx = 0; locvartemp != ''; locvarx++ ) {
		//keep looking until you reach the end of the string
		eval( 'var ' + locclean( locvartemp.substring( 0, locvartemp.indexOf( "&" ) ).replace( "\=", "='" ) + "'" ) );
		//eg var var1='carp'
		if( useArray ) {
			getVars[locclean( locvartemp.substring( 0, locvartemp.indexOf( "=" ) ) )] = locclean( locvartemp.substring( locvartemp.indexOf( "=" ) + 1, locvartemp.indexOf( "&" ) ), true );
			//eg var getVars[var1]=carp (quotes are not needed as strings are in variable form)
			getVars[locvarx] = locclean( locvartemp.substring( locvartemp.indexOf( "=" ) + 1, locvartemp.indexOf( "&" ) ), true );
			//eg var getVars[0]=carp
		}
		locvartemp = locvartemp.substr( locvartemp.indexOf( "&" ) + 1 );
		//eg locvartemp = 'var2=carp2&myvar=sugar&'
	}
}