

// Military.com login/out widget library
(function($){
                $.fn.login_widgets = function(options) {
                                var defaults = {};
                                var options = $.extend(defaults, options);

                                return this.each(function(){
                                                // Get the loginInfo cookie
                                                login = _login_widgets.get_login();
                                                fn = login ? $(this).attr('id')+'_lo' : $(this).attr('id')+'_li';

                                                // Check that we have a corrosponding function to the current ID.
                                                eval("var is_fn = $.isFunction(_login_widgets."+fn+");");
                                                if(is_fn) {
                                                                $(this).empty();
                                                                eval("$(this).html(_login_widgets."+fn+"());");
                                                }
                                });
                }


                /************************************************************

                HELPERS

                ************************************************************/

                _login_widgets = {
                                get_login : function(){
                                                var loginInfoCookie = GetCookie('LoginInfo');
                                                if(loginInfoCookie != null) {
                                                                return loginInfoCookie.split('|');
                                                } else {
                                                                return false;
                                                }
                                },


                                // These functions need to be named the same as the targetted element's ID.
                                // ex. <div id="login"></div>
                                // Then append '_li' for the login contents and '_lo' for the logout contents.

                                /* Standard login header */
        /* the login was leading to the old registration page, so changed that. and encoded the passed document.URL,as the valve service needs it this way.
            
          */
                                nav0_account_li : function(){ 
                                                return $('<li>Not a member? <a href="http://www.military.com/newmembers/member-registration?vlv_redir='+encodeURIComponent(document.URL)+'">Join now for FREE</a></li><li><a href="http://www.military.com/member-reg/login.html?vlv_redir='+encodeURIComponent(document.URL)+'">Login</a></li>');
                                },

                                nav0_account_lo : function(){
                                var strMyAccount =_login_widgets.get_login()? "http://www.military.com/profile/member-profile.html"  : "http://www.military.com/newmembers/member-registration?vlv_redir="+encodeURIComponent(document.URL) ;
                        
                                return $('<li>Welcome '+login[2]+'</li><li><a href='+strMyAccount+'>My Account</a></li><li><a href="http://www.military.com/Logout?strRedirectURL='+encodeURIComponent(document.URL)+'">Logout</a></li>');
                                }

                };
})(jQuery);
