//Date: 10/30/2006
//Andy Patel

  function breadcrumbs(){
    sURL = new String;
    bits = new Object;
	last = new String;
	sTitle = new String;
    var x = 0;
    var stop = 0;
    var output = "";//"<A HREF=\"/\">Home</A> > ";

    sURL = location.href;
    sURL = sURL.split("?")[0];
    sURL = sURL.slice(8,sURL.length);
    chunkStart = sURL.indexOf("/");
    sURL = sURL.slice(chunkStart+1,sURL.length)

    while(!stop){
      chunkStart = sURL.indexOf("/");
      if (chunkStart != -1){
        bits[x] = sURL.slice(0,chunkStart)
        sURL = sURL.slice(chunkStart+1,sURL.length);
		last = bits[x];
      }else{
        stop = 1;
      }
      x++;
    }
//if(x > 1){
    for(var i in bits){
	//for(var j = 0; j < 10; j++){
		//sTitle = bits[i].replace("_", " ");
		//sTitle = bits[i].replace(" ", " ");
		//sTitle = bits[i].replace("%20", " ");
	//}
		sTitle = bits[i];
		temp = new String;
		temp = sTitle;
		for(var i1 = 0; i1 < temp.length; i1++)
		{
			if(i1 == 0)
			{
				sTitle = temp.charAt(i1).toUpperCase();
			}
			else if(temp.charAt(i1).match("_") || (temp.charAt(i1).match("%") && temp.charAt(i1+1).match("2") && temp.charAt(i1+2).match("0")))
			{
				if(! temp.charAt(i1).match("_")){i1++;i1++;}
				sTitle += " ";
			}
			else if(temp.charAt(i1-1).match("_"))
			{
				sTitle += temp.charAt(i1).toUpperCase();
			}
			else
			{
				sTitle += temp.charAt(i1);
			}
		}
      output += "<li";
if(GetCurrentPageName() == "index.shtml" || GetCurrentPageName() == "")
{
      output += " id=\"current\"";
}
      output += "><A HREF=\"";

      for(y=1;y<x-i;y++){
        output += "../";
      }
      output += bits[i] + "/index.shtml\"><span>" + sTitle + "</span></A></li>";
    }
if(GetCurrentPageName() != "index.shtml" && GetCurrentPageName() != "")
{
	    output = output + "<li id=\"current\"><a href=\"#\"><span>" + document.title.replace(last,"") + "</span></a></li>";
}
//}
var mainHome = "";
if(document.URL == "http://www.dcr.virginia.gov/" || document.URL == "http://www.dcr.virginia.gov/index.shtml")
{
	mainHome = " id=\"current\"";
}

	output = "<ul><li><a class=\"firstBC\" href=\"/\" accesskey=\"H\" title=\"Access Key = H to go back to the homepage.\""+ mainHome + "><span>Home</span></a></li>" + output + "</ul>";
	document.getElementById('breadcrumb').innerHTML = output + "<br>";
}
function GetCurrentPageName() {
//method to get Current page name from url.
//return page name in small .
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
return sPage.toLowerCase()
}

  function breadcrumbs_bu(){
    sURL = new String;
    bits = new Object;
	last = new String;
	sTitle = new String;
    var x = 0;
    var stop = 0;
    var output = "";//"<A HREF=\"/\">Home</A> > ";

    sURL = location.href;
    sURL = sURL.slice(8,sURL.length);
    chunkStart = sURL.indexOf("/");
    sURL = sURL.slice(chunkStart+1,sURL.length)

    while(!stop){
      chunkStart = sURL.indexOf("/");
      if (chunkStart != -1){
        bits[x] = sURL.slice(0,chunkStart)
        sURL = sURL.slice(chunkStart+1,sURL.length);
		last = bits[x];
      }else{
        stop = 1;
      }
      x++;
    }
//if(x > 1){
    for(var i in bits){
	//for(var j = 0; j < 10; j++){
		//sTitle = bits[i].replace("_", " ");
		//sTitle = bits[i].replace(" ", " ");
		//sTitle = bits[i].replace("%20", " ");
	//}
		sTitle = bits[i];
		temp = new String;
		temp = sTitle;
		for(var i1 = 0; i1 < temp.length; i1++)
		{
			if(i1 == 0)
			{
				sTitle = temp.charAt(i1).toUpperCase();
			}
			else if(temp.charAt(i1).match("_") || (temp.charAt(i1).match("%") && temp.charAt(i1+1).match("2") && temp.charAt(i1+2).match("0")))
			{
				if(! temp.charAt(i1).match("_")){i1++;i1++;}
				sTitle += " ";
			}
			else if(temp.charAt(i1-1).match("_"))
			{
				sTitle += temp.charAt(i1).toUpperCase();
			}
			else
			{
				sTitle += temp.charAt(i1);
			}
		}
      output += "<A HREF=\"";
      for(y=1;y<x-i;y++){
        output += "../";
      }
      output += bits[i] + "/index.shtml\">" + sTitle + "</A> > ";
    }
	
	    output = " > " + output + document.title.replace(last,"");
//}
	document.write(output);
}
function modified(){
	document.write(document.lastModified);
}

function define(t, b, w, h) {
	with (window.open("","","menubars=no,location=no,toolbars=no,scrollbars=yes,resizable=yes,width="+w+",height="+h+",top=50,left=50").document)
	{
		open();
			write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html lang="en"><head><title>'+t+'</title><meta http-equiv="author" content="Michael Ware, Steve Hawks, Andy Patel, Sam Sieg"><link rel="stylesheet" type="text/css" href="http://www.dcr.virginia.gov/css/dcr.css"></head><body style="background:white;margin:5px;"><p class="redbold">'+t+'</p><p>'+b+"</p><p align='center'><a class='links' href='javascript:window.close()'>Close this window</a> | <a class='links' href='javascript:window.print()'>Print this page</a></p>");
		close();
   }
}

function getURLParameter(name)
{
	return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,""])[1]);
}

function getFullFileName()
{
	var url = document.location.href;
	url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#"));
	url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
	url = url.substring(url.lastIndexOf("/") + 1, url.length);
	return url;
}
function getFileExtension(filename)
{
	if(filename == ""){filename = getFullFileName();}
	var ext = /^.+\.([^.]+)$/.exec(filename);
	return ext == null ? "" : ext[1];
}
function getFileName(filename)
{
	if(filename == ""){filename = getFullFileName();}
	var ext = getFileExtension("");
	return Left(filename,filename.length - ext.length - 1);
}
function Left(str, n)
{
	if (n <= 0)
        	return "";
	else if (n > String(str).length)
		return str;
	else
	return String(str).substring(0,n);
}
function Right(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
	{
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}
function trim_str (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

