/*
 * date:	2002-12-13
 * info:	http://inspire.server101.com/js/xc/
 */

var xcNode = [];

function xcSet(m, c) {
if (document.getElementById && document.createElement) {
	m = document.getElementById(m).getElementsByTagName('ul');
	var d, p, x, h, i, j;
	for (i = 0; i < m.length; i++) {
		d = m[i].getAttribute('id');
		if (d) {
			x = xcCtrl(d, c, 'x', '[+]', 'Show', m[i].getAttribute('title')+' (expand menu)');
			x = xcCtrl(d, c, 'c', '[-]', 'Hide', m[i].getAttribute('title')+' (collapse menu)');

			p = m[i].parentNode;
			if (h = !p.className) {
				j = 2;
				while ((h = !(d == arguments[j])) && (j++ < arguments.length));
				if (h) {
					m[i].style.display = 'none';
					x = xcNode[d+'x'];
				}
			}

			p.className = c;
			p.insertBefore(x, p.firstChild);
		}
	}
}}


function xcShow(m) {
	xcXC(m, 'block', m+'c', m+'x');
}


function xcHide(m) {
	xcXC(m, 'none', m+'x', m+'c');
}


function xcXC(e, d, s, h) {
	e = document.getElementById(e);
	e.style.display = d;
	e.parentNode.replaceChild(xcNode[s], xcNode[h]);
	xcNode[s].firstChild.focus();
}


function xcCtrl(m, c, s, v, f, t) {
	var a = document.createElement('a');
	a.setAttribute('href', 'javascript:xc'+f+'(\''+m+'\');');
	a.setAttribute('title', t);
	a.appendChild(document.createTextNode(v));

	var d = document.createElement('div');
	d.className = c+s;
	d.appendChild(a);

	return xcNode[m+s] = d;
}


/* **** Treasury extension **** */
function setActiveMenuItem() {
	if (document.getElementById && document.getElementsByTagName)  {
		var url = document.location.toString();
		var pos;
		
		// apply to top navigation
		pos = url.findForward('/', 5);
		if (pos != -1) setActive("nav1", url.substring(0, pos), new SearchForward("/", 5), "#990000");
		
		// apply to secondary navigation
		pos = url.findRev('/', 2);
		if (pos != -1) setActive("nav2", url.substring(pos), new SearchRev("/", 2), "#990000");
		
	}
}

function setActive(id, key, searchMethod, colour) {
	var parent = document.getElementById(id);
	if (parent != null)  {
		var menuItems = parent.getElementsByTagName("a");
		for (var i = 0; i < menuItems.length; i++) {
			var mKey = searchMethod.find(menuItems[i].href);
			if (mKey != null && key == mKey) menuItems[i].style.color = colour;
		}
	}
}

var SearchForward = function (str, instance) {
	this.str = str;
	this.instance = instance;
}

SearchForward.prototype.find = function (href) {
	return href.substring(0, href.findForward(this.str, this.instance));
}

var SearchRev = function (str, instance) {
	this.str = str;
	this.instance = instance;
}

SearchRev.prototype.find = function (href) {
	return href.substring(href.findRev(this.str, this.instance));
}

String.prototype.findForward = function (str, instance) {
	var counter = 0;
	var pos = -1;
	
	while (counter < instance && pos < this.length) {
		if (this.charAt(++pos) == str) {
			counter++;
		}
	}
	
	return (counter == instance) ? pos : -1;
}

String.prototype.findRev = function (str, instance) {
	var counter = 0;
	var pos = this.length;
	
	while (counter < instance && pos >= 0) {
		if (this.charAt(--pos) == str) {
			counter++;
		}
	}
	
	return (counter == instance) ? pos : -1;
}