
function isCookieSet(c_name) {
    var cookieSet = false;
    if (document.cookie.length > 0) {
        if (document.cookie.indexOf(c_name + "=") >= 0) {
            cookieSet = true;
        }
    }
    return cookieSet;
}

function setCookie(c_name) {
    document.cookie = c_name + "=" + c_name;
}

function doRedirectionLogic() {
    var doRedirection = true;
    var cookieName = "FromMobileSite";
    if (isCookieSet(cookieName) == true) {
        doRedirection = false;
    } else {
        if (window.location.toString().indexOf("redirectFromMobile") != -1) {
            setCookie(cookieName);
            doRedirection = false;
        }
    }
    return doRedirection;
}

function Client() { }

Client.prototype.mobileClients = [
        "midp",
        "240x320",
        "blackberry",
        "netfront",
        "nokia",
        "panasonic",
        "portalmmm",
        "sharp",
        "sie-",
        "sonyericsson",
        "symbian",
        "windows ce",
        "benq",
        "mda",
        "mot-",
        "opera mini",
        "philips",
        "pocket pc",
        "sagem",
        "samsung",
        "sda",
        "sgh-",
        "vodafone",
        "xda",
        "htc",
        "lg-",
        "palm",
        "iphone",
        "android",
        "itouch",
        "ipod",
        "android"
        ];



Client.prototype.isMobileClient = function(userAgent) {
    if (doRedirectionLogic() == true) {
        userAgent = userAgent.toLowerCase();
        for (var i in this.mobileClients) {
            if (userAgent.indexOf(this.mobileClients[i]) != -1 & userAgent.indexOf("ipad") == -1) { // If matching mobile string IS contained in the MobileClients and DOES NOT equal 'ipad' > redirect
                window.location = "http://m.royaldocks.com"
            }
        }
    }
}

var client = new Client();
client.isMobileClient(navigator.userAgent);


