// // File: ash.js implementation of general scripts // Language: Javascript // Author: Clifford W. Racz // // Copyright © 2005, 2006 Purdue University Agricultural Safety and Health // All rights reserved. // function layBreadcrumbTrail() { // Element referenced for the base path value var refElement; var refID = "baseBreadcrumbHref"; // URL variables var baseURL; var myURL = location.href; var myExtension; var basePath; var myPath; var tempPath; var tempTitle; var tempLinkText; var tempPageName; var sDirs; var sDirVals = new Array(); var sPageVals = new Array(); var sDirTitles = new Array(); // Regular expressions var reBasePath = new RegExp("^(.*\/)[^\/]+?$"); var reStripDir = new RegExp("^([^\/]\/)(.*)$"); var reIsolatePath = new RegExp("^(.*\/)[^\/]+?$"); // Stuffing the reference arrays // NOTE: If there is an error in this function, it can be // because a directory name is redundant. Be sure to look // at this first thing when debugging. // Joining stuffRefArray("Joining", "Joining IRSHC", "index.html", sDirVals, sPageVals, sDirTitles); // Newsletter stuffRefArray("Newsletter", "Newsletter", "index.html", sDirVals, sPageVals, sDirTitles); // Organizational stuffRefArray("Organization", "Organizational Information", "index.html", sDirVals, sPageVals, sDirTitles); // Resources stuffRefArray("Resources", "Resources", "index.html", sDirVals, sPageVals, sDirTitles); stuffRefArray("Kids", "Kids", "kids.html", sDirVals, sPageVals, sDirTitles); stuffRefArray("SafetySnippets", "Safety Snippets", "safetySnippets.html", sDirVals, sPageVals, sDirTitles); // Contact Us stuffRefArray("Contact", "Contact Information", "index.html", sDirVals, sPageVals, sDirTitles); // Let us fetch the base path // Note: This is designed for use with Dreamweaver, which will // automatically maintain the URL of the base link in the webpage with // this HREF. Then, we fetch the HREF and use it to dissect the HREF // of the Javascript "location" object. refElement = document.getElementById(refID); baseURL = refElement.href; // Our page is of the form [baseURL] = [basePath][index.html] // so we need to strip out the [index.html] part, leaving // only [basePath] that we will use to construct the breadcrumbs. basePath = baseURL; reIsolatePath.exec(basePath); basePath = RegExp.$1; // Our page is of the form [myURL] = [myPath][foobar.html] // so we need to strip out the [foobar.html] part, leaving // only [myPath] that we will use to construct the breadcrumbs. myPath = myURL; reIsolatePath.exec(myPath); myPath = RegExp.$1; // Now, let us cut out the [baseURL] substring, leaving only the relative path // section of my current URL if( basePath == myPath.substr(0,(basePath.length)) ) { myExtension = myPath.substr( (basePath.length),(myPath.length-1) ) } // Slice and dice the extension path into an array of directory names that we will // then check against the predefined array of breadcrumb definitions sDirs = myExtension.slice(0).split('/'); // Write the breadcrumb then... tempPath = basePath; for(i=0;i<(sDirs.length-1);i++) { tempLinkText = "Previous"; tempTitle = "A previous directory"; tempPageName = ""; tempPath = tempPath + sDirs[i] + "/"; for(j=0;j<(sDirVals.length);j++) { // Debug //alert("sDirs[i]: " + sDirs[i] + " and sDirVals[j]: " + sDirVals[j]); if( sDirs[i] == sDirVals[j]) { tempLinkText = sDirTitles[j]; tempTitle = tempLinkText; tempPageName = sPageVals[j]; } } document.write(" > "); document.write(tempLinkText) document.write(""); } // And they lived happily ever after. The end. } function highlightLink() { // URL variables var myURL = location.href; var sLinks = new Array(); sLinks = document.getElementsByTagName('a'); for(j=0; j<(sLinks.length); j++) { // Debug //alert("sDirs[i]: " + sDirs[i] + " and sDirVals[j]: " + sDirVals[j]); if( sLinks[j] == myURL) { sLinks[j].className = sLinks[j].className + " currentLink"; //window.alert("Matched a link: " + sLinks[j].className); } } // And they lived happily ever after. The end. } function stuffRefArray(sValue, sTitle, sPageName, aValueArray, aPageNameArray, aTitleArray) { aValueArray.push(sValue); aPageNameArray.push(sPageName); aTitleArray.push(sTitle); } // Get the browser type 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("