
//  **************************************************************************
//  JOIN/JOINING THE KIWI PARTY JAVASCRIPT
//  site/nvu_slash_rapid_css_sourced_pages/join_the_kiwi_party/join.js
//  (C) 2007 Peter Newman
//  **************************************************************************

// ---------------------------------------------------------------------------
// join_the_kiwi_party_window_object
// ---------------------------------------------------------------------------

var join_the_kiwi_party_window_object ;

// ---------------------------------------------------------------------------
// join_the_kiwi_party
// ---------------------------------------------------------------------------

function join_the_kiwi_party() {

    // -----------------------------------------------------------------------

//      document_url        :   url__join_the_kiwi_party_dir + '/page1.html'    ,

    join_the_kiwi_party_window_object = new wos1_WebOS_Window( {
        width               :   '90%'                                           ,
        height              :   '90%'                                           ,
        title               :   'Join/Joining the Kiwi Party...'                ,
        document_url        :   get_url__for_target( 'join1' )                  ,
        control_buttons     :   '#o'                                ,
        status_bar_buttons  :   [   {   title           :   'First'     ,
                                        onclick         :   join_the_kiwi_party__goto_first_page
                                        } ,
                                    {   title           :   'Last'      ,
                                        onclick         :   join_the_kiwi_party__goto_last_page
                                        } ,
                                    {   title           :   'Previous'  ,
                                        onclick         :   join_the_kiwi_party__goto_previous_page
                                        } ,
                                    {   title           :   'Next'      ,
                                        onclick         :   join_the_kiwi_party__goto_next_page
                                        } ,
                                    {   title           :   'Close'     ,
                                        onclick_close   :   undefined
                                        }
                                    ]
        } ) ;

    // -----------------------------------------------------------------------

    }

// ---------------------------------------------------------------------------
// join_the_kiwi_party__goto_first_page
// ---------------------------------------------------------------------------

function join_the_kiwi_party__goto_first_page() {

    if ( is_ie && !is_opera ) {

        join_the_kiwi_party_window_object.iframe_element.contentWindow.location =
            get_url__for_target( 'join1' ) ;
            //  See:-   "contentWindow Property"
            //          Microsoft Developer Network
            //          http://msdn2.microsoft.com/en-us/library/ms533692.aspx
            //  NOTES!
            //  ------
            //  1.  With the standard version (in the else clause), IE loads
            //      the new document into the parent window (not the IFRAME).
            //  2.  "This feature requires Microsoft® Internet Explorer 5.5 or
            //      later."

    } else {

        get_iframe_document( join_the_kiwi_party_window_object.iframe_element ).location.href =
            get_url__for_target( 'join1' ) ;

        }

    }

// ---------------------------------------------------------------------------
// join_the_kiwi_party__goto_last_page
// ---------------------------------------------------------------------------

function join_the_kiwi_party__goto_last_page() {

    if ( is_ie && !is_opera ) {

        join_the_kiwi_party_window_object.iframe_element.contentWindow.location =
            get_url__for_target( 'join4' ) ;
            //  See:-   "contentWindow Property"
            //          Microsoft Developer Network
            //          http://msdn2.microsoft.com/en-us/library/ms533692.aspx
            //  NOTES!
            //  ------
            //  1.  With the standard version (in the else clause), IE loads
            //      the new document into the parent window (not the IFRAME).
            //  2.  "This feature requires Microsoft® Internet Explorer 5.5 or
            //      later."

    } else {

        get_iframe_document( join_the_kiwi_party_window_object.iframe_element ).location.href =
            get_url__for_target( 'join4' ) ;

        }

    }

// ---------------------------------------------------------------------------
// join_the_kiwi_party__get_current_page_number
// ---------------------------------------------------------------------------

