var b_all_expanded;
b_all_expanded = false;

var treeClass;
treeClass = "lmnktree";
var nodeClosedClass;
nodeClosedClass = "lC";
var nodeOpenClass;
nodeOpenClass = "lO";
var nodeBulletClass;
nodeBulletClass = "lB";
var nodeProductClass;
nodeProductClass = "lP";
var nodeLinkClass;
nodeLinkClass = "bullet";


function pp(p)
{
	var b;
	b = "elementk";
	var getVars = new Array();
	var locvartemp = ( window.location.href.indexOf( "?" ) + 1 ) ? window.location.href.substr( window.location.href.indexOf( "?" ) + 1 ) : "";
	locvartemp = locvartemp.split( "&" );
	var done;
	done = false;
	for( var x = 0; x < locvartemp.length && done == false; x++ ) {
	    var lvTempVar = locvartemp[x].split( "=" );
	    if(unescape( lvTempVar[0] ) == "b")
	    {
		    done = true;
	    	b = unescape( lvTempVar[1] );
    	}
	}

	popWindow('/lmnk/catalog/popup_syllabus.asp?b=' + b + '&p=' + p, 'syllabus' + p,'status=yes,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=780,height=580,top=5,left=5');
}

// Automatically attach a listener to the window onload, to convert the trees
//addEvent(window,"load",convertTrees);

// Utility function to add an event listener
function addEvent(o,e,f){
	if (o.addEventListener){ o.addEventListener(e,f,true); return true; }
	else if (o.attachEvent){ return o.attachEvent("on"+e,f); }
	else { return false; }
}

// Full expands a tree with a given ID
function expandTree(treeId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	expandCollapseListAll(ul,nodeOpenClass);
}

// Fully collapses a tree with a given ID
function collapseTree(treeId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	expandCollapseListAll(ul,nodeClosedClass);
}

// Expands enough nodes to expose an LI with a given ID
function expandToItem(treeId,itemId) {
	var ul = document.getElementById(treeId);
	if (ul == null) { return false; }
	var ret = expandCollapseList(ul,nodeOpenClass,itemId);
	if (ret) {
		var o = document.getElementById(itemId);
		if (o.scrollIntoView) {
			o.scrollIntoView(false);
		}
	}
}

// Performs 3 functions:
// a) Expand all nodes
// b) Collapse all nodes
// c) Expand all nodes to reach a certain ID
function expandCollapseList(ul,cName,itemId) {
	if (!ul.childNodes || ul.childNodes.length==0) { return false; }
	// Iterate LIs
	for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
		var item = ul.childNodes[itemi];
		if (itemId!=null && item.id==itemId) { return true; }
		if (item.nodeName == "LI") {
			// Iterate things in this LI
			var subLists = false;
			for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
				var sitem = item.childNodes[sitemi];
				if (sitem.nodeName=="UL") {
					subLists = true;
					var ret = expandCollapseList(sitem,cName,itemId);
					if (itemId!=null && ret) {
						item.className=cName;
						return true;
					}
				}
			}
			if (subLists && itemId==null) {
				item.className = cName;
			}
		}
	}
}

// Performs 3 functions:
// a) Expand all nodes
// b) Collapse all nodes
// c) Expand all nodes to reach a certain ID
function expandCollapseListAll(ul,cName) {
	var sitem;
	var item;
	var itemi;
	var subLists;
	var sitemi;

	if (!ul.childNodes || ul.childNodes.length==0) { return false; }
	// Iterate LIs
	subLists = true;
	for (itemi=0;itemi<ul.childNodes.length&&subLists == true;itemi++) {
		item = ul.childNodes[itemi];
		if (item.nodeName == "LI") {
			// Iterate things in this LI
			subLists = false;
			for (sitemi=0;sitemi<item.childNodes.length;sitemi++) {
				sitem = item.childNodes[sitemi];
				if (sitem.nodeName=="UL") {
					subLists = true;
					expandCollapseListAll(sitem,cName);
				}
			}
			if (subLists) {
				item.className = cName;
			}
		}
	}
}


