﻿<!--
//index 0: option text
//index 1: level
//index 2: visibility
//index 3: default text
//index 4: selected
//index 5: terminal node
//index 6: default id
//index 7: option id

var MenuArray;
var CurrentMenu;
var IdSection=new String(''),IdGroup=new String(''),IdDetail=new String('');
var MenuCellWidth=200-2;

function SetMenuArray(m)
{
    MenuArray=m;    
}

function SetCurrentMenu(cMenu)
{       
    CurrentMenu=cMenu;
}

function CreateMenu()
{
	try
	{
	    var properties,offset;
	    var continut='';
	    CurrentMenu=parseInt(CurrentMenu);
	    if (!isNaN(CurrentMenu))
	    {
	        properties=MenuArray[CurrentMenu].split(';');
	        MenuArray[CurrentMenu] = properties[0] + ';' + properties[1] + ';1;' + properties[3] + ';1;' + properties[5] + ';' + properties[6] + ';' + properties[7];
	        if (properties[1]=='1')
	        {
	            properties=MenuArray[CurrentMenu].split(';');
	            for(i=CurrentMenu+1;i<MenuArray.length;i++)
	            {
	                var p=MenuArray[i].split(';');
	                if (p[1]=='1') break;
	                MenuArray[i] = p[0] + ';' + p[1] + ';1;' + p[3] + ';' + p[4] + ';' + p[5] + ';' + p[6] + ';' + p[7];
	            }
	        }
	        else
	        {
	            for(j=CurrentMenu+1;j<MenuArray.length;j++)
	            {
	                var p=MenuArray[j].split(';');
	                if (p[1]=='1') break;
	                MenuArray[j] = p[0] + ';' + p[1] + ';1;' + p[3] + ';' + p[4] + ';' + p[5] + ';' + p[6] + ';' + p[7];
	            }
	            for(j=CurrentMenu-1;j>0;j--)
	            {
	                var p=MenuArray[j].split(';');
	                if (p[1]=='1') break;
	                MenuArray[j] = p[0] + ';' + p[1] + ';1;' + p[3] + ';' + p[4] + ';' + p[5] + ';' + p[6] + ';' + p[7];
	            }
	        }
	    }
	    for(i=0;i<MenuArray.length;i++)
	    {
    	    properties=MenuArray[i].split(';');
		    switch(properties[1])
		    {
			    case '1':
				    offset = 3;
				    break;
			    case '2':
				    offset = 30;
				    break;
			    case '3':
				    offset = 45;
				    break;
		    }
		    if (properties[2]=='1')
		    {		        
			    if (properties[4]=='1')
			    {
				    if (properties[1]=='1') continut+=('<a id="a_' + i + '" nohref class="item_selected" style="padding-left:' + offset + 'px;width:' + eval(MenuCellWidth - offset) + 'px;" onclick="CurrentMenu=' + i + ';MenuChanged();"><img src="images/orange_square.png" style="border:0;height:5px;width:5px;padding-top:8px;" align="left"><div style="height:25px;padding-top:3px;">&nbsp;&nbsp;' + properties[0] + '</div></a>');
				    else continut+='<a nohref class="item1_selected" style="padding-left:' + offset + 'px;width:' + eval(MenuCellWidth - offset) + 'px;" onclick="CurrentMenu=' + i + ';MenuChanged();"><div style="height:22px;padding-top:3px;">' + properties[0] + '</div></a>';
			    }
			    else
			    {			    
				    if (properties[1]=='1') continut+='<a id="a_' + i + '" nohref class="item" style="padding-left:' + offset + 'px;width:' + eval(MenuCellWidth - offset) + 'px;" onclick="CurrentMenu=' + i + ';MenuChanged();"><img src="images/orange_square.png" style="border:0;height:5px;width:5px;padding-top:8px;" align="left"><div style="height:25px;padding-top:3px;">&nbsp;&nbsp;' + properties[0] + '</div></a>';
				    else continut+='<a nohref class="item1" style="padding-left:' + offset + 'px;width:' + eval(MenuCellWidth - offset) + 'px;" onclick="CurrentMenu=' + i + ';MenuChanged();"><div style="height:22px;padding-top:3px;">' + properties[0] + '</div></a>';
			    }
		    }
	    }
	    document.getElementById('menu').innerHTML=continut;
	}
	catch (ex)
	{
		alert(ex.description);		
	}
}

