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

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
      // but leave # by itself in place so we don't highlight the drop links      
      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, but not for first (home) item
      if ((pathMatch(here,there, folderMatch, 1)) && (i>0)) {
        //A[i].className = A[i].className + "current";
        A[i].parentNode.className = A[i].parentNode.className + " current";
        // do we have a parent menu item? i.e. is this link in a drop menu?
        A[i].parentNode.parentNode.parentNode.className = A[i].parentNode.parentNode.parentNode.className = " current";        
      }
      else if (pathMatch(here,there,0,1)) {
        //A[i].className = A[i].className + "current";
        A[i].parentNode.className = A[i].parentNode.className + " current";
        // do we have a parent menu item? i.e. is this link in a drop menu?
        A[i].parentNode.parentNode.parentNode.className = A[i].parentNode.parentNode.parentNode.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');
}



