﻿if (typeof nonCachedCookieName != 'undefined' && typeof nonCachedQueryStringParam != 'undefined') {
    var queryStringStart = '&';
    var hasNonCachedCookie = false;
    var hasNonCachedQueryStringParam = (window.location.href.indexOf(nonCachedQueryStringParam) > 0);

    for (i = 0; i < allCookies.length; i++) {
        currentCookie = allCookies[i].split('=');
        currentCookie[0] = currentCookie[0].replace( /^\s+|\s+$/g , '');
        if (currentCookie[0] == nonCachedCookieName) {
            hasNonCachedCookie = true;
            break;
        }
    }

    if (window.location.href.indexOf('?') < 0) queryStringStart = '?';
    
    if (hasNonCachedCookie && !hasNonCachedQueryStringParam) {
        window.location = window.location + queryStringStart + nonCachedQueryStringParam + '=1';
    }
    else if (!hasNonCachedCookie && hasNonCachedQueryStringParam) {
        window.location = window.location.href.replace('?' + nonCachedQueryStringParam + '=1&', '?').replace('&' + nonCachedQueryStringParam + '=1', '').replace('?' + nonCachedQueryStringParam + '=1', '');
    }
}
