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

function highlightNav(divName, folderMatch, hashLinkHighlight) {
  var theDiv = document.getElementById(divName);
  if (theDiv) {
    var A = theDiv.getElementsByTagName('a');
    var here = "" + window.location;
    
    if (!hashLinkHighlight) {
      // 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
      if (A[i].href.length > 0) {
        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, unless
        // hashLinkHighlight = 1, so we can highlight the left hand links becaues they are linked
        // to pages, not just #
        if (!hashLinkHighlight) {
        
          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('/'));
    
        
        // match to subpath
        if ((pathMatch(here,there, folderMatch, 1))) {
          //A[i].className = A[i].className + "current";
          A[i].parentNode.className = A[i].parentNode.className + " current";
          A[i].parentNode.className = A[i].parentNode.className + " open";          
          // 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 = " open";        
        }
        else if (pathMatch(here,there,0,1)) {
          //A[i].className = A[i].className + "current";
          A[i].parentNode.className = A[i].parentNode.className + " current";
          A[i].parentNode.className = A[i].parentNode.className + " open";              
          // 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 = " open";
        }
      }
    }
  }
}

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');
}


  $(function() {
    
    // perform the open/closes on click
		$('#leftnav a').click(function() {
        if ($(this).attr('href') == '#') $(this).attr('href', 'javascript:;');
			  if ($(this).parent().hasClass('open')) {
					$(this).parent().removeClass('open');
					$(this).parent().addClass('closed');
				}
				else {
					$(this).parent().removeClass('closed');
					$(this).parent().addClass('open');
				}
		});
    
    // highlight the current page
    highlightNav('topnav', 1, 0);
    highlightNav('leftnav', 1 ,1);
	})



