
// MOBILE DEVICE COOKIE SETTINGS
function getMobileCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

function setMobileCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}



// Mobile detection & redirection
function DoMobileDetect() {
    var iOS = getMobileCookie("iOS");
    if (iOS != "true") {
        var deviceAgent = navigator.userAgent.toLowerCase();
        var agentID = deviceAgent.match(/(iphone|ipod|android|blackberry|windows phone)/);

        if (agentID) {
            var answer = confirm("New to Cracka Wines?\nSign up today to get $25 off your first purchase!")
            if (answer) {
                setMobileCookie("iOS", true, 180);
                window.location = "/mobile-25rego/index.html";
            }
            else {
                setMobileCookie("iOS", true, 14);
            }
        }
    }
}


window.onload = DoMobileDetect; 

