
// ===========================================================================
// Global variables...
// ===========================================================================

    var login_popup_id         = 'login_popup' ;
    var login_popup_title      = 'Kiwi Party member login...' ;
    var login_popup_attributes = '' ;
    var login_popup ;
        // For the "Login..." popup window...

    // -----------------------------------------------------------------------

    var logout_popup_id         = 'logout_popup' ;
    var logout_popup_title      = 'Kiwi Party member logout...' ;
    var logout_popup_attributes = '' ;
    var logout_popup ;
        // For the "Logout..." popup window...

    // -----------------------------------------------------------------------

    var login_div_element ;
    var logout_div_element ;
    var logout_username_element ;
        // For the "Login.../Logout..." links on the left sidebar...

// ===========================================================================
// update_login_logout_stuff__on_left_sidebar
// ===========================================================================

function update_login_logout_stuff__on_left_sidebar( username ) {

    // -----------------------------------------------------------------------
    // NOTE!
    // -----
    // "username" can either be an empty string - or a non-empty string.
    //
    // If it's an empty string, then the user has just logged out.
    //
    // If it's a non-empty string, then "username" has just logged in.
    // -----------------------------------------------------------------------

    // -----------------------------------------------------------------------
    // Make sure that the pointers to the various element objects we use are
    // initialised...
    // -----------------------------------------------------------------------

    if ( !login_div_element ) {
        login_div_element = xGetElementById( 'login_div' ) ;
        }

    if ( !logout_div_element ) {
        logout_div_element = xGetElementById( 'logout_div' ) ;
        }

    if ( !logout_username_element ) {
        logout_username_element = xGetElementById( 'logout_username_span' ) ;
        }

    // -----------------------------------------------------------------------
    // Processing is now Login/Logout specific...
    // -----------------------------------------------------------------------

    if ( username == '' ) {

        // -------------------------------------------------------------------
        // Logging OUT...
        // -------------------------------------------------------------------

        if ( logout_div_element ) {
            logout_div_element.style.display = 'none' ;
            }
            // Hide the "Logout username" div/message...

        if ( logout_username_element ) {
            logout_username_element.innerHTML = '' ;
            }
            // Clear out the "username"...
            //
            // Probably not really necessary.  But let's be thorough...

        if ( login_div_element ) {
            login_div_element.style.display = 'block' ;
            }
            // Show the "Login" div/message...

        // -------------------------------------------------------------------

    } else {

        // -------------------------------------------------------------------
        // Logging IN...
        // -------------------------------------------------------------------

        if ( login_div_element ) {
            login_div_element.style.display = 'none' ;
            }
            // Hide the "Login" div/message...

        if ( logout_username_element ) {
            logout_username_element.innerHTML = username ;
            }
            // Insert the newly logged-in user's username into the sidebar...

        if ( logout_div_element ) {
            logout_div_element.style.display = 'block' ;
            }
            // Show the "Logout username" div/message...

        // -------------------------------------------------------------------

        }

    // -----------------------------------------------------------------------
    // Update the center column content, if necessary...
    // -----------------------------------------------------------------------

    // -----------------------------------------------------------------------
    // SCCC_get_currently_selected_content_type_name__none2home()
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Returns the name of the currently selected 'standard center column
    // content type'.  Unless there's NO currently selected 'standard center
    // column content type', in which case, "home" is returned.
    //
    // NOTES!
    // ------
    // 1.   The currently selected 'standard center column content type'
    //      is stored in the client browser's:-
    //          COOKIE_NAME__SCCC_CURRENTLY_SELECTED_CONTENT_TYPE
    //      cookie.
    // 2.   Because a hacker can alter a cookie value without too much
    //      trouble, the value returned from this function SHOULDN'T BE
    //      TRUSTED (it may have been hacked).
    // 3.   "home" is:-
    //      o   A value that might be stored in the:-
    //              COOKIE_NAME__SCCC_CURRENTLY_SELECTED_CONTENT_TYPE
    //          cookie, and;
    //      o   The default 'standard center column content type' if none
    //          is explicitly specified.
    // 4.   Thus, "home" is returned by this function both:-
    //      o   If it's the value stored in the:-
    //              COOKIE_NAME__SCCC_CURRENTLY_SELECTED_CONTENT_TYPE
    //          cookie, and;
    //      o   If there's NO:-
    //              COOKIE_NAME__SCCC_CURRENTLY_SELECTED_CONTENT_TYPE
    //          cookie.
    // -----------------------------------------------------------------------

    if ( SCCC_get_currently_selected_content_type_name__none2home() === 'issues' ) {

        send_ajax_request_to_update_center_column() ;

        }

    // -----------------------------------------------------------------------
    // That's that!
    // -----------------------------------------------------------------------

    }

