

//--Copyright (C) 2007 Neotek Limited (http://www.neotek.co.nz). All rights reserved. -->
/*
Add functionality to allow viewing of all products in a category and its sub categories (using setTheory).
Have also added the use of Visted links. This requires that 'MenuVisited' class be added to menu.css. This currently 
will only be active on SetTheory menus. To disable, set the 'MenuVisited' class to the same as 'MenuUnselected'
*/
//i=integer, a=array, s=string, c=constant
var menuArray = new Array();
var aMenuItem = new Array();
var aLink = new Array();

var iMenuWidth = 300;
var iTitleChars = 100;
var sHiddenMenuItems = ''; //csv

var ShowMenuItemNo = 0;
var menuScrollTop = 0;
var basketScrollTop = 0;
var BasketTotalReady = false;
var iLink = 0;

var admin = false;
var iClaimId = 0;
var sType = 'Component';
var iCurMenuItem = 0;
var oTargetMenu;
var catMenuLastItem = 0;
var catdivType = 1;
var breakout = null;

var setTheory = false;
if (typeof (UseSetTheory) != 'undefined') {	//Make Backward compat
    setTheory = UseSetTheory;
}

function menuitem(Id, Text, Image, LinkId, Reference, Parent, FirstChild, LastChild, Next, Previous, Indent, IsNode, IsLoaded, IsActive) {
    this.Id = Id;
    this.Parent = Parent;
    this.FirstChild = FirstChild;
    this.LastChild = LastChild;
    this.Text = Text;
    this.LinkId = LinkId;
    this.Reference = Reference;
    this.Indent = Indent;
    this.IsNode = IsNode;
    this.IsLoaded = IsLoaded;
    this.IsActive = IsActive;
    this.Next = Next;
    this.Previous = Previous;
    this.Image = Image;
}

function menulink(Ref, Target) {
    this.Ref = Ref;
    this.Target = Target;
}

function setText(obj, text) {
    if (obj.innerHTML != null) {
        obj.innerHTML = text;
    } else if (document.getElementById) {
        rng = document.createRange();
        rng.setStartBefore(div);
        htmlFrag = rng.createContextualFragment(text)
        while (obj.hasChildNodes()) obj.removeChild(Node.lastChild);
        obj.appendChild(htmlFrag);
    }
}


function MenuItemIndentAmount(iItem, containerId) {
    var idx = iItem;
    var iIndent = 0;

    if (document.getElementById('concertina') != null) {
        while (menuArray[containerId][idx].Parent != 0) {
            idx = MenuItemIndex(menuArray[containerId][idx].Parent);
            iIndent = parseInt(iIndent) + parseInt(menuArray[containerId][idx].Indent);
        }
    }
    else {
        while (aMenuItem[idx].Parent != 0) {
            idx = MenuItemIndex(aMenuItem[idx].Parent);
            iIndent = parseInt(iIndent) + parseInt(aMenuItem[idx].Indent);
        }
    }

    return iIndent;
}

function setParentIndent(iItem, iIndent, containerId) {

    if (document.getElementById('concertina') != null) {
        return setIndent(menuArray[containerId][iItem].Parent, iIndent);
    }
    else {
        return setIndent(aMenuItem[iItem].Parent, iIndent);
    }

}

function setIndent(iItem, iIndent, containerId) {
    var idx = iItem;

    if (document.getElementById('concertina') != null) {
        if (menuArray[containerId][idx].Indent == 0) {
            var iIndent = 0;

            while (menuArray[containerId][idx].Parent != 0) {
                idx = menuArray[containerId][idx].Parent;
                iIndent = parseInt(iIndent) + parseInt(menuArray[containerId][idx].Indent);
            }

            idx = iItem;
            menuArray[containerId][idx].Indent = iIndent - iIndent;
        }

        return menuArray[containerId][idx].Indent;
    }
    else {
        if (aMenuItem[idx].Indent == 0) {
            var iIndent = 0;
            while (aMenuItem[idx].Parent != 0) {
                idx = aMenuItem[idx].Parent;
                iIndent = parseInt(iIndent) + parseInt(aMenuItem[idx].Indent);
            }
            idx = iItem;
            aMenuItem[idx].Indent = iIndent - iIndent;
        }
        return aMenuItem[idx].Indent;
    }

}

