//----------------------------------< cmbMenu_onchange >-----------------------
function cmbMenu_onchange(strElementName)
{
	if (document.getElementById(strElementName) == null)
		return;
	var strSelectedOption = GetSelectedOptions(strElementName);
	var numOptionText = strSelectedOption.split("#")[0];
	var numOptionTextLength = strSelectedOption.split("#")[0].length;
	var numOptionValue = parseInt(strSelectedOption.split("#")[1],10);
	var numLevelCurrent = parseInt(strElementName.split("_")[1],10);
	var numLevelNext = (numLevelCurrent + 1).toString();

	var arrMenu = document.getElementById("txtMenu").value.split("|");
	var oDiv = document.getElementById("divMenu");

	var numLevel;
	oColl = oDiv.childNodes;
	for( i = 0; i < oColl.length; i++ )
	{
		try
		{
			// Remove combo boxes with level greater than current
			if ( oColl[i].id.substring(0,8) == "cmbMenu_" )
			{
				numLevel = parseInt(oColl[i].id.split("_")[1],10);
//window.alert("DEBUG - numLevel: " + numLevel + " - numLevelCurrent: " + numLevelCurrent);
				if ( numLevel > numLevelCurrent )
				{
					oDiv.removeChild(oDiv.childNodes[i]);
					oColl = oDiv.childNodes;
					i = 0;
					continue;
				}
			}
		}
		catch(excp)
		{
		}
	}

	// Clear menu action
	document.getElementById("txtMenuAction").value = "";

	// If selected line is different from 'Select item...'
	if ( numOptionValue != -1 )
	{
		// If last character of option is equal to '>',
		//   there is a sub menu to show, it's not a link
		// Otherwise
		//   Add button with a direct link
		if ( numOptionText.charAt(numOptionTextLength -1) == ">" )
		{
			// Create SELECT object
			var oSelect = document.createElement("SELECT");

			// Create OPTION object with text equal to 'Select item...'
			oOption = document.createElement("OPTION");
			oOption.text = "Seleziona ...";
			oOption.value = "-1";
			oSelect.options.add(oOption);

			// Add all other items with the specified master value
			var i, arrMenuItem, oOption;
			for(i = 0; i < arrMenu.length; i++)
			{
				arrMenuItem = arrMenu[i].split("#");
				if ( arrMenuItem[2] == numOptionValue )
				{
					oOption = document.createElement("OPTION");
					
					// If no action is associated to this menu item,
					//   It has a sub menu under itself
					// Else
					//   It is a direct link
					if ( arrMenuItem[5] == "" )
						oOption.text = arrMenuItem[4] + " >";
					else
						oOption.text = arrMenuItem[4];
					oOption.value = arrMenuItem[0];	// unique identifier
					oSelect.options.add(oOption);
				}
			}
			oSelect.name = "cmbMenu_" + numLevelNext.toString();
			oSelect.id = "cmbMenu_" + numLevelNext.toString();
			oSelect.onchange = function (){ cmbMenu_onchange("cmbMenu_" + numLevelNext.toString())};
			oSelect.style.fontFamily = "Verdana";
			oSelect.style.fontSize = "12px";
//			oSelect.style.color = "darkred";
			oDiv.appendChild(oSelect);
		}
		else
		{
			var i, arrMenuItem;
			for(i = 0; i < arrMenu.length; i++)
			{
				arrMenuItem = arrMenu[i].split("#");
				if ( arrMenuItem[0] == numOptionValue )
				{
					document.getElementById("txtMenuAction").value = arrMenuItem[5];
					break;
				}
			}
		}
	}
}
//--------------------------------------< MenuLoad >---------------------------
function MenuLoad()
{
	var i;

	var arrMenu = document.getElementById("txtMenu").value.split("|");
	var oDiv = document.getElementById("divMenu");

	// Rimuove i combo box dei menu esistenti
	var oColl = oDiv.childNodes;
	for( i = 0; i < oColl.length; i++ )
	{
		try
		{
			if ( oColl[i].id.substring(0,8) == "cmbMenu_" )
			{
				oDiv.removeChild(oDiv.childNodes[i]);
				oColl = oDiv.childNodes;
				i = 0;
				continue;
			}
		}
		catch(excp)
		{
		}
	}

	oDiv.innerHTML = "Elezione&nbsp" + oDiv.innerHTML;

	var oSelect = document.createElement("SELECT");

	oOption = document.createElement("OPTION");
	oOption.text = "Seleziona ...";
	oOption.value = "-1";
	oSelect.options.add(oOption);

	var arrMenuItem, oOption;
	for(i = 0; i < arrMenu.length; i++)
	{
		arrMenuItem = arrMenu[i].split("#");
		if ( arrMenuItem[2] == "0" )
		{
			oOption = document.createElement("OPTION");
			if ( arrMenuItem[5] == "" )
				oOption.text = arrMenuItem[4] + " >";
			else
				oOption.text = arrMenuItem[4];
			oOption.value = arrMenuItem[0];
			oSelect.options.add(oOption);
		}
	}
	oSelect.name = "cmbMenu_0";
	oSelect.id = "cmbMenu_0";
	oSelect.onchange = function () {cmbMenu_onchange("cmbMenu_0")};
	oSelect.style.fontFamily = "Verdana";
	oSelect.style.fontSize = "12px";
//	oSelect.style.color = "darkred";
	oDiv.appendChild(oSelect);
}
//--------------------------------------< MenuLoad >---------------------------
function MenuSet(a_sParam)
{
	document.getElementById("txtMenu").value = a_sParam;
}
