function mtUpdateSignInWidget(u) {
    var separator = '&nbsp;| ';
    var el = document.getElementById('signin-widget-content');
    var content = '';
    if (!el) return;
    if (u) {
        if (u && u.is_authenticated) {
            user = u;
            mtSaveUser();
        } else {
            // user really isn't logged in; so let's do this!
            return mtSignIn();
        }
    } else {
        u = mtGetUser();
    }
    if (u && u.name) {
        var url;
        if (u.is_authenticated) {
            if (u.is_author) {
                url = 'http://www.tvweek.com/cgi-bin/mt431/mt-cp.cgi?__mode=view&blog_id=2';
                url += '&static=' + encodeURIComponent( location.href );
            } else {
                url = u.url;
            }
        } else if (u.url) {
            url = u.url;
        } else {
            url = null;
        }
        if (url)
            content += 'You are signed in as <a href="' + url + '">' + u.name + '</a>';
        else
            content += 'You are signed in as ' + u.name + '';
        if (u.is_author)
            content += separator + '<a href="http://www.tvweek.com/cgi-bin/mt431/mt-cp.cgi?__mode=edit&blog_id=2&return_to=' + encodeURIComponent(document.URL) + '">Edit&nbsp;profile</a>';
        
        content += separator + '<a href="javascript:void(0)" onclick="return mtSignOutOnClick()">Sign&nbsp;out</a>';
        
    } else if (u && u.is_banned) {
        content = 'You do not have permission to sign in to this blog.';
    } else {
        content = '<a href="javascript:void(0)" onclick="return mtSignInOnClick(\'signin-widget-content\')">Sign In</a>';
        
        
        content += separator + 'Not a member? <a href="http://www.tvweek.com/cgi-bin/mt431/mt-cp.cgi?__mode=register&blog_id=2&return_to=' + encodeURIComponent(document.URL) + '">Register</a>';
        
        
    }
    el.innerHTML = content;
}
mtAttachEvent('usersignin', mtUpdateSignInWidget);
mtUpdateSignInWidget();



