// BEGIN -- Place Below in a urlrewrite.js file
function ReplaceAll(Source,stringToFind,stringToReplace){
 
  var temp = Source;
 
    var index = temp.indexOf(stringToFind);
 
        while(index != -1){
 
            temp = temp.replace(stringToFind,stringToReplace);
 
            index = temp.indexOf(stringToFind);
 
        }
 
        return temp;
 
}
 
window.location.querystring = (function() {
 
    // by Chris O'Brien, prettycode.org
 
    var collection = {};
 
    // Gets the query string, starts with '?'
 
    var querystring = window.location.search;
 
    // Empty if no query string
 
    if (!querystring) {
        return { toString: function() { return ""; } };
    }
 
    // Decode query string and remove '?'
 
    querystring = decodeURI(querystring.substring(1));
 
   // Load the key/values of the return collection
 
    var pairs = querystring.toLowerCase().split("&");
 
    for (var i = 0; i < pairs.length; i++) {
 
        // Empty pair (e.g. ?key=val&&key2=val2)
 
        if (!pairs[i]) {
            continue;
        }
 
        // Don't use split("=") in case value has "=" in it
 
        var seperatorPosition = pairs[i].indexOf("=");
 
        if (seperatorPosition == -1) {
            collection[pairs[i].toLowerCase()] = "";
        }
        else {
            collection[pairs[i].toLowerCase().substring(0, seperatorPosition)] 
                = pairs[i].toLowerCase().substr(seperatorPosition + 1);
        }
    }
 
    // toString() returns the key/value pairs concatenated
 
    collection.toString = function() {
        return "?" + querystring;
    };
 
    return collection;
})();
 
function ReplaceKID(nameValue, tokenValue, defaultValue)
{
    var querystringvalue = window.location.querystring[nameValue.toLowerCase()];
 
    // what do you do if it is null
    if (querystringvalue != null &&
        querystringvalue != '')
    {
        document.body.innerHTML = ReplaceAll(document.body.innerHTML, tokenValue, querystringvalue);
    }
    else
    {
        document.body.innerHTML = ReplaceAll(document.body.innerHTML, tokenValue, defaultValue);
    }
}
 
// END -- Place Above Code in a urlrewrite.js