function addMenuItem(iParent, id, text, linkId, linkRef, isNode, isActive, imageURL, containerId) {

    if (document.getElementById('concertina') != null) {
        idx = menuArray[containerId].length; //menuArray[containerId].length;

        if (idx == 0) { idx = 1; } //start index from 1 not zero

        var iPos = idx;
        var iPrevious = 0;

        if (iParent != 0) {
            iPrevious = menuArray[containerId][iParent].LastChild;
            menuArray[containerId][iParent].LastChild = iPos;

            if (iPrevious == 0) {
                menuArray[containerId][iParent].FirstChild = iPos;
            }

            menuArray[containerId][iParent].IsLoaded = true;
        } else {
            iPrevious = iPos - 1
        }
        menuArray[containerId][iPos] = new menuitem(id, text, imageURL, linkId, linkRef,
	                                             iParent, 0, 0, 0, iPrevious, 0, isNode,
	                                             !isNode, isActive, containerId);
        if (iPrevious != 0) {
            menuArray[containerId][iPrevious].Next = iPos;
        }

        return iPos;
    }
    else {
        idx = aMenuItem.length;
        if (idx == 0) { idx = 1; } //start index from 1 not zero
        var iPos = idx;
        var iPrevious = 0;
        if (iParent != 0) {
            iPrevious = aMenuItem[iParent].LastChild;
            aMenuItem[iParent].LastChild = iPos;
            if (iPrevious == 0) {
                aMenuItem[iParent].FirstChild = iPos;
            }
            aMenuItem[iParent].IsLoaded = true;
        } else {
            iPrevious = iPos - 1
        }
        aMenuItem[iPos] = new menuitem(id, text, imageURL, linkId, linkRef, iParent, 0, 0, 0, iPrevious, 0, isNode, !isNode, isActive);
        if (iPrevious != 0) {
            aMenuItem[iPrevious].Next = iPos;
        }
        return iPos;
    }

}

function addLink(Ref, Target) {
    idx = aLink.length;
    var iPos = idx;
    aLink[iPos] = new menulink(Ref, Target);
    return iPos;
}

function MenuItemLevel(iItem, containerId) {

    if (document.getElementById('concertina') != null) {

        if (menuArray[containerId][iItem].Parent == 0)
            return 1;
        else
            return MenuItemLevel(menuArray[containerId][iItem].Parent, containerId) + 1;
    }
    else {

        if (aMenuItem[iItem].Parent == 0)
            return 1;
        else
            return MenuItemLevel(aMenuItem[iItem].Parent) + 1;
    }

}

function MenuItemIndexPath(iItem) {
    if (aMenuItem[iItem].Parent == 0)
        return iItem;
    else
        return MenuItemIndexPath(aMenuItem[iItem]) +
			',' + iItem;
}

function Menu(iItem, container, containerId) {
    if ($('concertina') != null) {
        // iItem +=catMenuLastItem;
        //	ShowMenuItemNo = iItem; //container
        //	curMenuItemIndex = menuArray[containerId][iItem].Parent;	
        //	container.innerHTML='<ul width="100%" id="divc' + catdivType + '">' + MenuHTML(iItem,null) + '</ul>';
        //	catdivType+=1;
        //	catMenuLastItem=menuArray[containerId].length-1;
        ShowMenuItemNo = iItem; //container
        curMenuItemIndex = menuArray[containerId][iItem].Parent;
        try {
            if (container == null) container = $('catHolder' + containerId);
            container.innerHTML = '<ul width="100%" id="div1">' + MenuHTML(iItem, null, containerId) + '</ul>';
        }
        catch (ex) {
            //alert('Menu.js func Menu: ' + ex.message);
        }
    }
    else {
        // iItem +=catMenuLastItem;
        //	ShowMenuItemNo = iItem; //container
        //	curMenuItemIndex = aMenuItem[iItem].Parent;	
        //	container.innerHTML='<ul width="100%" id="divc' + catdivType + '">' + MenuHTML(iItem,null) + '</ul>';
        //	catdivType+=1;
        //	catMenuLastItem=aMenuItem.length-1;
        ShowMenuItemNo = iItem; //container
        curMenuItemIndex = aMenuItem[iItem].Parent;
        container.innerHTML = '<ul width="100%" id="div1">' + MenuHTML(iItem, null) + '</ul>';
    }


}

