// Begining JS file pulled into ALL AWSM pages

// GLOBAL XSS FILTER //
// For protecting against XSS attacks. This should be used for any query and
// page location values that get written into a page
var filteredResult = (function xssFilter(val) {
    var valResponse = "";
    var illegalChars = /[^A-Za-z0-9\-\_\,\.\/\:\?\&\=\@]/; // find instances of non letters, numbers and -_,./:?&=@ (this filter has an additional @ symbol allowed)

    if (illegalChars.test(val)) {
        valResponse = "XXXX";
    } else {
        valResponse = val
    }
    return valResponse;
});


// GLOBAL QUERY VARIABLE //
//Sort through a string formatted as a URL with a querystring and return the vaule of a name value pair
var qsReturnValue = (function queryVarReturn(urlString, keyName) {
    var urlParams = {};
    (function () {
        var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space 
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = urlString.substring(urlString.indexOf("?") + 1, urlString.length);

        while (e = r.exec(q)) {
            urlParams[d(e[1])] = filteredResult(d(e[2]));
        }
    })();

    return urlParams[keyName];
});

// GLOBAL urlArray vaiable //
//Initalize Array for puling out current page from URL available for all scripts
var urlArray = new Array();
urlArray = location.href.split("/");
