/*
 * date:	2003-01-23
 * info:	http://inspire.server101.com/js/xc/
 */
 
function getElementsByClass(searchClass,tag, click) {
	var classElements = new Array();
	if ( tag == null )
		tag = '*';
	var els = document.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if (click == null) {
			classElements[j] = els[i];
			j++;
		}
		else {
			if ( pattern.test(els[i].className) ) {
				classElements = els[i];
				j++;
			}
		}
	}
	return classElements;
}
 
 
var xcNode = [];

function xcSet(m, c) {
if (document.createElement) {
	m = getElementsByClass(m, 'ul');
	//m = document.getElementById(m).getElementsByTagName('ul');
	var d, p, x, h, i, j;
	for (i = 1; i < m.length; i++) {
		o = m[i].getAttribute('class');
		if (o == null) o = m[i].getAttribute('className');
		if (d = o) {
			//xcCtrl(d, c, 'x', '[+]', 'Show', m[i].getAttribute('title')+' (expand menu)');
			//x = xcCtrl(d, c, 'c', '[-]', 'Hide', m[i].getAttribute('title')+' (collapse menu)');
			xcCtrl(d, c, 'x', '../phplm/images/tree_expand_corner_first.png', 'Show', m[i].getAttribute('title')+' (expand menu)');
			x = xcCtrl(d, c, 'c', '../phplm/images/tree_collapse_corner_first.png', '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');
	var maDiv = document.getElementById('global').offsetHeight;
	maDiv = maDiv - 404;
	document.getElementById('bas').style.top=maDiv;
}


function xcHide(m) {
	xcXC(m, 'none', m+'x', m+'c');
	var maDiv = document.getElementById('global').offsetHeight;
	maDiv = maDiv - 404;
	document.getElementById('bas').style.top=maDiv;
}


function xcXC(e, d, s, h) {
	//e = document.getElementById(e);
	e = getElementsByClass(e, 'ul', 'click');
	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));
	a.appendChild(createImageNode("plier/déplier", v));

	var d = document.createElement('div');
	d.className = c+s;
	d.appendChild(a);

	return xcNode[m+s] = d;
}

   function createImageNode( id, action )
   {
     var img = document.createElement("img");
     img.src = "media/" + action ;
     img.alt = id;
     img.id = "plus";
     return img;
   }
