﻿function GetSelectedValue(elementId)
{
    var elem = document.getElementById(elementId);
    var val = elem.options[elem.selectedIndex].value;
    
    return val;
}

function SetSelectedValue(elementId, value)
{
    var elem = document.getElementById(elementId);
    
    for (var i = 0; i < elem.options.length; ++i)
    {
        if (elem.options[i].value != value)
            elem.options[i].selected = false;
        else
            elem.options[i].selected = true;
    }
}

function AssembleQueryStr(params)
{
    var output = "?";
    
    for (var key in params)
    {
        output += key;
        output += "=";
        output += escape(params[key]);
        output += "&";
    }
    
    return output;
}

// Function from: http://snipplr.com/view/799/get-url-variables/
// Read a page's GET URL variables and return them as an associative array.
function GetUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for (var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
     
    return vars;
}