function join_the_kiwi_party__get_current_page_number() {

/*
    // -----------------------------------------------------------------------
    // The "Join/Joining the Kiwi Party" pages are:-
    //
    //      url__join_the_kiwi_party_dir + '/page1.html'
    //      url__join_the_kiwi_party_dir + '/page1.html'
    //      url__join_the_kiwi_party_dir + '/page3.php'
    //      url__join_the_kiwi_party_dir + '/page4.html'
    //
    // So we can get the current page number by inspecting the URL
    // returned by 'location.href'...
    // -----------------------------------------------------------------------

    var match = /\/page(\d)\.(html|php)$/.exec(
                    join_the_kiwi_party_window_object.iframe_element.contentDocument.location.href
                    ) ;

    if ( match && match.length === 3 ) {

        var page = parseInt( match[1] ) ;

        if ( page >= 1 && page <= 4 ) {
            return page ;
            }

        }

    alert( "Can't retrieve current \"Join/Joining the Kiwi Party\" page number!" +
                wos1__software_bug__get_detected_in(
                    "join_the_kiwi_party__get_current_page_number"  ,
                    url__join_the_kiwi_party_dir + '/join.js'
                    )
                ) ;

    return undefined ;
*/

/*
    // -----------------------------------------------------------------------
    // The "Join/Joining the Kiwi Party" pages are:-
    //
    //      <public_root_url>?target=join1
    //      <public_root_url>?target=join2
    //      <public_root_url>?target=join3
    //      <public_root_url>?target=join4
    //
    // So we can get the current page number by inspecting the URL
    // returned by 'location.href'...
    // -----------------------------------------------------------------------

    // -----------------------------------------------------------------------
    // NOTE!
    // -----
    // The following convert to Boolean false:-
    //      o   an unspecified value
    //      o   0
    //      o   -0
    //      o   null
    //      o   false
    //      o   NaN
    //      o   undefined
    //      o   the empty string ("")
    //
    // All other values, including any object or the string "false", create
    // an object with a value of true.
    // -----------------------------------------------------------------------

    var match = /\?target=join(\d)$/.exec(
                    join_the_kiwi_party_window_object.iframe_element.contentDocument.location.href
                    ) ;

    if ( match && match.length === 2 ) {

        var page = parseInt( match[1] ) ;

        if ( page >= 1 && page <= 4 ) {
            return page ;
            }

        }

    alert( "Can't retrieve current \"Join/Joining the Kiwi Party\" page number!" +
                wos1__software_bug__get_detected_in(
                    "join_the_kiwi_party__get_current_page_number"  ,
                    url__join_the_kiwi_party_dir + '/join.js'
                    )
                ) ;

    return undefined ;
*/
    //  Except that, though it works on 'localhost', it doesn't work on a
    //  normal web server...
    //
    //  Both Mozilla 2.0 and Opera 9.1 seem to object to the 'location.href'
    //  in:-
    //      join_the_kiwi_party_window_object.iframe_element.contentDocument.location.href
    //
    //  Mozilla 2 complains:-
    //      "uncaught exception: Permission denied to get property HTMLDocument.location"
    //
    //  And Opera 9.1 complains:-
    //      "JavaScript - http://www.kiwiparty.110mb.com/
    //      Event thread: click
    //      Error:
    //      name: ReferenceError
    //      message: Security error: attempted to read protected variable"
    //
    //  Who knows exactly why?

    // -----------------------------------------------------------------------
    // The "Join/Joining the Kiwi Party" pages have the following <TITLE>s:-
    //
    //      "Join/Joining the Kiwi Party - Page 1 of 4"
    //      "Join/Joining the Kiwi Party - Page 2 of 4"
    //      "Join/Joining the Kiwi Party - Page 3 of 4"
    //      "Join/Joining the Kiwi Party - Page 4 of 4"
    //
    // So we can get the current page number by inspecting the string
    // returned by 'document.title'...
    // -----------------------------------------------------------------------

//  var match = /^Join\/Joining the Kiwi Party - Page (\d) of 4$/.exec(
        //  This is perhaps too precise.  Will break if we change even a
        //  single character.

    var match = /page\s+(\d)\s+of/i.exec(
//                  join_the_kiwi_party_window_object.iframe_element.contentDocument.title
                    get_iframe_document( join_the_kiwi_party_window_object.iframe_element ).title
                    ) ;

    if ( match && match.length === 2 ) {

        var page = parseInt( match[1] ) ;

        if ( page >= 1 && page <= 4 ) {
            return page ;
            }

        }

    alert( "Can't retrieve current \"Join/Joining the Kiwi Party\" page number!" +
                wos1__software_bug__get_detected_in(
                    "join_the_kiwi_party__get_current_page_number"  ,
                    url__join_the_kiwi_party_dir + '/join.js'
                    )
                ) ;

    return undefined ;

    // -----------------------------------------------------------------------

    }

// ---------------------------------------------------------------------------
// join_the_kiwi_party__page_number_to_basename
// ---------------------------------------------------------------------------

/*
function join_the_kiwi_party__page_number_to_basename( page_number ) {

    switch ( page_number ) {
        case 1 : return 'page1.html'
        case 2 : return 'page2.html'
        case 3 : return 'page3.php'
        case 4 : return 'page4.html'
        }

    alert( "Invalid \"Join/Joining the Kiwi Party\" page number (`" + page_number + "' isn't in the range 1 to 4)!" +
                wos1__software_bug__get_detected_in(
                    "join_the_kiwi_party__page_number_to_basename"  ,
                    url__join_the_kiwi_party_dir + '/join.js'
                    )
                ) ;

    return undefined ;

    }
*/

// ---------------------------------------------------------------------------
// join_the_kiwi_party__goto_next_page
// ---------------------------------------------------------------------------

function join_the_kiwi_party__goto_next_page() {

    var current_page = join_the_kiwi_party__get_current_page_number() ;

    if ( current_page && current_page < 4 ) {

        current_page += 1 ;

/*
        var new_basename = join_the_kiwi_party__page_number_to_basename( current_page ) ;

        if ( new_basename ) {

            join_the_kiwi_party_window_object.iframe_element.contentDocument.location.href =
                url__join_the_kiwi_party_dir + '/' + new_basename ;

            }
*/

//      join_the_kiwi_party_window_object.iframe_element.contentDocument.location.href =
        get_iframe_document( join_the_kiwi_party_window_object.iframe_element ).location.href =
            get_url__for_target( 'join' + current_page ) ;

        }

    }

// ---------------------------------------------------------------------------
// join_the_kiwi_party__goto_previous_page
// ---------------------------------------------------------------------------

function join_the_kiwi_party__goto_previous_page() {

    var current_page = join_the_kiwi_party__get_current_page_number() ;

    if ( current_page && current_page > 1 ) {

        current_page -= 1 ;

/*
        var new_basename = join_the_kiwi_party__page_number_to_basename( current_page ) ;

        if ( new_basename ) {

            join_the_kiwi_party_window_object.iframe_element.contentDocument.location.href =
                url__join_the_kiwi_party_dir + '/' + new_basename ;

            }
*/

//      join_the_kiwi_party_window_object.iframe_element.contentDocument.location.href =
        get_iframe_document( join_the_kiwi_party_window_object.iframe_element ).location.href =
            get_url__for_target( 'join' + current_page ) ;

        }

    }

