// Breadcrumb script by Michael Leikam; 1/29/2004
// Annotated

// Updated 10/1/2004 by Tim Rudolph and NOT Nupur Shah
// Add ACS and link to all departments under ACS

// main function; call this to have your trail drawn on the page
// "subdir" is the subdirectory, if any, on the server that serves as the site home.
// "defp" is the default page name; e.g., 'index.html','index.htm','default.htm', etc.
function h_breadCrumbs(subdir,defp){
	// if no default filename is given, use "index.html", my favorite.
	if (defp==''){defp=''}
	// define the crumb delimiter.  usually a > or | charcter or an image; HTML ok
	delimiter = ">";
	// define the home directory as the current server plus the "subdir" directory
	base = document.location.hostname+'/'+subdir
	// convert the current URL into a string
	loc = document.location.toString();
	// split the URL string after "base" using "/" as a delimiter
	subs = loc.substr(loc.indexOf(base) + base.length + 1).split("/");
	// start the output by opening a paragraph with a breadcrumbs class
	//document.write('<p class="breadcrumbs">');
	// if we have crumbs, run through them; if not, just write "Home"
	if (subs.length>1){
		// the first crumb is a "Home" link that points to "base"
		document.write("<a href='http://"+base+"'>Home</a>  "+delimiter+" ");
		// run through the rest of the urls listed in the "subs" list
		for (i=0;i<(subs.length-2);i++) {
			if (unescape(subs[i]) == "fcpd")
				subs[i] = "FCPD";
			// Capitalize each word
			subs[i]=makeCaps(unescape(subs[i]));
			// generate the URL for this crumb
			j=Number(subs.length)-i-2
			href=getLoc(j)+defp
			// check if this is an ACS site if so add acs in front of department link
			if (checkacs(subs[i]) == 1) {
				addacs(subs[i],href,"0");
			} else {
				// write the crumb to the page
				document.write(" <a href="+href+">"+subs[i]+"</a> "+delimiter+" ");
			}
		}

		// get the text for the last crumb, which is the current directory
		finalDir = makeCaps(unescape(subs[subs.length-2]))
		// write it to the page
		if (checkacs(finalDir) == 1) {
			addacs(finalDir,"none","1");
		} else {
			if (finalDir == "fcpd") 
				finalDir = "FCPD";
			document.write(finalDir);
		}

	} else {
		// we don't have a trail, so just write "Home"
		document.write('Home');
	}
	// close the paragraph opened at the beginning of the trail.
//	document.write('</p>');
}
 
// check if it is an ACS site
function checkacs(n) {
//	if ((n == "THD") || (n == "FTC") || (n == "Acs Lab")) {
	if (n == "Acs Lab") {
		return 1;
	}
}

// add ACS to ACS sites
function addacs(n,l,f) {
	document.write(" <a href=\"http://www.csulb.edu/divisions/aa/academic_technology/acs/\">ACS</a> "+delimiter+" ");
	if (f == "1"){
		document.write(n);
	} else {
		document.write(" <a href="+l+">"+n+"</a> "+delimiter+" ");
	}
}


// subroutine to Capitalize words
function makeCaps(a) {
    g = a.split("_");
    for (l = 0; l < g.length; l++) {
	if (g.length == 1 && g[l].length <= 3) {
	   g[l] = g[l].toUpperCase(); }

	else {
           g[l] = g[l].toUpperCase().slice(0, 1) + g[l].slice(1); }
    }

    return g.join(" ");
}

// subroutine to concatenate "../" strings to build a URL for a higher directory
function getLoc(c) {
    var x = "";
    if (c > 0) {
        for (k = 0; k < c; k++) { x = x + "../";  }
    }
    return x;
}


// this is for opening the links in new pages
// no time to explain, educate yourself
var excludedomains=["csulb.edu"];
var auto=1;

var excludedomains=excludedomains.join("|")
rexcludedomains=new RegExp(excludedomains, "i")

function dynamiclink() {

if (auto||(!auto&&document.targetmain.targetnew.checked)){
	for (i=0; i<=(document.links.length-1); i++) {
		if (document.links[i].hostname.search(rexcludedomains)==-1&&document.links[i].href.indexOf("http:")!=-1)
			document.links[i].target="_blank"
	}
}

else {
	for (i=0; i<=(document.links.length-1); i++) {
		if (document.links[i].hostname.indexOf(mydomain)==-1)
			document.links[i].target=""
	}
}

	if (auto)
		window.onload=dynamiclink
}
