if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
    if ((!document.referrer.match(/behr.com/i)) || (document.referrer.match(/behr.com/i) && document.referrer.length > 50)) {
       if(!checkCookie('Apple2')) {
            var theDate = new Date();
            var threeDays = 3 * 1000 * 60 * 60 * 24;
            var threeDaysFromNow = new Date( theDate.getTime() + threeDays);
            var expiryDate = threeDaysFromNow.toGMTString();
            document.cookie="Apple2=true; expires="+expiryDate;
            window.location = "/apple/index.html?from=" + encodeURI(document.location.href);
        }
    }
}
if ( (navigator.userAgent.toLowerCase().search("android") > -1) && (navigator.userAgent.toLowerCase().search("mobile") > -1) ) {
     if (!document.referrer.match(/behr.com/i) || (document.referrer.match(/behr.com/i) && document.referrer.length > 50)) {
        if(!checkCookie('Android2')) {
            var theDate = new Date();
            var threeDays = 3 * 1000 * 60 * 60 * 24;
            var threeDaysFromNow = new Date( theDate.getTime() + threeDays);
            var expiryDate = threeDaysFromNow.toGMTString();
            document.cookie="Android2=true; expires="+expiryDate;
            window.location = "/android/index.html?from=" + encodeURI(document.location.href);
        }
    }
}
function checkCookie(name) {
    var theCookies = document.cookie.split(/[; ]+/);
    for (var i = 0 ; i < theCookies.length; i++) {
        var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));
        if (aName == name) {
            return true;
        }
    }
    return false;
}

