// Rev Agency tracking
// Legacy tracking taken into consideration
var ra_ref = "";
var hrefsplit = window.location.href.split("?");
var sourceURL = hrefsplit[0];
if (ra_ref === "") {
    if (hrefsplit.length == 2) {
        if (refmatch = hrefsplit[1].match(/\bra_ref=([^&]+)/gi)) {
            for (var i = 0; i < refmatch.length; i++) {
                var refsplit = refmatch[i].split("=");
                if (refsplit.length == 2) {
                    if (refsplit[0].toLowerCase() == "ra_ref") {
                        ra_ref = refsplit[1];
                        if (ra_ref != "") {
                            var expires = new Date();
                            expires.setTime(expires.getTime() + (180 * 24 * 60 * 60 * 1000));
                            document.cookie = "ra_ref=" + ra_ref + ";expires=" + expires.toUTCString() + ";path=/";
                        }
                        break;
                    }
                }
            }
        }
    }
}
if (ra_ref === "") {
    if (hrefsplit.length == 2) {
        if (refmatch = hrefsplit[1].match(/\bref=([^&]+)/gi)) {
            for (var i = 0; i < refmatch.length; i++) {
                var refsplit = refmatch[i].split("=");
                if (refsplit.length == 2) {
                    if (refsplit[0].toLowerCase() == "ref") {
                        ra_ref = refsplit[1];
                        if (ra_ref != "") {
                            var expires = new Date();
                            expires.setTime(expires.getTime() + (180 * 24 * 60 * 60 * 1000));
                            document.cookie = "ra_ref=" + ra_ref + ";expires=" + expires.toUTCString() + ";path=/";
                        }
                        break;
                    }
                }
            }
        }
    }
}
var allCookies = document.cookie.split(";");
if (ra_ref === "") {
    for (var i = 0; i < allCookies.length; i++) {
        var onePair = allCookies[i].split("=");
        if (onePair.length == 2) {
            if (onePair[0].replace(/\s/g, "") == "ra_ref") {
                ra_ref = onePair[1];
                break;
            }
        }
    }
}
if (ra_ref === "") {
    for (var i = 0; i < allCookies.length; i++) {
        var onePair = allCookies[i].split("=");
        if (onePair.length == 2) {
            if (onePair[0].replace(/\s/g, "") == "ref") {
                ra_ref = onePair[1];
                break;
            }
        }
    }
}
if (ra_ref === "") {
    var expires = new Date();
    expires.setTime(expires.getTime() + (180 * 24 * 60 * 60 * 1000));
    document.cookie = "ra_ref=-1;expires=" + expires.toUTCString() + ";path=/";
}
