//******************************************************************************
//
// Copyright © 2005  Clifford W. Racz
// All rights reserved.
//
// Language: Javascript
//
// Functions used for breadcrumb generation without the need for PHP or other
//  server-side scripting.  Obviously, this will only work in JavaScript
//  enabled browsers.
//
// Function: refURL()
// This will retrieve the source URL for an image on the page
// which will work in IE6 (at least, other versions have not been tested).
// This script relies on an image like this to be placed on the page:
// <img id="rootImg" src="./transp.png" alt="Placeholder" />
// This image should be something like a 1px transparent GIF or PNG.
//
//
// Function: refFrameURL()
// This will retrieve the sourceURL of an embedded
// IFRAME element on the page, which works on Mozilla:
// <iframe id="rootFrame" class="hideAtOrigin" src="./blank.html"></iframe>
// and corresponding CSS style:
// .hideAtOrigin {
//   visibility: hidden;
//   position: absolute;
//   top: 0;
//   left: 0;
//   height: 0;
//   width: 0;
// }
//
//******************************************************************************

function getBrowser()
{
 	var browser		= navigator.userAgent.toLowerCase();
  	//var is_major	= parseInt(navigator.appVersion);
    //var is_minor	= parseFloat(navigator.appVersion);
    
    var browserClass;
    if (browser.indexOf('msie')!= -1) {
    	browserClass = "ie";
    }
    else if (browser.indexOf('gecko')!= -1) {
    	browserClass = "mozilla";
    }
    else if (browser.indexOf('konqueror')!= -1) {
    	browserClass = "konqueror";
    }
    else {
    	browserClass = "generic";
    }
    
    //document.write("<div>");
	//document.write(browserClass);
	//document.write("</div>");
	
    return browserClass;
}

function echoBrowser(tagType)
{
	var tagLabel = "span";
	if(tagType != null) {
		tagLabel = tagType;
	}
    document.write("<" + tagLabel + ">");
	document.write( getBrowser() );
	document.write("</" + tagLabel + ">");
}

function breadcrumbs() {
	sURL = location.href;
	sBaseURL = location.protocol + "//" + location.hostname;
	document.write("<span>");
	document.write(sBaseURL);
	document.write("</span>");
}

function refURL() {
	document.write("<span>");
	document.write("Image src: ");

	try {
		var refURL = document.getElementById("rootImg");
		sBaseURL = refURL.getAttribute("src");
		document.write(sBaseURL);
	} catch(e) {
		// Do nothing... it doesn't work
	}

	document.write(", and that is all. ");
	document.write("</span>");
}

function refFrameURL() {
	document.write("<span>");
	document.write("Frame src: ");

	var refURL = document.getElementById("rootFrame");
	sBaseURL = refURL.src;
	document.write(sBaseURL);

	document.write(", and that is all. ");
	document.write("</span>");
}

//
// Not yet implemented!!!
//
function inferBaseURI() {
	var refFrame	= "rootFrame";
	var refImg		= "rootImg";
	var re			= new RegExp("(.*\/).+");
	var refElement;
	var baseURL;
	
	try {
		switch ( getBrowser() ) {
			case "ie":
				refElement	= document.getElementById(refImg);
				break;
			case "mozilla":
			default:
				refElement	= document.getElementById(refFrame);
				break;
		}
		baseURL	= refElement.src;
		re.exec(baseURL);
		baseURL = RegExp.$1;
	}
	catch(E) {
		baseURL = "";
	}

	document.write("<div class=\"breadcrumb\">");
	document.write(baseURL);
	document.write("<a class=\"breadcrumb\" href=\"./index.html\">Home</a>");
	document.write(" / ");
	document.write("<a class=\"breadcrumb\" href=\"./index.html\">Sample</a>");
	document.write(" / ");
	document.write("<a class=\"breadcrumb\" href=\"./index.html\">Breadcrumb</a>");
	document.write(" / ");
	document.write("<a class=\"breadcrumb\" href=\"./index.html\">Trail</a>");

	document.write("</div>");
}
