function QueryString (query_str)
{
    this.names = new Array ();
    this.values = new Array ();
    
    if (query_str)
    {
        this.parse (query_str);
    }
}

function addEntry (name, value)
{
    this.names.push (name);
    this.values.push (value);
}

function _getParameter (name)
{
    for (var i = 0; i < this.names.length; i++)
    {
        if (this.names[i].toLowerCase () == name.toLowerCase ())
        {
            return this.values[i];
        }
    }
    
    return null;
}

function _getParameterNames ()
{
    return this.names;
}

function _countOfParameters ()
{
    return this.names.length;
}

function splitQueryString (url_str) {
    var start = 0;
    var query_string = "";
    var temp_str;

    temp_str = "" + url_str;
//    alert ("splitQueryString: temp_str = " + temp_str);
    
    var idx = temp_str.indexOf ("?");
    if (idx != -1)
    {
        query_string = temp_str.substr (idx + 1);
    }
    else
    {
        query_string = "" + temp_str;
    }

    idx = query_string.indexOf ("&", start);
//    var n, v;
    
//    alert ("idx=" + idx);
    
    while (idx != -1)
    {
        temp_str = query_string.substring (start, idx);
        start = idx + 1;
//        alert ("temp_str: " + temp_str);
        
        idx = temp_str.indexOf ("=");
        if (idx != -1)
        {
//            n = temp_str.substring (0, idx);
//            v = temp_str.substr (idx + 1);          
//            alert ("n = " + n + "\nv = " + v);
            this.addParameter (temp_str.substring (0, idx), temp_str.substr (idx + 1));
        }

        idx = query_string.indexOf ("&", start);
    }

    if (query_string.length - start > 0)
    {
        temp_str = query_string.substr (start);
        idx = temp_str.indexOf ("=");
        if (idx != -1)
        {
            this.addParameter (temp_str.substring (0, idx), temp_str.substr (idx + 1));
        }
    }
}

QueryString.prototype.getParameterNames = _getParameterNames;
QueryString.prototype.getParameter = _getParameter;
QueryString.prototype.addParameter = addEntry;
QueryString.prototype.count = _countOfParameters;
QueryString.prototype.parse = splitQueryString;

