﻿// JScript File
// CSS change

function hideAll(id)
{
    var ids = document.getElementById("hiddenidspais").value;
    var idsSub = document.getElementById("hiddenidspaisSubMenus").value; //1 nivel de sub menu

    var ListaIDS = ids.split(",");
    var ListaIDSub = idsSub.split(",");

    //verifica em qual array está o id;
    var quallista = "";

    for (lis01 = 0; lis01 < ListaIDS.length; lis01++) {
        if (ListaIDS[lis01] == id) {
            quallista = "ListaIDS";
        }
    }
    for (lis02 = 0; lis02 < ListaIDSub.length; lis02++) {
        if (ListaIDSub[lis02] == id) {
            quallista = "ListaIDSub";
        }
    }
    
    if (quallista == "ListaIDSub") //DETERMINA QUAL LISTA É PARA TRABALHAR
    {
        //se estiver na lista de submenus, trabalha somente com a lista de submenus.        
        for (i = 0; i < ListaIDSub.length; i++) {
            try {
                RemoverSessionStorage(ListaIDSub[i]);
                if (ListaIDSub[i] != id) {
                    document.getElementById(ListaIDSub[i]).style.display = "none";
                }
            }
            catch (e) {
            }
        }   
    }
    else 
    {
        //se estiver na lista de menu raiz, oculta todos os submenus para depois trabalhar com a lista de menu raiz     
        for (i = 0; i < ListaIDSub.length; i++) {
            try {
                RemoverSessionStorage(ListaIDSub[i]);
                document.getElementById(ListaIDSub[i]).style.display = "none";
            }
            catch (e) {
            }
        }   
        
        for (i = 0; i < ListaIDS.length; i++) {
            try {
                RemoverSessionStorage(ListaIDS[i]);
                if (ListaIDS[i] != id) {
                    document.getElementById(ListaIDS[i]).style.display = "none";
                }
            }
            catch (e) {
            }
        } 
    }    
}



function showNewDisplay(id)
{   
    
	// setup vars
	var defaulDisplay = "none";
	var newDisplay = "block";
		
	hideAll(id);
	
	// other supported styles
	// myElement.style.fontSize = "24px";
	// myElement.style.fontFamily = "Verdana, Arial, Courier New";
	// myElement.style.textDecoration = "underline";
	// myElement.style.fontWeight = "normal";
	// myElement.style.visibility = "hidden";
	
	if((document.getElementById)&& (document.getElementById(id)!=null))
	{
  		// Get a reference to the element
		var myElement = document.getElementById(id);
		// Check the element's style object and background property are available
	 	if ((myElement.style)&& (myElement.style.display!=null))
	 	{
			// Check the value of the property
		    if(myElement.style.display == 'none' || myElement.style.display == '')
		    {
		        // change style to new color
		        //document.getElementById.style.display = defaulDisplay;
		        document.getElementById(id).style.display = newDisplay;
		        InserirSessionStorage(id);
			}
			else
			{
				// change style to default color
			    document.getElementById(id).style.display = defaulDisplay;
			    RemoverSessionStorage(id);
			}
		}
		else
		{	
			// This CSS property is not assigned or is not supported
			return;
		}
	}
	else 
	{
	  return;
	}
}

function showNewDisplay2(id, idsmenupai) {


    // setup vars
    var defaulDisplay = "none";
    var newDisplay = "block";

    hideAll(idsmenupai);


    // other supported styles
    // myElement.style.fontSize = "24px";
    // myElement.style.fontFamily = "Verdana, Arial, Courier New";
    // myElement.style.textDecoration = "underline";
    // myElement.style.fontWeight = "normal";
    // myElement.style.visibility = "hidden";

    if ((document.getElementById) && (document.getElementById(id) != null)) {
        // Get a reference to the element
        var myElement = document.getElementById(id);
        // Check the element's style object and background property are available
        if ((myElement.style) && (myElement.style.display != null)) {
            // Check the value of the property
            if (myElement.style.display == 'none' || myElement.style.display == '') {
                // change style to new color
                //document.getElementById.style.display = defaulDisplay;
                document.getElementById(id).style.display = newDisplay;
            }
            else {
                // change style to default color
                document.getElementById(id).style.display = defaulDisplay;
            }
        }
        else {
            // This CSS property is not assigned or is not supported
            return;
        }
    }
    else {
        return;
    }
}

function hideSelf(id) {
    var defaulDisplay = "none";
    document.getElementById(id).style.display = defaulDisplay;
}

function InserirSessionStorage(idValor) {

    
    var opcao = "";

    for (var i = 0, len = sessionStorage.length; i < len; i++) {
        var key = window.sessionStorage.key(i);
        var value = window.sessionStorage.getItem(key);
        if (value == idValor) {
            opcao = "sim";
        }
    }

    if (opcao == "") {
        window.sessionStorage.setItem(idValor, idValor);
    }
}

function RemoverSessionStorage(idValor) {
    //var value = sessionStorage.getItem(key);
    window.sessionStorage.removeItem(idValor);

}

function ConfigurarMenusSessionStorage() {

    for (var i = 0, len = window.sessionStorage.length; i < len; i++) {
        var key = window.sessionStorage.key(i);
        var value = window.sessionStorage.getItem(key);
        configurarSessionStorage(value);
    }
}

function configurarSessionStorage(id) {

    // setup vars
    var defaulDisplay = "none";
    var newDisplay = "block";


    // other supported styles
    // myElement.style.fontSize = "24px";
    // myElement.style.fontFamily = "Verdana, Arial, Courier New";
    // myElement.style.textDecoration = "underline";
    // myElement.style.fontWeight = "normal";
    // myElement.style.visibility = "hidden";

    if ((document.getElementById) && (document.getElementById(id) != null)) {
        // Get a reference to the element
        var myElement = document.getElementById(id);
        // Check the element's style object and background property are available
        if ((myElement.style) && (myElement.style.display != null)) {
            // Check the value of the property
            if (myElement.style.display == 'none' || myElement.style.display == '') {
                // change style to new color
                //document.getElementById.style.display = defaulDisplay;
                document.getElementById(id).style.display = newDisplay;
            }
            else {
                // change style to default color
                document.getElementById(id).style.display = defaulDisplay;
            }
        }
        else {
            // This CSS property is not assigned or is not supported
            return;
        }
    }
    else {
        return;
    }
}




