/*
ERROR! There is something making the first variable/value pairing be put into two entries (i.e. 0 && 1).
It doesn't really change anything important except for wasting a bit of processor time. I'm just noting
it here in case I ever need to find places to streamline this thing
*/

//Check if we need to act spedish or not. Appearantly. Opera is a speddish browser. Speddsh==uses charAt(x) instead of [x] for accessing chars in strings 
var compatible=(navigator.appName!="Microsoft Internet Explorer" && navigator.appName!="Opera")

function strToArray(string)
{
var re=new Array()
for(i=0; i<=string.length-1; i++)
	{
	re[i]=string.charAt(i)
	}
return re
}

function arrayToStr(array)
{
var re=""
for(i=0; i<=array.length-1; i++)
	{
	re=re+array[i]
	}
return re
}

function reverse(string)//reverse a string
{
returnString="";
len=string.length-1
if(!compatible) string=strToArray(string)
for(i=0;i<=len;i++) returnString=string[i]+returnString
return returnString
}

//ARGV OBJECT
function argv()
{
this.url=window.location.href
this.i=window.location.href.length-1
if(!compatible) this.url=strToArray(this.url)

this.values=new Array()
this.names=new Array()
this.numVals=0//number of values

while(this.url[this.i]!='?' && this.i>0)
{
if(this.url[this.i]=='=') //there is a new variable to add. This whole segment occurs once for each variable
	{
	this.names[this.numVals]=""
	this.values[this.numVals]=""
	this.ii=this.i-1
	//loop backwards to get name
	while(this.url[this.ii]!='?' && this.url[this.ii]!='&' && this.ii>=0)
		{
		this.names[this.numVals]=this.url[this.ii]+this.names[this.numVals]
		this.ii--
		}

	//loop forwards to get value && reset the ii var
	this.ii=this.i+1;
	while(this.ii<window.location.href.length && this.url[this.ii]!='&' && this.ii>=0)
		{
		this.values[this.numVals]=this.url[this.ii]+this.values[this.numVals]
		this.ii++
		}
	this.values[this.numVals]=reverse(this.values[this.numVals]) //flip the value cuz it's read in backwards
	this.numVals++
	}
this.vars=this.url[this.i]+this.vars
this.i--
}
this.numVals--//compensate by 1 for the number being too high
//alert(this.names[1]+":"+this.values[1])
//alert(this.names[0]+":"+this.values[0])

this.getVal=function(name) //syntax: arg.getVar(a); returns 1 assuming the args are: ?a=1&b=2
	{
	for(gvI=0;gvI<=this.numVals;gvI++)
		{if(this.names[gvI]==name) return this.values[gvI]}
	return null //if not found, return nothing at all
	}

/*Utterly useless. For finding the name of the var holding a given val*/
this.getVar=function(value) //syntax: arg.getVar(a); returns 1 assuming the args are: ?a=1&b=2
	{
	for(gvI=0;gvI<=this.numVals;gvI++)
		{if(this.names[gvI]==value) return this.values[gvI]}
	return null //if not found, return nothing at all
	}
}