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

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 edges into array
    var pos = new Array();
    pos[0] = get( activeMenu, 'left' ) + 2;
    pos[1] = get( activeMenu, 'left' ) + get( activeMenu, 'width' );
    pos[2] = get( activeMenu, 'top' ) - 2;
    pos[3] = get( activeMenu, 'top' ) + get( activeMenu, 'height' );

    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;

      // load the top 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' );

      // 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 ); }
      }
    } else { // check for mouseout in netscape
      if ( evt.pageX < pos[0] || evt.pageX > pos[1] || evt.pageY < ( pos[2] - 19 ) || evt.pageY > pos[3] ){ closeMenu( activeMenu ); }
    }
  }
}
function dateExt( val ) {
  // divide and check it's a whole number or add the th!
  var ext = ( Math.ceil( (val - 1)/10 ) == (val - 1)/10 && val != 11 ) ? 'st' : 'th';
  if ( ext == 'th' ) var ext = ( Math.ceil( (val - 2)/10 ) == (val - 2)/10 && val != 12 ) ? 'nd' : 'th';
  if ( ext == 'th' ) var ext = ( Math.ceil( (val - 3)/10 ) == (val - 3)/10 && val != 13 ) ? 'rd' : 'th';
  return ext;
}
function doLoad(){
  pageLoaded = 1;
  // get the mouse in netscape
  if ( !document.all ){
    document.captureEvents( Event.MOUSEMOVE );
    document.onmousemove = menuCheck;
  }
}
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');
}
function highlightLinks(){
  if ( document.all || document.getElementById ){
    var u = document.URL; // get the url
    var links = new Array(); // store the relevent links
    var s = u.split('/'); // get each directory in the url
    var path = s[0] + '//' + s[2] + '/'; // build the start of the path
    if ( s.length == 4 ){ links[0] = path; } // get the home link
    for ( var i = 3; i < s.length; i ++ ){ // insert the links
      if ( s[i] != '' ){ // a directory url leaves a blank entry
        path += s[i] + '/'; // build the path
        links[ links.length ] = path; // replicate a push
      }
    }
    if ( !u.match(/\/$/) ){ // if required remove the trailing '/'
      links[ (links.length-1) ] = path.substring(0, (path.length-1));
    }
    for ( var j = (document.links.length - 1); j >= 0; j -- ){
      var h = document.links[j].href; // get the link
      for ( var k = 0; k < links.length; k ++ ){
        if ( h == links[k] && k >= 2 ){ // get the matching file and directory at level 3
          document.links[j].style.color = 'Red';
          document.links[j].style.textDecoration='none'
        }
      }
    }
  }
}
