﻿/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Justin Whitford | http://www.whitford.id.au/ */
function breadcrumbs() {
  sURL = new String;
  bits = new Object;
  var x = 0;
  var stop = 0;
  var output = "<div id=\"breadcrumbs\"><ul><li><a href=/>" + "Home" + "</a></li>";
  // get page URL 
  sURL = location.href;
  // strip off the 'http://'
  sURL = sURL.slice(8,sURL.length);
  // find the first path separator
  chunkStart = sURL.indexOf("/");
  // remove the server name
  sURL = sURL.slice(chunkStart+1,sURL.length)
  // if it is the home page then show nothing and exit
  if (sURL == "index.htm" || sURL.length == 0) {
      return;
  }
  /* parse the URL path and put each piece in an array
     the part remaining in sURL will contain the page file */
  while(!stop){
    chunkStart = sURL.indexOf("/");
    if (chunkStart != -1){
      bits[x] = sURL.slice(0,chunkStart)
      sURL = sURL.slice(chunkStart+1,sURL.length);
    } else {
      stop = 1;
    }
    x++;
  }
  // for each piece of the path, output a list item with hyperlink
  for(var i in bits){
    output += "<li><a href=\"";
    for(y=1;y<x-i;y++){
      output += "../";
    }
    output += bits[i] + "/\">" + bits[i] + "</a></li>";
  }
  
  /* Here we are going to check to see if we are using the
     dealer locator.  This will require synthesizing a path
     for the breadcrumbs. */
     
  sTitle = new String;
  sTitle = document.title;
  sQuery = new String;
  sRegion = new String;
  sState = new String;
  var region = "";
  if (sTitle == "Dealer Locator") {
    // This is a dealer locator page, is it dealer detail?
    if (sURL.indexOf("detail.asp") > -1) {
      detailCrumbs(getQuerystring("ST"), getQuerystring("R"), output);
      return;
    }
    if (sURL.indexOf("dealer.asp") > -1) {
      dealerCrumbs(getQuerystring("ST"), getQuerystring("R"), output);
      return;
    }
    if (sURL.indexOf("region.htm") > -1) {
      regionCrumbs(sURL, output);
      return;
    } 
    if (sURL.indexOf("dealerlocator.htm") > -1) {
      // must be the main dealer locator page
      document.write(output + "<li>" + document.title + "</li></ul></div>");
      return;
    }
  } else {
    // if this is a normal page then just display the page title 
    document.write(output + "<li>" + document.title + "</li></ul></div>");
  }
}

function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function detailCrumbs(state, region, output) {
  sStateName = getStatename(state);
  sRegionname = getRegionname(region);
  output += "<li><a href=\"dealerlocator.htm\">Dealer Locator</a></li>";
  output += "<li><a href=\"" + region + "region.htm\">" + sRegionname + "</a></li>";
  output += "<li><a href=\"dealer.asp?ST=" + state + "&amp;R=" + region + "\">" + sStateName + " dealers</a></li>";
  document.write(output + "<li>Dealer detail</li></ul></div>");
}

function dealerCrumbs(state, region, output) {
  // Is it for a state?
  sRegion = getRegionname(region);
  sState = getStatename(state);
  output += "<li><a href=\"dealerlocator.htm\">Dealer Locator</a></li>";
  output += "<li><a href=\"" + region + "region.htm\">" + sRegion + "</a></li>";
  document.write(output + "<li>" + sState + " dealers</li></ul></div>");
}

function regionCrumbs(url, output) {
  // not for a state, is it for a region?
  sURL = new String(url);
  sDoc = document.URL;
  if (sURL.indexOf("region.htm") > -1) {
    if (sURL.indexOf("MWregion") > -1) {
      sDoc = "Midwest Region";
    } else if (sURL.indexOf("NEregion") > -1) {
      sDoc = "Northeast Region";
    } else if (sURL.indexOf("SCregion") > -1) {
      sDoc = "Southcentral Region";
    } else if (sURL.indexOf("SEregion") > -1) {
      sDoc = "Southeast Region";
    } else if (sURL.indexOf("Wregion") > -1) {
      sDoc = "West Region";
    }
  }
  output += "<li><a href=\"dealerlocator.htm\">Dealer Locator</a></li>";
  document.write(output + "<li>" + sDoc + "</li></ul></div>");
}

function getRegionname(region) {
  if (region == "MW") {
    return "Midwest Region";
  }
  if (region == "NE") {
    return "Northeast Region";
  }
  if (region == "SC") {
    return "Southcentral Region";
  }
  if (region == "SE") {
    return "Southeast Region";
  }
  if (region == "W") {
    return "West Region";
  }
  return "";
}

function getStatename(abbr) {
  var state;
  switch (abbr) {
    case "AL":
      state = "Alabama";
      break;
    case "AK":
      state = "Alaska";
      break;
    case "AZ":
      state = "Arizona";
      break;
    case "AR":
      state = "Arkansas";
      break;
    case "CA":
      state = "California";
      break;
    case "CO":
      state = "Colorado";
      break;
    case "CT":
      state = "Connecticut";
      break;
    case "DE":
      state = "Delaware";
      break;
    case "DC":
      state = "District of Columbia";
      break;
    case "FL":
      state = "Florida";
      break;
    case "GA":
      state = "Georgia";
      break;
    case "HI":
      state = "Hawaii";
      break;
    case "ID":
      state = "Idaho";
      break;
    case "IL":
      state = "Illinois";
      break;
    case "IN":
      state = "Indiana";
      break;
    case "IA":
      state = "Iowa";
      break;
    case "KS":
      state = "Kansas";
      break;
    case "KY":
      state = "Kentucky";
      break;
    case "LA":
      state = "Louisiana";
      break;
    case "ME":
      state = "Maine";
      break;
    case "MD":
      state = "Maryland";
      break;
    case "MA":
      state = "Massachusetts";
      break;
    case "MI":
      state = "Michigan";
      break;
    case "MN":
      state = "Minnesota";
      break;
    case "MS":
      state = "Mississippi";
      break;
    case "MO":
      state = "Missouri";
      break;
    case "MT":
      state = "Montanna";
      break;
    case "NE":
      state = "Nebraska";
      break;
    case "NV":
      state = "Nevada";
      break;
    case "NH":
      state = "New Hampshire";
      break;
    case "NJ":
      state = "New Jersey";
      break;
    case "NM":
      state = "New Mexico";
      break;
    case "NY":
      state = "New York";
      break;
    case "NC":
      state = "North Carolina";
      break;
    case "ND":
      state = "North Dakota";
      break;
    case "OH":
      state = "Ohio";
      break;
    case "OK":
      state = "Oklahoma";
      break;
    case "OR":
      state = "Oregon";
      break;
    case "PA":
      state = "Pennsylvania";
      break;
    case "RI":
      state = "Rhode Island";
      break;
    case "SC":
      state = "South Carolina";
      break;
    case "SD":
      state = "South Dakota";
      break;
    case "TN":
      state = "Tennessee";
      break;
    case "TX":
      state = "Texas";
      break;
    case "UT":
      state = "Utah";
      break;
    case "VT":
      state = "Vermont";
      break;
    case "VA":
      state = "Virginia";
      break;
    case "WA":
      state = "Washington";
      break;
    case "WV":
      state = "West Virginia";
      break;
    case "WI":
      state = "Wisconsin";
      break;
    case "WY":
      state = "Wyoming";
      break;
    default:
      state = "NotFound";
      break;
  }
  return state;
}

