/*
 * file:    xc.js
 * date:    2002-12-13
 * info:	http://inspire.server101.com/js/xc/
 *
 * change:  stef miladinova
 * date:    20/10/2006
 * desc:    I have added the xcSetTitle(...) function from the old Javascript file that we were using.
 *          I have also put in a check for a null document.getElementById(titleElement) to correct any errors.
 */


// nodes set
var xcNode = [];

// set the title above the navigation of the current page
// ul=the id of the root ul element of the navigation
// titleElement=the name of the element to set the title on
// page=the current document id
function xcSetTitle(ul, titleElement, pagename) {
    
    try {
        if ((document.getElementById) && (document.getElementById(ul).getElementsByTagName('a') != null)){
            a = document.getElementById(ul).getElementsByTagName('a');
            for (i = 0; i < a.length; i++) {
                id = a[i].getAttribute('id');
                if (id) {
                    if (id == pagename) {
                        if ((document.getElementById(titleElement) != null) && (a[i].getAttribute('title') != null)) {
                            document.getElementById(titleElement).innerHTML = a[i].getAttribute('title');
                        }
                    }
                }
            }
        }
    }
    catch(e) {
        if (e.number != -2146827850) {
            //alert(e.message + ", " + e.number);
        }
        return true;
    }
}

// setup menu (m:=id, c:=class [, ids expanded])
function xcSet(m, c) {
	if ((document.getElementById && document.getElementById(m) != null) && document.createElement && (navigator.userAgent.indexOf('MSIE 5.2') == -1 || navigator.userAgent.indexOf('Mac') == -1)) {
	m = document.getElementById(m).getElementsByTagName('ul');
	var d, p, x, h, i, j;
	for (i = 0; i < m.length; i++) {
	    //get 'id'
		d = m[i].getAttribute('id');
		if (d) {
            // +/- controls to expand/collapse node
            x = xcCtrl(d, c, 'x', '[+]', 'Show', m[i].getAttribute('title')+' (expand menu)');
			x = xcCtrl(d, c, 'c', '[-]', 'Hide', m[i].getAttribute('title')+' (collapse menu)');

            // hide node
            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);
		}
	}
}
}

// expand
function xcShow(m) {
	xcXC(m, 'block', m+'c', m+'x');
}

// collapse
function xcHide(m) {
	xcXC(m, 'none', m+'x', m+'c');
}

// toggle
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();
}

// +/- control nodes
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;
}