// ===========================================================================
// login_cancel
// ===========================================================================

function login_cancel() {

    login_popup.hide() ;
        // Close the "Login..." popup window

    login_popup = undefined ;

    }

// ===========================================================================
// logout_cancel
// ===========================================================================

function logout_cancel() {

    logout_popup.hide() ;
        // Close the "Logout..." popup window

    logout_popup = undefined ;

    }

// ===========================================================================
// login_open
// ===========================================================================

function login_open() {

    // -----------------------------------------------------------------------
    // Don't pop-up if already popped-up...
    // -----------------------------------------------------------------------

    if ( login_popup || logout_popup ) {
        return ;
        }

    // -----------------------------------------------------------------------
    // If the "Login..." popup's attribute string hasn't yet been created,
    // create it...
    // -----------------------------------------------------------------------

    if ( login_popup_attributes == '' ) {
        var popup_width  = Math.min( 500 , Math.round( wos1__get_viewport_width()  ) ) ;
        var popup_height = Math.min( 250 , Math.round( wos1__get_viewport_height() ) ) ;
        login_popup_attributes = 'width=' + popup_width + 'px,height=' + popup_height + 'px,center=1,resize=1,scrolling=1' ;
        }

    // -----------------------------------------------------------------------
    // Open the "Login..." popup window...
    // -----------------------------------------------------------------------

    // -----------------------------------------------------------------------
    // var uniquevar = dhtmlwindow.open(
    //                      uniqueID        ,
    //                      contenttype     ,
    //                      contentsource   ,
    //                      title           ,
    //                      attributes      ,
    //                      [recalonload]
    //                      )
    // - - - - - - - - - - - - - - - - - - -
    // PARAMETERS:-
    //
    //      uniquevar:      Whenever you call dhtmlwindow.open() the first
    //                      time to create and open a new window, you
    //                      should assign it to an arbitrary but unique
    //                      variable. It is through this variable that you
    //                      can later invoke additional methods to
    //                      manipulate the opened window.
    //
    //      uniqueID:       The first parameter of dhtmlwindow.open(), this
    //                      should be an arbitrary but unique ID, used by
    //                      the script to create the "ID" attribute of the
    //                      window's primary DIV container.
    //
    //      contenttype:    This parameter tells the script the content
    //                      type you'll be loading into the window. The
    //                      four valid values are: "iframe", "inline",
    //                      "ajax", or "div". See the next parameter for
    //                      more info.
    //
    //      contentsource:  This parameter specifies the content itself to
    //                      show inside the window, and varies depending on
    //                      the former "contenttype" parameter.
    //
    //                      For "iframe" content, specify the URL to the
    //                      page in question (ie: "http://www.google.com").
    //
    //                      For "inline" content, specify the complete HTML
    //                      you wish to show, though remember to backslash
    //                      any special JavaScript characters such as
    //                      apostrophes (ie: "<b>I\'m the window content to
    //                      show</b>").
    //
    //                      For "ajax" content, specify the relative path
    //                      to the external page on your site from the
    //                      current page to show (ie: "../external.htm").
    //
    //                      And finally, for "div" content, first, define a
    //                      DIV on the page with a unique ID attribute and
    //                      probably hidden (using style="display:none"),
    //                      then, use the DIV's id (ie: "mydiv") as the
    //                      parameter;s value.
    //
    //      title:          Arbitrary text that will be shown as the title
    //                      of the window.
    //
    //      attributes:     Set this parameter to toggle the various
    //                      display attributes of the window when it's
    //                      created, such as its dimensions, position on
    //                      the page etc. Separate each attribute with a
    //                      comma (,). Here they are in full force:
    //
    //                      - - - - - - - - - - - - - - - - - - - - - - -
    //                      Attribute       Description
    //                      - - - - - - -   - - - - - - - - - - - - - - -
    //                      width=600px     Width of the window, in px.
    //
    //                      height=450px    Height of the window, in px.
    //
    //                      left=30px       Horizontal position of the
    //                                      window relative to the window
    //                                      viewpoint (left/top edge of the
    //                                      visible window).
    //
    //                      top=100px       Vertical position of the window
    //                                      relative to the window
    //                                      viewpoint.
    //
    //                      center=1|0      Sets whether window should be
    //                                      centered on the page. If
    //                                      defined supersedes the left/top
    //                                      attributes above. 1=yes, 0=no.
    //
    //                      resize=1|0      Sets whether window should be
    //                                      resizable. 1=yes, 0=no.
    //
    //                      scrolling=1|0   Sets whether window should
    //                                      contain scrollbars (when
    //                                      needed). 1=yes, 0=no.
    //                      - - - - - - - - - - - - - - - - - - - - - - -
    //
    //                      Remember to separate each attribute with a
    //                      comma. All of them are optional, though you
    //                      should at least declare the width/height
    //                      attributes for a presentable window to be
    //                      created:
    //
    //                          "width=450px,height=200px,center=1,scrolling=1"
    //
    //      recalonload:    This is an optional parameter that should only
    //                      be used when you're opening up a DHTML window
    //                      automatically as the page is loading (versus
    //                      clicking on a link for example). By defining
    //                      and setting this parameter to a value of
    //                      "recal", the script will reposition the DHTML
    //                      window after the document has fully loaded to
    //                      take into account any scrolling of the document
    //                      that might have occured prior.
    // -----------------------------------------------------------------------

    login_popup = dhtmlwindow.open(
        login_popup_id                  ,
        'iframe'                        ,
        get_url__for_target( 'login' )  ,
        login_popup_title               ,
        login_popup_attributes
        ) ;

    // -----------------------------------------------------------------------

    login_popup.onclose= function () {
        login_popup = undefined ;
        return true ;
        }

    // -----------------------------------------------------------------------
    // Center the popup (within the browser window)...
    //
    // NOTE!
    // -----
    // We shouldn't need to do this  - since we asked "dhtmlwindow.open()"
    // to center the window.
    //
    // But the "dhtmlwindow.open()" centering doesn't work very well.  So we
    // manually center the popup ourselves...
    // -----------------------------------------------------------------------

    login_popup.moveTo('middle','middle') ;

    // -----------------------------------------------------------------------
    // That's that!
    // -----------------------------------------------------------------------

    }

