
function MenuRender(MenuId)
{
    try{  
        CreateArray(MenuId, MenuData[MenuId].length);        
        Render(MenuId);        
        OpenSelected(MenuId);
    }catch(E)
    {
        alert(E.message);
    };
}

function MouseIsOver(MenuId, LineId, pIndex)
{
//    if(MenuData[MenuId][pIndex].Level == 1)
//        document.getElementById('Lnk'+ LineId).className = 'MouseOverColor1Level';
//    else
//        document.getElementById('Lnk'+ LineId).className = 'MouseOverColor2Level';

//    document.getElementById('Td'+ LineId).className = 'MouseOver';
    
//    if(MenuData[MenuId][pIndex].Level == 1)
//        document.getElementById('TdRed' + LineId).className = 'MouseOverCornerOnLevel1';
//    else
//        document.getElementById('TdRed' + LineId).className = 'MouseOverCornerOn';
}

function MouseIsOut(MenuId, LineId, pIndex)
{
//    if(MenuData[MenuId][pIndex].Level == 1)
//        document.getElementById('Lnk'+ LineId).className = 'MenuLateral1Level';
//    else
//        document.getElementById('Lnk'+ LineId).className = 'MenuLateral2Level';
//    
//    if(MenuData[MenuId][pIndex].Level == 1)
//        document.getElementById('Td'+ LineId).className = 'MouseOut1Level';
//    else
//        document.getElementById('Td'+ LineId).className = 'MouseOut2Level';
//    
//    
//    if(MenuData[MenuId][pIndex].Level == 1)
//        document.getElementById('TdRed' + LineId).className = 'MouseOverCornerOffLevel1';
//    else
//        document.getElementById('TdRed' + LineId).className = 'MouseOverCornerOff';
//        
//    Selected = readCookie("Selected");
//	
//	if(Selected == ArrayOfMenus[pIndex].Layer)
//		if(document.getElementById(ArrayOfMenus[pIndex].Lnk) != null)
//		{
//		    if(ArrayOfMenus[pIndex].Level==1)
//			    document.getElementById(ArrayOfMenus[pIndex].Lnk).className = 'MouseOverColor1Level';
//			else
//			    document.getElementById(ArrayOfMenus[pIndex].Lnk).className = 'MouseOverColor2Level';
//		}
}

function Render(MenuId)
{
	var I = 0;
	document.write('<table width="' + MenuDef[MenuId].WIDTH + '" cellpadding="0" cellspacing="0" border="0" style="border:1px solid #809EBD">');
	for(I = 0; I < MenuData[MenuId].length; I++)
	{	    
		if(MenuData[MenuId][I].ParentId == -1)
		{		    
			document.write('<tr><td width="' + MenuDef[MenuId].WIDTH + '" bgcolor="' + MenuDef[MenuId].BGCOLOR_MAIN_ITEM +'">');
			RenderMenu(MenuId, I, MenuData[MenuId][I].Level);
			document.write('</td></tr>');
		}
	}
	document.write('</table>');
}

