function AddMainCategory(name)
{
	MainCategory.push(new Entry(MainCategory.length, name));
	SubCategory.push(new Array());
	SubCategory[SubCategory.length-1].push(new Entry(SubCategory.length-1, 'View Related Pages...', ''))
}

function AddSubCategory(name, url)
{
	SubCategory[SubCategory.length-1].push(new Entry(SubCategory.length-1, name, url));
}

function Entry(ID, Name, URL)
{
	this.ID = ID;
	if (String(Name).length > 150)
	{
		var endPosition = String(Name).indexOf(', ', String(Name).indexOf(', ') + 1);
		if (endPosition > 0)
		{
			Name = String(Name).substring(0, endPosition);
		}
	}
	this.Name = Name;
	this.URL = String(URL).toLowerCase();
}

function InitializeMainCategory(currentForm) {
	for (var i=0; i < MainCategory.length; i++) {
		eval(currentForm + ".MainCategory.options[i] = new Option('" + MainCategory[i].Name + "')");
		eval(currentForm + ".MainCategory.options[i].value = " + MainCategory[i].ID);
	}
}

function PopulatePane(currentPane, paneToPopulate) {
	var selectedArray, i;
	var selected = currentPane.options[currentPane.selectedIndex].value
	if (selected == 0) {
		if (currentPane.selectedIndex != 0)
			selected = currentPane.options[--currentPane.selectedIndex].value;
		else {
			currentPane.selectedIndex = -1;
			return false;
		}
	}

	selectedArray = eval(paneToPopulate + "[" + selected + "]");
	paneToPopulate = eval("currentPane.form." + paneToPopulate);

	// if we need to clear panes, we'll start clearing out options with the last pane and work back until we run out
	for (i = currentPane.form.elements.length - 1; i > 0; i--) {
		paneToClear = paneToPopulate.form.elements[i]
		if (paneToClear == paneToPopulate) {
			break;
		}
		// make sure we're only doing the clearing operation on panes we care about
		if (paneToClear.name == "SubCategory" || paneToClear.name == "MainCategory") {
			for (i = paneToClear.options.length; i != 0; i--) {
				paneToClear.options[i - 1] = null;
			}
		}
	}
	while (selectedArray.length < paneToPopulate.options.length) {
		paneToPopulate.options[(paneToPopulate.options.length - 1)] = null;
	}
	for (i = 0; i < selectedArray.length; i++) {
		if ( selectedArray[i] == null || selectedArray[i] == "" ) {
			alert("There is no " + paneToPopulate.Name + " associated with this " + currentPane.Name);
		} else {
			eval("paneToPopulate.options[i] = new Option('" + selectedArray[i].Name + "')");
			eval("paneToPopulate.options[i].value = '" + selectedArray[i].ID + "'");
		}
	}
}

function changePage(form) {
	if (form.SubCategory.selectedIndex != -1) {
		SubCategoryValue = form.SubCategory.options[form.SubCategory.selectedIndex].value;
		whichArray = eval("SubCategory[" + SubCategoryValue + "]");
		document.location.href = whichArray[form.SubCategory.selectedIndex].URL;
	}
}

var MainCategory = new Array();
var SubCategory = new Array();
AddMainCategory("Select ailment");

