function genmenu( aId )
{
	for (var i in Rubs) Rubs[i].isOpen = false;
	for (var i in Rubs) if (Rubs[i].ParentID == RootId && ( Rubs[i].SubRubCnt + Rubs[i].ContentCnt) > 0)				
	{
		Rubs[i].isOpen = (Rubs[i].RubID == aId);
		if ( !Rubs[i].isOpen ) Rubs[i].isOpen = initSels((typeof(aId)=='undefined' ? RootId : aId), Rubs[i].RubID);
		if (Rubs[i].isOpen) break;
	}
	var tbl = document.all[control_id + '_tree'];
	for(var i=0; i<tbl.rows.length; i++) tbl.deleteRow(i);
	var row_idx = tbl.rows.length;
	tbl.insertRow(row_idx);
	var tr = tbl.rows[row_idx];
	var cell_idx = tr.cells.length;
	tr.insertCell(cell_idx);
	var td = tr.cells[cell_idx];
	var sHtml = '<table CellPadding = 0 CellSpacing = 0 border=0  >';
	sHtml += '<tr><td align=center>';
    sHtml += '<table CellPadding = 0 CellSpacing = 0 border=0 width=235 >';
	td.innerHTML = genSheet(sHtml, RootId, 0);
	
	//td.innerHTML += '<tr><td></td><td style="border-top: 1px solid #d69bb9;"><img src="oper/img/blank.gif" width="1" height="1"></td></tr> ';

	td.innerHTML +='</table></td></tr>';
	td.innerHTML += '</table>'
}

function genSheet(sHtml, pid, level)
{
	for (var i in Rubs) if (Rubs[i].ParentID == pid)				
	{
		var sh = Rubs[i];
		sHtml += '<tr><td>';
		sHtml += ( level > 0 ) ? '<img src="' + ((sh.SubRubCnt*1 > 0) ? 'Oper/img/menu_pil.gif' : 'Oper/img/Dot.gif') + '" border=0>' : '&nbsp;';
		sHtml += '</td><td class="left_menu_style">';
		sHtml += '<a href="' + ((sh.ContentCnt*1 > 0 || (sh.hasMaterials + sh.hasSubRubs) == 0) ? 'Site.aspx?id=' + sh.RubID : 'javascript:genmenu( ' + sh.RubID + ');') +  '">';
//		sHtml += '<a href="' + ((sh.ContentCnt*1 > 0 || (sh.hasMaterials + sh.hasSubRubs) == 0) ? 'Site.aspx?id=' + sh.RubID : 'javascript:genmenu( ' + sh.RubID + ');') + '" class="' + ((level == 0) ? RootCSS : SheetCSS) + '">';
        aa = new String(sh.RubBtnText);
		aa = aa.toUpperCase();
		sHtml += aa;
		sHtml += '</a>';
		sHtml += '</td></tr>';

//подменю

		if ( sh.isOpen && sh.SubRubCnt*1 > 0)
		{
			sHtml += '<tr><td>';
			//sHtml += '<img src="Oper/img/blanck.gif" Width=14 Height=1 Border=0>';
			sHtml += '</td><td>';
			sHtml += '<table CellPadding = 0 CellSpacing = 0 border=0>';
			sHtml = genSheet(sHtml, sh.RubID, level+1);
			sHtml += '</table></td></tr>';
		}
		
	}
 if (level==0)		
 {
 sHtml += '<tr><td></td><td class="left_menu_style"><img src="oper/img/blank.gif" width="1" height="1"></td></tr> ';
}
	return sHtml;
}

function initSels(aId, pid)
{

	for (var i in Rubs) if (Rubs[i].ParentID == pid)				
	{
		var sh = Rubs[i];
		sh.isOpen = (sh.RubID == aId );
		if (sh.isOpen) return(true);
		if ( (sh.SubRubCnt + sh.ContentCnt) > 0 )
		{
			sh.isOpen = initSels(aId, sh.RubID);
			if (sh.isOpen) return(true);
		}
	}
	return false;

}

function sheet( rid, pid, rn, hm, hs, sc, cc )
{
	this.RubID = rid;
	this.ParentID = pid;
	this.RubBtnText = rn;
	this.hasMaterials = (hm==1);
	this.hasSubRubs = (hs==1);
	this.SubRubCnt = sc;
	this.ContentCnt = cc; 
	this.isOpen = false;
}

    
    
