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


function doLoad(){
  pageLoaded = 1;
  // get the mouse in netscape
  if ( !document.all ){
    document.captureEvents( Event.MOUSEMOVE );
  }
  highlightNav('topnav', 1);
  highlightNav('left', 1);
  initRollovers();
}

function initRollovers() {
  if ( document.images ){
    var preLoad = new Array();
    var tempSrc;
    for (var i = 0; i < document.images.length; i ++ ){

      // Only add rollover to images with the classname 'rollover'
      if ( document.images[i].className == 'rollover' ){
        var src = document.images[i].getAttribute('src'); // get the src
        var ext = src.substring( src.lastIndexOf('.'), src.length ); // get the file extension
        var hsrc = src.replace( ext, '_r' + ext ); // store the rollover src
        document.images[i].setAttribute('hsrc', hsrc); // set the new src attribute
        document.images[i].style.cursor = 'hand'; // Hand cursor where supported

        // Preload the image
        preLoad[i] = new Image();
        preLoad[i].src = hsrc;

        // Add the rollover functions
        document.images[i].onmouseover = function(){
          tempSrc = this.getAttribute('src');
          this.setAttribute('src', this.getAttribute('hsrc'));
        }
        document.images[i].onmouseout = function(){
          if (!tempSrc) tempSrc = this.getAttribute('src').replace('_r'+ftype, ftype);
          this.setAttribute('src', tempSrc);
        }
      }
    }
  }
}

function highlightNav(divName, folderMatch) {
  var theDiv = document.getElementById(divName);
  if (theDiv) {
    var A = theDiv.getElementsByTagName('a');
    var here = "" + window.location;
    // strip any #<name> from the end
    here = here.replace(new RegExp("#.*"),"");  
    // strip /index.htm or last / from the end
    here = here.replace(new RegExp("/index\.htm"),"");
    here = here.replace(new RegExp("/$"),"");
    // split the protocol off
    here = here.toLowerCase().split('//')[1];
    // split the domain name off
    here = here.substring(here.indexOf('/'));
    
    for (var i=0; i<A.length; i++ ) { // check each link
      // split the protocol off
      var there = A[i].href.toLowerCase().split('//')[1];
      // strip any #<name> from the end
      there = there.replace(new RegExp("#.*"),"");        
      // strip /index.htm or last / from the end
      there = there.replace(new RegExp("/index\.htm"),"");
      there = there.replace(new RegExp("/$"),"");      
      // split the domain name from the front
      there = there.substring(there.indexOf('/'));
      alertString = '';
      
      // match to subpath
      if ((pathMatch(here,there, folderMatch, 1))) { // && (i>0)) {
        A[i].className = A[i].className + "current";
      }
      else if (pathMatch(here,there,0,1)) {
        A[i].className = A[i].className + "current";
      }        
    }
  }
}

function pathMatch(here, there, folderMatch, n) {
  if (here==there) {
    if (((here=='') && (n==1)) || (here!='')) {
      return 1;
    }
    else {
      return 0;
    }  
  }
  else if ((folderMatch == 1) && (here != '')) {
    here  = here.substring(0,here.lastIndexOf('/'));
    return pathMatch(here, there, folderMatch, n+1);
  }    
}

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;