function MenuHTML(iItem, container, containerId) {
    //var iParent = iItem;
    var str = '';

    if ($('concertina') != null) {
        idx = iItem;
        iLevel = MenuItemLevel(iItem, containerId);
        
        if (iLevel != 1) {

            if (menuArray[containerId][iItem].IsActive || admin) {
                str = str + MenuItemHTML(iItem, containerId)

                if (iItem > catMenuLastItem) {
                    str = str + '<div width="100%" ID="div' + iItem + '" STYLE="display:none">';
                }

            }
        }

        if (menuArray[containerId][idx].FirstChild != 0) {

            for (var find = menuArray[containerId][idx].FirstChild; find != 0; find = menuArray[containerId][find].Next) {
                str = str + MenuHTML(find, null, containerId);
            }
        }
        if (iLevel != 1) {

            if (iItem > catMenuLastItem) {
                str = str + '</div>';
            }
        }
    }
    else {
        idx = iItem;
        iLevel = MenuItemLevel(iItem);


        if (iLevel != 1) {
            if (aMenuItem[iItem].IsActive || admin) {
                str = str + MenuItemHTML(iItem)
                if (iItem > catMenuLastItem) { str = str + '<div width="100%" ID="div' + iItem + '" STYLE="display:none">'; }
            }
        }
        if (aMenuItem[idx].FirstChild != 0) {
            for (var find = aMenuItem[idx].FirstChild; find != 0; find = aMenuItem[find].Next) {
                str = str + MenuHTML(find, null);
            }
        }
        if (iLevel != 1) {
            if (iItem > catMenuLastItem) {
                str = str + '</div>';
            }
        }
    }


    return str;
}

function getMenuHTML(iItem, container) {
    iLevel = MenuItemLevel(iItem);
    var str = '';

    if (iLevel != 1) {
        if (aMenuItem[iItem].IsActive || admin) {
            str = str + MenuItemHTML(iItem)
            if (iItem > catMenuLastItem) { str = str + '<div width="100%" ID="div' + iItem + '" STYLE="display:none">'; }
        }
    }
    if (aMenuItem[idx].FirstChild != 0) {
        for (var find = aMenuItem[idx].FirstChild; find != 0; find = aMenuItem[find].Next) {
            str = str + getMenuHTML(find, null);
        }
    }
    if (iLevel != 1) {
        if (iItem > catMenuLastItem) {
            str = str + '</div>';
        }
    }
}


function getConcertinaMenuHTML(iItem, container, containerId) {
    iLevel = MenuItemLevel(iItem, containerId);
    var str = '';

    if (iLevel != 1) {

        if (menuArray[containerId][iItem].IsActive || admin) {
            str = str + MenuItemHTML(iItem, containerId)

            if (iItem > catMenuLastItem) {
                str = str + '<div width="100%" ID="div' + iItem + '" STYLE="display:none">';
            }

        }
    }

    if (menuArray[containerId][idx].FirstChild != 0) {

        for (var find = menuArray[containerId][idx].FirstChild; find != 0; find = menuArray[containerId][find].Next) {
            str = str + getConcertinaMenuHTML(find, null, containerId);
        }
    }
    if (iLevel != 1) {

        if (iItem > catMenuLastItem) {
            str = str + '</div>';
        }
    }
}

function InsertChildHTML(iItem, control, container, showItem, containerId) {
    idx = iItem;

    if (document.getElementById('concertina') != null) {
        if (showItem && (menuArray[containerId][iItem].IsActive || admin)) {
            control.innerHTML = control.innerHTML + MenuItemHTML(iItem); // + '<div width="100%" ID="div'+iItem+'" STYLE="display:none">';
        }

        if (menuArray[containerId][idx].FirstChild != 0) {
            var childDiv;

            if (containerId == 0) {
                childDiv = GetElement(container, 'ndiv' + iItem);
            } else {
                childDiv = GetElement(container, 'cat' + containerId + 'ndiv' + iItem);
            }

            for (var find = menuArray[containerId][idx + cFirstChild]; find != 0; find = menuArray[containerId][find].Next) {
                InsertChildHTML(find, childDiv, container, true);
            }
        }

        if (showItem) {
            control.innerHTML = control.innerHTML;
        } //+ '</div>';
    }
    else {
        if (showItem && (aMenuItem[iItem].IsActive || admin)) {
            control.innerHTML = control.innerHTML + MenuItemHTML(iItem); // + '<div width="100%" ID="div'+iItem+'" STYLE="display:none">';
        }

        if (aMenuItem[idx].FirstChild != 0) {
            var childDiv = GetElement(container, 'ndiv' + iItem);
            for (var find = aMenuItem[idx + cFirstChild]; find != 0; find = aMenuItem[find].Next) {
                InsertChildHTML(find, childDiv, container, true);
            }
        }
        if (showItem) control.innerHTML = control.innerHTML; //+ '</div>';
    }

}

