// Node object

function click(menuId)
{
	e.o(menuId);

		 if(menuId == "1")
		 {
			  hetconcept.style.visibility = 'visible';
			  onzeaanpak.style.visibility = 'hidden';
			  voorbedrijven.style.visibility = 'hidden';
		 }

		 if(menuId == "4")
		 {
			  hetconcept.style.visibility = 'hidden';
			  onzeaanpak.style.visibility = 'visible';
			  voorbedrijven.style.visibility = 'hidden';
		 }

		 if(menuId == "7")
		 {
			  hetconcept.style.visibility = 'hidden';
			  onzeaanpak.style.visibility = 'hidden';
			  voorbedrijven.style.visibility = 'visible';
		 }
}

function lftNode(id, pid, name, url, title, target, icon, iconOpen, open) {
	this.id = id;
	this.pid = pid;
	this.name = name;
	this.url = url;
	this.title = title;
	this.target = target;
	this.icon = icon;
	this.iconOpen = iconOpen;
	this._io = open || false;
	this._is = false;
	this._ls = false;
	this._hc = false;
	this._ai = 0;
	this._p;
};

// Tree object
function lftTree(objName) {
	this.config = {
		target		: null,
		folderLinks	: true,
		useSelection	: true,
		useCookies	: true,
		useLines	: false,
		useIcons	: false,
		useStatusText	: false,
		closeSameLevel	: false,
		inOrder		: true
	}
	this.icon = {
		root			: 'images/spacer.gif',
		folder			: 'images/spacer.gif',
		folderOpen		: 'images/spacer.gif',
		node			: 'images/spacer.gif',
		empty			: 'images/spacer.gif',
		line			: 'images/spacer.gif',
		join			: 'images/spacer.gif',
		joinBottom		: 'images/spacer.gif',
		plus			: 'images/spacer.gif',
		plusBottom		: 'images/spacer.gif',
		minus			: 'images/spacer.gif',
		minusBottom		: 'images/spacer.gif',
		nlPlus			: 'images/spacer.gif',
		nlMinus			: 'images/spacer.gif'
	};
	this.obj = objName;
	this.aNodes = [];
	this.aIndent = [];
	this.root = new lftNode(-1);
	this.selectedNode = null;
	this.selectedFound = false;
	this.completed = false;
};

// Adds a new node to the node array
lftTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {
	this.aNodes[this.aNodes.length] = new lftNode(id, pid, name, url, title, target, icon, iconOpen, open);
};

// Open/close all nodes
lftTree.prototype.openAll = function() {
	this.oAll(true);
};
lftTree.prototype.closeAll = function() {
	this.oAll(false);
};

// Outputs the tree to the page
lftTree.prototype.toString = function() {
	var str = '<div class="lftTree">\n';
	if (document.getElementById) {
		if (this.config.useCookies) this.selectedNode = this.getSelected();
		str += this.addNode(this.root);
	} else str += 'Browser not supported.';
	str += '</div>';
	if (!this.selectedFound) this.selectedNode = null;
	this.completed = true;
	return str;
};

// Creates the tree structure
lftTree.prototype.addNode = function(pNode) {
	var str = '';
	var n=0;
	if (this.config.inOrder) n = pNode._ai;
	for (n; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == pNode.id) {
			var cn = this.aNodes[n];
			cn._p = pNode;
			cn._ai = n;
			this.setCS(cn);
			if (!cn.target && this.config.target) cn.target = this.config.target;
			if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
			if (!this.config.folderLinks && cn._hc) cn.url = null;
			if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
					cn._is = true;
					this.selectedNode = n;
					this.selectedFound = true;
			}
			str += this.node(cn, n);
			if (cn._ls)
			{
				if(cn.pid == 0)
				{
					//str +='<img src="images/line.gif" width="162" height="2" />';
				}
				break;
			}
		}
	}
	return str;
};

