﻿function detectMobile() {
    if (document.cookie.indexOf("mobile_redirect=false") < 0) 
    {
        if (!navigator.userAgent.match(/Opera/i) && !navigator.userAgent.match(/Dolphin/i)) 
        {
            if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) 
            {
                setMobileCookies();
                if (confirm("Go.dk har nu en iPhone app! Klik ok for at få mere information."))
                    window.location = "http://itunes.apple.com/dk/app/go.dk/id491282889?l=da&mt=8";
            }
            /*else if (navigator.userAgent.match(/iPad/i)) 
            {
                setMobileCookies();
                if (confirm("This forum has an app for iPad!"))
                    window.location = "http://itunes.apple.com/dk/app/go.dk/id491282889?l=da&mt=8";
            }*/
            else if (navigator.userAgent.match(/android/i)) 
            {
                setMobileCookies();
                if (confirm("Go.dk har nu en Android app! Klik ok for at få mere information."))
                    window.location = "market://details?id=dk.go.app";
            }
            /*else if (navigator.userAgent.match(/webOS/i)) 
            {
                setMobileCookies();
                if (confirm("This forum has an app for webOS phone!"))
                    window.location = "http://developer.palm.com/appredirect/?packageid=******";
            }*/
            /*else if (navigator.userAgent.match(/BlackBerry/i)) 
            {
                setMobileCookies();
                if (confirm("This forum has an app for BlackBerry!"))
                    window.location = "http://appworld.blackberry.com/webstore/content/*****?lang=en";
            }*/
        }
    }
}

function setMobileCookies() {
    var date = new Date();
    var days = 90;
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
    document.cookie = "mobile_redirect=false" + expires;
}

detectMobile();
