/*
 * date:	2003-01-23
 * info:	http://inspire.server101.com/js/xc/
 */
 
/****** CONSTANT(S) ********************/
var MENU_ID_PREFIX = "menu";

var xcNode = [];
 

/****** PREPARE IMAGES ********************/
function newOpenGraphic() {
	var im = document.createElement("img");
	im.setAttribute("src","/lls/llonline/assets/images/list-arrow.gif");
	im.setAttribute("width","11");
	im.setAttribute("height","11");
	im.setAttribute("alt","Expand menu");
	im.className = "list-expand";
	return im;
}

function newOpenGraphic2() {
	var im = document.createElement("img");
	im.setAttribute("src","/lls/llonline/assets/images/list-arrow2.gif");
	im.setAttribute("width","11");
	im.setAttribute("height","11");
	im.setAttribute("alt","Expand menu");
	im.className = "list-expand";
	return im;
}

function newCloseGraphic() {
	var im = document.createElement("img");
	im.setAttribute("src","/lls/llonline/assets/images/list-arrow-down.gif");
	im.setAttribute("width","11");
	im.setAttribute("height","11");
	im.setAttribute("alt","Collapse menu");
	im.className = "list-close";
	return im;
}

function newExpandGraphic() {
	var im = document.createElement("img");
	im.setAttribute("src","/lls/llonline/assets/images/plus.gif");
	im.setAttribute("width","16");
	im.setAttribute("height","14");
	im.setAttribute("alt","Expand all menus");
	im.setAttribute("title","Expand all menus");
	return im;
}

function newCollapseGraphic() {
	var im = document.createElement("img");
	im.setAttribute("src","/lls/llonline/assets/images/minus.gif");
	im.setAttribute("width","16");
	im.setAttribute("height","14");
	im.setAttribute("alt","Collapse all menus");
	im.setAttribute("title","Collapse all menus");
	return im;
}





function xcSet(m, c) {
if (document.getElementById && document.createElement) {
	var z;
	if ((z=getCookie(("llmenu-"+currentMenu))!=null?getCookie(("llmenu-"+currentMenu)):"").length > 0) z = z.split("-");
	//alert("cookie=" + z);
	if (document.getElementById(m)) {
		m = document.getElementById(m).getElementsByTagName('ul');
		var d, p, x, h, i, j;
		for (i = 0; i < m.length; i++) {
			if (d = m[i].getAttribute('id')) {
				xcCtrl(d, c, 'x', 'open', 'Show', m[i].getAttribute('title')+' (expand menu)');
				x = xcCtrl(d, c, 'c', 'close', '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));
					j = 0;
					while ((h = !(d == MENU_ID_PREFIX + z[j])) && (j++ < z.length));
					if (h) {
						m[i].style.display = 'none';
						x = xcNode[d+'x'];
					}
				}
				p.className = c;
				p.insertBefore(x, p.firstChild);
				p.childNodes[1].className="menuDiv";
			}
		}
		openCurrentLevel();
		createButs();
		
		runOnLoad("checkIfOpen();");
	}
}}

function xcShow(m) {
	xcXC(m, 'block', m+'c', m+'x');
	record();
}

function xcHide(m) {
	xcXC(m, 'none', m+'x', m+'c');
	record();
}

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);
	
	
	
	if (v == 'open') {
		a.appendChild(newOpenGraphic());
		//set the status bar - the browser default for firefox wont allow this to show
		a.onmouseover=function() { window.status='Expand menu';return true;};
	}
	else {
		a.appendChild(newCloseGraphic());
		//set the status bar - the browser default for firefox wont allow this to show
		a.onmouseover=function() { window.status='Collapse menu';return true;};
	}
	
	var d = document.createElement('div');
	d.className = c+s;
	d.appendChild(a);
	return xcNode[m+s] = d;
}

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
}

function getCookie(name) {
  var dc = document.cookie,prefix = name + "=",begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function checkStatus() {
	var i=2,m,rmList="";
	while((m=document.getElementById(MENU_ID_PREFIX + i++)) != null) {
		if(m.style.display != "none") rmList += (i-1) + "-";
	}
	return rmList.substr(0,rmList.length-1);
}

function getExpiry() {
	var today = new Date();
	return new Date(today.getTime() + 24 * 60 * 60 * 1000); // 1 day expiry on cookie
}

function record() {
	setCookie("llmenu-"+currentMenu,checkStatus(),getExpiry(),"/");
}

function expandAll() {
	var p,sm,i;
	p=document.getElementById(MENU_ID_PREFIX + "1");
	sm=p.getElementsByTagName("ul");
	for (i=0;i<sm.length;i++) {
		if ((v=sm[i].parentNode.firstChild.firstChild.href).indexOf("Show") > -1) eval(v.substr(11));
	}
	record();
}

function contractAll() {
	var p,sm,i,sma;
	p=document.getElementById(MENU_ID_PREFIX + "1");
	sm=p.getElementsByTagName("ul");
	sma=new Array();
	for(i=0;i<sm.length;i++) sma[i] = sm[i];
	sma=sma.reverse();
	for (i=0;i<sm.length;i++) {
		if ((v=sm[i].parentNode.firstChild.firstChild.href).indexOf("Hide") > -1) eval(v.substr(11));
	}
	openCurrentLevel();
}

function openCurrentLevel() {
	var l,p,i,c,v;
	l=getRelativeLink();
	p=document.getElementById(MENU_ID_PREFIX + "1");
	c=document.getElementById("menuselected").parentNode;
	while (c.id != MENU_ID_PREFIX + "1") {
		if ((v=c.parentNode.firstChild.firstChild.href).indexOf("Show") > -1) eval(v.substr(11));
		c=c.parentNode.parentNode;
	}
}

function createButs() {
	var md=document.getElementById("menu-buts");
	
	var a=document.createElement("a");
	a.appendChild(newCollapseGraphic());
	a.setAttribute("href","javascript:contractAll()");
	md.appendChild(a);
	//set the status bar - the browser default for firefox wont allow this to show
	a.onmouseover=function() { window.status='Collapse all menus';return true;};
	a.style.marginRight="5px";
	
	a=document.createElement("a");
	a.appendChild(newExpandGraphic());
	a.setAttribute("href","javascript:expandAll()");
	md.appendChild(a);	
	//set the status bar - the browser default for firefox wont allow this to show
	a.onmouseover=function() { window.status='Expand all menus';return true;};
}


function checkIfOpen() {
	var cm;
	if (cm=document.getElementById("menuselected")) {
		while (cm.childNodes.length > 0 && cm.nodeName.toLowerCase() != "a") cm=cm.firstChild;
		//alert(cm.nodeName);
		if (cm.nodeName.toLowerCase() == "a") {
			if (cm.href.indexOf("Show") > -1) eval(cm.href.substr(11));
		}
	}
}
/** this runOnLoad function is used in HDR site **/
//to handle multiple onload items, this function queues script and runs it when the event triggers.
var onLoadScript="";
function runOnLoad(script) {
	if (typeof(script) == "object" || typeof(script) == "undefined") { 	//being called by event handler
		if (onLoadScript != "") eval(onLoadScript);
	}
	else onLoadScript += script;
}
window.onload = runOnLoad;
/** the above runOnLoad function is used in HDR site **/