function MenuItemHTML(iItem, containerId) {

    if (document.getElementById('concertina') != null) {
        if (iItem > catMenuLastItem) {
            idx = iItem;
            s_Validation = new String(',' + sHiddenMenuItems + ',');

            if (s_Validation.indexOf(',' + menuArray[containerId][idx].Id + ',') > -1) {

                if (menuArray[containerId][idx] == 0) {
                    return '';
                }

            }

            var title = menuArray[containerId][idx].Text;
            var image = menuArray[containerId][idx].Image;
            var menuitemid = menuArray[containerId][idx].Id;
            text = menuArray[containerId][idx].Text;
            iLevel = MenuItemLevel(iItem, containerId);

            if (text.length > iTitleChars - (iLevel * 3)) {
                text = text.substring(0, iTitleChars - (iLevel * 3)) + '...';
            }

            iLinkId = menuArray[containerId][idx].LinkId;
            iLinkIndex = iLinkId;

            if (iLevel == 1) {
                return '';
            }

            iIndent = (iLevel - 2) * 13;
            iRemainingWidth = iMenuWidth - iIndent;

            sCSSClass = 'menuLevel' + (iLevel - 1);

            if (menuArray[containerId][iItem].IsActive == false) sCSSClass = sCSSClass + ' style="color:gray"';

            sHRef = '<A id="n' + iItem + '" name="n' + iItem + '" class="menuItem" href="#" ';

            if (setTheory || menuArray[containerId][iItem].IsNode == 0) {
                sHRef += ' onclick="javascript: return nodeClick(' + iItem + ', ' + iLinkId + ', ';

                if (aLink[iLinkIndex].Ref == '') {
                    sHRef = 'window';
                } else {
                    sHRef += aLink[iLinkIndex].Target;
                }

                sHRef += ', window, ' + containerId + ')" ';
            } else {
                sHRef += ' onclick="javascript: return toggleNode(' + iItem + ', document, ' + containerId + ')" ';
            }

            sHRef += ' onMouseOver="return sSts(this);"';
            sHRef += ' onMouseDown="return sSts(this);"';
            sHRef += ' onMouseUp="return cSts();"';
            sHRef += ' onMouseOut="return cSts();"';
            sHRef += ' title="' + title + '">';

            if (image == null) {
                sHRef += text;
            } else {
                sHRef += '<img onmouseover="Fade(this,60,10,5);" onmouseout="Fade(this,100,10,5);" style="FILTER: alpha(opacity=100)" src="' + image + '">';
            }

            sHRef += '</a>';

            sMenu = '<li ';

            sMenu += ' STYLE="display:block"';
            sMenu += ' class="' + sCSSClass + '" >';

            if (setTheory && menuArray[containerId][iItem].IsNode == 1) {

                if (containerId == 0) {
                    sMenu += '<span id="div' + iItem + '" class="expand" ';
                } else {
                    sMenu += '<span id="cat' + containerId + 'div' + iItem + '" class="expand" ';
                }
                alert('containerId: ' + containerId);
                sMenu += ' onclick="javascript: return toggleNode(' + iItem + ', document, ' + containerId + ')"';
                sMenu += '>&nbsp;</span>';
            }

            sMenu += '<span>' + sHRef;
            if (menuArray[containerId][iItem].IsNode == 1) {

                if (containerId == 0) {
                    sMenu += '<ul id="ndiv' + iItem + '" style="display:none;"></ul>';
                } else {
                    sMenu += '<ul id="cat' + containerId + 'ndiv' + iItem + '" style="display:none;"></ul>';
                }
            }
            sMenu += '</span></li>';

            //alert(sMenu);

            return sMenu;
        }
        else {
            return '';
        }
    }
    else {
        if (iItem > catMenuLastItem) {
            idx = iItem;
            s_Validation = new String(',' + sHiddenMenuItems + ',');
            if (s_Validation.indexOf(',' + aMenuItem[idx].Id + ',') > -1) {
                if (aMenuItem[idx] == 0) return '';
            }
            var title = aMenuItem[idx].Text;
            var image = aMenuItem[idx].Image;
            var menuitemid = aMenuItem[idx].Id;
            text = aMenuItem[idx].Text;
            iLevel = MenuItemLevel(iItem);
            if (text.length > iTitleChars - (iLevel * 3)) text = text.substring(0, iTitleChars - (iLevel * 3)) + '...';
            iLinkId = aMenuItem[idx].LinkId;
            iLinkIndex = iLinkId;
            if (iLevel == 1) return '';
            iIndent = (iLevel - 2) * 13;
            iRemainingWidth = iMenuWidth - iIndent;

            sCSSClass = 'menuLevel' + (iLevel - 1);

            if (aMenuItem[iItem].IsActive == false) sCSSClass = sCSSClass + ' style="color:gray"';

            sHRef = '<A id="n' + iItem + '" name="n' + iItem + '" class="menuItem" href="#" ';

            if (setTheory || aMenuItem[iItem].IsNode == 0) {
                sHRef += ' onclick="javascript: return nodeClick(' + iItem + ', ' + iLinkId + ', ';
                if (aLink[iLinkIndex].Ref == '') {
                    sHRef = 'window';
                } else {
                    sHRef += aLink[iLinkIndex].Target;
                }
                sHRef += ', window)" ';
            } else {
                sHRef += ' onclick="javascript: return toggleNode(' + iItem + ', document)" ';
            }

            sHRef += ' onMouseOver="return sSts(this);"';
            sHRef += ' onMouseDown="return sSts(this);"';
            sHRef += ' onMouseUp="return cSts();"';
            sHRef += ' onMouseOut="return cSts();"';
            sHRef += ' title="' + title + '">';

            if (image == null) {
                sHRef += text;
            } else {
                sHRef += '<img onmouseover="Fade(this,60,10,5);" onmouseout="Fade(this,100,10,5);" style="FILTER: alpha(opacity=100)" src="' + image + '">';
            }
            sHRef += '</a>';

            sMenu = '<li ';

            sMenu += ' STYLE="display:block"';
            sMenu += ' class="' + sCSSClass + '" >';

            if (setTheory && aMenuItem[iItem].IsNode == 1) {
                sMenu += '<span id="div' + iItem + '" class="expand" ';
                sMenu += ' onclick="javascript: return toggleNode(' + iItem + ', document)"';
                sMenu += '>&nbsp;</span>';
            }

            sMenu += '<span>' + sHRef;
            if (aMenuItem[iItem].IsNode == 1) {
                sMenu += '<ul id="ndiv' + iItem + '" style="display:none;"></ul>';
            }
            sMenu += '</span></li>';

            //alert(sMenu);

            return sMenu;
        }
        else {
            return '';
        }
    }

}

