
function cmDrawTree (Tree) {	
	var str = '<ul id="mainlevel">';
	var i;
	var item;
	var hasChild;
	var link = null, target = '_self';

	var itemtext = '';
	
	for (i = 0; i < Tree.length; ++i) {
		item = Tree[i];
		if (!item) continue;
		
		itemtext = item[1].replace("<b>",'').replace("</b>","").replace("&nbsp;",'');
		link = (item.length > 2) ? item[2] : '';
		target = (item.length > 3) ? item[3] : '_self';
		str += '<li>';
		
		hasChild = (item.length > 5);
		activeStr = item[0]==1 ? 'id="active_menu" ' : '';
		
		if(hasChild) {
			classStr = item[0]==1 ? 'mainlevel_current' : 'mainlevel_active';
			str += '<a ' + activeStr + 'class="' + classStr + '" href="' + link + '" target="' + target + '">' + itemtext + '</a>';
			str += cmDrawTreeLeaves(item);
		} else {
			classStr = item[0]==1 ? 'mainlevel_current' : 'mainlevel';
			str += '<a ' + activeStr + 'class="' + classStr + '" href="' + link + '" target="' + target + '">' + itemtext + '</a>';
		}
		str += '</li>';
	}
	str += '</ul>';
	return str;
}


function cmDrawTreeLeaves (Tree) {	
	var str = '<ul>';
	var i;
	var item;
	var hasChild;
	var link = null, target = '_self';
	
	for (i = 5; i < Tree.length; ++i) {
		item = Tree[i];
		if (!item) continue;
		
		itemtext = item[1].replace("<b>",'').replace("</b>","").replace("&nbsp;",'');
		link = (item.length > 2) ? item[2] : '';
		target = (item.length > 3) ? item[3] : '_self';
		str += '<li>';

		hasChild = (item.length > 5);
		activeStr = item[0]==1 ? 'id="active_menu" ' : '';
		classStr = item[0]==1 ? 'sublevel_current' : 'sublevel';
		
		if(hasChild) {
			str += '<a ' + activeStr + 'class="sublevel_active" href="' + link + '" target="' + target + '">' + itemtext + '</a>';
			str += cmDrawTreeLeaves(item);
		} else {
			
			str += '<a ' + activeStr + 'class="' + classStr + '" href="' + link + '" target="' + target + '">' + itemtext + '</a>';
		}
		str += '</li>';
	}
	str += '</ul>';
	return str;
}
