﻿function QueryString() {
	// PROPERTIES
	this.arg = new Array;
	this.status = false;
	
	// METHODS
	this.clear = Clear;
	this.get = Get;
	this.getAll = GetAll;
	this.getStatus = GetStatus;
	this.read = Read;
	this.set = Set;
	this.write = Write;
	
	// FUNCTIONS
	
	// Clears the array, this.arg, of all query string data
	function Clear()
	{	this.arg = new Array;
	}
	
	// Returns a named value from the query string
	function Get(sName)
	{	return this.arg[sName];
	}
	
	// Return all data as an associative array
	function GetAll()
	{	return this.arg;
	}
	
	function GetStatus()
	{	return this.status;
	}
	
	// Reads the query string into an array named this.arg
	function Read(sUrl) 
	{	var aArgsTemp, aTemp, sQuery;
		// You can pass in a URL query string
		if(sUrl)
		{	sQuery = sUrl.substr(sUrl.lastIndexOf("?")+1, sUrl.length);
		}
		// Or read it from the browser location
		else
		{	sQuery = window.location.search.substr(1, window.location.search.length);
		}
		// Check that query string exists and contains data
		// If not (length < 1) then return
		if(sQuery.length < 1) {return;}
		// Else set this.status to true and proceed
		else {this.status = true;}
		//
		aArgsTemp = sQuery.split("&");	
		for (var i=0 ; i<aArgsTemp.length; i++)
		{	aTemp = aArgsTemp[i].split("=");
			this.arg[aTemp[0]] = aTemp[1];
		}
	}
	
	// Overwrites an existing named value in the array, this.arg
	// You can also pass null to delete from array
	function Set(sName,sValue)
	{	if (sValue == null) {delete this.arg[sName];}
		else {this.arg[sName] = sValue;}
	}
	
	// Writes out a string from the data in this.arg array
	// This string can be used to pass a new query string to the browser
	// when navigating to the next page. This allows a page
	// to create and pass data to another page via JavaScript.
	function Write()
	{	var sQuery = new String(""); 
		for (var sName in this.arg)
		{	if (sQuery != "") {sQuery += "&";}
			if (this.arg[sName]) {sQuery += sName + "=" + this.arg[sName];}
		}
		if (sQuery.length > 0) {return "?" + sQuery;}
		else {return sQuery;}
	}
}
	
	function breadcrumbs()
	{
		// Create a new QueryString object
		var myQuery = new QueryString();

		// Read query string from browser into the new QueryString object, name myQuery
		myQuery.read();

		// Check the status, to make sure it read the query string
		// Then write out the query string arguments
		
		var breadcrumb = "&nbsp;&nbsp;&nbsp;<a href=\"index.php\">Myōfū-An Gunma Dōjō</a> &raquo; "
		document.write(breadcrumb);

		// If there's a querystring
		if(myQuery.getStatus())
		{
			var aQueryData = myQuery.getAll();
			breadcrumb = aQueryData["go"];

			// Replace underscores with spaces if needed
			var intIndex = breadcrumb.indexOf("_");
			
			while(intIndex != -1)
			{
				breadcrumb = breadcrumb.replace("_", " ");
				intIndex = breadcrumb.indexOf("_");
			}
			
			// Replace hyphen with breadcrumb marker
			intIndex = breadcrumb.indexOf("-");
			
			while(intIndex != -1)
			{
				breadcrumb = breadcrumb.replace("-", " &raquo; ");
				intIndex = breadcrumb.indexOf("-");
			}
			
			// Fix small o with macron
			
			intIndex = breadcrumb.indexOf("%C5%8");
			
			while(intIndex != -1)
			{
				breadcrumb = breadcrumb.replace("%C5%8D", "ō");
				intIndex = breadcrumb.indexOf("%C5%8D");
			}
		}
		else
		{
			breadcrumb = "Home";
		}
		
		document.write(breadcrumb);
	}