

function ImageListAuthoring_TypeDropDownChange(DropDownList, linkEnhanced)
{
	//var altLabel = document.getElementById( DropDownList.id.toString().replace("leftCelltypes", "middleCellaltLabel" ) );
	//var altTextbox = document.getElementById( DropDownList.id.toString().replace("leftCelltypes", "middleCellalt" ) );
	var pathTextbox = document.getElementById( DropDownList.id.toString().replace("leftCelltypes", "middleCellpath" ) );
	var textTextbox = document.getElementById( DropDownList.id.toString().replace("leftCelltypes", "middleCelltext" ) );
	var colourDropDown = document.getElementById( DropDownList.id.toString().replace("leftCelltypes", "rightCellcolours" ) );
	var browseButton = document.getElementById( DropDownList.id.toString().replace("leftCelltypes", "rightCellbrowse" ) );
	var linkTable = document.getElementById( DropDownList.id.toString().replace("leftCelltypes", "middleCelllinkTable" ) );
	var linkLabelsTable = document.getElementById( DropDownList.id.toString().replace("leftCelltypes", "leftCelllinkLabelTable" ) );

	if(ImageListAuthoring_CheckNoneSelection(DropDownList))
	{
		switch (DropDownList.options[DropDownList.selectedIndex].text)
		{
			case 'None':
				//altLabel.style.display = "none";
				//altTextbox.style.display = "none";
				pathTextbox.style.display = "none";
				textTextbox.style.display = "none";
				browseButton.style.display = "none";
				colourDropDown.style.display = "none";
				linkTable.style.display = "none";
				break;
			case 'Image':
				pathTextbox.style.display = "";
				textTextbox.style.display = "none";
				browseButton.style.display = "";
				colourDropDown.style.display = "none";
				linkTable.style.display = "none";
				pathTextbox.value = "";
				//altLabel.style.display = "";
				//altTextbox.style.display = "";
				//altTextbox.value = "";
				break;
			case 'Text':
				//altLabel.style.display = "none";
				//altTextbox.style.display = "none";			
				pathTextbox.style.display = "none";
				textTextbox.style.display = "";
				browseButton.style.display = "none";
				colourDropDown.style.display = "";
				if (linkEnhanced) 
				{
					linkTable.style.display = "";
					linkLabelsTable.style.display = "";		
				}
				textTextbox.value = "";
				colourDropDown.selectedIndex = 0;
				break;
		}
	}
	else
	{
		alert("Valid combinations are:\nnone\ntop filled\ntop and middle filled\ntop, middle and bottom filled.");
		if (pathTextbox.style.display == "none")
		{
			if (textTextbox.style.display == "none")
			{
				for (var a=0; a<DropDownList.options.length; a++)
				{
					if (DropDownList.options[a].text == "None")
					{
						useIndex = a;
					}
				}

				DropDownList.selectedIndex = useIndex; //none
			}
			else
			{
				for (var a=0; a<DropDownList.options.length; a++)
				{
					if (DropDownList.options[a].text == "Text")
					{
						useIndex = a;
					}
				}

				DropDownList.selectedIndex = useIndex; //text
			}			
		}
		else
		{
			for (var a=0; a<DropDownList.options.length; a++)
			{
				if (DropDownList.options[a].text == "Image")
				{
					useIndex = a;
				}
			}

			DropDownList.selectedIndex = useIndex; //image
		}
	}
}

function ImageListAuthoring_CheckNoneSelection(DropDownList)
// function returns true if the selected option can be selected, otherwise false
{
	var dropdownlistIndex = DropDownList.id.toString().charAt(DropDownList.id.toString().length - 14);

	var firstDropDown = document.getElementById( DropDownList.id.toString().replace(dropdownlistIndex + "leftCelltypes", "0leftCelltypes" ) );
	var secondDropDown = document.getElementById( DropDownList.id.toString().replace(dropdownlistIndex + "leftCelltypes", "1leftCelltypes" ) );
	var thirdDropDown = document.getElementById( DropDownList.id.toString().replace(dropdownlistIndex + "leftCelltypes", "2leftCelltypes" ) );

	if (DropDownList.selectedIndex == 0 && dropdownlistIndex < 2)
	{
		// Check if selecting None is valid
		if (dropdownlistIndex == 0)
		{
			return (secondDropDown.selectedIndex == 0 && thirdDropDown.selectedIndex == 0);
		}
		else // (dropdownlistIndex == 1)
		{
			return (thirdDropDown.selectedIndex == 0);
		}
	}

	else if ((DropDownList.selectedIndex == 1 || DropDownList.selectedIndex == 2) && dropdownlistIndex > 0)
	{
		// Check if None is selected in lists above the current
		if (dropdownlistIndex == 1)
		{
			return (firstDropDown.selectedIndex != 0);
		}
		else  // (dropdownlistIndex == 2)
		{
			return (firstDropDown.selectedIndex != 0 && secondDropDown.selectedIndex != 0);
		}
	}

	return true;
}

