// Javascript zum Erzeugen der Frame- und Fenster-Struktur einer Site
//
//  Copyright Heiner Kuhlmann : hkuhlmann@dr-kuhlmann.com
//  The software is licensed under the GNU Library General Public License.
//
//  $Id: frame.js,v 1.4 2003/10/21 11:50:16 firma Exp $

// hard coded:
//              withtree.htm     HTML page showin the navigation tree in a subfame
//              withouttree.htm  HTML page showing no navigation tree
//              logo.htm         HTML page shown initially in the upper (right) subframe, the navigation bar
//              init.htm         HTML page shown initially in the central subframe, the base frame

// exported:
//
//    view_inframe ( url )
//       If there is a window showing the frame structure url is shown
//       otherwise a new window with is created.
//
//    view_in_windows ( tree_url, base_url, width_of_tree )
//       Create a window showing the base frame with base_url
//       and a window showing the naviagation tree with tree_url and width_of_tree
//
//    view_tree ( url, width )
//       Create a window showing the naviagation tree with url and width
//       This window is not connected to the base window.
//
//    replace_frame ( url )
//       Replace the current top window with the url
//
//    may_view_home_frame ( url )
//       if there is no proper frame start with_tree or without_tree
//       else show url in the baseframe
//
//    may_swap_tree ()
//       If the browser is supporting dynamic HTML:
//          if the current frame is showing the navigation tree the tree is hidden
//          if the current frame is not showing the navigation tree the tree is shown
//       The current url will be lost but the initial url shown!!!!
//
//    view_tree_in_window (url, root, width)
//       The navigation tree will be shown in its own window.
//       If the navigation tree is shown in the current frame a frame without
//       a navigation tree is shown.
//       If the browser is IE the current url will be lost but the initial url shown!!!!
//
//    load_navigation_bar ( url )
//       Load the navigation bar if the frame structure is suitable.
//
//--    view_contact ( url )
//       View the contact window.    Is not running in IE
//       ToDo: like lost_base_window and lost_tree_window
//
//    lost_base_window ()
//       Tell the base window the tree window is unloded or closed.
//
//    lost_tree_window ()
//       Tell the tree window the base window is unloded or closed.
//

function lost_base_window () {

   if( window.top.tree_window ) window.top.tree_window.base_window = null;

}; // lost_base_window

function lost_tree_window () {

   if( window.top.base_window ) window.top.base_window.tree_window = null;

}; // lost_tree_window

function insert_frame ( doc, top_url, base_url ) {

   doc.write ( '<FRAMESET ' ,
               'onUnload="if( window.top.tree_window ) window.top.tree_window.base_window = null;"' ,
               'border=0 frameborder=0 framespacing=0 ROWS=50,*>' ,
               '<FRAME SRC="' + top_url + '" NAME="topfrm" scrolling=no noresize>' ,
               '<FRAME SRC="' + base_url + '" NAME="basefrm">' ,
               '</FRAMESET>'
             );
   doc.close ();

}; // insert_frame

function extend_inframe ( url, message ) {

   window.top.message_into_frame = message;
   view_inframe ( url );

}; // extend_inframe

function insert_inframe () {

   if ( window.top.tree_window )
      if ( window.top.tree_window.message_into_frame )
         document.write ( window.top.tree_window.message_into_frame );

}; // insert_inframe

function view_inframe ( url ) {
   if ( browser_is.min ) {
      if ( window.top.basefrm ) {
         window.top.basefrm.location = url;
      } else if ( window.base_window && window.base_window.basefrm ) {
         window.base_window.basefrm.focus();
         window.base_window.basefrm.location = url;
      } else {
         window.base_window = create_base_window ( url );
         window.base_window.tree_window = window;
      };
   };
}; // view_inframe

function view_in_windows ( tree_url, base_url, width_of_tree ) {
// View the naviagion tree and the base frame in its own windows

   if ( browser_is.min ) {
      window.top.base_window = create_base_window ( base_url );
      window.top.tree_window = create_tree_window ( tree_url, width_of_tree );

      window.top.tree_window.base_window = window.top.base_window;
      window.top.base_window.tree_window = window.top.tree_window;
   };
   
}; // view_in_windows

function create_base_window ( base_url ) {

   var base_window;

   base_window = window.open ( 'init.htm', "Dynamic_HTML_base_window", "status=no,resizable=yes" );

   insert_frame ( base_window.document, 'logo.htm', base_url );

   return ( base_window );

}; // create_base_window

function create_tree_window ( url, width ) {

   var tree_window;

   if ( browser_is.ns )
      tree_window = window.open ( url, "Dynamic_HTML_folder_tree",
                                           "status=no,resizable=yes,height=" + (window.outerHeight-30) +
                                           ",width=" + width + ",scrollbars=yes");
   else
      tree_window = window.open ( url, "Dynamic_HTML_folder_tree",
                                           "status=no,resizable=yes,width=" + width + ",scrollbars=yes");

   return ( tree_window );

}; // create_tree_window

function view_tree ( url, width ) {

   create_tree_window ( url, width );

}; // view_tree

function replace_frame ( url ) {

   window.top.location.replace( url );

}; // replace_frame

function may_view_home_frame ( root, url ) {
   if ( window.top.topfrm && window.top.basefrm ) {
      window.top.basefrm.location = root + url
   } else if ( browser_is.min && screen.width > 700 ) {
     window.top.location = root + 'withtree.htm';
   } else {
     window.top.location = root + 'withouttree.htm';
   };
}; // may_view_home_frame

function may_swap_tree () {

   if ( browser_is.min ) {
      if (window.top.treeframe)
         window.top.location.replace('withouttree.htm');
      else
         window.top.location.replace('withtree.htm');
   };

}; // may_swap_tree

function generate_frame ( top_url, base_url ) {

   insert_frame ( window.top.document, top_url, base_url );

}; // generate_frame

function view_tree_in_window (url, root, width, view_tree) {

   if ( browser_is.min ) {
      if ( window.top.tree_window ) {
         if ( ! window.top.tree_window.closed ) {
            window.top.tree_window.focus();
            return;
         };
      } else {
         if ( window.top.treeframe && window.top.basefrm ) window.top.location.replace ( root + 'withouttree.htm' );
         if ( view_tree ) {
            window.top.tree_window = create_tree_window ( url, width );
            window.top.tree_window.base_window = window.top;
         };
      };
   };
}; // view_tree_in_window

function load_navigation_bar ( url ) {

   window.top.buttons_are_active = false;

   if ( window.top.topfrm ) window.top.topfrm.location.replace(url);
   window.top.buttons_are_active = true;

}; // load_navigation_bar

function view_contact ( url ) {

   if ( ! browser_is.min || ! browser_is.ns ) return true;
   if ( window.top.contact_window && ! window.top.contact_window.closed ) {
      window.top.contact_window.focus();
      if ( window.top.contact_window.top.treeframe )
         window.top.contact_window.top.treeframe.location.replace(url);
      else
         window.top.contact_window.location.replace(url);
   } else {
      window.top.contact_window = window.open( url,
                                        'contact_to_owner',
                                        "width=500,height=300,resizresizable" );
      window.top.contact_window.created_by = window;
   };
   return false;

}; // view_contact