// ===========================================================================
// logout_open
// ===========================================================================

function logout_open() {

    // -----------------------------------------------------------------------
    // Don't pop-up if already popped-up...
    // -----------------------------------------------------------------------

    if ( login_popup || logout_popup ) {
        return ;
        }

    // -----------------------------------------------------------------------
    // Get the 'username' to log-out (and abort if we can't find it)...
    // -----------------------------------------------------------------------

    if ( !logout_username_element ) {
        logout_username_element = xGetElementById( 'logout_username_span' ) ;
        }

    // -----------------------------------------------------------------------

    var username ;

    if ( logout_username_element ) {
        username = logout_username_element.innerHTML ;
        }

    // -----------------------------------------------------------------------

    if ( !username ) {
        alert( "Can't find the username to log-out!" + wos1__software_bug ) ;
        return ;
        }

    // -----------------------------------------------------------------------
    // Open the "Logout..." popup window...
    // -----------------------------------------------------------------------

/*
    var content = '<html>' +
                    '<head>' +
                        '<title>Kiwi Party - Logout</title>' +
                        '<link rel="stylesheet" href="' +
                            add_path__to_public_root( '/site/login_logout/login_logout.css' ) +
                            '" type="text/css">' +
                    '</head>' +
                    '<body class="indent_left_and_right"><center><i>' +
                        '<p>Logout <strong>' + username + '</strong>?</p>' +
                       '<p>ARE YOU SURE?</p>' +
                        '<p><span>Yes</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>No</span></p>' +
                    '</i></center></body>' +
                '</html>' ;
*/

/*
    var content = '<div class="indent_left_and_right"><center><i>' +
                        '<p>Logout <strong>' + username + '</strong>?</p>' +
                       '<p>ARE YOU SURE?</p>' +
                        '<p><span>Yes</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>No</span></p>' +
                    '</i></center></div>' ;

    // -----------------------------------------------------------------------

    logout_popup = dhtmlwindow.open(
        logout_popup_id             ,
        'inline'                    ,
        content                     ,
        logout_popup_title          ,
        logout_popup_attributes
        ) ;

    // -----------------------------------------------------------------------
    // Center the popup (within the browser window)...
    //
    // NOTE!
    // -----
    // We shouldn't need to do this  - since we asked "dhtmlwindow.open()"
    // to center the window.
    //
    // But the "dhtmlwindow.open()" centering doesn't work very well.  So we
    // manually center the popup ourselves...
    // -----------------------------------------------------------------------

    logout_popup.moveTo('middle','middle') ;
*/

    // -----------------------------------------------------------------------
    // -----------------------------------------------------------------------

    if ( !confirm( "Logout " + username + "?\n\nARE YOU SURE?" ) ) {
        return ;
        }

    // -----------------------------------------------------------------------
    // If the "Logout..." popup's attribute string hasn't yet been created,
    // create it...
    // -----------------------------------------------------------------------

    if ( logout_popup_attributes == '' ) {
        var popup_width  = Math.min( 500 , Math.round( wos1__get_viewport_width()  ) ) ;
        var popup_height = Math.min( 250 , Math.round( wos1__get_viewport_height() ) ) ;
        logout_popup_attributes = 'width=' + popup_width + 'px,height=' + popup_height + 'px,center=1,resize=1,scrolling=1' ;
        }

    // -----------------------------------------------------------------------
    // -----------------------------------------------------------------------

    logout_popup = dhtmlwindow.open(
        logout_popup_id                     ,
        'iframe'                            ,
        get_url__for_target( 'logout' )     ,
        logout_popup_title                  ,
        logout_popup_attributes
        ) ;

    // -----------------------------------------------------------------------

    logout_popup.onclose= function () {
        logout_popup = undefined ;
        return true ;
        }

    // -----------------------------------------------------------------------
    // FUTURE UPGRADE ???
    // ------------------
    // Maybe we should send the username to the server logout script - so
    // that it can check the the specified username - and the username of
    // the member who owns the current session id - are the same ???
    // -----------------------------------------------------------------------

    // -----------------------------------------------------------------------
    // Center the popup (within the browser window)...
    //
    // NOTE!
    // -----
    // We shouldn't need to do this  - since we asked "dhtmlwindow.open()"
    // to center the window.
    //
    // But the "dhtmlwindow.open()" centering doesn't work very well.  So we
    // manually center the popup ourselves...
    // -----------------------------------------------------------------------

    logout_popup.moveTo('middle','middle') ;

    // -----------------------------------------------------------------------
    // That's that!
    // -----------------------------------------------------------------------

    }