function MenuChanged()
{
	try
	{
		var lvl;
		var properties=MenuArray[CurrentMenu].split(';');
		switch(properties[1])
		{
			case '1':
				IdSection = properties[7];
				IdGroup = '';
				IdDetail = '';
				break;
			case '2':
			    for (i=CurrentMenu;i>=0;i--)
			    {
			        var p=MenuArray[i].split(';');
			        if (p[1]=='1')
			        {
			            IdSection=p[7];
			            break;
			        }
			    }
			    IdGroup = properties[7];
				IdDetail = '';
				break;
			case '3':
				for (i=CurrentMenu;i>=0;i--)
			    {
			        var p=MenuArray[i].split(';');
			        if ((p[1]=='2')&&(IdGroup=='')) IdGroup=p[7];
			        if (p[1]=='1')
			        {
			            IdSection=p[7];
			            break;
			        }
			    }
				IdDetail = properties[7];
				break;
		}
		var pg=new String('');
		
		if (properties[5]=='1')
		{
		    pg='page_redirect.aspx?IdSection=' + IdSection + '&IdGroup=' + IdGroup + '&IdDetail=' + IdDetail;
		}
		else
		{
			if ((properties[1]=='1') && (properties[6] !=''))
			{
			    pg='page_redirect.aspx?IdSection=' + IdSection + '&IdGroup=' + properties[6] + '&IdDetail=' + IdDetail;
			}		
			if ((properties[1]=='2') && (properties[6] !=''))
			{
			    pg='page_redirect.aspx?IdSection=' + IdSection + '&IdGroup=' + IdGroup + '&IdDetail=' + properties[6];
			}
		}		
    	lvl=parseInt(properties[1]);
	    CloseLevel(lvl);
	    MenuArray[CurrentMenu] = properties[0] + ';' + properties[1] + ';' + properties[2] + ';' + properties[3] + ';1;' + properties[5] + ';' + properties[6] + ';' + properties[7];
	    for(i=CurrentMenu+1;i<MenuArray.length;i++)
	    {
		    properties=MenuArray[i].split(';');
		    if(parseInt(properties[1])<=lvl) break;
		    if((lvl + 1)==parseInt(properties[1]))
		    {
			    properties[2]='1';
			    MenuArray[i]=properties[0] + ';' + properties[1] + ';' + properties[2] + ';' + properties[3] + ';' + properties[4] + ';' + properties[5] + ';' + properties[6] + ';' + properties[7];
		    }
	    }
		if (pg!='')
		{
		    document.getElementById('ctl00_tbMenuState').value=CurrentMenu;
		    document.getElementById('ctl00_tbPage').value=pg;
            __doPostBack('ctl00$tbMenuState','');
        }
        else CreateMenu();
    }
	catch (ex)
	{
		alert(ex.description);
	}
}

function CloseLevel(lvl)
{
    try
	{
	    var properties;
	    for(i=0;i<MenuArray.length;i++)
	    {
		    properties=MenuArray[i].split(';');
		    if(parseInt(properties[1])>lvl)
		    {
			    properties[2]='0';
			    MenuArray[i]=properties[0] + ';' + properties[1] + ';' + properties[2] + ';' + properties[3] + ';' + properties[4] + ';' + properties[5] + ';' + properties[6] + ';' + properties[7];
		    }
		    properties[4]='0';
		    MenuArray[i]=properties[0] + ';' + properties[1] + ';' + properties[2] + ';' + properties[3] + ';' + properties[4] + ';' + properties[5] + ';' + properties[6] + ';' + properties[7];
	    }
	}
    catch (ex)
	{
	    //NOP
	}
}
-->