$(document).ready(function() {

    var target = $('body.pg-join');
    if (target.length >= 1) {



        if (getCookie("HolderDetails") == null || getCookie("HolderDetails") == '') {
            if (GetRadWindowManager() != null && GetRadWindowManager().GetWindowByName("LogInWindow") != null) {




                return false;
            }
        } //end:if

        if (getCookie("HolderDetails")) {
            if (GetRadWindowManager() != null && GetRadWindowManager().GetWindowByName("LogInWindow") == null) {
                redirectMe();
                // doExtraStuff();
                // setTimeout("redirectMe()", 5000); // if cookie is there and LogInWindow is not in 5 sec redirection will happen
            }
        } //end:if


    } //end:if this is body.pg-join
    else {
        window.onunload = function() { setUpNewCookie(); }
    }



});  //end:DOM ready



function redirectMe() {
    var c = $.cookie('pathCookie');
    if (c) {
        window.location = c;
    }   
} //end:function



function setUpNewCookie() {
    var ourURL = window.location.href;
    $.cookie('pathCookie', ourURL, { path: '/', expires: 14 });
}


function doExtraStuff() {
    document.getElementById('s_membership').style.display = "none";
    document.getElementById('signUpImg').src = "/images/hdrs/loggedin.gif";
} // return false; if you wanna nothing to do




/* http://www.dustindiaz.com/top-ten-javascript/ */

function getCookie(name) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(';', len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

function setCookie(name, value, expires, path, domain, secure) {
    var today = new Date();
    today.setTime(today.getTime());
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));
    document.cookie = name + '=' + escape(value) +
		((expires) ? ';expires=' + expires_date.toGMTString() : '') + //expires.toGMTString()
		((path) ? ';path=' + path : '') +
		((domain) ? ';domain=' + domain : '') +
		((secure) ? ';secure' : '');
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) document.cookie = name + '=' +
			((path) ? ';path=' + path : '') +
			((domain) ? ';domain=' + domain : '') +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}


/************************************************** extra #bd padding *********************************/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}


    function getWindowHeight() {
        var windowHeight = 0;
        if (typeof (window.innerHeight) == 'number') {
            windowHeight = window.innerHeight;
        }
        else {
            if (document.documentElement && document.documentElement.clientHeight) {
                windowHeight = document.documentElement.clientHeight;
            }
            else {
                if (document.body && document.body.clientHeight) {
                    windowHeight = document.body.clientHeight;
                }
            }
        }
        return windowHeight;
    }

    function setFooter() {

        if (document.getElementById('hd') && document.getElementById('bd') && document.getElementById('global-chrome-content')) {
            document.getElementById('global-chrome-content').style.display = 'block';
            
            var windowHeight = getWindowHeight();
            var hdHeight = document.getElementById('hd').offsetHeight;
            var bdHeight = document.getElementById('bd').offsetHeight;
            var ftHeight = document.getElementById('global-chrome-content').offsetHeight;
            var diff = (windowHeight - (hdHeight + bdHeight)) - ftHeight;
            if (diff >= 0) {
                document.getElementById('bd').style.paddingBottom = diff - 30 + 'px';
            }
        } //end:if
    }
    addLoadEvent(setFooter);
    window.onresize = function() { setFooter(); }
    /************************************************** end: extra #bd padding *********************************/