// Creates the node icon, url and text
lftTree.prototype.node = function(node, nodeId) {

	var imgNam;
	var prtId = new String(node.pid);
	prtId = prtId.substring(0,1);

	var imgNamL;
	var imgPar;
	var extPar;

	if(prtId == "-")
	{
		extPar =  '';
		imgNam = "images/spacer.gif";
	}

	if(prtId == 0)
	{
		imgNam = "images/spacer.gif";
		extPar =  '';
	}

	if(prtId == 1)
	{
		imgNam = "images/spacer.gif";
		extPar =  '';
	}
	if(prtId == 2)
	{
		imgNam = "images/spacer.gif";
		extPar =  '';
	}

	  selImgPath = "";
	  selImgName = "";	   	
	  	  
	   switch(nodeId)
	   {	    
		 case 1:
	      selImgPath = "images/home-o.gif";
	      selImgName = "Image1";
	     break;
		 
		 case 2:
	      selImgPath = "images/about-us-o.gif";
	      selImgName = "Image2";
	     break;
	     
	     case 3:
	      selImgPath = "images/product&services-o.gif";
	      selImgName = "Image3";
	     break;
	     
	     case 4:
	      selImgPath = "images/motorola1.gif";
	      selImgName = "Image4";
	     break;
	     
	     case 5:
	      selImgPath = "images/vhf.gif";
	      selImgName = "Image5";
	     break;
	     
	     case 6:
	      selImgPath = "images/base.gif";
	      selImgName = "Image6";
	     break;   
	     
	     case 7:
	      selImgPath = "images/handled.gif";
	      selImgName = "Image7";
	     break;
		 
		case 8:
	      selImgPath = "images/uhf.gif";
	      selImgName = "Image8";
	     break;
		 
		 case 9:
	      selImgPath = "images/vertex1.gif";
	      selImgName = "Image9";	      
	     break;
		 		
		case 10:
	      selImgPath = "images/vhf-uhf.gif";
	      selImgName = "Image10";
	     break; 
		 
		 case 11:
	      selImgPath = "images/base.gif";
	      selImgName = "Image11";
	     break; 	
		 
		 case 12:
	      selImgPath = "images/handled.gif";
	      selImgName = "Image12";
	     break; 
		 
		 case 13:
	      selImgPath = "images/uhf.gif";
	      selImgName = "Image13";
	     break; 
		 
		 case 14:
	      selImgPath = "images/hf.gif";
	      selImgName = "Image14";
	     break; 
		 
		  case 15:
	      selImgPath = "images/airo-vhf.gif";
	      selImgName = "Image15";
	     break; 
		 
		 case 16:
	      selImgPath = "images/marine.gif";
	      selImgName = "Image16";
	     break; 

		 case 17:
	      selImgPath = "images/base.gif";
	      selImgName = "Image17";
	     break; 

		 case 18:
	      selImgPath = "images/handled.gif";
	      selImgName = "Image18";
	     break; 

		 case 19:
	      selImgPath = "images/repetors.gif";
	      selImgName = "Image19";
	     break; 
 
		  case 20:
	      selImgPath = "images/wireless-data-modem.gif";
	      selImgName = "Image20";
	     break; 
		 
		  case 21:
	      selImgPath = "images/canopy2.gif";
	      selImgName = "Image21";
	     break; 
		 
		 case 22:
	      selImgPath = "images/alverion.gif";
	      selImgName = "Image22";
	     break; 
		 
		 case 23:
	      selImgPath = "images/icom.gif";
	      selImgName = "Image23";
	     break; 
		 
		 case 24:
	      selImgPath = "images/call-management-systems.gif";
	      selImgName = "Image24";
	     break; 
		 
		 case 25:
	      selImgPath = "images/accesories1.gif";
	      selImgName = "Image25";
	     break; 

		case 26:
	      selImgPath = "images/services-o.gif";
	      selImgName = "Image26";
	     break; 

		 case 27:
	      selImgPath = "images/enquiry-o.gif";
	      selImgName = "Image27";
	     break; 

		 case 28:
	      selImgPath = "images/contact-us-o.gif";
	      selImgName = "Image28";
	   break;
		
		case 29:
	      selImgPath = "images/handheld-radio.gif";
	      selImgName = "Image29";
	     break;

		case 30:
	      selImgPath = "images/uhf-mobile-station.gif";
	      selImgName = "Image30";
	     break;

		case 31:
	      selImgPath = "images/uhf-handheld.gif";
	      selImgName = "Image31";
	     break;

		case 32:
	      selImgPath = "images/vertel.gif";
	      selImgName = "Image32";
	     break;
		 
	   }	   
	var str ='<div class="lftNode" style="vertical-align:middle;'+extPar+'text-align:left;background-image:url('+imgNam+')">'+this.indent(node, nodeId);
	//alert("node.url"+" "+node.url);
	//alert("nodeID"+" "+nodeId);
	//alert("title"+" "+node.name);
	if (node.url)
	{
		str +='<a id="j' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
		if (node.title) str += ' title="' + node.title + '"';
		if (node.target) str += ' target="' + node.target + '"';
		if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;"';
		if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
		str +=' onclick=""';
		str +='onMouseOver="MM_swapImage(\''+selImgName+'\',\'\',\''+selImgPath+'\',1)" onMouseOut="MM_swapImgRestore();">';
	}
	else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
		str +='<a href="javascript:' + this.obj + '.o(' + nodeId + '); onMouseOver="MM_swapImage(\''+selImgName+'\',\'\',\''+selImgPath+'\',1)" onMouseOut="MM_swapImgRestore();">';
	str += " " + node.name;
	if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str +='</a>';
	str +='</div>';
	//alert("node._hc"+" "+node._hc);
	//if (node._hc) {
		str +='<div id="l' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
		str += this.addNode(node);
		str +='</div>';
	//}
	this.aIndent.pop();
	//alert(str);
	return str;
};

