/* 	
Hierarchical tree by Patrick TAI 03/04/2002 
modified 09/10/2002
*/
function MenuItem(id,pId,pCatID,isP,lab,lchild,lnk){
		this.catId = id;
		this.parentId = pId;
		this.parentCatId = pCatID;
		this.isParent = isP;
		this.label = lab;
		this.link = lnk;
		this.childrenNodes = lchild;
		this.expand = 0;
}

var Menu = new Array(), currentSelection = -1;
Menu[0] =  new MenuItem(0,-1,-1,1,"ALL","0","");

//creates the menu data

var selectedID, displayed = false;
var theContent;
/*
function check(){
try{
	with(document.F_GPCat){
		for(var i=0;i<selCat.length;i++){
			if(parent.mainnav.cat[selCat[i].value]){selCat[i].checked = true}
			else selCat[i].checked = false;
		}
	}
	}
	catch(e){};// the form element L_mpID is not existing when the query returns no records.
}
*/

function refreshMenu(targ,allExpanded){
	theContent ='<html><Head><title></title><link rel="stylesheet" href="/customsite.css" type="text/css"></HEAD><body background="images/cat_background.jpg">';
	theContent += "<table  border='0' cellspacing='0' cellpadding='0' width='200' align='center'>";
	theContent += "<tr><td><img src='images/spacer.gif' width='0' height='5' border='0'></td></tr>";
	selectedID = Menu[targ].catId;
	Menu[targ].expand ? Menu[targ].expand = 0 : Menu[targ].expand = 1;
	for(var i = 1; i < Menu.length; i++){
		if(Menu[i].parentId == -1 || (Menu[i].catId == topNode && showTop) || (Menu[i].parentCatId == topNode && !showTop)){
			//if(Menu[i].expand && targ != i && Menu[targ].parentId == 0){Menu[i].expand = 0}
			sign = noSign;
			
			if(Menu[i].isParent){
				if(allExpanded)(sign = shSign);
				else Menu[i].expand ? sign= shSign :sign = expSign;
			}
			Menu[i].catId == selectedID ? style = "navMenu" : style = "navMenu";
			if(Menu[i].link==""){
				theContent += '<tr><td nowrap><span class="'+style+'">'+'<a href="##" onclick="parent.refreshMenu('+i+','+allExpanded+')" target="products">'+sign+ '' + Menu[i].label  + '</a></span></td></tr>'
			}
			else {
			theContent += '<tr><td nowrap><span class="'+style+'"><a href="'+Menu[i].link+'##'+i+'" onclick="parent.refreshMenu('+i+','+allExpanded+')" target="products">'+sign+ '' + Menu[i].label  + '</a></span></td></tr>'}
			if(Menu[i].isParent){
					if(allExpanded){displaySub(Menu[i].catId,allExpanded);}
					else if(Menu[i].expand){
						displaySub(Menu[i].catId, allExpanded);
						}
			}
		}
	}
	theContent +="</table></body></html>";
	nav.document.open();
	nav.document.write(theContent);
	nav.document.close();

	if(targ!=currentSelection && !first)	{
		products.location = "search.cfm?cat="+Menu[targ].childrenNodes;
		currentSelection = targ;
		}
	first = false;
}

function displaySub(id,allExpanded){
	cLvl++; 
	for(var a = 1; a < Menu.length; a++){
		if(Menu[a].parentCatId == id){
			
			sign = "";
			if(Menu[a].isParent){
				if(allExpanded)(sign = shSign);
				//else Menu[a].expand ? sign = shSign : sign = expSign;
			}
			
			Menu[a].catId == selectedID ? style = "selectedCat" : style = "selectedCat";
			thespace = ((cLvl-2)*12)+10;
			if(cLvl > 1){var spacer = "<img src='empty.gif' hspace='2' border='0' height='5' width='"+ thespace +"'>"}
			else var spacer = "";
				if(Menu[a].link==""){
					theContent +='<tr><td nowrap>' + spacer + '<span class="'+style+'"><a href="##" onclick="parent.refreshMenu('+a+','+allExpanded+')" target="products">'+ childSign + sign  + '' + Menu[a].label  + '</a></span></td></tr>';
					Rowspan = "";
				}
				else {theContent += '<tr><td nowrap>' + spacer  + '<span class="'+style+'">'+ '<a href="'+Menu[a].link+'##'+a+'" onclick="parent.refreshMenu('+a+','+allExpanded+')" target="products">'+ childSign + sign + '' + Menu[a].label  + '</a></span></td></tr>';
				Rowspan = "";}
				if(Menu[a].isParent){ 
					if(allExpanded){displaySub(Menu[a].catId,allExpanded)} 
					else if(Menu[a].expand){
						displaySub(Menu[a].catId,allExpanded);
						};
				}
			}
		}
	cLvl--; 
}
