/*TimC: I wrote this to parse query strings into properties of the Querystring Object
    To Use: 
        var qs = new QueryString('http://www.foobar.com/page.htm?testArg=itworked&booleanOperator);
        alert('qs.testarg = ' + qs.testarg);
        alert(qs["testarg"]); //can also be written as 
        alert('qs.booleanoperator = ' + qs.booleanoperator); //this should pop up true, since it has no value
        
    Note: the querystring token names get lower cased when added to the object as properties
*/
function Querystring(qs) { // optionally pass a querystring to parse
    /// <summary>Parses the querystring into proerties of this object. The keys of the querystring are parsed into lower case property names</summary>
    /// <param name="qs">Optional query string value to pass in. If not passed in, will default to location.search</param>
	
	if (!qs) qs = top.location.search; 
	if (qs.length == 0) return;

    var re = new RegExp(/(?:[\?|\&]){1,1}([^\=\&]+\=?[^\=\&]*)/g);
    
    while (match = re.exec(qs)){
        var mv = new String(match[1]);
        if(mv.indexOf('=') != -1){
            var vals = mv.split("="); 
            this[unescape(vals[0]).toLowerCase()] = unescape(vals[1]);
        }else{
            this[unescape(mv).toLowerCase()] = true;
        }
    }    
}
