var defaultChoice;
defaultChoice = "";

function showSub(fatherId, childId, position) 
{
    var fatherObj;
    var childObj;
    
    var contentDivList;
    var contentMainDivList;
    var contentDiv;
    var contentMainDiv;
	
	JQ("img[name='divisorio']").show();
	JQ("#sfAutoMenu" + (position)).hide();
	JQ("#sfAutoMenu" + (position-1)).hide();
	
    fatherObj = document.getElementById(fatherId);
    childObj = document.getElementById(childId);
	
    contentMainDiv = document.getElementById('MainLevel');
    contentMainDivList = contentMainDiv.getElementsByTagName('*');
    contentDiv = document.getElementById('FirstLevel');
    contentDivList = contentDiv.getElementsByTagName('*');
    
    for (i = 0; i < contentMainDivList.length; i++)
    {
        if (contentMainDivList[i].nodeName == 'TD')
        {
            if (contentMainDivList[i].name != 'doNotTouch')
            {
                if (contentMainDivList[i].className != 'sfareautente')
                    contentMainDivList[i].className = 'sfmenu';
            }
        }
    }
    
    for (j = 0; j < contentDivList.length; j++)
    {
        if (contentDivList[j].nodeName == 'DIV')
        {
            contentDivList[j].style.display = 'none';
        }
    }
	
    fatherObj.className = 'sftestomenuon';
    childObj.style.display = 'block';
	
	if ((fatherId != 'areautenteregistrato')&&(fatherId != 'areautenteabbonato'))
	{
		var utenteregistrato = document.getElementById('areautenteregistrato');
		var utenteabbonato = document.getElementById('areautenteabbonato');
	
		if (utenteregistrato != null)
			utenteregistrato.className = 'sfareautente';
		else if (utenteabbonato != null)
			utenteabbonato.className = 'sfareautente';
	}
	
	clearCP(childId);
}

function showCP(action, fatherId, childId, chosenChoice)
{
	if (defaultChoice == "")
		defaultChoice = chosenChoice;

    var fatherObj;
    var childObj;
    var shadowObj;
    var nomeClasseUp;
    var nomeClasseDown;
	
    fatherObj = document.getElementById(fatherId);
    childObj = document.getElementById(childId);
    shadowObj = document.getElementById(fatherId + 'ombra');
	
    switch(action)
    {
        case 'show':
            if (fatherId != defaultChoice)
                fatherObj.className = 'testomenu2';
            else
                fatherObj.className = 'testomenu3';
            
            shadowObj.className = 'menuombra';
			JQ("#" + childId).show();
			
			if (JQ("#divtable" + childId.substring(2)).attr("class") != "doneShadow")
			{
				JQ("#divtable" + childId.substring(2)).attr("class", "doneShadow");
				JQ("#divtable" + childId.substring(2)).shadow();
			}
            break;
        case 'hide':
            if (fatherId != defaultChoice)
            {
                fatherObj.className = 'testomenu1';
                shadowObj.className = 'testomenu1';
            }
            else
            {
                fatherObj.className = 'testomenu4';
            }
            
            childObj.style.display = 'none';
            break;
    }
}

function keepCP(action, childId, grandFatherId, parentId)
{
    var childObj;
    var fatherObj;
    var grandFatherObj;
    var parentObj;
    
    var className = '';
    var visibility = '';
    
    childObj = document.getElementById(childId);
    grandFatherObj = document.getElementById(grandFatherId);
    parentObj = document.getElementById(parentId);
    shadowObj = document.getElementById(parentId + 'ombra');
	
    switch(action)
    {
        default:
            color = '';
            visibility = '';
            break;
        case 'keep':
            visibility = 'block';
            if (parentId != defaultChoice)
                className = 'testomenu5';
            else
                className = 'testomenu3';
                
            shadowObj.className = 'menuombra';
            break;
        case 'remove':
            visibility = 'none';
			if (parentId != defaultChoice)
			{
				className = 'testomenu1';
				shadowObj.className = className;
			}
			else
			{
				className = 'testomenu4';
			}
            break;
    }

    childObj.style.display = visibility;
    parentObj.className = className;
	
	clearCP(childId);
}

function clearCP(divNotToClearId)
{
	var cpList;
	var cp;
	
	cpList = document.getElementsByTagName('div');
	for(i = 0; i < cpList.length; i++)
	{
		if (cpList[i].id != divNotToClearId)
		{
			if (cpList[i].id.substring(0, 2) == 'cp')
			{
				document.getElementById(cpList[i].id).style.display = 'none';
			}
		}
	}
}