function RenderMenu(MenuId, pIndex, pLevel)
{
	var I;
	var ColSpan = pLevel + 1;
    var Url;
    var LineId = MenuData[MenuId][pIndex].Id;
    
    if(MenuData[MenuId][pIndex].Url != '')
        Url = 'javascript:OpenOrCloseMenu(' + MenuId + ', \'SubMenu' + MenuData[MenuId][pIndex].Id + '\', true, true,\'' + MenuData[MenuId][pIndex].Caption + '\')';
    else
        Url = 'javascript:OpenOrCloseMenu(' + MenuId + ', \'SubMenu' + MenuData[MenuId][pIndex].Id + '\', true, false,\'' + MenuData[MenuId][pIndex].Caption + '\')';

	document.write('<table class="TblMenuLateral" width="100%" id="Tbl' + MenuData[MenuId][pIndex].Id + '" cellpadding="0" cellspacing="0" border="0" OnMouseOver="MouseIsOver(' + MenuId + ',' + LineId + ',' + pIndex + ')" OnMouseOut="MouseIsOut(' + MenuId + ',' + LineId + ',' + pIndex + ')" OnClick="' + Url + '" style="cursor=hand">');

	//if(pLevel != 1)
	document.write('<tr><td width="100%" colspan="0" bgcolor="' + MenuDef[MenuId].LINE + '"><img src="./img/px.gif"></img></td><td width="9" colspan="0" bgcolor="' + MenuDef[MenuId].LINE + '"><img src="./img/px.gif"></img></td></tr>');
	
	document.write('<tr><td width="100%" id="Td' + MenuData[MenuId][pIndex].Id + '">');
	
	document.write('<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>');
	
	
    document.write('<td width="' + (5 * ColSpan) + '" nowrap="nowrap">&#160;</td>');
	    
	document.write('<td width="1" height="21" valign="top" nowrap="nowrap" align="center">');
	document.write('</td><td width="100%" valign="middle">');
	
	
	if(pLevel==1)
	    document.write('<a class="MenuLateral1Level" id="Lnk' + MenuData[MenuId][pIndex].Id +'" name="' + MenuData[MenuId][pIndex].Id + '" title="'+ MenuData[MenuId][pIndex].Caption +'">');
    else
        document.write('<a class="MenuLateral2Level" id="Lnk' + MenuData[MenuId][pIndex].Id +'" name="' + MenuData[MenuId][pIndex].Id + '" title="'+ MenuData[MenuId][pIndex].Caption +'">');	   
		
	document.write(MenuData[MenuId][pIndex].Caption);
	
	if(pLevel==1)
	    document.write('</a></td><td width="10" style="border-left:1px Solid #809EBD" align="center" nowrap><img src="./img/setaMenu.gif"/></td></tr></table></td>');
	else
	    document.write('</a></td></tr></table></td>');
    
    if(pLevel==1)
        document.write('<td id="TdRed' + MenuData[MenuId][pIndex].Id + '" width="9" bgcolor="' + MenuDef[MenuId].BGCOLOR_MAIN_ITEM +'">&nbsp;</td>');
    else
        document.write('<td id="TdRed' + MenuData[MenuId][pIndex].Id + '" width="9" bgcolor="' + MenuDef[MenuId].BGCOLOR_SUB_ITEM +'">&nbsp;</td>');
        	
	document.write('</tr></table>');

	if(!MenuData[MenuId][pIndex].HaveSons)
		AddMenu(MenuId, null, OPEN, 'SubMenu' + MenuData[MenuId][pIndex].Id, 'ImageMenu' + MenuData[MenuId][pIndex].Id, MenuData[MenuId][pIndex].Url, 'Lnk' + MenuData[MenuId][pIndex].Id, false, 'Td' + MenuData[MenuId][pIndex].Id);
	else
	{
		MakeDiv(MenuId, 'SubMenu' + MenuData[MenuId][pIndex].Id);
		
		AddMenu(MenuId, null, OPEN, 'SubMenu' + MenuData[MenuId][pIndex].Id, 'ImageMenu' + MenuData[MenuId][pIndex].Id, MenuData[MenuId][pIndex].Url, 'Lnk' + MenuData[MenuId][pIndex].Id, true, 'Td' + MenuData[MenuId][pIndex].Id);
		document.write('<table width="100%" cellpadding="0" cellspacing="0" border="0">');	
		document.write('<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>');
		

		if(MenuData[MenuId][pIndex].Level == 1)
			document.write('<td width="100%" colspan="2" BgColor="' + MenuDef[MenuId].BGCOLOR_SUB_ITEM + '">');
		else
			document.write('<td width="100%" colspan="2" BgColor="' + MenuDef[MenuId].BGCOLOR_SUB_SUB_ITEM + '">');
		
		for(I = 0; I < MenuData[MenuId].length; I++)
		{
			if(MenuData[MenuId][I].ParentId == MenuData[MenuId][pIndex].Id)
			{
				RenderMenu(MenuId, I, MenuData[MenuId][I].Level)				
			}
		}
								
		document.write("</td></tr></table>");
		CloseDiv();
	}
}

