/***********************************************
** File:      %M%  version %I%
** Author:    nat
** Modified:  %G%
** Copyright: I-Next Ltd
***********************************************/
/* ident %W% */

var dropOffset = -1; // Global var set on load

function openMenu( d ){
  // if page has loaded
  if ( pageLoaded == 1 ){
    // show the correct div
    for ( var i = 0; i < divs.length; i ++ ){
      // open menu and close others
      set( divs[i], 'visibility', ( ( d == divs[i] ) ? 'visible' : 'hidden' ) );
    }
    // store the active menu
    activeMenu = d;
  }
}
function closeMenu( n ){
  set( n, 'visibility', 'hidden' );
  if ( activeMenu == n ){ activeMenu = ''; }
}
function menuCheck( evt ){
  // if a menu is open
  if ( activeMenu != '' ){

    // load the drop menu edges into an array
    var pos = new Array();
    pos[0] = get( activeMenu, 'left' ) + 2;
    pos[1] = get( activeMenu, 'left' ) + get( activeMenu, 'width' );
    pos[2] = get( activeMenu, 'top' ) - 4;
    pos[3] = get( activeMenu, 'top' ) + get( activeMenu, 'height' );

    // load the main menu edges into an array
    var mm = new Array();
    mm[0] = get( topMenu, 'left' ) + 2;
    mm[1] = get( topMenu, 'left' ) + get( topMenu, 'width' );
    mm[2] = get( topMenu, 'top' ) - 2;
    mm[3] = get( topMenu, 'top' ) + get( topMenu, 'height' ) + 5;

    if ( document.all ){ // check for mouseout in ie

      // get the mouse pos from the window event and add any window scroll
      var we = window.event;
      var x = we.x + document.body.scrollLeft;
      var y = we.y + document.body.scrollTop;

    } else if ( evt ){ // non ie
      var x = evt.pageX;
      var y = evt.pageY;
    }

    // check if the cursor is in the main menu
    if ( x < mm[0] || x > mm[1] || y < mm[2] || y > mm[3] ){

      // not in MM so check if in drop menu
      if ( x < pos[0] || x > pos[1] || y < pos[2] || y > pos[3] ){ closeMenu( activeMenu ); }
    }
  }
}

function doLoad(){
  pageLoaded = 1;
  // get the mouse in netscape
  if ( !document.all ){
    document.captureEvents( Event.MOUSEMOVE );
    document.onmousemove = menuCheck;
  }
  window.onresize = moveMenus; // Move the menu's on resize
  activateMenus(); // Position drops and add mouseovers
  if ( footerDiv != '' ){ // If we have a footer div
    moveFooter(); // Move the footer to the correct place
    set('footer','visibility','visible'); // Show the footer
    window.onresize = moveFooter; // Move it on window resize
    checkIFrames(); // Move the footer on iframe onload
  }
}

function checkIFrames(){
  var iframes = document.getElementsByTagName('iframe'); // Get the iframes
  for ( var i = 0; i < iframes.length; i ++ ){ // Go through them
    if ( window.attachEvent ){ // For IE do an attach event
      iframes[i].attachEvent("onload", moveFooter );
    } else if ( ( navigator.userAgent.indexOf('Netscape') != -1 ) && ( navigator.userAgent.indexOf('Windows') != -1 ) ){ // Netscape on windows
      iframes[i].onload = function(){ setTimeout('moveFooter();',1000); } // Delay the footer move
    } else { // For others assign the function
      iframes[i].onload = function(){ moveFooter(); }
    }
  }
}

function activateMenus(){
  var TD = document.getElementsByTagName('td'); // Get the TD tag array
  for ( var i = 0; i < TD.length; i ++ ){ // Go through ...
    if ( TD[i].className.indexOf('opendrop-0') != -1 ){ // Zero closes any open ones
      TD[i].onmouseover = function(){ openMenu(''); } // Assign the function
    } else if ( TD[i].className.indexOf('opendrop-') != -1 ){ // If matching class name
      // If the dropOffset has not been set
      if ( dropOffset == -1 ){
        // Work out the dropOffset for the menu's which is: Div left + div width - table width ( tr, tbody, table )
        dropOffset = get( topMenu, 'left' ) + get( topMenu, 'width' ) - TD[i].parentNode.parentNode.parentNode.offsetWidth - 4;
      }
      TD[i].dropNum = TD[i].className.split('-')[1]; // Set attribute in the tag
      TD[i].onmouseover = function(){ openMenu( 'drop' + this.dropNum ); } // Assign the function
      TD[i].onfocus = function(){ openMenu( 'drop' + this.dropNum ); } // Assign the function
      TD[i].onblur = function(){ closeMenu( activeMenu ); } // Assign the function
      TD[i].style.cursor = 'default'; // Set the cursor
      set( 'drop' + TD[i].dropNum, 'left', ( TD[i].offsetLeft + dropOffset + 3 ) ); // Move the drop
    }
  }
}
function moveMenus(){
  dropOffset = -1; // Reset the offset
  var TD = document.getElementsByTagName('td'); // Get the TD tag array
  for ( var i = 0; i < TD.length; i ++ ){ // Go through ...
    if ( TD[i].className.indexOf('opendrop-') != -1 && TD[i].className != 'opendrop-0' ){ // If matching class name
      // If the dropOffset has not been set
      if ( dropOffset == -1 ){
        // Work out the dropOffset for the menu's which is: Div left + div width - table width ( tr, tbody, table )
        dropOffset = get( topMenu, 'left' ) + get( topMenu, 'width' ) - TD[i].parentNode.parentNode.parentNode.offsetWidth;
      }
      // Set the drop position
      set( 'drop' + TD[i].className.split('-')[1], 'left', ( TD[i].offsetLeft + dropOffset + 3 ) );
    }
  }
}

function moveFooter(){
  // Calc the full height of the content
  var contentHeight = get(contentDiv,'top') + get(contentDiv,'height') + 26;
  // Figure out the window height (safari or not)
  var winHt = ( typeof( window.innerHeight ) == 'number' )? window.innerHeight : document.body.clientHeight;
  // Move the footer to the bottom of the content or the window
  set('footer','top', ((( contentHeight > winHt )?contentHeight:winHt)-26));
}

function popup( win, w, h ){
  if ( window.pop ){ window.pop.close(); } // close an open one
  if ( popup.arguments.length < 2 ){ w = 320; };
  if ( popup.arguments.length < 3 ){ h = 480; };
  pop = window.open( win,'return','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,copyhistory=no,locationbar=no,width=' + w + ',height=' + h + ',screenX=0,screenY=0,top=0,left=0');
}

// window.onload = doLoad; not required
