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

function set( name, p, v ){ // object, param and value
  var o = get( name );
  var b = bIndex();
  if ( p == 'height' ) var myA = new Array('style.height','document.height','style.height');
  if ( p == 'width' ) var myA = new Array('style.width','document.width','style.width');
  if ( p == 'top' ) var myA = new Array('style.pixelTop','top','style.top');
  if ( p == 'left' ) var myA = new Array('style.pixelLeft','left','style.left');
  if ( p == 'visibility' ) var myA = new Array('style.visibility','visibility','style.visibility');
  if ( p == 'clip' ){
    var a = set.arguments;
    if ( document.layers ){ o.clip.top = a[2]; o.clip.right = a[3]; o.clip.bottom = a[4]; o.clip.left = a[5]; }
    else { o.style.clip = 'rect(' + a[2] + 'px, ' + a[3] + 'px, ' + a[4] + 'px, ' + a[5] + 'px)'; }
  } else {
    if ( v.NaN ) eval( 'o.' + myA[ b ] + ' = "' + v + '"'); // setting with string value
    else eval( 'o.' + myA[ b ] + ' = \'' + v + '\''); // setting with numeric value
  }
}

function get( name, p ){ // ('ie','n4+','n6')
  var retObj = '';
  var b = bIndex();
  var pair = '';
  // check for a nested div
  if ( name.search(/:/) != -1 ){ // get the last div name
    var pair = name.split(':');
    name = pair[ pair.length - 1 ];
  }
  // build the object
  if ( b == 0 ){ retObj = 'document.all("' + name + '")'; } // ie
  else if ( b == 1 ){ // check for nesting
    if ( pair != '' ){
      for ( var i=0; i < pair.length; i ++ ){ retObj += ( retObj == '' )? 'document.' + pair[i] : '.document.' + pair[i]; }
    } else{ retObj = 'document.layers["' + name + '"]'; } // netscape 4 +
  } else if ( b == 2 ){ retObj = 'document.getElementById("' + name + '")'; } // netscape 6
  if ( !p ) { return eval(retObj); }
  else if ( p == 'dom' ) { return ( b == 1 )? retObj : retObj + '.style'; }
  else {
    if ( p == 'height' ) var myA = new Array('clientHeight','document.height','offsetHeight');
    if ( p == 'width' ) var myA = new Array('clientWidth','document.width','offsetWidth');
    if ( p == 'top' ) var myA = new Array('offsetTop','top','offsetTop');
    if ( p == 'left' ) var myA = new Array('offsetLeft','left','offsetLeft');
    if ( p == 'visibility' ) var myA = new Array('style.visibility','visibility','style.visibility');
    return eval( retObj + '.' + myA[ b ] );
  }
}

function bIndex(){ // return browser index
  if ( document.all ) return 0; // ie
  else if ( document.layers ) return 1; // netscape pre 6
  else if ( document.getElementById ) return 2; // netscape 6 +
}

function tail( s ) { // trims the first character from string s and returns the remaining string
  return s.substring(1, s.length);
}

function replaceChar(str, c1, c2) { // replaces character c1 with character c2 in string str could use regex instead
    str = str.split(c1);
    str = str.join(c2);
    return str;
}

String.prototype.toProperCase = function()
{
  return this.toLowerCase().replace(/^(.)|\s(.)/g,
      function($1) { return $1.toUpperCase(); });
}

function breadcrumbs( c, links ) {
  // displays breadcrumb trail in span.crumbs based on folder names with '_' replaced with ' '
  // c is the character (or string) separating the crumb items, "" for none
  // if links = false then no hyperlinks on the crumbs,
  // if links = true then hyperlinks are added to the crumbs

		var path = document.location.pathname;
    path = tail(path);  // remove leading "/"

    var last = path.substring(path.lastIndexOf('/'), path.length);
    if ( (last == "/index.htm") || (last.length == 1) ) {
      path = path.substring( 0, path.lastIndexOf('/') );
      //remove index if this is the last part of the path
    }
    else if (last.length > 1) {
      last = path.substring(path.lastIndexOf('.'), path.length); // remove file suffix - should be .htm
      path = path.substring(0,path.lastIndexOf('.'),path.length); // remove suffix from path
    }

    var crumbs = path.split('/');
    var href = "";
    var crumbs_real_path = "";
    for ( var i = 0; i<crumbs.length; i++ ) {
      if (crumbs[i].length > 0 ) {
        crumbs_real_path += "/" + crumbs[i];
        if ( (crumbs.length > 0 ) && (i == crumbs.length-1) ) {
          href = crumbs_real_path + last; // put the file suffix back on - should be .htm, or /index.htm if default page for folder
        }
        else if (crumbs.length > 0) {
          href = crumbs_real_path;
        }

        // replace '_' with ' '
        crumbs[i] = replaceChar(crumbs[i], '_', ' ');
        crumbs[i] = crumbs[i].toProperCase();
        //if ( i==0 ) {
        //  crumbs[i] = "<a href='/'>Home</a>"+"<a href='" + href + "'>" + crumbs[i] + "</a>";
        //} else {
          crumbs[i] ="<a href='" + href + "'>" + crumbs[i] + "</a>";
        //}
      }
    }
    crumbs = crumbs.join(c);
    // join the links up to form the breadcrumb trail
    document.write("</p><p class='crumb'>"+crumbs);
  }
