// Retrieves the specified query string parameter.
function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0; i<vars.length;i++)
    {
        var pair = vars[i].split("=");
        if (pair[0] == variable)
        {
            return pair[1];
        }
    }
}

// Function that gets called on the onload property of the body to
// set the source code in the hidden field of a form and to append
// the source code to a link. The link should contain the word 'Source='.
function SetSourceCode(fieldToSet, linkToAppendCodeTo)
{			    
    var source = getQueryVariable('source');
    
    // If source cannot be found, check for Source.
    if (!source) {
        source = getQueryVariable('Source');
    }
    
    // If the source cannot be found, default to MS.
    if (!source) {
        source = "MS";
    }
    
    // The Input Hidden source code.
    document.getElementById(fieldToSet).value = source;
    
    // The Privacy Policy source code.
    if (linkToAppendCodeTo) {
        document.getElementById(linkToAppendCodeTo).href = document.getElementById(linkToAppendCodeTo).href.replace('Source=', 'Source=' + source);
    }
}