// Adds the empty and line icons
lftTree.prototype.indent = function(node, nodeId) {


	var prtId = new String(node.pid);
	prtId = prtId.substring(0,1);


	var imgNamL;
	var imgPar;

	imgNamL = "images/spacer.gif";

	var str = '';
	if (this.root.id != node.pid) {
		for (var n=0; n<this.aIndent.length; n++)
			str +='';
		(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
		if (node._hc) {
			str +='';
			str +='';
		} else str += '';
	}
	//alert(str);
	return str;
};

// Checks if a node has any children and if it is the last sibling
lftTree.prototype.setCS = function(node) {
	var lastId;
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == node.id) node._hc = true;
		if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
	}
	if (lastId==node.id) node._ls = true;
};

// Returns the selected node
lftTree.prototype.getSelected = function() {
	var sn = this.getCookie('cs' + this.obj);
	return (sn) ? sn : null;
};

// Highlights the selected node
lftTree.prototype.s = function(id) 
{
	if (!this.config.useSelection) return;
	var cn = this.aNodes[id];
	if (cn._hc && !this.config.folderLinks) return;
	if (this.selectedNode != id) {
		if (this.selectedNode || this.selectedNode==0) {
			eOld = document.getElementById("s" + this.obj + this.selectedNode);
			eOld.className = "node";
		}
		eNew = document.getElementById("s" + this.obj + id);
		eNew.className = "nodeSel";
		this.selectedNode = id;
		if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
	}
};

// Toggle Open or close
lftTree.prototype.o = function(id) {
	var cn = this.aNodes[id];
	this.nodeStatus(!cn._io, id, cn._ls,cn.pid);
	cn._io = !cn._io;
	if (this.config.closeSameLevel) this.closeLevel(cn);
	if (this.config.useCookies) this.updateCookie();
};

// Open or close all nodes
lftTree.prototype.oAll = function(status) {
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
			this.nodeStatus(status, n, this.aNodes[n]._ls, this.aNodes[n].pid)
			this.aNodes[n]._io = status;
		}
	}
	if (this.config.useCookies) this.updateCookie();
};

// Opens the tree to a specific node
lftTree.prototype.openTo = function(nId, bSelect, bFirst) {
	if (!bFirst) {
		for (var n=0; n<this.aNodes.length; n++) {
			if (this.aNodes[n].id == nId) {
				nId=n;
				break;
			}
		}
	}
	var cn=this.aNodes[nId];
	if (cn.pid==this.root.id || !cn._p) return;
	cn._io = true;
	cn._is = bSelect;
	if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls, cn.pid);
	if (this.completed && bSelect) this.s(cn._ai);
	else if (bSelect) this._sn=cn._ai;
	this.openTo(cn._p._ai, false, true);
};

// Closes all nodes on the same level as certain node
lftTree.prototype.closeLevel = function(node) {
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
			this.nodeStatus(false, n, this.aNodes[n]._ls, this.aNodes[n].pid);
			this.aNodes[n]._io = false;
			this.closeAllChildren(this.aNodes[n]);
		}
	}
}

// Closes all children of a node
lftTree.prototype.closeAllChildren = function(node) {
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
			if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls,this.aNodes[n].pid);
			this.aNodes[n]._io = false;
			this.closeAllChildren(this.aNodes[n]);
		}
	}
}

// Change the status of a node(open or closed)
lftTree.prototype.nodeStatus = function(status, id, bottom, ppid) {
	eDiv	= document.getElementById('l' + this.obj + id);
	eJoin	= document.getElementById('j' + this.obj + id);
	
	//alert("eDiv"+" "+eDiv);
	//alert("eJoin"+" "+eJoin);

	var imgNamL;
	var prtId = new String(ppid);
	

	prtId = prtId.substring(0,1);

	if(prtId == 0)
	{
		imgNamL = "images/spacer.gif";
	}

	if(prtId == 1)
	{
		imgNamL = "images/spacer.gif";
	}

	if(prtId == 2)
	{
		imgNamL = "images/spacer.gif";
	}

	eJoin.src = imgNamL;
	eDiv.style.display = (status) ? 'block': 'none';
};


// [Cookie] Clears a cookie
lftTree.prototype.clearCookie = function() {
	var now = new Date();
	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
	this.setCookie('co'+this.obj, 'cookieValue', yesterday);
	this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};

// [Cookie] Sets value in a cookie
lftTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
};

// [Cookie] Gets a value from a cookie
lftTree.prototype.getCookie = function(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
};

// [Cookie] Returns ids of open nodes as a string
lftTree.prototype.updateCookie = function() {
	var str = '';
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
			if (str) str += '.';
			str += this.aNodes[n].id;
		}
	}
	this.setCookie('co' + this.obj, str);
};

// [Cookie] Checks if a node id is in a cookie
lftTree.prototype.isOpen = function(id) {
	var aOpen = this.getCookie('co' + this.obj).split('.');
	for (var n=0; n<aOpen.length; n++)
		if (aOpen[n] == id) return true;
	return false;
};

// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
	Array.prototype.push = function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
};
if (!Array.prototype.pop) {
	Array.prototype.pop = function array_pop() {
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
};
