
function MenuRender(MenuId, SelectedId, ChildSelectedId, ParentId)
{
    try{  
        CreateArray(MenuId, MenuData[MenuId].length);
        Render(MenuId, SelectedId, ChildSelectedId, ParentId);        
        OpenSelected(MenuId);
    }catch(E)
    {
        alert(E.message);
    };
}

function MouseIsOver(MenuId, LineId, pIndex)
{
//    if(MenuData[MenuId][pIndex].Level == 1)
//        document.getElementById('Lnk'+ LineId).className = 'MouseOverColor1Level';
}

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 Clicked() {
    document.getElementById('TdMenu1Level').className = 'MenuLateral1LevelTd Selected';
}

function Render(MenuId, SelectedId, ChildSelectedId, ParentId)
{
	var I = 0;
	document.write('<table width="' + MenuDef[MenuId].WIDTH + '" cellpadding="0" cellspacing="0" border="0px">');
	for(I = 0; I < MenuData[MenuId].length; I++)
	{	    
		if(MenuData[MenuId][I].ParentId == -1)
		{		    
			document.write('<tr><td width="' + MenuDef[MenuId].WIDTH + '">');
			RenderMenu(MenuId, I, MenuData[MenuId][I].Level, SelectedId, ChildSelectedId, ParentId);
			document.write('</td></tr>');
		}
	}
	document.write('</table>');
}

function RenderMenu(MenuId, pIndex, pLevel, SelectedId, ChildSelectedId, ParentId)
{
	var I;
	var ColSpan = pLevel + 1;
    var Url;
    var LineId = MenuData[MenuId][pIndex].Id;
    
    if(MenuData[MenuId][pIndex].Level != 1)
        Url = 'javascript:OpenOrCloseMenu(' + MenuId + ', \'SubMenu' + MenuData[MenuId][pIndex].Id + '\', false, true,\'' + MenuData[MenuId][pIndex].CaptionEncode + '\')';
    else
        Url = 'javascript:OpenOrCloseMenu(' + MenuId + ', \'SubMenu' + MenuData[MenuId][pIndex].Id + '\', false, false,\'' + MenuData[MenuId][pIndex].CaptionEncode + '\')';

    document.write('<table class="TblMenuLateral" width="100%" id="Tbl' + MenuData[MenuId][pIndex].Id + '" cellpadding="1" cellspacing="0" border="0px" OnMouseOver="MouseIsOver(' + MenuId + ',' + LineId + ',' + pIndex + ')" OnMouseOut="MouseIsOut(' + MenuId + ',' + LineId + ',' + pIndex + ')" OnClick="' + Url + '" style="cursor=hand; cursor:pointer;">');

	if(pLevel == 1)
	    document.write('<tr><td></td></tr>'); // TRANSPARENCY BETWEEN ROWS

	document.write('<tr><td width="100%" id="Td' + MenuData[MenuId][pIndex].Id + '" >');
	
	document.write('<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>');

	if (pLevel == 1) {
	    if (MenuData[MenuId][pIndex].Id == ParentId || MenuData[MenuId][pIndex].Id == SelectedId) {
	        document.write('<td width="100%" align="left" class="MenuLateral1LevelTd Selected">');
	        document.write('<a class="MenuLateral1Level Selected" id="Lnk' + MenuData[MenuId][pIndex].Id + '" name="' + MenuData[MenuId][pIndex].Id + '" title="' + MenuData[MenuId][pIndex].Caption + '">');
	    }
	    else {
	        document.write('<td width="100%" align="left" class="MenuLateral1LevelTd">');
	        document.write('<a class="MenuLateral1Level" id="Lnk' + MenuData[MenuId][pIndex].Id + '" name="' + MenuData[MenuId][pIndex].Id + '" title="' + MenuData[MenuId][pIndex].Caption + '">');
        }
    }
    else {
        if (MenuData[MenuId][pIndex].Id == ChildSelectedId) {
            document.write('<td width="100%" align="left" class="MenuLateral2LevelTd SonSelected">');
        }
        else {
            document.write('<td width="100%" align="left" class="MenuLateral2LevelTd">');
        }

        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);
    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) {
        if(MenuData[MenuId][pIndex].Id == SelectedId)
            AddMenu(MenuId, null, CLOSE, '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, MenuData[MenuId][pIndex].CaptionEncode);
        else
            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, MenuData[MenuId][pIndex].CaptionEncode);
	}
    else {
	    MakeDiv(MenuId, 'SubMenu' + MenuData[MenuId][pIndex].Id);

	    if (MenuData[MenuId][pIndex].Id == SelectedId)
        {
	        AddMenu(MenuId, null, CLOSE, '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, MenuData[MenuId][pIndex].CaptionEncode);
        }
	    else
	        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, MenuData[MenuId][pIndex].CaptionEncode);

	    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">');
	    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, SelectedId, ChildSelectedId, ParentId)
	        }
	    }

	    document.write("</td></tr></table>");
	    CloseDiv();
	}
}