// var start;
// var end;
// var start2;
// var end2;
// var tot;
// tot = 0;

// Search the document for UL elements with the correct CLASS name, then process them
function convertTrees(isSyllabus) {
	if (!document.createElement) { return; } // Without createElement, we can't do anything
	uls = document.getElementsByTagName("ul");
	for (var uli=0;uli<uls.length;uli++) {
		var ul=uls[uli];
		if (ul.nodeName=="UL" && ul.className==treeClass) {
			if(isSyllabus == false)
			{
 				//start = new Date();
				processList(ul);
 				//end = new Date();
			}
			else
			{
				processListSyllabus(ul);
			}
		}
	}
	//document.getElementsByTagName("div");
	uls = document.getElementsByTagName("ul");
	for (var uli=0;uli<uls.length;uli++) {
		var ul=uls[uli];
		ul.display='block';
	}
 	//alert((end - start)/1000);
}



// Process a UL tag and all its children, to convert to a tree
function processList(ul, textlinks) {

	var t;
	var s;
	var item;
	var itemi;
	var subLists;

	if (!ul.childNodes || ul.childNodes.length==0) { return; }
	for (itemi=0;itemi<ul.childNodes.length;itemi++) {
		item = ul.childNodes[itemi];
		if (item.nodeName == "LI") {
			subLists = false;
			for (sitemi=0;sitemi<item.childNodes.length;sitemi++) {
				sitem = item.childNodes[sitemi];
				if (sitem.nodeName=="UL") {
					subLists = true;
					processList(sitem);
				}
			}
			if (subLists) {
				s= document.createElement("SPAN");
				t= '\u00A0'; // &nbsp;
				s.className = nodeLinkClass;

				t = t+item.firstChild.nodeValue;
				item.removeChild(item.firstChild);
				s.onclick = function () {openClose(this);}

				s.appendChild(document.createTextNode(t));
				item.insertBefore(s,item.firstChild);
			}
		}
	}
}

function openClose(obj)
{
	obj.parentNode.className=(obj.parentNode.className==nodeOpenClass)?nodeClosedClass:nodeOpenClass;return false;
}


// Process a UL tag and all its children, to convert to a tree
function processListSyllabus(ul, textlinks) {
	var t;
	var s;
	var item;
	var itemi;
	var subLists;

	if (!ul.childNodes || ul.childNodes.length==0) { return; }
	// Iterate LIs
	for (itemi=0;itemi<ul.childNodes.length;itemi++) {
		item = ul.childNodes[itemi];
		if (item.nodeName == "LI") {
			// Iterate things in this LI
			subLists = false;
			for (sitemi=0;sitemi<item.childNodes.length;sitemi++) {
				sitem = item.childNodes[sitemi];
				if (sitem.nodeName=="UL") {
					subLists = true;
					processListSyllabus(sitem);
				}
			}

			s= document.createElement("SPAN");
			t= '\u00A0'; // &nbsp;
			s.className = nodeLinkClass;

			s.onclick = function () {return false;}

			s.appendChild(document.createTextNode(t));
			item.insertBefore(s,item.firstChild);
		}
	}
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function uriencode(param)
{
	if (window.encodeURIComponent)
	   param = encodeURIComponent(param);
	else if (window.escape)
	   param = escape(param);
	return param;
}

function expand()
{
	document.getElementById('otherbutton').style.display='block';expandTree('offertree');MM_swapImage('expandcollapsebutton','','/gfx/btn_collapseAll.gif',1);
	document.catalogform.expandcollapsebutton.disabled=false;
	document.catalogform.bottomcollapsebutton.disabled=false;
}
function collapse()
{
	document.getElementById('otherbutton').style.display='none';collapseTree('offertree');MM_swapImage('expandcollapsebutton','','/gfx/btn_expandAll.gif',1);
	document.catalogform.expandcollapsebutton.disabled=false;
	document.catalogform.bottomcollapsebutton.disabled=false;
}