﻿function disableAllGrupos()
{
    // Procurar por todas as divs que tenham no nome do ID "GrupoExclusivo__"
    var divsGrupoExclusivo = $$("div.clsGrupoExclusivoDisabled");

    // Colocar todos os campos a disabled
    divsGrupoExclusivo.each(function(div)
    {
        // Inputs
        var inputListToDisable = div.getElementsByTagName('input');
        var inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            if(node.type != "checkbox")
            {
                node.className = "clsInputDisabled";
            }
            else
            {
                node.className = "clsCheckDisabled";
            }
        });
        
        // Textareas
        inputListToDisable = div.getElementsByTagName('textarea');
        inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            node.className = "clsInputDisabled";
        });
        
        // Selects
        inputListToDisable = div.getElementsByTagName('select');
        inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            node.className = "clsInputDisabled";
        });
    });
}

function disableAllCampos()
{
    // Procurar por todas as divs que tenham no nome do ID "CampoExclusivo__"
    var divsCampoExclusivo = $$("div.clsCampoExclusivoDisabled");

    // Colocar todos os campos a disabled
    divsCampoExclusivo.each(function(div)
    {
        // Inputs
        var inputListToDisable = div.getElementsByTagName('input');
        var inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            if(node.type != "checkbox")
            {
                node.className = "clsInputDisabled";
            }
            else
            {
                node.className = "clsCheckDisabled";
            }
        });
        
        // Textareas
        inputListToDisable = div.getElementsByTagName('textarea');
        inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            node.className = "clsInputDisabled";
        });
        
        // Selects
        inputListToDisable = div.getElementsByTagName('select');
        inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            node.className = "clsInputDisabled";
        });
    });
}

function showExclusivo(grupoToEnable, grupoPai)
{
    /////////// DESACTIVAR //////////
    
    // Inputs
    var inputListToDisable = $(grupoPai).getElementsByTagName('input');
    var inputsToDisable = $A(inputListToDisable);
     
    inputsToDisable.each(function(node)
    {
        node.disabled = true;
        if(node.type != "checkbox")
        {
            node.className = "clsInputDisabled";
        }
        else
        {
            node.className = "clsCheckDisabled";
        }
    });
    
    // Textareas
    inputListToDisable = $(grupoPai).getElementsByTagName('textarea');
    inputsToDisable = $A(inputListToDisable);
     
    inputsToDisable.each(function(node)
    {
        node.disabled = true;
        node.className = "clsInputDisabled";
    });
    
    // Selects
    inputListToDisable = $(grupoPai).getElementsByTagName('select');
    inputsToDisable = $A(inputListToDisable);
     
    inputsToDisable.each(function(node)
    {
        node.disabled = true;
        node.className = "clsInputDisabled";
    });
    
	/////////// ACTIVAR OS CAMPOS DO GRUPO SELECCIONADO //////////////
	
    // Inputs
    var inputListToEnable = $(grupoToEnable).getElementsByTagName('input');
    var inputsToEnable = $A(inputListToEnable);
     
    inputsToEnable.each(function(node)
    {        
        node.disabled = false;
        if(node.type != "checkbox")
        {
            node.className = "clsInputEnabled";
        }
        else
        {
            node.className = "clsCheckEnabled";
        }
    });
    
    // Textareas
    inputListToEnable = $(grupoToEnable).getElementsByTagName('textarea');
    inputsToEnable = $A(inputListToEnable);
     
    inputsToEnable.each(function(node)
    {        
        node.disabled = false;
        node.className = "clsInputEnabled";        
    });
    
    // Selects
    inputListToEnable = $(grupoToEnable).getElementsByTagName('select');
    inputsToEnable = $A(inputListToEnable);
     
    inputsToEnable.each(function(node)
    {        
        node.disabled = false;
        node.className = "clsInputEnabled";        
    });
    
    ///////////////////////////////////////////////////////////////////
    
    // Mudar o estilo das divs para disabled
    var divsGrupoExclusivo = document.getElementsByClassName("clsGrupoExclusivoEnabled", $(grupoPai));

    divsGrupoExclusivo.each(function(div)
    {
        div.className = "clsGrupoExclusivoDisabled";
    });
    
    // Mudar o estilo da div do grupo exclusivo seleccionado para enabled
    $(grupoToEnable).className = "clsGrupoExclusivoEnabled";
    
    ///////////////////////////////////////////////////////////////////
    
    var divsCampoExclusivo = document.getElementsByClassName('clsCampoExclusivoDisabled', $(grupoToEnable));
	     
    // Inputs	     
    divsCampoExclusivo.each(function(nodeCampo)
    {
        inputListToDisable = nodeCampo.getElementsByTagName('input');
        inputsToDisable = $A(inputListToDisable);
         
        inputsToDisable.each(function(node)
        {
            if(node.type != "checkbox")
            {
                node.disabled = true;
                node.className = "clsInputDisabled";
            }
            else
            {
                node.className = "clsCheckDisabled";
            }
        });
    });
    
    // Textareas
    divsCampoExclusivo.each(function(nodeCampo)
    {        
        inputListToDisable = nodeCampo.getElementsByTagName('textarea');
        inputsToDisable = $A(inputListToDisable);
         
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            node.className = "clsInputDisabled";
        });
    });
    
    // Selects
    divsCampoExclusivo.each(function(nodeCampo)
    {        
        inputListToDisable = nodeCampo.getElementsByTagName('select');
        inputsToDisable = $A(inputListToDisable);
         
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            node.className = "clsInputDisabled";
        });
    });
    
    ///////////////////////////////////////////////////////////////////
    
    divsCampoExclusivo = document.getElementsByClassName('clsCampoExclusivoEnabled', $(grupoToEnable));
     
    // Inputs
    divsCampoExclusivo.each(function(nodeCampo)
    {
        inputListToEnable = nodeCampo.getElementsByTagName('input');
        inputsToEnable = $A(inputListToEnable);
         
        inputsToEnable.each(function(node)
        {        
            if(node.type != "checkbox")
            {
                node.disabled = false;
                node.className = "clsInputEnabled";
            }
            else
            {
                node.className = "clsCheckEnabled";
            }
        });
    });
    
    // TextAreas
    divsCampoExclusivo.each(function(nodeCampo)
    {
        inputListToEnable = nodeCampo.getElementsByTagName('textarea');
        inputsToEnable = $A(inputListToEnable);
         
        inputsToEnable.each(function(node)
        {        
            node.disabled = false;
            node.className = "clsInputEnabled";        
        });
    });
    
    // Selects
    divsCampoExclusivo.each(function(nodeCampo)
    {
        inputListToEnable = nodeCampo.getElementsByTagName('select');
        inputsToEnable = $A(inputListToEnable);
         
        inputsToEnable.each(function(node)
        {        
            node.disabled = false;
            node.className = "clsInputEnabled";        
        });
    });
}

