// Request.js
// This will parse the document URL and make various variables availible.

//First check the name space...

var com;
if (!com || !com.jchristy) { throw new Error("com.jchristy: Required object 'com.jchristy.Support' does not exist."); }

//Name space is ready.

com.jchristy.Request = {};
com.jchristy.Request._parse = function() {
	this.hostname = window.location.hostname;
	
	var pn = window.location.pathname.replace(/\\/g, "/");
	this.fileid = pn.substring(pn.lastIndexOf("/") + 1);
	this.pageid = this.fileid.substr(0, this.fileid.lastIndexOf("."));
	
	var pa = pn.split("/").slice(1, -1);
	
	this.path = [];
	this.sections = [];
	
	for (var i = 0; i < pa.length; i++) {
		if (pa[i] != "") { 
			this.path.push(pa[i]);
			this.sections.unshift(pa[i]);
		}	
	}
	
	this.sectionid = this.sections[0];
	
	var query = location.search.substring(1);
	if (!query.length) { return; }
	
	var pairs = query.split("&");
	
	for (var i = 0; i < pairs.length; i++) {
		var p = pairs[i].indexOf("=");
		if (p == -1) { continue; }
		var name = pairs[i].substring(0, p);
		var value = pairs[i].substring(p + 1);
		value = decodeURIComponent(value);
		this[name] = value;
	}
}

com.jchristy.Request._parse();
