<!--
/*

Script : navigation-trail.js 
Version : 4.0 
Date : 11 July 2001
Contacts : 
  Laurence Clear - clearl@maf.govt.nz
  Dylan Hazlehurst - hazlehurstd@maf.govt.nz
Usage : <script type="text/javascript" language="JavaScript" src="/scripts/navigation-trail-v4.js"></script>

*/

/* 
splt()
Only here for IE3 compatibility (IE3 doesn't support href.split ?)
*/

function splt( s, c ) {

var splits = new Array();
var v = 0, prev = 0, n = 0;
while( v < s.length ) {
  if( s.charAt(v) != c )
   v++;
  else {
   if( v != prev ) 
    splits[n] = s.substring( prev, v );
   else 
    splits[n] = "";
   n++;
   v++;
   prev = v;
  }
}

if( v != prev ) 
  splits[n++] = s.substring( prev, v );
if( s.charAt(s.length-1) == c )
  splits[n++] = "";
return splits;
}




//
//  Set up data
//

var delimiter = " &gt; ";  //navigation trail delimeter
var host="home";            //text for base dir in the trail
var hostdir="/";           //URL for base dir

/*
Array of contexts.
-this array can be added to.
-paths are from the root and *must* begin and end with a /
*/
var arrContextData = new Array();

/*
arrContextData[0] = new contextObject("/acvm/test/pending/business/va/","");
arrContextData[0] = new contextObject("/animalproducts/",delimiter + "<a href='/industry/'>industry</a>");
arrContextData[1] = new contextObject("/meatdoc/",delimiter + "<a href='/industry/'>industry</a>");
arrContextData[2] = new contextObject("/acvm/",delimiter + "<a href='/industry/'>industry</a>");
arrContextData[3] = new contextObject("/dairy/",delimiter + "<a href='/industry/'>industry</a>");
arrContextData[4] = new contextObject("/standards/seafood/",delimiter + "<a href='/industry/'>industry</a>");
*/
/*
Array of substitute names for directories.
Where a match is made the substitute name will be displayed.
These arrays can be added to.
arrDirectories is for global substitutes.
arrLocalDirs is for local overrides of global substitutes.
*/

var arrDirectories = new Array();
var arrLocalDirs = new Array();

arrLocalDirs["/dairy/"] = "dairy products";
//arrLocalDirs["/acvm/archive/superceded/"] = "/skip!";
//arrLocalDirs["/acvm/archive/draft/"] = "/skip!";
arrLocalDirs["/standards/"] = "/skip!";
arrDirectories["antimicrobial"] = "antimicrobial resistance";
arrDirectories["certs"] = "certificates";
arrDirectories["ext-org"] = "other organisations";
arrDirectories["govcomments"] = "nz government comments";
arrDirectories["infopapers"] = "information papers";
arrDirectories["meatdoc"] = "meat";
arrDirectories["meatman"] = "manuals";
arrDirectories["animalproducts"] = "animal products";
arrDirectories["op_policies"] = "policies and procedures";
arrDirectories["pests-diseases"] = "pests &amp; diseases";
arrDirectories["reg-lists"] = "registers &amp; lists";
arrDirectories["registers-lists"] = "registers &amp; lists";
arrDirectories["standards-guidelines"] = "standards &amp; guidelines";
arrDirectories["policies-procedures"] = "policies &amp; procedures";
arrDirectories["techdir"] = "technical directives";
arrDirectories["ecert"] = "e-cert";
arrDirectories["safe"] = "issues &amp; concepts";



//
// Do not modify below this point 
//


/*
contextObject creator 
   this.matchpath = the path that will be matched
   this.addpath = the extra bit of the path that you want added to the front of the path to create the desired navigation trail
*/

function contextObject(matchpath,addpath) { 
//   this.matchpath = matchpath.split("/");
   this.matchpathbits = splt( matchpath, "/");
   this.matchpath = matchpath;
   this.addpath = addpath;
} 

var path = "<a href=\"/\">" + host + "</a>";   // base dir
var direc = hostdir;  // path to nav trail component on the server


if(!uri){
 var uri = document.location.pathname;
}

//var arrPathBits = uri.split("/"); 
var arrPathBits = splt(uri, "/"); 
var startat = 1;
var newstartat;
var idirectories, jdirectories;

/*
Loop throught the array of context objects until a directory or
group of directories is matched
If a match is found then 
-add the addpath value of the object to the path string
-fill in any missing directories for direc, since we start at an arbitrary place in the path.
-set the startat value to the startat value of the object. 
-stop the loop.
*/

for( var icontext = 0; icontext < arrContextData.length; icontext++ ) {
 if( uri.substring(0,arrContextData[icontext].matchpath.length) == arrContextData[icontext].matchpath ) {
 // Fill any skipped parts of the path
  newstartat = arrContextData[icontext].matchpathbits.length - 2;
  for( jdirectories = startat; jdirectories < newstartat; jdirectories++ )
   direc += arrPathBits[jdirectories] + "/"; 
  path += arrContextData[icontext].addpath;
  startat = newstartat;
  break;
  }
}

/*
Loop through location string
*/

var lastdirectory=false;
var isindex = arrPathBits[arrPathBits.length-1] == "index.htm" || arrPathBits[arrPathBits.length-1] == "index.html" || arrPathBits[arrPathBits.length-1] == "";

for( idirectories = startat; idirectories < arrPathBits.length-1; idirectories++ ) {
 // Check if this is the last directory in the path
 if (idirectories==arrPathBits.length-2)
  lastdirectory=true;

 /*
 If last directory then there is no link
 Test if index file index.htm, index.html
 */
 var strName = arrPathBits[idirectories];

 direc += strName + "/";

 /*
 Where a directory has a substitute name in the arrDirectories array use this 
 to display instead of the real name
 Super-Dehyphenation:
  -If there is no "friendly" name for directory then automatically convert hyphens "-" to spaces, 
   as they nearly always substitute for spaces anyway.
 */

 // Look for local first
 if( arrLocalDirs[direc] ) {
  finalstrName = arrLocalDirs[direc];
  }
 else // look for global
  if( arrDirectories[strName] ) {
   finalstrName = arrDirectories[strName];
   }
  else {
   if ( document.layers || document.all ) {
    re = new RegExp( "-", "g" );
    finalstrName = strName.replace( re, " " );
    }
   else { 
    //browser is too old for .replace() so the hyphens are safe...for now
    finalstrName = strName;
    }
   }

if( finalstrName!="/skip!" ) {
 path += delimiter;
 if( !(lastdirectory && isindex) ) 
  path += "<a href=\"" + direc + "\">";
  
 path += finalstrName;

 //If last directory then there is no link
 if( !(lastdirectory && isindex) ) 
  path += "</a>";
 }

}


document.write (path);

//End -->
