// this method determines whether the device is a mobile device or not
function isMobile()
{
    var userAgent = navigator.headers['user-agent'];
    var accept = navigator.headers['accept'];
    var wapProfile = navigator.headers['x-wap-profile'];
    var profile = navigator.headers['profile'];
    var opera = navigator.headers['X-OperaMini-Phone'];
    var uaPixels = navigator.headers['ua-pixels'];

    // Checks the user-agent
    if (userAgent != null)
    {
        // Checks if its a Windows browser but not a Windows Mobile browser
        if (userAgent.value.indexOf("windows") != -1
                && userAgent.value.indexOf("windows ce") == -1)
        {
            return false;
        }

        // Checks if it is a mobile browser
        var mobileBrowserPattern = /up.browser|up.link|windows ce|iphone|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp/;
        var mobileBrowserRegex = new RegExp(mobileBrowserPattern, "g");

        if (mobileBrowserRegex.test(userAgent))
        {
            return true;
        }

        var userAgents = ["acs-","alav","alca","amoi",
            "audi","aste","avan","benq",
            "bird","blac","blaz","brew",
            "cell","cldc","cmd-","dang",
            "doco","eric","hipt","inno",
            "ipaq","java","jigs","kddi",
            "keji","leno","lg-c","lg-d",
            "lg-g","lge-","maui","maxo",
            "midp","mits","mmef","mobi",
            "mot-","moto","mwbp","nec-",
            "newt","noki","opwv","palm",
            "pana","pant","pdxg","phil",
            "play","pluc","port","prox",
            "qtek","qwap","sage","sams",
            "sany","sch-","sec-","send",
            "seri","sgh-","shar","sie-",
            "siem","smal","smar","sony",
            "sph-","symb","t-mo","teli",
            "tim-","tosh","tsm-","upg1",
            "upsi","vk-v","voda","w3c ",
            "wap-","wapa","wapi","wapp",
            "wapr","webc","winw","winw",
            "xda","xda-"];

        // look for the possible user agents of mobile browsers
        for(var i = 0; i < userAgents.length; i++ )
        {
            if (userAgents[i] == userAgent.substring(0,3))
            {
                return true;
            }
        }

        // Checks the accept header for wap.wml or wap.xhtml support
        if (accept != null) {
            if (accept.value.indexOf("text/vnd.wap.wml") != -1
                    || accept.value.indexOf("application/vnd.wap.xhtml+xml") != -1)
            {
                return true;
            }
        }

        // Checks if it has any mobile HTTP headers
        if (wapProfile != null 
                || profile != null
                || opera != null
                || uaPixels != null)
        {
            return true;
        }

        // otherwise, not mobile
        return false;
    }
}

function doRedirect(url)
{
    if (isMobile())
    {
        window.location('http://m.southafrica.info');
    }
}