function inMenuItem(iItem, cur_item, containerId) {
    if (document.getElementById('concertina') != null) {
        if (iItem == cur_item)
            return true;
        else {
            if (cur_item == 0)
                return false;
            else
                return inMenuItem(iItem, menuArray[containerId][cur_item], containerId);
        }
    }
    else {
        if (iItem == cur_item)
            return true;
        else {
            if (cur_item == 0)
                return false;
            else
                return inMenuItem(iItem, aMenuItem[cur_item]);
        }
    }

}

function nodeClick(node_num, linkId, target, container, containerId) {
    if (breakout != null) {
        try {
            breakout(GetElement(container, 'n' + node_num));
        } catch (e) {
        }
    }
    oTargetMenu = container;
    var node = GetElement(container, 'n' + node_num);

    if (document.getElementById('concertina') != null) {
        	if (iCurMenuItem!=0){
        		if (setTheory){
        			GetElement(container,'n' + iCurMenuItem).className = 'menuItem MenuVisited';
        		}else{
        			GetElement(container,'n' + iCurMenuItem).className = 'menuItem MenuUnselected';
        		}
        	}
        	node.className = 'menuItem MenuSelected';
        iCurMenuItem = node_num;
        if (node.style.color == 'gray') return false;
        idx = node_num;
        text = menuArray[containerId][idx].Text;
        iNodeId = menuArray[containerId][idx].Id;
        linkRef = menuArray[containerId][idx].Reference;
        iHRefId = linkId;
        //if (menuArray[containerId][idx].IsNode == 0) {
        sURL = aLink[iHRefId].Ref;
        if (sURL.indexOf('mailto:') != 0) {
            if (sURL.indexOf('?') == -1)
                sURL += '?';
            else
                sURL += '&';
            sURL += 'Id=' + iNodeId + '&Ref=' + linkRef;
            top.showprocessing();
        }
        target.location.href = sURL;
        //} else {
        //	toggleNode(node_num, container);
        //}	

        return false;
    }
    else {
        	if (iCurMenuItem!=0){
        		if (setTheory){
        			GetElement(container,'n' + iCurMenuItem).className = 'menuItem MenuVisited';
        		}else{
        			GetElement(container,'n' + iCurMenuItem).className = 'menuItem MenuUnselected';
        		}
        	}
        	node.className = 'menuItem MenuSelected';
        iCurMenuItem = node_num;
        if (node.style.color == 'gray') return false;
        idx = node_num;
        text = aMenuItem[idx].Text;
        iNodeId = aMenuItem[idx].Id;
        linkRef = aMenuItem[idx].Reference;
        iHRefId = linkId;
        //if (aMenuItem[idx].IsNode == 0) {
        sURL = aLink[iHRefId].Ref;
        if (sURL.indexOf('mailto:') != 0) {
            if (sURL.indexOf('?') == -1)
                sURL += '?';
            else
                sURL += '&';
            sURL += 'Id=' + iNodeId + '&Ref=' + linkRef;
            top.showprocessing();
        }
        target.location.href = sURL;
        //} else {
        //	toggleNode(node_num, container);
        //}	

        return false;
    }

}



