/***********************************************
** File:      %M%  version %I%
** Author:    Gill
** Modified:  %G%
** Copyright: I-Next Ltd
** Created:   30/03/2006
**
***********************************************/
/* ident %W% */

	function findPosX(obj)
	{
		// returns the x coord of the left of obj
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
        curleft += obj.offsetLeft;
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}	

  function findPosY(obj) {
    // returns the y coord of the top of obj
    var curTop = 0;
    if (obj.offsetParent) {
      while (obj.offsetParent) {
          curTop += obj.offsetTop;
          obj = obj.offsetParent;
      }
    }
    else if (obj,y)
      curTop += obj.y;
    return curTop;
  }
	
	function firstIndexOf( s, c ) { // return the first index of character c in string s
		for (var i = 0; i<s.length; i++) {
			if (s.charAt(i) == c) { return i; }	// character found at position i
		}
		return -1; // character not found 
	}	

	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
			str = str.split(c1);
			str = str.join(c2);
			return str;
	}	 
	
	function globalReplaceString(str, s1, s2) { // replaces all occurrences of s1 with s2 in str
			var regEx = new RegExp(s1, "gi");
			return str.replace(regEx, s2)
	}
	
  function breadcrumbs( c, links ) {
  // displays breadcrumb trail in span.crumbs based on folder names with '_' replaced with ' ' and "Home" at the start.
  // c is the character (or string) separating the crumb items
  // if links = false then no hyperlinks on the crumbs,
  // if links = true then hyperlinks are added to the crumbs
  // to style these links add a "span.crumbs a" style to the stylesheet

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

    var last = path.substring(path.lastIndexOf('/'), path.length);
    if ( last == "/index.htm" ) {
      path = path.substring( 0, path.lastIndexOf('/') );     // remove index if this is the last part of the path
    }
    else {
      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++ ) {
      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 + "/index.htm"; // link to the index default page in the folder only if not at site root
      }
      // replace '_' with ' '
      crumbs[i] = replaceChar(crumbs[i], '_', ' ');
			// also replace 'and' with '&' for Dorseys
      crumbs[i] = globalReplaceString(crumbs[i], " and ", " &amp; ");
      if ( i==0 ) {
        if ( crumbs[0] == "index" ) {
          crumbs[i] = "<a href='/index.htm'>Home</a>";
        } else {
          crumbs[i] = "<a href='/index.htm'>Home</a> > " + "<a href='" + href + "'>" + crumbs[i] + "</a>";
        }
      } else {  
        crumbs[i] ="<a href='" + href + "'>" + crumbs[i] + "</a>";
      }
    }
    var nLinks = crumbs.length;
    crumbs = crumbs.join(c); // join the links up to form the breadcrumb trail

		var span = document.getElementById("crumbs");
		span.innerHTML = crumbs;
  } 


