    function replaceDesktopToMobileDomain(desktopDomain)
    {
        if(desktopDomain.indexOf("uat.gene.eurorscgsf.com") != -1)
            return 'mobile.tamiflu_mobile-uat.gene.eurorscgsf.com';
        else if(desktopDomain.indexOf("tamiflu-stage01.eurorscgsf.com") != -1)
            return 'm.tamiflu-stage01.eurorscgsf.com';
        else if(desktopDomain.indexOf("tamiflu-stage02.eurorscgsf.com") != -1)
            return 'm.tamiflu-stage02.eurorscgsf.com';
        else if(desktopDomain.indexOf("tamiflu-stage03.eurorscgsf.com") != -1)
            return 'm.tamiflu-stage03.eurorscgsf.com';
        else if(desktopDomain.indexOf("tamiflu-dev01.eurorscgsf.com") != -1)
            return 'm.tamiflu-dev01.eurorscgsf.com';
        else if(desktopDomain.indexOf("tamiflu-dev02.eurorscgsf.com") != -1)
            return 'm.tamiflu-dev02.eurorscgsf.com';
        else if(desktopDomain.indexOf("tamiflu-dev03.eurorscgsf.com") != -1)
            return 'm.tamiflu-dev03.eurorscgsf.com';
        else if(desktopDomain.indexOf(".gene.eurorscgsf.com") != -1)
            return 'mobile.tamiflu_mobile01.gene.eurorscgsf.com';
        else if(desktopDomain.indexOf("tamiflu-qa.gene.com") != -1)
            return 'mobile.tamiflu-mobile-qa.gene.com';
        else if(desktopDomain.indexOf("tamiflu.local") != -1)
            return 'mobile.tamiflu-mobile.local';
        else
            return 'mobile.tamiflu.com';
    }

    function redirectMobile(){
        var queryString = window.location.search;
        var lowercaseUrl = document.URL.replace(document.domain, '');
        var isHCP = lowercaseUrl.indexOf('hcp') == 1;  // hcp should be the first element in the path

        location.replace("http://" + replaceDesktopToMobileDomain(document.domain) + ((isHCP== true) ? "/hcp/":"/") + queryString);
    }

    function removeFullSiteCookieAndRedirectMobile()
    {
        removeFullSiteCookie();
        redirectMobile();
    }

    var redirect_devices = ['iphone', 'android','mobile',  'j2me', 'blackberry' ];

	function setFullSiteCookie(){
		//expires in 1 days
		$.cookie("fullSite", 1, { path: '/',expires : 1});
	}

    function removeFullSiteCookie(){
        $.cookie('fullSite',null, { path: '/'});
    }

	function isFullSiteCookieTrue(){
		return $.cookie('fullSite')?true:false;
	}

    function fullSiteCookieExists()
    {
        return $.cookie('fullSite') != null;
    }

    function isMobileDevice()
    {
        var lowerCaseDeviceString = navigator.userAgent.toLowerCase();
        for (var i in redirect_devices) {
            if (lowerCaseDeviceString.indexOf(redirect_devices[i]) != -1)
                return  true;
        }
        return false;
    }

    function isTamifluMobileReferrer()
    {
        if (document.referrer.indexOf('tamiflu') != -1 && (document.referrer.indexOf('m.') != -1 || document.referrer.indexOf('mobile') != -1))
        return true;
        else
        return false;
    }

    function isDirectToFullSitePage()
    {
        var el = document.getElementById('directToFullSitePage');
        if (el != null)
            return true;
        else
            return false;
    }

    function doMobileRedirect(){
        // if it's a mobile device then check the referrer
        // if the referrer is our mobile site and the fullSiteCookie does not exist, then set the cookie
        // if the referrer is our mobile site and the fullSiteCookie does exist but is false, then redirect
        // if the referrer is not our mobile site, and if the cookie does not exist or if the cookie is false, then do not set the cookie and redirect.
        // if it's not a mobile device then do not set the cookie.
        if (isMobileDevice())
        {
            if (isTamifluMobileReferrer())
            {
                if (!fullSiteCookieExists())
                {
                    setFullSiteCookie();
                }
                else
                {
                    if (!isFullSiteCookieTrue())
                    {
                        redirectMobile();
                    }
                }
            }
            else
            {
                if (isDirectToFullSitePage() && !fullSiteCookieExists())
                    setFullSiteCookie();
                else if (!fullSiteCookieExists() || !isFullSiteCookieTrue())
                    redirectMobile();
            }
        }
    }