function toggleNode(node_num, container, containerId) {
    if (breakout != null) {
        try {
            breakout(GetElement(container, 'n' + node_num));
        } catch (e) {
        }
    }
    
    oTargetMenu = container;

    if (document.getElementById('concertina') != null) {
        var Node;
        var img;

        if (containerId == 0) {
            Node = GetElement(container, 'ndiv' + node_num);
            img = GetElement(container, 'div' + node_num);
        } else {
            Node = GetElement(container, 'cat' + containerId + 'ndiv' + node_num);
            img = GetElement(container, 'cat' + containerId + 'div' + node_num);
        }

        if (Node.style['display'] == "none") {
            var menuDiv = Node.parentNode;

            while (menuDiv.id.indexOf('category') != 0) {
                menuDiv = menuDiv.parentNode;
            }

            hideExpandedMenus(Node.parentNode.parentNode.parentNode);

            var menuElement = Node.parentNode;
            var elementxCoord = menuElement.offsetTop;
            menuDiv.style['top'] = -elementxCoord + 'px';
            var menuUpButton = GetElement(container, 'category' + containerId + 'up')
            menuUpButton.style['display'] = "block";

            idx = node_num;
            if (menuArray[containerId][idx].IsLoaded) {
                Node.style['display'] = "block";
                if (setTheory) { img.className = img.className.replace('expand', 'shrink'); }
            } else {
                if (setTheory) {
                    img.className = img.className.replace('expand', 'processing');
                }

                if (admin) {
                    neotekscript('/catalog/menu/menuajax.aspx?admin=1&parentNode=' + node_num + '&Id=' + menuArray[containerId][idx].Id +
				             '&TypeId=' + top.iCurMenuType + '&containerId=' + containerId);
                } else {
                    neotekscript('/catalog/menu/menuajax.aspx?parentNode=' + node_num + '&Id=' + menuArray[containerId][idx].Id +
				             '&TypeId=' + top.iCurMenuType + '&containerId=' + containerId);
                }
            }
        } else {
            Node.style['display'] = "none";
            if (setTheory) { img.className = img.className.replace('shrink', 'expand'); }
        }
        try {
            categoryscroller.move(0);
        } catch (e) { }

        return false;
    }
    else {
        var Node = GetElement(container, 'ndiv' + node_num);
        var img = GetElement(container, 'div' + node_num);
        var menuDiv = Node.parentNode;

        while (menuDiv.id.indexOf('category') != 0) {
            menuDiv = menuDiv.parentNode;
        }

        if (Node.style['display'] == "none") {
            idx = node_num;
            if (aMenuItem[idx].IsLoaded) {
                Node.style['display'] = "block";
                if (setTheory) { img.className = img.className.replace('expand', 'shrink'); }
            } else {
                if (setTheory) {
                    img.className = img.className.replace('expand', 'processing');
                }

                if (admin) {
                    neotekscript('/catalog/menu/menuajax.aspx?admin=1&parentNode=' + node_num + '&Id=' + aMenuItem[idx].Id + '&TypeId=' + top.iCurMenuType);
                } else {
                    neotekscript('/catalog/menu/menuajax.aspx?parentNode=' + node_num + '&Id=' + aMenuItem[idx].Id + '&TypeId=' + top.iCurMenuType);
                }
            }
        } else {
            Node.style['display'] = "none";
            if (setTheory) { img.className = img.className.replace('shrink', 'expand'); }
        }
        try {
            categoryscroller.move(0);
        } catch (e) { }

        return false;
    }

}


