﻿function ToggleMenu()
{
    window.onload = ExecuteToggleMenu; 
}

function ExecuteToggleMenu()
{
    try
    {
        var a = location.search.substring(location.search.indexOf('sezione=')).replace('sezione=', 'Menu-');
        
        if (a == 'Menu-iscrizione')
        {
            a = 'Menu-contatti';
        }
        
        if (a == 'Menu-default')
        {
            a = 'Menu-dettaglio';
        }
        
        if (a == 'Menu-il_medico_risponde')
        {
            a = 'Menu-servizi';
        }
        
        if (a == 'Menu-sportello_legale')
        {
            a = 'Menu-servizi';
        }
        
        if (location.href.toLowerCase().indexOf('dettaglio.aspx')>=0)
        {
            if (location.search.toLowerCase().indexOf('sezione')<0)
            {
                 a = 'Menu-dettaglio';
            }
        }
          
        var list;        
        var sidebar = document.getElementById(a);
        if (sidebar!=null)
        {
            sidebar.style['display']='';
            list = sidebar.getElementsByTagName('li');
        }
        else
        {
            list = document.getElementsByTagName('li');
        }
                 

        for(i=0; i < list.length; i++) {
            try {

                if (list[i].children[0].attributes['href'].value.toLowerCase() == window.location.href.toLowerCase()) {

                    list[i].attributes['class'].value = 'active';
                    if (list[i].parentElement.parentElement.parentElement.tagName.toLowerCase() == 'li')
                    {
                        list[i].parentElement.parentElement.parentElement.attributes['class'].value = 'active';
                    }
                    //list[i].parentElement.attributes['class'].value = 'active';
                    break;
                }
            }
            catch (ex1) { }
            
        }
        
    }
    catch(ex){}
    
    try
    {
        var b = location.search.substring(location.search.indexOf('sezione=')).replace('sezione=', 'Top-');
        
        if (b == 'Top-iscrizione')
        {
            b = 'Top-contatti';
        }
        
        if (location.href.toLowerCase().indexOf('iscrizione.aspx')>=0)
        {
             b = 'Top-contatti';
        }
        
        var menu = document.getElementById(b);
        menu.attributes['class'].value='active';
        
    }
    catch (ex) { }
}

