/**
 * checkUserLoggedIn
 *
 * @author mrKelly
 * @classDescription This checks to see if the user is logged in to the website.
 **/

mdp.checkUserLoggedIn = function(){
    /* ---[ CLASS VARIABLES ]--- */

    /* private */
    var c_name, c_end;

    /* ---[ CONSTRUCTOR ]--- */
    function init(){

    }

    /* ---[ PUBLIC METHODS ]--- */
    /* ---  this function grabs the cookie passed to it, checks to see if the user is logged in, then updates the header
            and footer with the proper login / logout / join now --- */
    this.loadCookie = function ( mdpCookie ) {
        var newCookie = Cookie.get( mdpCookie );
        var cookieInfo = null;

        if (newCookie) cookieInfo = newCookie.split('|');

        if (cookieInfo != null) {

            var loggedInName = cookieInfo[2];
                /* thisAbsolutePath is set outside of this file in the xsl for betterRecipes */
            if(loggedInName != null && loggedInName.length > 0 ) {
               if ( $("headerUserInfo") ) $("headerUserInfo").setHTML('Hello <b>' + loggedInName + '</b>, not <a href = "' + thisAbsolutePath + '/common/profile/member/logout.jsp?successPage=' + window.location + '&absoluteLinkBrand=br">' + loggedInName + '</a>?');
               if ( $("footerUserInfo") ) $("footerUserInfo").setHTML('<a href = "' + thisAbsolutePath + '/common/profile/member/logout.jsp?successPage=' + window.location + '&absoluteLinkBrand=br">Log Out</a>');
            } else {
               if ( $("headerUserInfo") ) $("headerUserInfo").setHTML("<a href = '" + thisAbsolutePath + "/common/profile/login1.jsp?regSource=8260&returnURL=" + window.location + "&absoluteLinkBrand=br'><img src = 'http://images.meredith.com/betterrecipes/images/tmp/buttons/login.jpg' alt = 'Log In'/></a> <a href = '" + thisAbsolutePath + "/common/profile/regStep1.jsp?regSource=8260&returnURL=" + window.location + "&absoluteLinkBrand=br'><img src = 'http://images.meredith.com/betterrecipes/images/tmp/buttons/joinnow.jpg' /></a> ");
               if ( $("footerUserInfo") ) $("footerUserInfo").setHTML("<a href = '" + thisAbsolutePath + "/common/profile/login1.jsp?regSource=8260&returnURL=" + window.location + "&absoluteLinkBrand=br'>Log In</a> | <a href = '/common/profile/regStep1.jsp?regSource=8260&returnURL=" + window.location + "&absoluteLinkBrand=br'>Join Now</a> ");
            }

        } else {
               if ( $("headerUserInfo") ) $("headerUserInfo").setHTML("<a href = '" + thisAbsolutePath + "/common/profile/login1.jsp?regSource=8260&returnURL=" + window.location + "&absoluteLinkBrand=br'><img src = 'http://images.meredith.com/betterrecipes/images/tmp/buttons/login.jpg' alt = 'Log In'/></a> <a href = '" + thisAbsolutePath + "/common/profile/regStep1.jsp?regSource=8260&returnURL=" + window.location + "&absoluteLinkBrand=br'><img src = 'http://images.meredith.com/betterrecipes/images/tmp/buttons/joinnow.jpg' /></a> ");
               if ( $("footerUserInfo") ) $("footerUserInfo").setHTML("<a href = '" + thisAbsolutePath + "/common/profile/login1.jsp?regSource=8260&returnURL=" + window.location + "&absoluteLinkBrand=br'>Log In</a> | <a href = '/common/profile/regStep1.jsp?regSource=8260&returnURL=" + window.location + "&absoluteLinkBrand=br'>Join Now</a> ");
            }

    };

    /* ---[ RUN ]--- */
    init();
};

window.addEvent('domready', function(){
    mdp.checkUserLoggedIn = new mdp.checkUserLoggedIn();
    mdp.checkUserLoggedIn.loadCookie('mdp_partner');
});