function NodeHTML(iParent, sHTML, containerId) {

    if (document.getElementById('concertina') != null) {
        if (iParent != 0) {
            for (var find = menuArray[containerId][iParent].FirstChild; find != 0; find = menuArray[containerId][find].Next) {
                if (menuArray[containerId][find].IsActive || admin) {
                    sHTML = sHTML + MenuItemHTML(find, containerId) //+ '<ul ID="ndiv'+find+'" STYLE="display:none"></ul>';
                }
            }
            menuArray[containerId][iParent].IsLoaded = true;
        }
    }
    else {
        if (iParent != 0) {
            for (var find = aMenuItem[iParent].FirstChild; find != 0; find = aMenuItem[find].Next) {
                if (aMenuItem[find].IsActive || admin) {
                    sHTML = sHTML + MenuItemHTML(find) //+ '<ul ID="ndiv'+find+'" STYLE="display:none"></ul>';
                }
            }
            aMenuItem[iParent].IsLoaded = true;
        }
    }

    return sHTML;
}

function GetElement(container, id) {
    //	if (container!=null){                       NSM 270907 ??
    //		return container.document.getElementById(id);
    //	}else{
    return document.getElementById(id);
    //	}
}

function insertChildNodes(iParent, container, containerId) {

    if (document.getElementById('concertina') != null) {
        //if (container==null) container=oTargetMenu;
        var sContent = NodeHTML(iParent, '', containerId);
        Node = GetElement(null, 'cat' + containerId + 'ndiv' + iParent);
        setText(Node, sContent);
        Node.style['display'] = "block";
        if (setTheory) {
            var img = GetElement(container, 'cat' + containerId + 'div' + iParent);
            img.className = img.className.replace('processing', 'shrink');
        }
        try {
            categoryscroller.move(0);
        } catch (e) { }
    }
    else {
        //if (container==null) container=oTargetMenu;
        var sContent = NodeHTML(iParent, '');
        Node = GetElement(null, 'ndiv' + iParent);
        setText(Node, sContent);
        Node.style['display'] = "block";
        if (setTheory) {
            var img = GetElement(container, 'div' + iParent);
            img.className = img.className.replace('processing', 'shrink');
        }
        try {
            categoryscroller.move(0);
        } catch (e) { }
    }

}

function closeNodes() {

    try {
        for (var i = 0; i < aMenuItem.length; i++) {
            var Node = GetElement(document, 'ndiv' + i);
            var img = GetElement(document, 'div' + i);
            if (Node) { Node.style['display'] = "none"; }
            if (setTheory) {
                if (img) { img.className = img.className.replace('shrink', 'expand'); }
            }
        }
        categoryscroller.move(0);
    } catch (e) { }

}

function hideExpandedMenus(menuRoot) {
    var menuToHide;

    for (i = 0; i < menuRoot.childNodes.length; ++i) {

        if (menuRoot.childNodes[i].tagName == 'LI') {
            menuToHide = menuRoot.childNodes[i].childNodes[0].childNodes[1];

            if (typeof (menuToHide) != 'undefined') {
                menuToHide.style['display'] = 'none';
            }
        }

    }
}