function showCampoExclusivo(campoToEnable, campoPai)
{
    // Mudar o estilo das divs para disabled
    divsCampoExclusivo = document.getElementsByClassName("clsCampoExclusivoEnabled", $(campoPai));
    
    divsCampoExclusivo.each(function(div)
    {
        div.className = "clsCampoExclusivoDisabled";
        
        // Inputs
        var inputListToDisable = $(div).getElementsByTagName('input');
        var inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            if(node.type != "checkbox")
            {                
                node.disabled = true;
                node.className = "clsInputDisabled";
            }
            else
            {
                node.className = "clsCheckDisabled";
            }
            
            if(div.id != campoToEnable)
            {
                node.value = "";
                node.checked = false;
            }
        });
        
        // Textareas
        inputListToDisable = $(div).getElementsByTagName('textarea');
        inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            node.className = "clsInputDisabled";
            
            if(div.id != campoToEnable)
            {
                node.value = "";
            }
        });
        
        // Selects
        inputListToDisable = $(div).getElementsByTagName('select');
        inputsToDisable = $A(inputListToDisable);
	     
        inputsToDisable.each(function(node)
        {
            node.disabled = true;
            node.className = "clsInputDisabled";
            
            if(div.id != campoToEnable)
            {
                node.selectedIndex = 0;
            }
        });
    });
    
    // Mudar o estilo da div do campo exclusivo seleccionado para enabled
    $(campoToEnable).className = "clsCampoExclusivoEnabled";
    
    // Activar agora os inputs do campo exclusivo seleccionado
    var inputListToEnable = $(campoToEnable).getElementsByTagName('input');
    var inputsToEnable = $A(inputListToEnable);
     
    inputsToEnable.each(function(node)
    {
        if(node.type != "checkbox")
        {
            node.disabled = false;
            node.className = "clsInputEnabled";
        }
        else
        {
            node.className = "clsCheckEnabled";
        }
        try { node.focus(); } catch(Err) { };
    });
    
    // Textareas
    inputListToEnable = $(campoToEnable).getElementsByTagName('textarea');
    inputsToEnable = $A(inputListToEnable);
     
    inputsToEnable.each(function(node)
    {
        node.disabled = false;
        node.className = "clsInputEnabled";
        try { node.focus(); } catch(Err) { };
    });
    
    // Selects
    inputListToEnable = $(campoToEnable).getElementsByTagName('select');
    inputsToEnable = $A(inputListToEnable);
     
    inputsToEnable.each(function(node)
    {
        node.disabled = false;
        node.className = "clsInputEnabled";
        try { node.focus(); } catch(Err) { };
    });
}