    function checkAndReloadURL() {
        if (readCookie('ngage_countryname') == null) {
            //do nothing
        } else {
            //cookie exist, check for insconsistencies between url and cookies
            var correctURLValue = correctURL();
            if (correctURLValue != null){
                location.href = correctURLValue;
            }
        } //end of exist cookie checking

    }

    function correctURL(){
        //check if the content tree has ngage in it then only execute the logic
        if (location.href.indexOf('/ngage/web/') == -1) {
            return null;
        }
        //ignore location page.
        if (location.href.indexOf('location') != -1) {
            return null;
        }
        //collect countryid and languageid from current url
        var urlHandleCountryId = location.href.substr(location.href.indexOf('web') + 4, 2); //g0
        var urlHandleLanguage = location.href.substr(location.href.indexOf('web') + 7, 2); //en

        //collect countryid and languageid from ngage_home
        var cookieHomeCountryCodeId = readCookie('ngage_home').substr(readCookie('ngage_home').indexOf('/web/') + 5, 2);
        var cookieLanguage = readCookie('ngage_home').substr(readCookie('ngage_home').indexOf('/web/') + 8, 2);

        //if country and/or language from url doesnt match with those of cookie
        //then replace country and/or language of url with those of cookie and redirect
        var correctURL = null;
        if ( (urlHandleCountryId != cookieHomeCountryCodeId) || (urlHandleLanguage != cookieLanguage)) {
            correctURL = location.href;
            correctURL = correctURL.replace('/' + urlHandleCountryId + '/' + urlHandleLanguage, '/' + cookieHomeCountryCodeId + '/' + cookieLanguage);
        }

        return correctURL;
    }

    function checkCountryExist() {
        var cc = readCookie('ngage_countryid');
        if(cc == null){
			var urlSplit = (location.href).split ('/');
            var pageContext = urlSplit[3];
			var pageCountry = urlSplit[6];
			var pageLang = urlSplit[7];
			var nonSecureHost = getNonSecureBaseURL();

            var locationPage = nonSecureHost + '/' + pageContext + '/ngage/web/' + pageCountry + '/' + pageLang + '/location.html';
            var backTrackURL = window.location.href;

            createCookie('ngage_backtrack',backTrackURL,20);
            window.location.href = locationPage;
        }
    }

	function backtrackDeepLink() {
		var backTrack = '';
		var backTrack = readCookie('ngage_backtrack');
		if(backTrack) {
			eraseCookie('ngage_backtrack');
			window.location = backTrack;
		}
	}

    if (mode) {
		backtrackDeepLink();
        checkAndReloadURL();
        checkCountryExist();
    }